-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e2d9a8
commit e497675
Showing
13 changed files
with
4,172 additions
and
569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
backend/db/migrations/20240704123000_create_users_and_cards_tables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- +goose Up | ||
-- SQL in section 'Up' is executed when this migration is applied. | ||
|
||
CREATE TABLE users | ||
( | ||
id VARCHAR(255) PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE cardgroups | ||
( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE cards | ||
( | ||
id SERIAL PRIMARY KEY, | ||
front TEXT NOT NULL, | ||
back TEXT NOT NULL, | ||
review_date TIMESTAMP NOT NULL, | ||
interval_days INT NOT NULL DEFAULT 1, | ||
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
cardgroup_id INTEGER NOT NULL, | ||
CONSTRAINT fk_cardgroup | ||
FOREIGN KEY (cardgroup_id) | ||
REFERENCES cardgroups (id) | ||
ON DELETE CASCADE | ||
); | ||
|
||
CREATE TABLE cardgroups_users | ||
( | ||
cardgroup_id INTEGER NOT NULL, | ||
user_id VARCHAR(255) NOT NULL, | ||
PRIMARY KEY (cardgroup_id, user_id), | ||
FOREIGN KEY (cardgroup_id) REFERENCES cardgroups (id) ON DELETE CASCADE, | ||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE | ||
); | ||
|
||
CREATE TABLE roles | ||
( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(50) NOT NULL UNIQUE | ||
); | ||
|
||
CREATE TABLE users_roles | ||
( | ||
user_id VARCHAR(255) NOT NULL, | ||
role_id INTEGER NOT NULL, | ||
PRIMARY KEY (user_id, role_id), | ||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, | ||
FOREIGN KEY (role_id) REFERENCES roles (id) ON DELETE CASCADE | ||
); | ||
|
||
-- +goose Down | ||
-- SQL section 'Down' is executed when this migration is rolled back. | ||
|
||
DROP TABLE IF EXISTS users_roles; | ||
DROP TABLE IF EXISTS roles; | ||
DROP TABLE IF EXISTS cardgroups_users; | ||
DROP TABLE IF EXISTS cards; | ||
DROP TABLE IF EXISTS cardgroups; | ||
DROP TABLE IF EXISTS users; |
23 changes: 0 additions & 23 deletions
23
backend/db/migrations/20240704123000_create_users_and_todos_tables.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.