
ALTER TABLE _sft_db ADD COLUMN mig_name TEXT;

UPDATE _sft_db SET mig_name="0_init.sql" WHERE _sft_db.db_rev=0;
UPDATE _sft_db SET mig_name="1_rev1.sql" WHERE _sft_db.db_rev=1;
UPDATE _sft_db SET mig_name="2_rev2.sql" WHERE _sft_db.db_rev=2;
UPDATE _sft_db SET mig_name="3_rev3.sql" WHERE _sft_db.db_rev=3;
UPDATE _sft_db SET mig_name="4_rev4.sql" WHERE _sft_db.db_rev=4;
UPDATE _sft_db SET mig_name="5_clear_old_tables.sql" WHERE _sft_db.db_rev=5;

CREATE TABLE _temp_sft_db AS SELECT * FROM _sft_db;
DROP TABLE _sft_db;


CREATE TABLE IF NOT EXISTS _sft_db (
    db_rev INTEGER PRIMARY KEY,
    sft_ver TEXT,
    applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    mig_name TEXT NOT NULL
);

INSERT INTO _sft_db (db_rev, sft_ver, applied_at, mig_name)
    SELECT db_rev, sft_ver, applied_at, mig_name FROM _temp_sft_db;

DROP TABLE _temp_sft_db;


INSERT INTO _sft_db (db_rev, sft_ver, applied_at, mig_name)
    VALUES (6, "0.0.1-pre-alpha1", CURRENT_TIMESTAMP, "6_add_migration_name.sql");
