From e905899c60462d6d709ccd47ae1ffe450fde96f8 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Sun, 10 May 2026 22:38:25 -0700 Subject: [PATCH] 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)