CREATE TABLE AppConfig (
    id VARCHAR(191) NOT NULL, `key` VARCHAR(100) NOT NULL, `value` TEXT NOT NULL,
    description VARCHAR(500), environment VARCHAR(32) NOT NULL DEFAULT 'production',
    updatedBy VARCHAR(100), createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    updatedAt DATETIME(3) NOT NULL,
    UNIQUE INDEX AppConfig_key_key(`key`), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE FeatureFlag (
    id VARCHAR(191) NOT NULL, `name` VARCHAR(100) NOT NULL, enabled BOOLEAN NOT NULL DEFAULT false,
    description VARCHAR(500), rolloutPct INTEGER NOT NULL DEFAULT 100,
    updatedBy VARCHAR(100), createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    updatedAt DATETIME(3) NOT NULL,
    UNIQUE INDEX FeatureFlag_name_key(`name`), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE ConfigChangeLog (
    id VARCHAR(191) NOT NULL, entityType VARCHAR(32) NOT NULL, entityId VARCHAR(100) NOT NULL,
    field VARCHAR(100) NOT NULL, oldValue TEXT, newValue TEXT,
    changedBy VARCHAR(100), createdAt DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    INDEX ConfigChangeLog_entityType_entityId_idx(entityType, entityId),
    INDEX ConfigChangeLog_createdAt_idx(createdAt), PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
