This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
+6
-6
@@ -5,14 +5,14 @@ import path from 'path'
|
|||||||
const migrate = require('node-pg-migrate')
|
const migrate = require('node-pg-migrate')
|
||||||
|
|
||||||
// Database connection configuration
|
// 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 = {
|
const dbConfig = {
|
||||||
user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user'
|
user: DB_USERNAME || 'your_user', // Use the environment variable if it exists, otherwise use 'your_user'
|
||||||
host: DB_HOST || 'localhost',
|
host: DB_HOST || 'localhost',
|
||||||
database: DB_DATABASE || 'your_database',
|
database: DB_DATABASE || 'your_database',
|
||||||
password: DB_PASSWORD || 'your_password',
|
password: DB_PASSWORD || 'your_password',
|
||||||
port: parseInt(DB_PORT, 10) || 5432, // Convert the environment variable to a number if it exists, otherwise use 5432
|
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 pool = new Pool(dbConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user