Drop qt_users dependency for configs and track app version
This commit is contained in:
@@ -14,6 +14,7 @@ CREATE TABLE local_configuration_versions (
|
||||
data TEXT NOT NULL,
|
||||
change_note TEXT NULL,
|
||||
created_by TEXT NULL,
|
||||
app_version TEXT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (configuration_uuid) REFERENCES local_configurations(uuid),
|
||||
UNIQUE(configuration_uuid, version_no)
|
||||
@@ -36,6 +37,7 @@ INSERT INTO local_configuration_versions (
|
||||
data,
|
||||
change_note,
|
||||
created_by,
|
||||
app_version,
|
||||
created_at
|
||||
)
|
||||
SELECT
|
||||
@@ -58,10 +60,12 @@ SELECT
|
||||
'synced_at', synced_at,
|
||||
'sync_status', sync_status,
|
||||
'original_user_id', original_user_id,
|
||||
'original_username', original_username
|
||||
'original_username', original_username,
|
||||
'app_version', NULL
|
||||
) AS data,
|
||||
'Initial snapshot backfill (v1)' AS change_note,
|
||||
NULL AS created_by,
|
||||
NULL AS app_version,
|
||||
COALESCE(created_at, CURRENT_TIMESTAMP) AS created_at
|
||||
FROM local_configurations;
|
||||
|
||||
|
||||
25
migrations/007_detach_configurations_from_qt_users.sql
Normal file
25
migrations/007_detach_configurations_from_qt_users.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Detach qt_configurations from qt_users (ownership is owner_username text)
|
||||
-- Safe for MySQL 8+/MariaDB 10.2+ via INFORMATION_SCHEMA checks.
|
||||
|
||||
SET @fk_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.TABLE_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'qt_configurations'
|
||||
AND CONSTRAINT_NAME = 'fk_qt_configurations_user'
|
||||
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
|
||||
);
|
||||
|
||||
SET @drop_fk_sql := IF(
|
||||
@fk_exists > 0,
|
||||
'ALTER TABLE qt_configurations DROP FOREIGN KEY fk_qt_configurations_user',
|
||||
'SELECT ''fk_qt_configurations_user not found, skip'' '
|
||||
);
|
||||
PREPARE stmt_drop_fk FROM @drop_fk_sql;
|
||||
EXECUTE stmt_drop_fk;
|
||||
DEALLOCATE PREPARE stmt_drop_fk;
|
||||
|
||||
-- user_id becomes optional legacy column (can stay NULL)
|
||||
ALTER TABLE qt_configurations
|
||||
MODIFY COLUMN user_id BIGINT UNSIGNED NULL;
|
||||
|
||||
4
migrations/008_add_app_version_to_configurations.sql
Normal file
4
migrations/008_add_app_version_to_configurations.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Track application version used for configuration writes (create/update via sync)
|
||||
ALTER TABLE qt_configurations
|
||||
ADD COLUMN app_version VARCHAR(64) NULL DEFAULT NULL AFTER owner_username;
|
||||
|
||||
Reference in New Issue
Block a user