diff --git a/internal/repository/migrations/sqlite3/06_change-config.down.sql b/internal/repository/migrations/sqlite3/06_change-config.down.sql index 74a8299..eccc0ce 100644 --- a/internal/repository/migrations/sqlite3/06_change-config.down.sql +++ b/internal/repository/migrations/sqlite3/06_change-config.down.sql @@ -1,4 +1,10 @@ -ALTER TABLE configuration ADD COLUMN value_new varchar(255); -INSERT INTO configuration (value_new) SELECT value FROM configuration; -ALTER TABLE configuration DROP COLUMN value; -ALTER TABLE configuration RENAME COLUMN value_new TO value; +CREATE TABLE IF NOT EXISTS configuration_new ( +username varchar(255), +confkey varchar(255), +value varchar(255), +PRIMARY KEY (username, confkey), +FOREIGN KEY (username) REFERENCES user (username) ON DELETE CASCADE ON UPDATE NO ACTION); + +INSERT INTO configuration_new SELECT * FROM configuration; +DROP TABLE configuration; +ALTER TABLE configuration_new RENAME TO configuration; diff --git a/internal/repository/migrations/sqlite3/06_change-config.up.sql b/internal/repository/migrations/sqlite3/06_change-config.up.sql index 0dae70c..408ce21 100644 --- a/internal/repository/migrations/sqlite3/06_change-config.up.sql +++ b/internal/repository/migrations/sqlite3/06_change-config.up.sql @@ -1,4 +1,10 @@ -ALTER TABLE configuration ADD COLUMN value_new TEXT; -INSERT INTO configuration (value_new) SELECT value FROM configuration; -ALTER TABLE configuration DROP COLUMN value; -ALTER TABLE configuration RENAME COLUMN value_new TO value; +CREATE TABLE IF NOT EXISTS configuration_new ( +username varchar(255), +confkey varchar(255), +value text, +PRIMARY KEY (username, confkey), +FOREIGN KEY (username) REFERENCES user (username) ON DELETE CASCADE ON UPDATE NO ACTION); + +INSERT INTO configuration_new SELECT * FROM configuration; +DROP TABLE configuration; +ALTER TABLE configuration_new RENAME TO configuration;