fixed things to be more inline with how migrations work
Build and Push Image / build-and-push (push) Failing after 24s
Build and Push Image / build-and-push (push) Failing after 24s
This commit is contained in:
@@ -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;
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user