(SQL/MIGRATION): First DB migration. Created the users table.

Also, needed to update to using plural table names.
This commit is contained in:
Hayden Hargreaves 2025-06-14 00:02:04 -07:00
parent 86913faed7
commit 3c4710bb48
3 changed files with 56 additions and 38 deletions

View File

@ -222,7 +222,7 @@ this application. It will describe the required tables, fields, and other expect
##### Table ID Choice ##### Table ID Choice
Typically, I like to use UUID's for ID's. However, after some research I have concluded that for this Typically, I like to use UUID's for ID's. However, after some research I have concluded that for this
application, the use of the `SERIAL` or `BIGSERIAL` type will work sufficiently. Security is not a huge application, the use of the `SERIAL` or `SERIAL` type will work sufficiently. Security is not a huge
concern with this application since no major data will be stored, however, measures will still be in concern with this application since no major data will be stored, however, measures will still be in
place (of course). place (of course).
@ -239,8 +239,8 @@ also have a list of attributes which are to be implemented at the database level
data fields will also have a small example object. A more in-depth data structure can be data fields will also have a small example object. A more in-depth data structure can be
found in **OTHER** section. found in **OTHER** section.
- [ ] Recipe: Represents a single recipe. - [ ] Recipes: Represents a single recipe.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] Title (Unique, Required) string(128) - [ ] Title (Unique, Required) string(128)
- [ ] Description (Required) text - [ ] Description (Required) text
- [ ] Instructions (Required) string(1024)[] - [ ] Instructions (Required) string(1024)[]
@ -249,78 +249,78 @@ found in **OTHER** section.
- [ ] Duration (Required) JSONB({ "total": int, "prep": int, "cook": int }) - [ ] Duration (Required) JSONB({ "total": int, "prep": int, "cook": int })
- [ ] Category (Required) E_Meal (defined in the [enums](#enums-and-types) section) - [ ] Category (Required) E_Meal (defined in the [enums](#enums-and-types) section)
- [ ] Ingredients (Required) JSONB({ "item_a": [{ "name": string, "quantity": string }], "item_b": ... }) - [ ] Ingredients (Required) JSONB({ "item_a": [{ "name": string, "quantity": string }], "item_b": ... })
- [ ] UserId (FK: User.Id) BigSerial - [ ] UserId (FK: User.Id) Serial
- [ ] Modified () date/time stamp - [ ] Modified () date/time stamp
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] User: Represents a single user. - [ ] Users: Represents a single user.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] GoogleId (Unique, Required) text - [ ] GoogleId (Unique, Required) text
- [ ] Name (Required) string(64) - [ ] Name (Required) string(64)
- [ ] Email (Unique, Required) string(128) - [ ] Email (Unique, Required) string(128)
- [ ] ImageURL () text - [ ] ImageURL () text
- [ ] GoogleToken () text - [ ] GoogleRefreshToken () text
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Session: Represents a single user-session. - [ ] Sessions: Represents a single user-session.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] Token (Required) text - [ ] Token (Required) text
- [ ] Expiration (Required) date/time stamp - [ ] Expiration (Required) date/time stamp
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Engagement: Represents a single engagement from a single user. - [ ] Engagements: Represents a single engagement from a single user.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] Message () text (Used to store any relevant notes, if needed) - [ ] Message () text (Used to store any relevant notes, if needed)
- [ ] Entity (BigSerial) BigSerial (Used to relate an entity, if needed) - [ ] Entity (Serial) Serial (Used to relate an entity, if needed)
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Like: **Many-to-many** table to represent a list of recipes liked by a user. - [ ] Likes: **Many-to-many** table to represent a list of recipes liked by a user.
- [ ] ID (PK) *Composite key*** - [ ] ID (PK) *Composite key***
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial - [ ] RecipeId (FK: Recipe.Id, Required) Serial
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Tag: Represents a single tag that can be had by many recipes. - [ ] Tags: Represents a single tag that can be had by many recipes.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] Name (Unique, Required) string(32) - [ ] Name (Unique, Required) string(32)
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] RecipeTag: **Many-to-many** table to represent a list of tags on a recipe. - [ ] RecipeTags: **Many-to-many** table to represent a list of tags on a recipe.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial - [ ] RecipeId (FK: Recipe.Id, Required) Serial
- [ ] TagId (FK: Tag.Id, Required) BigSerial - [ ] TagId (FK: Tag.Id, Required) Serial
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] List: Represents a single users shopping list. - [ ] Lists: Represents a single users shopping list.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] Content (Required) JSONB([ { "name": string, "quantity": string }, ... ]) - [ ] Content (Required) JSONB([ { "name": string, "quantity": string }, ... ])
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Image: Represents a single image used by a single recipe. - [ ] Images: Represents a single image used by a single recipe.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial - [ ] RecipeId (FK: Recipe.Id, Required) Serial
- [ ] Alt (Required) string(128) (alt text for accessibility, same as recipe title) - [ ] Alt (Required) string(128) (alt text for accessibility, same as recipe title)
- [ ] Url (Required) text - [ ] Url (Required) text
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Review: Represents a single review on a recipe from a single author. - [ ] Reviews: Represents a single review on a recipe from a single author.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] Comment (Required) text - [ ] Comment (Required) text
- [ ] Rating () int(0..5) (Optional b/c nested replies don't need a rating) - [ ] Rating () int(0..5) (Optional b/c nested replies don't need a rating)
- [ ] ReviewId (FK: Review.Id) BigSerial (This is used for nested replies) - [ ] ReviewId (FK: Review.Id) Serial (This is used for nested replies)
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial - [ ] RecipeId (FK: Recipe.Id, Required) Serial
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp
- [ ] Notification: Represents a single user notification. - [ ] Notifications: Represents a single user notification.
- [ ] ID (PK) BigSerial - [ ] ID (PK) Serial
- [ ] UserId (FK: User.Id, Required) BigSerial - [ ] UserId (FK: User.Id, Required) Serial
- [ ] Type (Required) E_Notification - [ ] Type (Required) E_Notification
- [ ] Message (Required) text - [ ] Message (Required) text
- [ ] Entity (BigSerial) BigSerial (Used to relate an entity, if needed) - [ ] Entity (Serial) Serial (Used to relate an entity, if needed)
- [ ] Read (Required, Default: F) boolean - [ ] Read (Required, Default: F) boolean
- [ ] Created (Required) date/time stamp - [ ] Created (Required) date/time stamp

View File

@ -0,0 +1,18 @@
-- Author: Hayden Hargreaves (hhargreaves2006@gmail.com)
-- Desc: Create the users table in the database.
-- Date: 06/13/2025
BEGIN;
-- Create the users table
CREATE TABLE IF NOT EXISTS Users (
Id SERIAL PRIMARY KEY NOT NULL,
GoogleId TEXT UNIQUE NOT NULL,
Name VARCHAR(64) NOT NULL,
Email VARCHAR(128) UNIQUE NOT NULL,
ImageUrl TEXT,
GoogleRefreshToken TEXT,
Created TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
COMMIT;