fixed things to be more inline with how migrations work
Build and Push Image / build-and-push (push) Failing after 24s

This commit is contained in:
2026-05-12 23:27:49 -07:00
parent 0d146bda6b
commit 569a41f053
11 changed files with 54 additions and 185 deletions
+1 -5
View File
@@ -25,11 +25,7 @@ jobs:
- name: Build and Push Image - name: Build and Push Image
run: | run: |
docker build \ docker build \
--build-arg DB_HOST=${{ secrets.DB_HOST }} \ --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} \
--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 }} . -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 push gitea.nelson-household.com/hard-at-work/tcg-collectors-server/tcg-collectors-server:${{ github.sha }}
+1 -5
View File
@@ -1,10 +1,6 @@
FROM node:24-alpine FROM node:24-alpine
ENV DB_HOST=<your_db_host> ENV DATABASE_URL=<the database url>
ENV DB_USERNAME=<your_db_username>
ENV DB_PASSWORD=<your_db_password>
ENV DB_PORT=<your_db_port>
ENV DB_DATABASE=<your_db_database>
WORKDIR /app WORKDIR /app
COPY . . COPY . .
+9 -15
View File
@@ -1,20 +1,14 @@
export default { export const up = (pgm) => {
name: 'create_collection_table', pgm.sql(`
up: async () => {
const sql = `
CREATE TABLE collection ( CREATE TABLE collection (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
name TEXT name TEXT
); );
` `)
await migrate.run([sql], pool) }
console.log('Collection table created successfully!')
}, export const down = (pgm) => {
down: async () => { pgm.sql(`
const sql = ` DROP TABLE collection;
DROP TABLE collection; `)
`
await migrate.run([sql], pool)
console.log('Collection table dropped successfully.')
},
} }
+9 -15
View File
@@ -1,21 +1,15 @@
export default { export const up = (pgm) => {
name: 'create_image_table', pgm.sql(`
up: async () => {
const sql = `
CREATE TABLE image ( CREATE TABLE image (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
file TEXT, file TEXT,
image BYTEA image BYTEA
); );
` `)
await migrate.run([sql], pool) }
console.log('Image table created successfully!')
}, export const down = (pgm) => {
down: async () => { pgm.sql(`
const sql = ` DROP TABLE image;
DROP TABLE image; `)
`
await migrate.run([sql], pool)
console.log('Image table dropped successfully.')
},
} }
+6 -19
View File
@@ -1,8 +1,5 @@
export default { export const up = (pgm) => {
up: async (pool) => { pgm.sql(`
try {
await pool.query(
`
CREATE TABLE item ( CREATE TABLE item (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
collection_id UUID, collection_id UUID,
@@ -16,21 +13,11 @@ export default {
FOREIGN KEY (collection_id) REFERENCES collection(id), FOREIGN KEY (collection_id) REFERENCES collection(id),
FOREIGN KEY (image_id) REFERENCES image(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) => { export const down = (pgm) => {
try { pgm.sql(`
await pool.query(`
DROP TABLE item; DROP TABLE item;
`) `)
} catch (error) {
console.error('Error dropping item table:', error)
throw error
}
},
} }
+5 -19
View File
@@ -1,28 +1,14 @@
export default { export const up = (pgm) => {
up: async (pool) => { pgm.sql(`
try {
await pool.query(
`
CREATE TABLE location ( CREATE TABLE location (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
name TEXT UNIQUE NOT NULL name TEXT UNIQUE NOT NULL
); );
` `)
)
} catch (error) {
console.error('Error creating location table:', error)
throw error
} }
},
down: async (pool) => { export const down = (pgm) => {
try { pgm.sql(`
await pool.query(`
DROP TABLE location; DROP TABLE location;
`) `)
} catch (error) {
console.error('Error dropping location table:', error)
throw error
}
},
} }
+5 -19
View File
@@ -1,8 +1,5 @@
export default { export const up = (pgm) => {
up: async (pool) => { pgm.sql(`
try {
await pool.query(
`
CREATE TABLE set ( CREATE TABLE set (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
collection_id UUID NOT NULL, collection_id UUID NOT NULL,
@@ -13,22 +10,11 @@ export default {
FOREIGN KEY (collection_id) REFERENCES collection(id), FOREIGN KEY (collection_id) REFERENCES collection(id),
FOREIGN KEY (location_id) REFERENCES location(id) FOREIGN KEY (location_id) REFERENCES location(id)
); );
` `)
)
} catch (error) {
console.error('Error creating set table:', error)
throw error
} }
},
down: async (pool) => { export const down = (pgm) => {
try { pgm.sql(`
await pool.query(`
DROP TABLE set; DROP TABLE set;
`) `)
} catch (error) {
console.error('Error dropping set table:', error)
throw error
}
},
} }
+6 -19
View File
@@ -1,8 +1,5 @@
export default { export const up = (pgm) => {
up: async (pool) => { pgm.sql(`
try {
await pool.query(
`
CREATE TABLE user ( CREATE TABLE user (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
username TEXT UNIQUE NOT NULL, username TEXT UNIQUE NOT NULL,
@@ -13,21 +10,11 @@ export default {
updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updatedAt TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (role_id) REFERENCES role(id) FOREIGN KEY (role_id) REFERENCES role(id)
); );
` `)
)
} catch (error) {
console.error('Error creating user table:', error)
throw error
} }
},
down: async (pool) => { export const down = (pgm) => {
try { pgm.sql(`
await pool.query(`
DROP TABLE user; DROP TABLE user;
`) `)
} catch (error) {
console.error('Error dropping user table:', error)
throw error
}
},
} }
+6 -19
View File
@@ -1,27 +1,14 @@
export default { export const up = (pgm) => {
up: async (pool) => { pgm.sql(`
try {
await pool.query(
`
CREATE TABLE role ( CREATE TABLE role (
id UUID PRIMARY KEY, id UUID PRIMARY KEY,
name TEXT UNIQUE NOT NULL name TEXT UNIQUE NOT NULL
); );
` `)
)
} catch (error) {
console.error('Error creating role table:', error)
throw error
} }
},
down: async (pool) => { export const down = (pmg) => {
try { pgm.sql(`
await pool.query(`
DROP TABLE role; DROP TABLE role;
`) `)
} catch (error) {
console.error('Error dropping role table:', error)
throw error
}
},
} }
-44
View File
@@ -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()
+1 -1
View File
@@ -9,7 +9,7 @@
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"format": "prettier --config prettier.config.js --write .", "format": "prettier --config prettier.config.js --write .",
"migrate": "node ./migrations/index.js" "migrate": "node-pg-migrate"
}, },
"type": "module", "type": "module",
"keywords": [ "keywords": [