Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
- main
paths:
- 'sticker-business/**'
- 'backend/init_tables.sql'
- '.github/workflows/backend.yml'
pull_request:
paths:
- 'sticker-business/**'
- 'backend/init_tables.sql'
- '.github/workflows/backend.yml'

permissions:
Expand Down Expand Up @@ -40,6 +42,8 @@ jobs:
services:
mysql:
image: mysql:8.4
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: ci-root-password
MYSQL_DATABASE: sticker_business
Expand All @@ -50,5 +54,15 @@ jobs:
--health-retries=10
--health-start-period=30s
steps:
- name: Confirm MySQL is healthy
run: echo "MySQL 8.4 is ready."
- name: Check out repository
uses: actions/checkout@v4

- name: Install MySQL client
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y mysql-client

- name: Run database schema
env:
MYSQL_PWD: ci-root-password
run: mysql --host=127.0.0.1 --user=root --database=sticker_business --batch --show-warnings < backend/init_tables.sql
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ docker compose up --build
- `--build` rebuilds the images so they include your latest code. Docker compiles the backend for you inside a container.
- The **first** build takes several minutes while Docker downloads Java, Node.js, MySQL and all libraries. Later builds are much faster because Docker caches (reuses) those downloads.
- Wait until the logs stop scrolling. The database needs up to ~30 seconds to become healthy before the backend starts.
- Runs `backend/init_tables.sql` to create the tables. Initialization scripts create new tables only when the database volume is empty; changing the script later does not update an existing database.
- Open http://localhost:8080. You should see **Hello Docker World**.
- Open http://localhost:5173. You should see the React starter page.

Expand Down
142 changes: 142 additions & 0 deletions backend/init_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
-- defaults to innoDB in case future changes to mySQL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing StagingItems table

CREATE TABLE IF NOT EXISTS `User` (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table name will need to be "Account" due to reserved key words

`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255),
`passwordHash` VARCHAR(255),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the size needed for this depends on our algorithm, I haven't been able to find an exact number. All of this to say it may have to change someday

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PermissionType` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255),
PRIMARY KEY (`id`),
UNIQUE KEY `UK_PermissionType_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `Permission` (
`id` INT NOT NULL AUTO_INCREMENT,
`permissionTypeId` INT,
PRIMARY KEY (`id`),
KEY `IDX_Permission_permissionTypeId` (`permissionTypeId`),
CONSTRAINT `FK_Permission_permissionType`
FOREIGN KEY (`permissionTypeId`) REFERENCES `PermissionType` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `UserPermission` (
`userId` INT NOT NULL,
`permissionId` INT NOT NULL,
PRIMARY KEY (`userId`, `permissionId`),
KEY `IDX_UserPermission_permissionId` (`permissionId`),
CONSTRAINT `FK_UserPermission_user`
FOREIGN KEY (`userId`) REFERENCES `User` (`id`),
CONSTRAINT `FK_UserPermission_permission`
FOREIGN KEY (`permissionId`) REFERENCES `Permission` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `Tag` (
`id` INT NOT NULL AUTO_INCREMENT,
`label` VARCHAR(255),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't allow tags this long. How about 100 char?

PRIMARY KEY (`id`),
UNIQUE KEY `UK_Tag_label` (`label`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `Sticker` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255),
`length` DOUBLE NOT NULL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The m,n in the ERD is important because it specifies the exact size of double we expect and creates a max and min cap on value. I set the range for this field at 5 total digits with up to 2 points precision, which gives a range of -999.99 to 999.99

`width` DOUBLE NOT NULL,
`desc` VARCHAR(255),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest increasing this to 500char

`svgPath` VARCHAR(255),
`active` TINYINT(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `StickerSheets` (
`id` INT NOT NULL AUTO_INCREMENT,
`filePath` VARCHAR(255),
`stickerIdsJSON` LONGTEXT,
`stickerIds` LONGTEXT,
Comment on lines +57 to +58

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the JSON field needs to exist, the other is for java only and holds the deserialized json transformed into a map

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `PlacedOrder` (
`id` INT NOT NULL AUTO_INCREMENT,
`customerId` INT,
`placementTimestamp` TIMESTAMP(6),
`status` VARCHAR(255),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe mysql supports enums. If it doesn't, this can still be shrunk to like 50char or less

`addressJSON` LONGTEXT,
`note` VARCHAR(255),
`address` LONGTEXT,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above about JSON fields

PRIMARY KEY (`id`),
KEY `IDX_PlacedOrder_customerId` (`customerId`),
CONSTRAINT `FK_PlacedOrder_customer`
FOREIGN KEY (`customerId`) REFERENCES `User` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `OrderItems` (
`id` INT NOT NULL AUTO_INCREMENT,
`orderId` INT,
`sheetId` INT,
`quantity` INT NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_OrderItems_orderId` (`orderId`),
KEY `IDX_OrderItems_sheetId` (`sheetId`),
CONSTRAINT `FK_OrderItems_order`
FOREIGN KEY (`orderId`) REFERENCES `PlacedOrder` (`id`),
CONSTRAINT `FK_OrderItems_sheet`
FOREIGN KEY (`sheetId`) REFERENCES `StickerSheets` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `OrderItemsStatus` (
`id` INT NOT NULL AUTO_INCREMENT,
`orderItemsId` INT,
`complete` TINYINT(1) NOT NULL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can set a default value of false

PRIMARY KEY (`id`),
UNIQUE KEY `UK_OrderItemsStatus_orderItemsId` (`orderItemsId`),
CONSTRAINT `FK_OrderItemsStatus_orderItem`
FOREIGN KEY (`orderItemsId`) REFERENCES `OrderItems` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `OrderUpdates` (
`id` INT NOT NULL AUTO_INCREMENT,
`orderId` INT,
`timestamp` TIMESTAMP(6),
`orderType` VARCHAR(255),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above about enums

PRIMARY KEY (`id`),
KEY `IDX_OrderUpdates_orderId` (`orderId`),
CONSTRAINT `FK_OrderUpdates_order`
FOREIGN KEY (`orderId`) REFERENCES `PlacedOrder` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `Collection` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255),
PRIMARY KEY (`id`),
UNIQUE KEY `UK_Collection_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `CollectionItems` (
`id` INT NOT NULL AUTO_INCREMENT,
`stickerId` INT,
`collectionId` INT,
PRIMARY KEY (`id`),
KEY `IDX_CollectionItems_stickerId` (`stickerId`),
KEY `IDX_CollectionItems_collectionId` (`collectionId`),
CONSTRAINT `FK_CollectionItems_sticker`
FOREIGN KEY (`stickerId`) REFERENCES `Sticker` (`id`),
CONSTRAINT `FK_CollectionItems_collection`
FOREIGN KEY (`collectionId`) REFERENCES `Collection` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `TagItems` (
`id` INT NOT NULL AUTO_INCREMENT,
`tagId` INT,
`stickerId` INT,
PRIMARY KEY (`id`),
KEY `IDX_TagItems_tagId` (`tagId`),
KEY `IDX_TagItems_stickerId` (`stickerId`),
CONSTRAINT `TAG_ID_FK`
FOREIGN KEY (`tagId`) REFERENCES `Tag` (`id`),
CONSTRAINT `STICKER_ID_FK`
FOREIGN KEY (`stickerId`) REFERENCES `Sticker` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
env_file: .env
volumes:
- mysql_data:/var/lib/mysql
- ./backend/init_tables.sql:/docker-entrypoint-initdb.d/1-init_tables.sql:ro
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
interval: 5s
Expand Down
Loading