diff --git a/.vscode/settings.json b/.vscode/settings.json index 0f409aa..ac51e4e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,8 @@ "editor.defaultFormatter": "esbenp.prettier-vscode", "[go]": { "editor.defaultFormatter": "golang.go" + }, + "[sql]": { + "editor.defaultFormatter": "inferrinizzard.prettier-sql-vscode" } } diff --git a/internal/db/sqlite/queries.sql b/internal/db/sqlite/queries.sql index 15cd74e..812ffbb 100644 --- a/internal/db/sqlite/queries.sql +++ b/internal/db/sqlite/queries.sql @@ -1,38 +1,158 @@ -- name: CreateResource :exec -INSERT INTO resource (uuid, title, content_md, image_url, resource_type, created_at, updated_at,deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?); +INSERT INTO + resource ( + uuid, + title, + content_md, + image_url, + resource_type, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?, ?, ?); -- name: CreateEvent :exec -INSERT INTO event (uuid, location, start_at, end_at, is_all_day, host, visibility) VALUES (?, ?, ?, ?, ?, ?, ?); +INSERT INTO + event ( + uuid, + location, + start_at, + end_at, + is_all_day, + host, + visibility + ) +VALUES + (?, ?, ?, ?, ?, ?, ?); -- name: CreatePerson :exec -INSERT INTO person (uuid, name, preferred_pronoun) VALUES (?, ?, ?); +INSERT INTO + person (uuid, name, preferred_pronoun) +VALUES + (?, ?, ?); -- name: CreateResourceGroupMapping :exec -INSERT INTO resource_id_group_id_mapping (resource_uuid, group_uuid, type, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?); +INSERT INTO + resource_id_group_id_mapping ( + resource_uuid, + group_uuid, + type, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?); -- name: CreateGroupResourceMapping :exec -INSERT INTO group_id_resource_list_mapping (group_uuid, resource_uuid, index_in_list, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?); +INSERT INTO + group_id_resource_list_mapping ( + group_uuid, + resource_uuid, + index_in_list, + created_at, + updated_at, + deleted_at + ) +VALUES + (?, ?, ?, ?, ?, ?); -- name: CreateAnnouncement :exec -INSERT INTO announcement (uuid, event_groups_group_uuid, approved_by_list_uuid, visibility, announce_at, discord_channel_id, discord_message_id) VALUES (?, ?, ?, ?, ?, ?, ?); +INSERT INTO + announcement ( + uuid, + event_groups_group_uuid, + approved_by_list_uuid, + visibility, + announce_at, + discord_channel_id, + discord_message_id + ) +VALUES + (?, ?, ?, ?, ?, ?, ?); -- name: DeleteResource :exec -DELETE FROM resource WHERE id = ?; +DELETE FROM resource +WHERE + id = ?; -- name: GetResource :exec -SELECT uuid, title, content_md, image_url, resource_type, created_at, updated_at,deleted_at from resource where uuid = ?; +SELECT + uuid, + title, + content_md, + image_url, + resource_type, + created_at, + updated_at, + deleted_at +from + resource +where + uuid = ?; -- name: GetEvent :exec -SELECT uuid, location, start_at, end_at, is_all_day, host, visibility from event where uuid = ?; +SELECT + uuid, + location, + start_at, + end_at, + is_all_day, + host, + visibility +from + event +where + uuid = ?; -- name: GetPerson :exec -SELECT uuid, name, preferred_pronoun from person where uuid = ?; +SELECT + uuid, + name, + preferred_pronoun +from + person +where + uuid = ?; -- name: GetResourceGroupMapping :exec -SELECT resource_uuid, group_uuid, type, created_at, updated_at, deleted_at from resource_id_group_id_mapping where resource_uuid = ?; +SELECT + resource_uuid, + group_uuid, + type, + created_at, + updated_at, + deleted_at +from + resource_id_group_id_mapping +where + resource_uuid = ?; -- name: GetGroupResourceMapping :exec -SELECT group_uuid, resource_uuid, index_in_list, created_at, updated_at, deleted_at from group_id_resource_list_mapping where group_uuid = ?; +SELECT + group_uuid, + resource_uuid, + index_in_list, + created_at, + updated_at, + deleted_at +from + group_id_resource_list_mapping +where + group_uuid = ?; -- name: GetAnnouncement :exec -SELECT uuid, event_groups_group_uuid, approved_by_list_uuid, visibility, announce_at, discord_channel_id, discord_message_id from announcements where uuid = ?; \ No newline at end of file +SELECT + uuid, + event_groups_group_uuid, + approved_by_list_uuid, + visibility, + announce_at, + discord_channel_id, + discord_message_id +from + announcements +where + uuid = ?; \ No newline at end of file diff --git a/internal/db/sqlite/schema.sql b/internal/db/sqlite/schema.sql index cf99925..2108afc 100644 --- a/internal/db/sqlite/schema.sql +++ b/internal/db/sqlite/schema.sql @@ -1,64 +1,65 @@ -- Language: sqlite - -- Create the 'resource_mapping' table. -CREATE TABLE IF NOT EXISTS resource_id_group_id_mapping ( - resource_uuid TEXT REFERENCES resource(uuid), - group_uuid TEXT NOT NULL REFERENCES group_resource_list_mapping(uuid), - type TEXT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, -); +CREATE TABLE + IF NOT EXISTS resource_id_group_id_mapping ( + resource_uuid TEXT REFERENCES resource (uuid), + group_uuid TEXT NOT NULL REFERENCES group_resource_list_mapping (uuid), + type TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + ); -CREATE TABLE IF NOT EXISTS group_id_resource_list_mapping ( - group_uuid TEXT, - resource_uuid TEXT NOT NULL REFERENCES resource(uuid), - index_in_list INTEGER NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, -); +CREATE TABLE + IF NOT EXISTS group_id_resource_list_mapping ( + group_uuid TEXT, + resource_uuid TEXT NOT NULL REFERENCES resource (uuid), + index_in_list INTEGER NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + ); -- Create the 'resource' table. -CREATE TABLE IF NOT EXISTS resource ( - uuid TEXT PRIMARY KEY, - title TEXT NOT NULL, - content_md TEXT NOT NULL, - image_url TEXT, - resource_type TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, -); +CREATE TABLE + IF NOT EXISTS resource ( + uuid TEXT PRIMARY KEY, + title TEXT NOT NULL, + content_md TEXT NOT NULL, + image_url TEXT, + resource_type TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + ); -- Create the 'events' table which is a table of event resources. -CREATE TABLE IF NOT EXISTS event ( - uuid TEXT PRIMARY KEY REFERENCES resource(uuid), - location TEXT NOT NULL, - start_at NUMBER NOT NULL, -- Start time in UTC milliseconds. - end_at NUMBER NOT NULL, - is_all_day BOOLEAN NOT NULL, - host TEXT NOT NULL, -- Accepts team ID or plain text. - visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. -) - --- Create the 'person' table which is a table of person resources. -CREATE TABLE IF NOT EXISTS person ( - uuid TEXT REFERENCES resource(uuid), - name TEXT, - preferred_pronoun TEXT -) - --- Create the 'announcement' table which is a table of announcement resources. -CREATE TABLE IF NOT EXISTS announcement ( - uuid TEXT PRIMARY KEY REFERENCES resource(uuid), - event_groups_group_uuid TEXT REFERENCES resource_group_mapping(resource_uuid), - approved_by_list_uuid TEXT REFERENCES group_id_resource_list_mapping(uuid), - visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. - announce_at INTEGER NOT NULL, -- UTC milliseconds. - discord_channel_id TEXT, -- Discord channel ID. - discord_message_id TEXT, -- Discord message ID. If present, the announcement has been posted. - UNIQUE (id) -) - - +CREATE TABLE + IF NOT EXISTS event ( + uuid TEXT PRIMARY KEY REFERENCES resource (uuid), + location TEXT NOT NULL, + start_at NUMBER NOT NULL, -- Start time in UTC milliseconds. + end_at NUMBER NOT NULL, + is_all_day BOOLEAN NOT NULL, + host TEXT NOT NULL, -- Accepts team ID or plain text. + visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. + ) + -- Create the 'person' table which is a table of person resources. +CREATE TABLE + IF NOT EXISTS person ( + uuid TEXT REFERENCES resource (uuid), + name TEXT, + preferred_pronoun TEXT + ) + -- Create the 'announcement' table which is a table of announcement resources. +CREATE TABLE + IF NOT EXISTS announcement ( + uuid TEXT PRIMARY KEY REFERENCES resource (uuid), + event_groups_group_uuid TEXT REFERENCES resource_group_mapping (resource_uuid), + approved_by_list_uuid TEXT REFERENCES group_id_resource_list_mapping (uuid), + visibility TEXT NOT NULL, -- Accepts 'public' or 'private'. + announce_at INTEGER NOT NULL, -- UTC milliseconds. + discord_channel_id TEXT, -- Discord channel ID. + discord_message_id TEXT, -- Discord message ID. If present, the announcement has been posted. + UNIQUE (id) + ) \ No newline at end of file