(SQL/MIGRATION): First DB migration. Created the users table.
Also, needed to update to using plural table names.
This commit is contained in:
parent
86913faed7
commit
3c4710bb48
@ -222,7 +222,7 @@ this application. It will describe the required tables, fields, and other expect
|
||||
##### Table ID Choice
|
||||
|
||||
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
|
||||
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
|
||||
found in **OTHER** section.
|
||||
|
||||
- [ ] Recipe: Represents a single recipe.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] Recipes: Represents a single recipe.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] Title (Unique, Required) string(128)
|
||||
- [ ] Description (Required) text
|
||||
- [ ] Instructions (Required) string(1024)[]
|
||||
@ -249,78 +249,78 @@ found in **OTHER** section.
|
||||
- [ ] Duration (Required) JSONB({ "total": int, "prep": int, "cook": int })
|
||||
- [ ] Category (Required) E_Meal (defined in the [enums](#enums-and-types) section)
|
||||
- [ ] 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
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] User: Represents a single user.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] Users: Represents a single user.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] GoogleId (Unique, Required) text
|
||||
- [ ] Name (Required) string(64)
|
||||
- [ ] Email (Unique, Required) string(128)
|
||||
- [ ] ImageURL () text
|
||||
- [ ] GoogleToken () text
|
||||
- [ ] GoogleRefreshToken () text
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Session: Represents a single user-session.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] Sessions: Represents a single user-session.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] Token (Required) text
|
||||
- [ ] Expiration (Required) date/time stamp
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Engagement: Represents a single engagement from a single user.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] Engagements: Represents a single engagement from a single user.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] Message () text (Used to store any relevant notes, if needed)
|
||||
- [ ] Entity (BigSerial) BigSerial (Used to relate an entity, if needed)
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] Entity (Serial) Serial (Used to relate an entity, if needed)
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] 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***
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) Serial
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Tag: Represents a single tag that can be had by many recipes.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] Tags: Represents a single tag that can be had by many recipes.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] Name (Unique, Required) string(32)
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] RecipeTag: **Many-to-many** table to represent a list of tags on a recipe.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial
|
||||
- [ ] TagId (FK: Tag.Id, Required) BigSerial
|
||||
- [ ] RecipeTags: **Many-to-many** table to represent a list of tags on a recipe.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) Serial
|
||||
- [ ] TagId (FK: Tag.Id, Required) Serial
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] List: Represents a single users shopping list.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] Lists: Represents a single users shopping list.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] Content (Required) JSONB([ { "name": string, "quantity": string }, ... ])
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Image: Represents a single image used by a single recipe.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial
|
||||
- [ ] Images: Represents a single image used by a single recipe.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) Serial
|
||||
- [ ] Alt (Required) string(128) (alt text for accessibility, same as recipe title)
|
||||
- [ ] Url (Required) text
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Review: Represents a single review on a recipe from a single author.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] Reviews: Represents a single review on a recipe from a single author.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] Comment (Required) text
|
||||
- [ ] 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)
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) BigSerial
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] ReviewId (FK: Review.Id) Serial (This is used for nested replies)
|
||||
- [ ] RecipeId (FK: Recipe.Id, Required) Serial
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
- [ ] Notification: Represents a single user notification.
|
||||
- [ ] ID (PK) BigSerial
|
||||
- [ ] UserId (FK: User.Id, Required) BigSerial
|
||||
- [ ] Notifications: Represents a single user notification.
|
||||
- [ ] ID (PK) Serial
|
||||
- [ ] UserId (FK: User.Id, Required) Serial
|
||||
- [ ] Type (Required) E_Notification
|
||||
- [ ] 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
|
||||
- [ ] Created (Required) date/time stamp
|
||||
|
||||
|
||||
@ -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;
|
||||
Loading…
x
Reference in New Issue
Block a user