From 7ce41cd0345c70f2ac6894fcdf28ad05ea8cd067 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 28 Feb 2025 09:46:26 +0100 Subject: [PATCH] chore: combine migrations into one --- migrations/2025-02-23-095541_auth/down.sql | 2 - migrations/2025-02-23-095541_auth/up.sql | 13 ---- migrations/2025-02-23-095541_initial/down.sql | 8 +++ migrations/2025-02-23-095541_initial/up.sql | 69 +++++++++++++++++++ migrations/2025-02-23-165014_devices/down.sql | 1 - migrations/2025-02-23-165014_devices/up.sql | 13 ---- .../2025-02-24-133517_subscriptions/down.sql | 1 - .../2025-02-24-133517_subscriptions/up.sql | 9 --- .../down.sql | 6 -- .../up.sql | 6 -- 10 files changed, 77 insertions(+), 51 deletions(-) delete mode 100644 migrations/2025-02-23-095541_auth/down.sql delete mode 100644 migrations/2025-02-23-095541_auth/up.sql create mode 100644 migrations/2025-02-23-095541_initial/down.sql create mode 100644 migrations/2025-02-23-095541_initial/up.sql delete mode 100644 migrations/2025-02-23-165014_devices/down.sql delete mode 100644 migrations/2025-02-23-165014_devices/up.sql delete mode 100644 migrations/2025-02-24-133517_subscriptions/down.sql delete mode 100644 migrations/2025-02-24-133517_subscriptions/up.sql delete mode 100644 migrations/2025-02-24-201146_subscription_timestamps/down.sql delete mode 100644 migrations/2025-02-24-201146_subscription_timestamps/up.sql diff --git a/migrations/2025-02-23-095541_auth/down.sql b/migrations/2025-02-23-095541_auth/down.sql deleted file mode 100644 index 6341b5c..0000000 --- a/migrations/2025-02-23-095541_auth/down.sql +++ /dev/null @@ -1,2 +0,0 @@ -drop table sessions; -drop table users; diff --git a/migrations/2025-02-23-095541_auth/up.sql b/migrations/2025-02-23-095541_auth/up.sql deleted file mode 100644 index 40e99a7..0000000 --- a/migrations/2025-02-23-095541_auth/up.sql +++ /dev/null @@ -1,13 +0,0 @@ -create table users ( - id integer primary key not null, - username text unique not null, - password_hash text not null -); - -create table sessions ( - id bigint primary key not null, - user_id bigint not null - references users (id) - on delete cascade, - unique (id, user_id) -); diff --git a/migrations/2025-02-23-095541_initial/down.sql b/migrations/2025-02-23-095541_initial/down.sql new file mode 100644 index 0000000..8b768e4 --- /dev/null +++ b/migrations/2025-02-23-095541_initial/down.sql @@ -0,0 +1,8 @@ +drop table episode_actions; + +drop table subscriptions; + +drop table devices; + +drop table sessions; +drop table users; diff --git a/migrations/2025-02-23-095541_initial/up.sql b/migrations/2025-02-23-095541_initial/up.sql new file mode 100644 index 0000000..c97a60b --- /dev/null +++ b/migrations/2025-02-23-095541_initial/up.sql @@ -0,0 +1,69 @@ +create table users ( + id integer primary key not null, + username text unique not null, + password_hash text not null +); + +create table sessions ( + id bigint primary key not null, + user_id bigint not null + references users (id) + on delete cascade, + unique (id, user_id) +); + +create table devices ( + id integer primary key not null, + + device_id text not null, + user_id bigint not null + references users (id) + on delete cascade, + + caption text not null, + type text not null, + + unique (user_id, device_id) +); + +create table subscriptions ( + id integer primary key not null, + device_id bigint not null + references devices (id) + on delete cascade, + url text not null, + + time_changed bigint not null default 0, + deleted boolean not null default false, + + unique (device_id, url) +); + +create table episode_actions ( + id integer primary key not null, + + subscription_id bigint not null + references subscriptions (id) + on delete cascade, + + -- Can be null, as the device is not always provided + device_id bigint + references devices (id) + on delete set null, + + episode text not null, + timestamp bigint, + action text not null, + started integer, + position integer, + total integer, + + -- Position should be set if the action type is "Play" and null otherwise + check ((action = "Play") = (position is not null)), + + -- Started and position can only be set if the action type is "Play" + check (action = "Play" or (started is null and position is null)), + + -- Started and position should be provided together + check ((started is null) = (total is null)) +); diff --git a/migrations/2025-02-23-165014_devices/down.sql b/migrations/2025-02-23-165014_devices/down.sql deleted file mode 100644 index 3960a97..0000000 --- a/migrations/2025-02-23-165014_devices/down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table devices; diff --git a/migrations/2025-02-23-165014_devices/up.sql b/migrations/2025-02-23-165014_devices/up.sql deleted file mode 100644 index 2e77c08..0000000 --- a/migrations/2025-02-23-165014_devices/up.sql +++ /dev/null @@ -1,13 +0,0 @@ -create table devices ( - id integer primary key not null, - - device_id text not null, - user_id bigint not null - references users (id) - on delete cascade, - - caption text not null, - type text not null, - - unique (user_id, device_id) -); diff --git a/migrations/2025-02-24-133517_subscriptions/down.sql b/migrations/2025-02-24-133517_subscriptions/down.sql deleted file mode 100644 index c0928a3..0000000 --- a/migrations/2025-02-24-133517_subscriptions/down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table subscriptions; diff --git a/migrations/2025-02-24-133517_subscriptions/up.sql b/migrations/2025-02-24-133517_subscriptions/up.sql deleted file mode 100644 index b70aa77..0000000 --- a/migrations/2025-02-24-133517_subscriptions/up.sql +++ /dev/null @@ -1,9 +0,0 @@ -create table subscriptions ( - id integer primary key not null, - device_id bigint not null - references devices (id) - on delete cascade, - url text not null, - - unique (device_id, url) -); diff --git a/migrations/2025-02-24-201146_subscription_timestamps/down.sql b/migrations/2025-02-24-201146_subscription_timestamps/down.sql deleted file mode 100644 index f953d58..0000000 --- a/migrations/2025-02-24-201146_subscription_timestamps/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- This file should undo anything in `up.sql` -alter table subscriptions - drop column time_changed; - -alter table subscriptions - drop column deleted; diff --git a/migrations/2025-02-24-201146_subscription_timestamps/up.sql b/migrations/2025-02-24-201146_subscription_timestamps/up.sql deleted file mode 100644 index e0d4f8c..0000000 --- a/migrations/2025-02-24-201146_subscription_timestamps/up.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Your SQL goes here -alter table subscriptions - add column time_changed bigint not null default 0; - -alter table subscriptions - add column deleted boolean not null default false;