mirror of
https://github.com/therootcompany/golib.git
synced 2026-11-04 06:55:00 +00:00
Example CLI todo app demonstrating sqlmigrate + pgmigrate for running migrations directly via pgx/v5 instead of shelling out to psql. Uses embed.FS for migration files, auto-migrates on startup, and includes full CRUD for todos and folders with sqlc-ready query files.
17 lines
536 B
SQL
17 lines
536 B
SQL
-- create-folders-and-folders-todos (up)
|
|
|
|
CREATE TABLE folders (
|
|
id CHAR(8) PRIMARY KEY,
|
|
name VARCHAR(100) NOT NULL,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE folders_todos (
|
|
folder_id CHAR(8) NOT NULL REFERENCES folders(id) ON DELETE CASCADE,
|
|
todo_id CHAR(8) NOT NULL REFERENCES todos(id) ON DELETE CASCADE,
|
|
PRIMARY KEY (folder_id, todo_id)
|
|
);
|
|
|
|
-- leave this as the last line
|
|
INSERT INTO _migrations (name, id) VALUES ('2026-04-05-003000_create-folders-and-folders-todos', 'c3d4e5f6');
|