entretien/migrations/each_user/0002_frequency_targets.sql

36 lines
942 B
SQL

-- foreign_keys can only up/down outside of transactions
-- so we first pre-commit the one started by sqlx...
COMMIT TRANSACTION;
-- turn off foreign keys...
PRAGMA foreign_keys=OFF;
-- start our own transaction...
BEGIN TRANSACTION;
create table if not exists __replace_frequencies (
id integer primary key autoincrement,
description text not null default '',
target_period number not null
);
insert into __replace_frequencies (id, description, target_period) values
(1, 'daily', 1),
(2, 'weekly', 7),
(3, 'fortnightly', 14),
(4, 'monthly', 30),
(5, 'seasonally', 91),
(6, 'semiannually', 182),
(7, 'yearly', 365);
drop table frequencies;
alter table __replace_frequencies rename to frequencies;
PRAGMA foreign_key_check;
-- commit our own transaction...
COMMIT TRANSACTION;
-- put our own pragmas back...
PRAGMA foreign_keys=ON;
-- and start a dummy transaction so sqlx's COMMIT doesn't explode
BEGIN TRANSACTION;