fix(flyway): V4 RENAME COLUMN conditionnel + V6 CREATE TABLE IF NOT EXISTS

V4: system_logs colonnes niveau/stacktrace déjà renommées en prod
→ RENAME COLUMN enveloppé dans DO blocks IF EXISTS

V6: conversations/messages/conversation_participants existent déjà en prod
→ CREATE TABLE + CREATE INDEX → IF NOT EXISTS
This commit is contained in:
dahoud
2026-04-05 11:24:15 +00:00
parent 93fc69ec22
commit f22b3472a8
2 changed files with 24 additions and 18 deletions

View File

@@ -7,9 +7,15 @@
-- dans system_logs pour correspondre à l'entité JPA SystemLog
-- ============================================================================
-- 1. Renommer les colonnes avec des noms incorrects
ALTER TABLE system_logs RENAME COLUMN niveau TO level;
ALTER TABLE system_logs RENAME COLUMN stacktrace TO details;
-- 1. Renommer les colonnes avec des noms incorrects (si elles existent encore)
DO $$ BEGIN
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='system_logs' AND column_name='niveau') THEN
ALTER TABLE system_logs RENAME COLUMN niveau TO level;
END IF;
IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='system_logs' AND column_name='stacktrace') THEN
ALTER TABLE system_logs RENAME COLUMN stacktrace TO details;
END IF;
END $$;
-- 2. Modifier utilisateur_id: UUID → VARCHAR(255) et renommer user_id
-- D'abord supprimer la colonne UUID, puis ajouter VARCHAR

View File

@@ -5,7 +5,7 @@
-- ============================================================================
-- Table conversations
CREATE TABLE conversations (
CREATE TABLE IF NOT EXISTS conversations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
description VARCHAR(1000),
@@ -31,13 +31,13 @@ CREATE TABLE conversations (
);
-- Index pour conversations
CREATE INDEX idx_conversation_organisation ON conversations(organisation_id);
CREATE INDEX idx_conversation_type ON conversations(type);
CREATE INDEX idx_conversation_archived ON conversations(is_archived);
CREATE INDEX idx_conversation_created ON conversations(date_creation);
CREATE INDEX IF NOT EXISTS idx_conversation_organisation ON conversations(organisation_id);
CREATE INDEX IF NOT EXISTS idx_conversation_type ON conversations(type);
CREATE INDEX IF NOT EXISTS idx_conversation_archived ON conversations(is_archived);
CREATE INDEX IF NOT EXISTS idx_conversation_created ON conversations(date_creation);
-- Table de jointure conversation_participants (many-to-many)
CREATE TABLE conversation_participants (
CREATE TABLE IF NOT EXISTS conversation_participants (
conversation_id UUID NOT NULL,
membre_id UUID NOT NULL,
joined_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -51,11 +51,11 @@ CREATE TABLE conversation_participants (
);
-- Index pour conversation_participants
CREATE INDEX idx_conv_participants_membre ON conversation_participants(membre_id);
CREATE INDEX idx_conv_participants_conversation ON conversation_participants(conversation_id);
CREATE INDEX IF NOT EXISTS idx_conv_participants_membre ON conversation_participants(membre_id);
CREATE INDEX IF NOT EXISTS idx_conv_participants_conversation ON conversation_participants(conversation_id);
-- Table messages
CREATE TABLE messages (
CREATE TABLE IF NOT EXISTS messages (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
conversation_id UUID NOT NULL,
sender_id UUID NOT NULL,
@@ -92,12 +92,12 @@ CREATE TABLE messages (
);
-- Index pour messages
CREATE INDEX idx_message_conversation ON messages(conversation_id);
CREATE INDEX idx_message_sender ON messages(sender_id);
CREATE INDEX idx_message_organisation ON messages(organisation_id);
CREATE INDEX idx_message_status ON messages(status);
CREATE INDEX idx_message_created ON messages(date_creation);
CREATE INDEX idx_message_deleted ON messages(is_deleted);
CREATE INDEX IF NOT EXISTS idx_message_conversation ON messages(conversation_id);
CREATE INDEX IF NOT EXISTS idx_message_sender ON messages(sender_id);
CREATE INDEX IF NOT EXISTS idx_message_organisation ON messages(organisation_id);
CREATE INDEX IF NOT EXISTS idx_message_status ON messages(status);
CREATE INDEX IF NOT EXISTS idx_message_created ON messages(date_creation);
CREATE INDEX IF NOT EXISTS idx_message_deleted ON messages(is_deleted);
-- Commentaires
COMMENT ON TABLE conversations IS 'Conversations (fils de discussion) du système de messagerie';