From 7ca5c4e5743ca01f059dfa616208f1cbd25a7d9a Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 11:28:25 -0700 Subject: [PATCH 01/24] adding package.json file --- package.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..ff4c1ea --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "express-postgres-example", + "version": "1.0.0", + "description": "A basic Express application with PostgreSQL integration.", + "main": "app.js", + "scripts": { + "start": "node app.js", + "dev": "nodemon app.js" + }, + "keywords": [ + "express", + "node.js", + "postgres", + "postgresql", + "database" + ], + "author": "Your Name", + "license": "MIT", + "dependencies": { + "express": "^4.18.2", + "pg": "^8.8.0", + "dotenv": "^16.0.3", + "nodemon": "^3.0.0" + }, + "devDependencies": { + "jest": "^29.0.0" + } +} -- 2.52.0 From 6942a2de8ffd43c797845b099534eb848b5d5ddc Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 13:20:08 -0700 Subject: [PATCH 02/24] added some base code to start doing work --- .gitignore | 2 ++ app.js | 30 ++++++++++++++++++++++++++++++ config/index.js | 10 ++++++++++ eslint.config.js | 27 +++++++++++++++++++++++++++ package.json | 21 +++++++++++++++------ prettier.config.js | 8 ++++++++ 6 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 config/index.js create mode 100644 eslint.config.js create mode 100644 prettier.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5f19d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json diff --git a/app.js b/app.js new file mode 100644 index 0000000..b8629cf --- /dev/null +++ b/app.js @@ -0,0 +1,30 @@ +const express = require('express') +const path = require('path') + +const authRoutes = require('./routes/auth') +const productsRoutes = require('./routes/products') +const usersRoutes = require('./routes/users') + +const app = express() +const port = process.env.PORT || 3000 + +// Middleware +app.use(express.json()) // For parsing application/json +app.use(express.urlencoded({ extended: true })) // For parsing URL-encoded form data + +// Static Files (Serving Frontend) +app.use(express.static(path.join(__dirname, 'public'))) + +// Mount Routes +app.use('/auth', authRoutes) +app.use('/products', productsRoutes) +app.use('/users', usersRoutes) + +// Default Route (Catch-all for undefined routes) +app.use((req, res, next) => { + res.status(404).send('Sorry, the resource you requested could not be found.') +}) + +app.listen(port, () => { + console.log(`Server listening on port ${port}`) +}) diff --git a/config/index.js b/config/index.js new file mode 100644 index 0000000..c3f9d4b --- /dev/null +++ b/config/index.js @@ -0,0 +1,10 @@ +// config/index.js +export default { + database: { + host: process.env.DB_HOST || 'localhost', + user: process.env.DB_USER || 'your_db_user', + password: process.env.DB_PASSWORD || 'your_db_password', + database: process.env.DB_NAME || 'your_db_name', + port: process.env.DB_PORT || 5432, + }, +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..6ea7cfd --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,27 @@ +// eslint.config.js (Advanced alternative) +import prettierPlugin from 'eslint-plugin-prettier' +import prettierConfig from 'eslint-config-prettier' +import prettierOptions from './prettier.config.js' // Import your config directly +import importPlugin from 'eslint-plugin-import' + +export default [ + { + plugins: { + prettier: prettierPlugin, + import: importPlugin, + }, + rules: { + ...prettierConfig.rules, + 'prettier/prettier': ['error', prettierOptions], + 'no-sequences': 'off', + 'no-console': 'warn', + 'import/first': 'error', + 'import/newline-after-import': 'error', + 'import/no-duplicates': 'error', + 'import/no-unresolved': 'error', + 'import/no-unused-modules': ['warn', { missingExports: true }], + quotes: ['error', 'single'], + semi: 'off', + }, + }, +] diff --git a/package.json b/package.json index ff4c1ea..4d25064 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,16 @@ { - "name": "express-postgres-example", + "name": "tcg-collectors-server", "version": "1.0.0", "description": "A basic Express application with PostgreSQL integration.", "main": "app.js", "scripts": { "start": "node app.js", - "dev": "nodemon app.js" + "dev": "nodemon app.js", + "lint": "eslint .", + "lint:fix": "eslint . --fix", + "format": "prettier --config prettier.config.js --write ." }, + "type": "module", "keywords": [ "express", "node.js", @@ -17,12 +21,17 @@ "author": "Your Name", "license": "MIT", "dependencies": { - "express": "^4.18.2", - "pg": "^8.8.0", "dotenv": "^16.0.3", - "nodemon": "^3.0.0" + "express": "^4.18.2", + "pg": "^8.8.0" }, "devDependencies": { - "jest": "^29.0.0" + "eslint": "^10.3.0", + "eslint-config-prettier": "^10.1.8", + "eslint-plugin-import": "^2.32.0", + "eslint-plugin-prettier": "^5.5.5", + "jest": "^29.0.0", + "nodemon": "^3.0.0", + "prettier": "^3.8.3" } } diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..b54afba --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,8 @@ +// prettier.config.js +export default { + trailingComma: 'es5', + tabWidth: 2, + semi: false, // Crucial: Sets semicolon removal. + useTabs: true, + singleQuote: true, +} -- 2.52.0 From 6aa89984a627ce04ad29247dd25cdf27f9406b1d Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 19:05:35 -0700 Subject: [PATCH 03/24] added more modules for when I download data from CSV files --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d25064..5be9b82 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,9 @@ "dependencies": { "dotenv": "^16.0.3", "express": "^4.18.2", - "pg": "^8.8.0" + "pg": "^8.8.0", + "p-limit": "^7.3.0", + "csv-parser": "^3.0.0" }, "devDependencies": { "eslint": "^10.3.0", -- 2.52.0 From f4403032138810d54dc60567252c972e210cde5d Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 19:13:38 -0700 Subject: [PATCH 04/24] added migration package --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5be9b82..72792c2 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,11 @@ "author": "Your Name", "license": "MIT", "dependencies": { + "csv-parser": "^3.0.0", "dotenv": "^16.0.3", "express": "^4.18.2", - "pg": "^8.8.0", "p-limit": "^7.3.0", - "csv-parser": "^3.0.0" + "pg": "^8.8.0" }, "devDependencies": { "eslint": "^10.3.0", @@ -33,6 +33,7 @@ "eslint-plugin-import": "^2.32.0", "eslint-plugin-prettier": "^5.5.5", "jest": "^29.0.0", + "node-pg-migrate": "^8.0.4", "nodemon": "^3.0.0", "prettier": "^3.8.3" } -- 2.52.0 From 3cdec698ef447de2423c0b4ee97c998a0e986dce Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 19:17:37 -0700 Subject: [PATCH 05/24] changed pg library --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 72792c2..d7b0fde 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "csv-parser": "^3.0.0", "dotenv": "^16.0.3", "express": "^4.18.2", - "p-limit": "^7.3.0", - "pg": "^8.8.0" + "node-pg": "^1.0.1", + "p-limit": "^7.3.0" }, "devDependencies": { "eslint": "^10.3.0", -- 2.52.0 From 5318a1eb4a7551a553f51d2f1dd4e88572c339d7 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 19:51:13 -0700 Subject: [PATCH 06/24] working on first setup of pg migrations --- migrations/001_create-collection-table.js | 20 +++++++++++ migrations/002_create-image-table.js | 21 ++++++++++++ migrations/003_create-item-table.js | 36 +++++++++++++++++++ migrations/index.js | 42 +++++++++++++++++++++++ package.json | 3 +- 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 migrations/001_create-collection-table.js create mode 100644 migrations/002_create-image-table.js create mode 100644 migrations/003_create-item-table.js create mode 100644 migrations/index.js diff --git a/migrations/001_create-collection-table.js b/migrations/001_create-collection-table.js new file mode 100644 index 0000000..873423a --- /dev/null +++ b/migrations/001_create-collection-table.js @@ -0,0 +1,20 @@ +export default { + name: 'create_collection_table', + up: async () => { + const sql = ` + CREATE TABLE collection ( + id UUID PRIMARY KEY, + name TEXT + ); + ` + await migrate.run([sql], pool) + console.log('Collection table created successfully!') + }, + down: async () => { + const sql = ` + DROP TABLE collection; + ` + await migrate.run([sql], pool) + console.log('Collection table dropped successfully.') + }, +} diff --git a/migrations/002_create-image-table.js b/migrations/002_create-image-table.js new file mode 100644 index 0000000..e5cebe7 --- /dev/null +++ b/migrations/002_create-image-table.js @@ -0,0 +1,21 @@ +export default { + name: 'create_image_table', + up: async () => { + const sql = ` + CREATE TABLE image ( + id UUID PRIMARY KEY, + file TEXT, + image BYTEA + ); + ` + await migrate.run([sql], pool) + console.log('Image table created successfully!') + }, + down: async () => { + const sql = ` + DROP TABLE image; + ` + await migrate.run([sql], pool) + console.log('Image table dropped successfully.') + }, +} diff --git a/migrations/003_create-item-table.js b/migrations/003_create-item-table.js new file mode 100644 index 0000000..7425c9d --- /dev/null +++ b/migrations/003_create-item-table.js @@ -0,0 +1,36 @@ +export default { + up: async (pool) => { + try { + await pool.query( + ` + CREATE TABLE item ( + id UUID PRIMARY KEY, + collection_id UUID, + image_id UUID, + productId TEXT, + name TEXT, + cleanName TEXT, + extCardText TEXTAREA, + marketPrice TEXT, + extRarity TEXT, + FOREIGN KEY (collection_id) REFERENCES collection(id), + FOREIGN KEY (image_id) REFERENCES image(id) + ); + ` + ) + } catch (error) { + console.error('Error creating item table:', error) + throw error // Re-throw to signal failure to the migration runner + } + }, + down: async (pool) => { + try { + await pool.query(` + DROP TABLE item; + `) + } catch (error) { + console.error('Error dropping item table:', error) + throw error + } + }, +} diff --git a/migrations/index.js b/migrations/index.js new file mode 100644 index 0000000..4fb9ce3 --- /dev/null +++ b/migrations/index.js @@ -0,0 +1,42 @@ +import { Pool } from 'pg' +import * as fs from 'fs' +import path from 'path' + +const migrate = require('node-pg-migrate') + +// Database connection configuration +const dbConfig = { + user: 'your_user', + host: 'localhost', + database: 'your_database', + password: 'your_password', + port: 5432, +} + +const pool = new Pool(dbConfig) + +const migrations = [] + +fs.readdirSync(__dirname) + .filter((file) => { + // Filter out hidden files, index.js itself, and non-JS files + return ( + file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js' + ) + }) + .forEach((file) => { + // Require each file and add its default export to the list + const migration = require(path.join(__dirname, file)) + migrations.push(migration) + }) + +async function runMigrations() { + try { + await migrate.run(migrations, pool) + console.log('Migrations completed successfully!') + } catch (error) { + console.error('Migration failed:', error) + } +} + +runMigrations() diff --git a/package.json b/package.json index d7b0fde..09edf49 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "dotenv": "^16.0.3", "express": "^4.18.2", "node-pg": "^1.0.1", - "p-limit": "^7.3.0" + "p-limit": "^7.3.0", + "pg": "^8.20.0" }, "devDependencies": { "eslint": "^10.3.0", -- 2.52.0 From e905899c60462d6d709ccd47ae1ffe450fde96f8 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 22:38:25 -0700 Subject: [PATCH 07/24] starting to create dockerfile for ci work --- Dockerfile | 14 ++++++++++++ migrations/004_create-user-table.js | 33 +++++++++++++++++++++++++++++ migrations/005_create-role-table.js | 27 +++++++++++++++++++++++ migrations/index.js | 12 ++++++----- 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 migrations/004_create-user-table.js create mode 100644 migrations/005_create-role-table.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f73827d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM node:24-alpine + +ENV DB_HOST= +ENV DB_USERNAME= +ENV DB_PASSWORD= +ENV DB_PORT= +ENV DB_DATABASE= + +ARG CMD +WORKDIR /app +COPY . . +RUN npm install --force + +CMD ["node", "run", "$CMD"] diff --git a/migrations/004_create-user-table.js b/migrations/004_create-user-table.js new file mode 100644 index 0000000..a4a346c --- /dev/null +++ b/migrations/004_create-user-table.js @@ -0,0 +1,33 @@ +export default { + up: async (pool) => { + try { + await pool.query( + ` + CREATE TABLE user ( + id UUID PRIMARY KEY, + username TEXT UNIQUE NOT NULL, + password TEXT NOT NULL, + role_id UUID, + email TEXT UNIQUE NOT NULL, + createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (role_id) REFERENCES role(id) + ); + ` + ) + } catch (error) { + console.error('Error creating user table:', error) + throw error + } + }, + down: async (pool) => { + try { + await pool.query(` + DROP TABLE user; + `) + } catch (error) { + console.error('Error dropping user table:', error) + throw error + } + }, +} diff --git a/migrations/005_create-role-table.js b/migrations/005_create-role-table.js new file mode 100644 index 0000000..fd49ccd --- /dev/null +++ b/migrations/005_create-role-table.js @@ -0,0 +1,27 @@ +export default { + up: async (pool) => { + try { + await pool.query( + ` + CREATE TABLE role ( + id UUID PRIMARY KEY, + name TEXT UNIQUE NOT NULL + ); + ` + ) + } catch (error) { + console.error('Error creating role table:', error) + throw error + } + }, + down: async (pool) => { + try { + await pool.query(` + DROP TABLE role; + `) + } catch (error) { + console.error('Error dropping role table:', error) + throw error + } + }, +} diff --git a/migrations/index.js b/migrations/index.js index 4fb9ce3..a567c2a 100644 --- a/migrations/index.js +++ b/migrations/index.js @@ -5,12 +5,14 @@ import path from 'path' const migrate = require('node-pg-migrate') // Database connection configuration +const { DB_USERNAME, DB_HOST, DB_DATABASE, DB_PASSWORD, DB_PORT } = process.env; + const dbConfig = { - user: 'your_user', - host: 'localhost', - database: 'your_database', - password: 'your_password', - port: 5432, + user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user' + host: DB_HOST || 'localhost', + database: DB_DATABASE || 'your_database', + password: DB_PASSWORD || 'your_password', + port: parseInt(DB_PORT, 10) || 5432, // Convert the environment variable to a number if it exists, otherwise use 5432 } const pool = new Pool(dbConfig) -- 2.52.0 From 2020e326beb4414835c20282054cbf47291e4652 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 23:19:31 -0700 Subject: [PATCH 08/24] getting ready to do damage --- .gitea/workflows/build.yaml | 25 +++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build.yaml diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..2989362 --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,25 @@ +name: Build and Push Image +on: [push] +jobs: + build-and-push: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Log in to Gitea Registry + uses: docker/login-action@v2 + with: + registry: gitea.nelson-household.com # Replace with your Gitea domain + username: ${{ gitea.actor }} + password: ${{ secrets.RUNNER_TOKEN }} + - name: Delete Old Images and Containers + run: | + docker rm $(docker ps -a -q -f "name=tcg-collectors-server") + docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}" | grep "tcg-collectors-server") + - name: Build and Push Image + run: | + docker build -t gitea.nelson-household.com/Hard-at-Work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . + docker push gitea.nelson-household.com/Hard-at-Work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} diff --git a/package.json b/package.json index 09edf49..0dffcb8 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "nodemon app.js", "lint": "eslint .", "lint:fix": "eslint . --fix", - "format": "prettier --config prettier.config.js --write ." + "format": "prettier --config prettier.config.js --write .", + "migrations": "node ./migrations/index.js" }, "type": "module", "keywords": [ -- 2.52.0 From 282d902115bd6c35a89a401382046615337aa419 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Mon, 11 May 2026 23:33:22 -0700 Subject: [PATCH 09/24] testing an issue out when a container does not exist --- .gitea/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 2989362..aa9ada2 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -17,8 +17,8 @@ jobs: password: ${{ secrets.RUNNER_TOKEN }} - name: Delete Old Images and Containers run: | - docker rm $(docker ps -a -q -f "name=tcg-collectors-server") - docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}" | grep "tcg-collectors-server") + docker ps -a -q -f "name=tcg-collectors-server" | xargs -I {} docker rm {} || true + docker images --format "{{.Repository}}:{{.Tag}}" | grep "tcg-collectors-server" | xargs -I {} docker rmi {} || true - name: Build and Push Image run: | docker build -t gitea.nelson-household.com/Hard-at-Work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . -- 2.52.0 From b33ae3d9a78cc819284802f59d9b0a4a8cbd3c60 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Mon, 11 May 2026 23:35:06 -0700 Subject: [PATCH 10/24] lower case path --- .gitea/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index aa9ada2..fce4c12 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -21,5 +21,5 @@ jobs: docker images --format "{{.Repository}}:{{.Tag}}" | grep "tcg-collectors-server" | xargs -I {} docker rmi {} || true - name: Build and Push Image run: | - docker build -t gitea.nelson-household.com/Hard-at-Work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . - docker push gitea.nelson-household.com/Hard-at-Work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} + docker build -t gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . + docker push gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} -- 2.52.0 From 0601c41f464b4128d29f383f7e81422cd83d6d67 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:28:51 -0700 Subject: [PATCH 11/24] updated migrations --- migrations/004_create-location-table.js | 28 +++++++++++++++ migrations/005_create-set-table.js | 34 +++++++++++++++++++ ...user-table.js => 006_create-user-table.js} | 0 ...role-table.js => 007_create-role-table.js} | 0 migrations/index.js | 12 +++---- 5 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 migrations/004_create-location-table.js create mode 100644 migrations/005_create-set-table.js rename migrations/{004_create-user-table.js => 006_create-user-table.js} (100%) rename migrations/{005_create-role-table.js => 007_create-role-table.js} (100%) diff --git a/migrations/004_create-location-table.js b/migrations/004_create-location-table.js new file mode 100644 index 0000000..ffdfaaf --- /dev/null +++ b/migrations/004_create-location-table.js @@ -0,0 +1,28 @@ +export default { + up: async (pool) => { + try { + await pool.query( + ` + CREATE TABLE location ( + id UUID PRIMARY KEY, + name TEXT UNIQUE NOT NULL + ); + ` + ) + } catch (error) { + console.error('Error creating location table:', error) + throw error + } + }, + + down: async (pool) => { + try { + await pool.query(` + DROP TABLE location; + `) + } catch (error) { + console.error('Error dropping location table:', error) + throw error + } + }, +} diff --git a/migrations/005_create-set-table.js b/migrations/005_create-set-table.js new file mode 100644 index 0000000..8d36b43 --- /dev/null +++ b/migrations/005_create-set-table.js @@ -0,0 +1,34 @@ +export default { + up: async (pool) => { + try { + await pool.query( + ` + CREATE TABLE set ( + id UUID PRIMARY KEY, + collection_id UUID NOT NULL, + name TEXT NOT NULL, + location_id UUID, + createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (collection_id) REFERENCES collection(id), + FOREIGN KEY (location_id) REFERENCES location(id) + ); + ` + ) + } catch (error) { + console.error('Error creating set table:', error) + throw error + } + }, + + down: async (pool) => { + try { + await pool.query(` + DROP TABLE set; + `) + } catch (error) { + console.error('Error dropping set table:', error) + throw error + } + }, +} diff --git a/migrations/004_create-user-table.js b/migrations/006_create-user-table.js similarity index 100% rename from migrations/004_create-user-table.js rename to migrations/006_create-user-table.js diff --git a/migrations/005_create-role-table.js b/migrations/007_create-role-table.js similarity index 100% rename from migrations/005_create-role-table.js rename to migrations/007_create-role-table.js diff --git a/migrations/index.js b/migrations/index.js index a567c2a..c895109 100644 --- a/migrations/index.js +++ b/migrations/index.js @@ -5,14 +5,14 @@ import path from 'path' const migrate = require('node-pg-migrate') // Database connection configuration -const { DB_USERNAME, DB_HOST, DB_DATABASE, DB_PASSWORD, DB_PORT } = process.env; +const { DB_USERNAME, DB_HOST, DB_DATABASE, DB_PASSWORD, DB_PORT } = process.env const dbConfig = { - user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user' - host: DB_HOST || 'localhost', - database: DB_DATABASE || 'your_database', - password: DB_PASSWORD || 'your_password', - port: parseInt(DB_PORT, 10) || 5432, // Convert the environment variable to a number if it exists, otherwise use 5432 + user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user' + host: DB_HOST || 'localhost', + database: DB_DATABASE || 'your_database', + password: DB_PASSWORD || 'your_password', + port: parseInt(DB_PORT, 10) || 5432, // Convert the environment variable to a number if it exists, otherwise use 5432 } const pool = new Pool(dbConfig) -- 2.52.0 From d47633b638d8209784a4ebd4d29633917fb75492 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:44:46 -0700 Subject: [PATCH 12/24] updated build file, package file, and dockerfile --- .gitea/workflows/build.yaml | 15 ++++++++++++++- Dockerfile | 3 +-- package.json | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index fce4c12..72f2b65 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -9,17 +9,30 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Log in to Gitea Registry uses: docker/login-action@v2 with: registry: gitea.nelson-household.com # Replace with your Gitea domain username: ${{ gitea.actor }} password: ${{ secrets.RUNNER_TOKEN }} + - name: Delete Old Images and Containers run: | docker ps -a -q -f "name=tcg-collectors-server" | xargs -I {} docker rm {} || true docker images --format "{{.Repository}}:{{.Tag}}" | grep "tcg-collectors-server" | xargs -I {} docker rmi {} || true + - name: Build and Push Image run: | - docker build -t gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . + docker build \ + --build-arg DB_HOST=${{ secrets.DB_HOST }} \ + --build-arg DB_USERNAME=${{ secrets.DB_USERNAME }} \ + --build-arg DB_PASSWORD=${{ secrets.DB_PASSWORD }} \ + --build-arg DB_PORT=${{ secrets.DB_PORT }} \ + --build-arg DB_DATABASE=${{ secrets.DB_DATABASE }} \ + -t gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . docker push gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} + + - name: Execute Migrations + run: | + docker exec gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate diff --git a/Dockerfile b/Dockerfile index f73827d..e302c85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,8 @@ ENV DB_PASSWORD= ENV DB_PORT= ENV DB_DATABASE= -ARG CMD WORKDIR /app COPY . . RUN npm install --force -CMD ["node", "run", "$CMD"] +CMD ["npm", "run", "start"] diff --git a/package.json b/package.json index 0dffcb8..8f82aa3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --config prettier.config.js --write .", - "migrations": "node ./migrations/index.js" + "migrate": "node ./migrations/index.js" }, "type": "module", "keywords": [ -- 2.52.0 From 5bc734a51a823ba398f924ea504cf9459719ce05 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:50:10 -0700 Subject: [PATCH 13/24] changed command to run instead of exec --- .gitea/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 72f2b65..89c0e96 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -35,4 +35,4 @@ jobs: - name: Execute Migrations run: | - docker exec gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate + docker run gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate -- 2.52.0 From 39c09287ed3b00299675dadc74b64984239b0b48 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:51:28 -0700 Subject: [PATCH 14/24] forgot to add -it to migration run build --- .gitea/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 89c0e96..1f1a4dd 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -35,4 +35,4 @@ jobs: - name: Execute Migrations run: | - docker run gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate + docker run -it gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate -- 2.52.0 From 0d146bda6b5e6b9a6bdd84f2865306f1a70b8f2f Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:56:57 -0700 Subject: [PATCH 15/24] removed -it --- .gitea/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 1f1a4dd..89c0e96 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -35,4 +35,4 @@ jobs: - name: Execute Migrations run: | - docker run -it gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate + docker run gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate -- 2.52.0 From 569a41f0539a7c0d9fcc7dfe4490d0b70e16fff6 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 23:27:49 -0700 Subject: [PATCH 16/24] fixed things to be more inline with how migrations work --- .gitea/workflows/build.yaml | 6 +--- Dockerfile | 6 +--- migrations/001_create-collection-table.js | 24 +++++-------- migrations/002_create-image-table.js | 24 +++++-------- migrations/003_create-item-table.js | 27 ++++---------- migrations/004_create-location-table.js | 26 ++++---------- migrations/005_create-set-table.js | 26 ++++---------- migrations/006_create-user-table.js | 27 ++++---------- migrations/007_create-role-table.js | 27 ++++---------- migrations/index.js | 44 ----------------------- package.json | 2 +- 11 files changed, 54 insertions(+), 185 deletions(-) delete mode 100644 migrations/index.js diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 89c0e96..e3d8804 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -25,11 +25,7 @@ jobs: - name: Build and Push Image run: | docker build \ - --build-arg DB_HOST=${{ secrets.DB_HOST }} \ - --build-arg DB_USERNAME=${{ secrets.DB_USERNAME }} \ - --build-arg DB_PASSWORD=${{ secrets.DB_PASSWORD }} \ - --build-arg DB_PORT=${{ secrets.DB_PORT }} \ - --build-arg DB_DATABASE=${{ secrets.DB_DATABASE }} \ + --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} \ -t gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} . docker push gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index e302c85..6d9543a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,6 @@ FROM node:24-alpine -ENV DB_HOST= -ENV DB_USERNAME= -ENV DB_PASSWORD= -ENV DB_PORT= -ENV DB_DATABASE= +ENV DATABASE_URL= WORKDIR /app COPY . . diff --git a/migrations/001_create-collection-table.js b/migrations/001_create-collection-table.js index 873423a..9e001e2 100644 --- a/migrations/001_create-collection-table.js +++ b/migrations/001_create-collection-table.js @@ -1,20 +1,14 @@ -export default { - name: 'create_collection_table', - up: async () => { - const sql = ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE collection ( id UUID PRIMARY KEY, name TEXT ); - ` - await migrate.run([sql], pool) - console.log('Collection table created successfully!') - }, - down: async () => { - const sql = ` - DROP TABLE collection; - ` - await migrate.run([sql], pool) - console.log('Collection table dropped successfully.') - }, + `) +} + +export const down = (pgm) => { + pgm.sql(` + DROP TABLE collection; + `) } diff --git a/migrations/002_create-image-table.js b/migrations/002_create-image-table.js index e5cebe7..012dba8 100644 --- a/migrations/002_create-image-table.js +++ b/migrations/002_create-image-table.js @@ -1,21 +1,15 @@ -export default { - name: 'create_image_table', - up: async () => { - const sql = ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE image ( id UUID PRIMARY KEY, file TEXT, image BYTEA ); - ` - await migrate.run([sql], pool) - console.log('Image table created successfully!') - }, - down: async () => { - const sql = ` - DROP TABLE image; - ` - await migrate.run([sql], pool) - console.log('Image table dropped successfully.') - }, + `) +} + +export const down = (pgm) => { + pgm.sql(` + DROP TABLE image; + `) } diff --git a/migrations/003_create-item-table.js b/migrations/003_create-item-table.js index 7425c9d..fc764f2 100644 --- a/migrations/003_create-item-table.js +++ b/migrations/003_create-item-table.js @@ -1,8 +1,5 @@ -export default { - up: async (pool) => { - try { - await pool.query( - ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE item ( id UUID PRIMARY KEY, collection_id UUID, @@ -16,21 +13,11 @@ export default { FOREIGN KEY (collection_id) REFERENCES collection(id), FOREIGN KEY (image_id) REFERENCES image(id) ); - ` - ) - } catch (error) { - console.error('Error creating item table:', error) - throw error // Re-throw to signal failure to the migration runner - } - }, - down: async (pool) => { - try { - await pool.query(` + `) +} + +export const down = (pgm) => { + pgm.sql(` DROP TABLE item; `) - } catch (error) { - console.error('Error dropping item table:', error) - throw error - } - }, } diff --git a/migrations/004_create-location-table.js b/migrations/004_create-location-table.js index ffdfaaf..f341d51 100644 --- a/migrations/004_create-location-table.js +++ b/migrations/004_create-location-table.js @@ -1,28 +1,14 @@ -export default { - up: async (pool) => { - try { - await pool.query( - ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE location ( id UUID PRIMARY KEY, name TEXT UNIQUE NOT NULL ); - ` - ) - } catch (error) { - console.error('Error creating location table:', error) - throw error - } - }, + `) +} - down: async (pool) => { - try { - await pool.query(` +export const down = (pgm) => { + pgm.sql(` DROP TABLE location; `) - } catch (error) { - console.error('Error dropping location table:', error) - throw error - } - }, } diff --git a/migrations/005_create-set-table.js b/migrations/005_create-set-table.js index 8d36b43..30a6b93 100644 --- a/migrations/005_create-set-table.js +++ b/migrations/005_create-set-table.js @@ -1,8 +1,5 @@ -export default { - up: async (pool) => { - try { - await pool.query( - ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE set ( id UUID PRIMARY KEY, collection_id UUID NOT NULL, @@ -13,22 +10,11 @@ export default { FOREIGN KEY (collection_id) REFERENCES collection(id), FOREIGN KEY (location_id) REFERENCES location(id) ); - ` - ) - } catch (error) { - console.error('Error creating set table:', error) - throw error - } - }, + `) +} - down: async (pool) => { - try { - await pool.query(` +export const down = (pgm) => { + pgm.sql(` DROP TABLE set; `) - } catch (error) { - console.error('Error dropping set table:', error) - throw error - } - }, } diff --git a/migrations/006_create-user-table.js b/migrations/006_create-user-table.js index a4a346c..8d0c1f6 100644 --- a/migrations/006_create-user-table.js +++ b/migrations/006_create-user-table.js @@ -1,8 +1,5 @@ -export default { - up: async (pool) => { - try { - await pool.query( - ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE user ( id UUID PRIMARY KEY, username TEXT UNIQUE NOT NULL, @@ -13,21 +10,11 @@ export default { updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (role_id) REFERENCES role(id) ); - ` - ) - } catch (error) { - console.error('Error creating user table:', error) - throw error - } - }, - down: async (pool) => { - try { - await pool.query(` + `) +} + +export const down = (pgm) => { + pgm.sql(` DROP TABLE user; `) - } catch (error) { - console.error('Error dropping user table:', error) - throw error - } - }, } diff --git a/migrations/007_create-role-table.js b/migrations/007_create-role-table.js index fd49ccd..1cf4128 100644 --- a/migrations/007_create-role-table.js +++ b/migrations/007_create-role-table.js @@ -1,27 +1,14 @@ -export default { - up: async (pool) => { - try { - await pool.query( - ` +export const up = (pgm) => { + pgm.sql(` CREATE TABLE role ( id UUID PRIMARY KEY, name TEXT UNIQUE NOT NULL ); - ` - ) - } catch (error) { - console.error('Error creating role table:', error) - throw error - } - }, - down: async (pool) => { - try { - await pool.query(` + `) +} + +export const down = (pmg) => { + pgm.sql(` DROP TABLE role; `) - } catch (error) { - console.error('Error dropping role table:', error) - throw error - } - }, } diff --git a/migrations/index.js b/migrations/index.js deleted file mode 100644 index c895109..0000000 --- a/migrations/index.js +++ /dev/null @@ -1,44 +0,0 @@ -import { Pool } from 'pg' -import * as fs from 'fs' -import path from 'path' - -const migrate = require('node-pg-migrate') - -// Database connection configuration -const { DB_USERNAME, DB_HOST, DB_DATABASE, DB_PASSWORD, DB_PORT } = process.env - -const dbConfig = { - user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user' - host: DB_HOST || 'localhost', - database: DB_DATABASE || 'your_database', - password: DB_PASSWORD || 'your_password', - port: parseInt(DB_PORT, 10) || 5432, // Convert the environment variable to a number if it exists, otherwise use 5432 -} - -const pool = new Pool(dbConfig) - -const migrations = [] - -fs.readdirSync(__dirname) - .filter((file) => { - // Filter out hidden files, index.js itself, and non-JS files - return ( - file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js' - ) - }) - .forEach((file) => { - // Require each file and add its default export to the list - const migration = require(path.join(__dirname, file)) - migrations.push(migration) - }) - -async function runMigrations() { - try { - await migrate.run(migrations, pool) - console.log('Migrations completed successfully!') - } catch (error) { - console.error('Migration failed:', error) - } -} - -runMigrations() diff --git a/package.json b/package.json index 8f82aa3..b661d5b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "prettier --config prettier.config.js --write .", - "migrate": "node ./migrations/index.js" + "migrate": "node-pg-migrate" }, "type": "module", "keywords": [ -- 2.52.0 From e9dd340b447975958199dc307c73f5944a17addc Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 23:30:10 -0700 Subject: [PATCH 17/24] fixed spacing in string --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6d9543a..82ef265 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM node:24-alpine -ENV DATABASE_URL= +ENV DATABASE_URL= WORKDIR /app COPY . . -- 2.52.0 From f6ff2ee69b43dd723658ff40262201a343eac20e Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 23:34:12 -0700 Subject: [PATCH 18/24] did not save up --- .gitea/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index e3d8804..6a96d10 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -31,4 +31,4 @@ jobs: - name: Execute Migrations run: | - docker run gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate + docker run gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }} npm run migrate up -- 2.52.0 From 7dc66697ea1e000c14a1c6a42f53762e481535ac Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 22:30:45 -0700 Subject: [PATCH 19/24] fixing arg to be assigned to ENV --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 82ef265..d1a5e5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM node:24-alpine -ENV DATABASE_URL= +ARG DATABASE_URL + +ENV DATABASE_URL=${DATABASE_URL} WORKDIR /app COPY . . -- 2.52.0 From 4c2851cee5c7c266c29f97b5bd9e260f8e6a5744 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 22:44:40 -0700 Subject: [PATCH 20/24] fixed migration issues --- ...02_create-image-table.js => 001_create-image-table.js} | 4 +++- ...collection-table.js => 002_create-collection-table.js} | 6 +++++- migrations/003_create-item-table.js | 4 +++- migrations/004_create-location-table.js | 2 ++ migrations/005_create-set-table.js | 8 +++++--- migrations/006_create-user-table.js | 4 ++-- migrations/007_create-role-table.js | 4 +++- 7 files changed, 23 insertions(+), 9 deletions(-) rename migrations/{002_create-image-table.js => 001_create-image-table.js} (65%) rename migrations/{001_create-collection-table.js => 002_create-collection-table.js} (52%) diff --git a/migrations/002_create-image-table.js b/migrations/001_create-image-table.js similarity index 65% rename from migrations/002_create-image-table.js rename to migrations/001_create-image-table.js index 012dba8..1841160 100644 --- a/migrations/002_create-image-table.js +++ b/migrations/001_create-image-table.js @@ -3,7 +3,9 @@ export const up = (pgm) => { CREATE TABLE image ( id UUID PRIMARY KEY, file TEXT, - image BYTEA + image BYTEA, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW(), ); `) } diff --git a/migrations/001_create-collection-table.js b/migrations/002_create-collection-table.js similarity index 52% rename from migrations/001_create-collection-table.js rename to migrations/002_create-collection-table.js index 9e001e2..2ba94e2 100644 --- a/migrations/001_create-collection-table.js +++ b/migrations/002_create-collection-table.js @@ -2,7 +2,11 @@ export const up = (pgm) => { pgm.sql(` CREATE TABLE collection ( id UUID PRIMARY KEY, - name TEXT + name TEXT, + image_id UUID, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW(), + FOREIGN KEY (image_id) REFERENCES image(id) ); `) } diff --git a/migrations/003_create-item-table.js b/migrations/003_create-item-table.js index fc764f2..4434ab7 100644 --- a/migrations/003_create-item-table.js +++ b/migrations/003_create-item-table.js @@ -7,9 +7,11 @@ export const up = (pgm) => { productId TEXT, name TEXT, cleanName TEXT, - extCardText TEXTAREA, + extCardText TEXT, marketPrice TEXT, extRarity TEXT, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW(), FOREIGN KEY (collection_id) REFERENCES collection(id), FOREIGN KEY (image_id) REFERENCES image(id) ); diff --git a/migrations/004_create-location-table.js b/migrations/004_create-location-table.js index f341d51..6a0c267 100644 --- a/migrations/004_create-location-table.js +++ b/migrations/004_create-location-table.js @@ -3,6 +3,8 @@ export const up = (pgm) => { CREATE TABLE location ( id UUID PRIMARY KEY, name TEXT UNIQUE NOT NULL + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() ); `) } diff --git a/migrations/005_create-set-table.js b/migrations/005_create-set-table.js index 30a6b93..117df2b 100644 --- a/migrations/005_create-set-table.js +++ b/migrations/005_create-set-table.js @@ -5,10 +5,12 @@ export const up = (pgm) => { collection_id UUID NOT NULL, name TEXT NOT NULL, location_id UUID, - createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + image_id UUID, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW(), FOREIGN KEY (collection_id) REFERENCES collection(id), - FOREIGN KEY (location_id) REFERENCES location(id) + FOREIGN KEY (location_id) REFERENCES location(id), + FOREIGN KEY (image_id) REFERENCES image(id) ); `) } diff --git a/migrations/006_create-user-table.js b/migrations/006_create-user-table.js index 8d0c1f6..49a69cc 100644 --- a/migrations/006_create-user-table.js +++ b/migrations/006_create-user-table.js @@ -6,8 +6,8 @@ export const up = (pgm) => { password TEXT NOT NULL, role_id UUID, email TEXT UNIQUE NOT NULL, - createdAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW(), FOREIGN KEY (role_id) REFERENCES role(id) ); `) diff --git a/migrations/007_create-role-table.js b/migrations/007_create-role-table.js index 1cf4128..e516aab 100644 --- a/migrations/007_create-role-table.js +++ b/migrations/007_create-role-table.js @@ -2,7 +2,9 @@ export const up = (pgm) => { pgm.sql(` CREATE TABLE role ( id UUID PRIMARY KEY, - name TEXT UNIQUE NOT NULL + name TEXT UNIQUE NOT NULL, + created_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() ); `) } -- 2.52.0 From 3eb3b39b79e15eb56991e2964cf902704c6eb215 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 22:48:06 -0700 Subject: [PATCH 21/24] fixed comma issue --- migrations/001_create-image-table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/001_create-image-table.js b/migrations/001_create-image-table.js index 1841160..c39b6e8 100644 --- a/migrations/001_create-image-table.js +++ b/migrations/001_create-image-table.js @@ -5,7 +5,7 @@ export const up = (pgm) => { file TEXT, image BYTEA, created_at TIMESTAMP DEFAULT NOW(), - updated_at TIMESTAMP DEFAULT NOW(), + updated_at TIMESTAMP DEFAULT NOW() ); `) } -- 2.52.0 From e12bb7834de424a1e75cfd03e67bf77c47f20d54 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 22:52:18 -0700 Subject: [PATCH 22/24] found an issue with missing comma for migrations --- migrations/004_create-location-table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/004_create-location-table.js b/migrations/004_create-location-table.js index 6a0c267..6074cbf 100644 --- a/migrations/004_create-location-table.js +++ b/migrations/004_create-location-table.js @@ -2,7 +2,7 @@ export const up = (pgm) => { pgm.sql(` CREATE TABLE location ( id UUID PRIMARY KEY, - name TEXT UNIQUE NOT NULL + name TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW() ); -- 2.52.0 From 2c8baa339a0027afc29689bbfa3d615ebfb7b492 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 22:59:55 -0700 Subject: [PATCH 23/24] fixed naming of tables to be plural and fixed order of migration execution --- migrations/001_create-image-table.js | 4 ++-- migrations/002_create-collection-table.js | 6 +++--- migrations/003_create-item-table.js | 8 ++++---- migrations/004_create-location-table.js | 4 ++-- migrations/005_create-set-table.js | 10 +++++----- ...7_create-role-table.js => 006_create-role-table.js} | 4 ++-- ...6_create-user-table.js => 007_create-user-table.js} | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) rename migrations/{007_create-role-table.js => 006_create-role-table.js} (83%) rename migrations/{006_create-user-table.js => 007_create-user-table.js} (77%) diff --git a/migrations/001_create-image-table.js b/migrations/001_create-image-table.js index c39b6e8..aa5ba6c 100644 --- a/migrations/001_create-image-table.js +++ b/migrations/001_create-image-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE image ( + CREATE TABLE images ( id UUID PRIMARY KEY, file TEXT, image BYTEA, @@ -12,6 +12,6 @@ export const up = (pgm) => { export const down = (pgm) => { pgm.sql(` - DROP TABLE image; + DROP TABLE images; `) } diff --git a/migrations/002_create-collection-table.js b/migrations/002_create-collection-table.js index 2ba94e2..fa29a28 100644 --- a/migrations/002_create-collection-table.js +++ b/migrations/002_create-collection-table.js @@ -1,18 +1,18 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE collection ( + CREATE TABLE collections ( id UUID PRIMARY KEY, name TEXT, image_id UUID, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW(), - FOREIGN KEY (image_id) REFERENCES image(id) + FOREIGN KEY (image_id) REFERENCES images(id) ); `) } export const down = (pgm) => { pgm.sql(` - DROP TABLE collection; + DROP TABLE collections; `) } diff --git a/migrations/003_create-item-table.js b/migrations/003_create-item-table.js index 4434ab7..75f88e1 100644 --- a/migrations/003_create-item-table.js +++ b/migrations/003_create-item-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE item ( + CREATE TABLE items ( id UUID PRIMARY KEY, collection_id UUID, image_id UUID, @@ -12,14 +12,14 @@ export const up = (pgm) => { extRarity TEXT, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW(), - FOREIGN KEY (collection_id) REFERENCES collection(id), - FOREIGN KEY (image_id) REFERENCES image(id) + FOREIGN KEY (collection_id) REFERENCES collections(id), + FOREIGN KEY (image_id) REFERENCES images(id) ); `) } export const down = (pgm) => { pgm.sql(` - DROP TABLE item; + DROP TABLE items; `) } diff --git a/migrations/004_create-location-table.js b/migrations/004_create-location-table.js index 6074cbf..3298635 100644 --- a/migrations/004_create-location-table.js +++ b/migrations/004_create-location-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE location ( + CREATE TABLE locations ( id UUID PRIMARY KEY, name TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT NOW(), @@ -11,6 +11,6 @@ export const up = (pgm) => { export const down = (pgm) => { pgm.sql(` - DROP TABLE location; + DROP TABLE locations; `) } diff --git a/migrations/005_create-set-table.js b/migrations/005_create-set-table.js index 117df2b..3c220f5 100644 --- a/migrations/005_create-set-table.js +++ b/migrations/005_create-set-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE set ( + CREATE TABLE sets ( id UUID PRIMARY KEY, collection_id UUID NOT NULL, name TEXT NOT NULL, @@ -8,15 +8,15 @@ export const up = (pgm) => { image_id UUID, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW(), - FOREIGN KEY (collection_id) REFERENCES collection(id), - FOREIGN KEY (location_id) REFERENCES location(id), - FOREIGN KEY (image_id) REFERENCES image(id) + FOREIGN KEY (collection_id) REFERENCES collections(id), + FOREIGN KEY (location_id) REFERENCES locations(id), + FOREIGN KEY (image_id) REFERENCES images(id) ); `) } export const down = (pgm) => { pgm.sql(` - DROP TABLE set; + DROP TABLE sets; `) } diff --git a/migrations/007_create-role-table.js b/migrations/006_create-role-table.js similarity index 83% rename from migrations/007_create-role-table.js rename to migrations/006_create-role-table.js index e516aab..52ef845 100644 --- a/migrations/007_create-role-table.js +++ b/migrations/006_create-role-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE role ( + CREATE TABLE roles ( id UUID PRIMARY KEY, name TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT NOW(), @@ -11,6 +11,6 @@ export const up = (pgm) => { export const down = (pmg) => { pgm.sql(` - DROP TABLE role; + DROP TABLE roles; `) } diff --git a/migrations/006_create-user-table.js b/migrations/007_create-user-table.js similarity index 77% rename from migrations/006_create-user-table.js rename to migrations/007_create-user-table.js index 49a69cc..1be04d5 100644 --- a/migrations/006_create-user-table.js +++ b/migrations/007_create-user-table.js @@ -1,6 +1,6 @@ export const up = (pgm) => { pgm.sql(` - CREATE TABLE user ( + CREATE TABLE users ( id UUID PRIMARY KEY, username TEXT UNIQUE NOT NULL, password TEXT NOT NULL, @@ -8,13 +8,13 @@ export const up = (pgm) => { email TEXT UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW(), - FOREIGN KEY (role_id) REFERENCES role(id) + FOREIGN KEY (role_id) REFERENCES roles(id) ); `) } export const down = (pgm) => { pgm.sql(` - DROP TABLE user; + DROP TABLE users; `) } -- 2.52.0 From 5384aadd7a3e1b1f3b065e6833f63ef98a5f3be1 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 13 May 2026 23:15:01 -0700 Subject: [PATCH 24/24] added a pre-hook to make sure things are linted before commits happen and fixed workflow --- .gitea/hooks/pre-commit | 20 ++++++++++++++++++++ .gitea/workflows/build.yaml | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 .gitea/hooks/pre-commit diff --git a/.gitea/hooks/pre-commit b/.gitea/hooks/pre-commit new file mode 100755 index 0000000..4b6a65f --- /dev/null +++ b/.gitea/hooks/pre-commit @@ -0,0 +1,20 @@ +#!/bin/bash + +# Check if the lint fix command fails +# If it does, exit with a non-zero status to prevent the commit. + +echo "Running lint fix..." +# Replace with your actual lint fix command +# This is just an example, adapt it to your linter and project +npm run lint:fix # e.g., "eslint . --fix" + +# Example: Capture the exit code of the command +lint_fix_result=$? + +if [ $lint_fix_result -ne 0 ]; then + echo "Linting failed. Commit aborted." + exit 1 # Exit with a non-zero status to prevent the commit +fi + +echo "Lint fix completed successfully. Commit allowed." +exit 0 # Exit with a zero status to allow the commit diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 6a96d10..cd24e97 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,7 +1,12 @@ name: Build and Push Image -on: [push] +on: + pull_request: + branches: + - main + types: [closed] jobs: build-and-push: + if: gitea.event.pull_request.merged == true runs-on: ubuntu-latest container: image: catthehacker/ubuntu:act-latest -- 2.52.0