chore: combine migrations into one
							parent
							
								
									2be126a7b3
								
							
						
					
					
						commit
						7ce41cd034
					
				| 
						 | 
				
			
			@ -1,2 +0,0 @@
 | 
			
		|||
drop table sessions;
 | 
			
		||||
drop table users;
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
drop table episode_actions;
 | 
			
		||||
 | 
			
		||||
drop table subscriptions;
 | 
			
		||||
 | 
			
		||||
drop table devices;
 | 
			
		||||
 | 
			
		||||
drop table sessions;
 | 
			
		||||
drop table users;
 | 
			
		||||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
drop table devices;
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			@ -1 +0,0 @@
 | 
			
		|||
drop table subscriptions;
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
		Loading…
	
		Reference in New Issue