Skip to content

Commit

Permalink
feat: add todo categories to migrations (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzoh authored Jan 17, 2025
1 parent be8bf6f commit ba8b604
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
22 changes: 22 additions & 0 deletions migrations/deploy/categories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Deploy toudou:categories to pg

BEGIN;

-- data definition
create table api.categories (
id bigint primary key generated always as identity,
title varchar (50) not null,
color varchar (7) not null check ( color ~* '^#[a-f0-9]{6}$') -- check for hex formatted colors
);

create table api.categories_todos (
category_id bigint references api.categories(id) on delete restrict,
todo_id bigint references api.todos(id) on delete cascade,
primary key (category_id, todo_id)
);

-- permissions
grant all on api.categories to web_anon;
grant all on api.categories_todos to web_anon;

COMMIT;
2 changes: 1 addition & 1 deletion migrations/deploy/todos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BEGIN;

-- data definition
create table api.todos (
id bigint generated always as identity,
id bigint primary key generated always as identity,
title varchar (250) not null,
content text,
due_date date,
Expand Down
13 changes: 13 additions & 0 deletions migrations/revert/categories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Revert toudou:categories from pg

BEGIN;

-- permissions
revoke all on api.categories_todos from web_anon;
revoke all on api.categories from web_anon;

-- data definition
drop table api.categories_todos;
drop table api.categories;

COMMIT;
7 changes: 6 additions & 1 deletion migrations/revert/todos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

BEGIN;

-- XXX Add DDLs here.
-- permissions
revoke usage on schema api from web_anon;
revoke all on api.todos from web_anon;

-- data definition
drop table api.todos;

COMMIT;
1 change: 1 addition & 0 deletions migrations/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
%uri=https://github.com/jobtrek/toudou/

todos 2025-01-17T05:45:53Z fuzoh <[email protected]> # Add table to store todos
categories 2025-01-17T08:56:49Z fuzoh <[email protected]> # Add table to store todo categories
7 changes: 7 additions & 0 deletions migrations/verify/categories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify toudou:categories on pg

BEGIN;

-- XXX Add verifications here.

ROLLBACK;
2 changes: 1 addition & 1 deletion migrations/verify/todos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

BEGIN;

-- XXX Add verifications here.
-- TODO

ROLLBACK;

0 comments on commit ba8b604

Please sign in to comment.