From 0601c41f464b4128d29f383f7e81422cd83d6d67 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Tue, 12 May 2026 22:28:51 -0700 Subject: [PATCH] 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)