Working base server with migrations and build steps ironed out #1

Merged
joseph.nelson4456 merged 24 commits from base-setup into main 2026-05-13 23:16:22 -07:00
4 changed files with 81 additions and 5 deletions
Showing only changes of commit e905899c60 - Show all commits
+14
View File
@@ -0,0 +1,14 @@
FROM node:24-alpine
ENV DB_HOST=<your_db_host>
ENV DB_USERNAME=<your_db_username>
ENV DB_PASSWORD=<your_db_password>
ENV DB_PORT=<your_db_port>
ENV DB_DATABASE=<your_db_database>
ARG CMD
WORKDIR /app
COPY . .
RUN npm install --force
CMD ["node", "run", "$CMD"]
+33
View File
@@ -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
}
},
}
+27
View File
@@ -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
}
},
}
+7 -5
View File
@@ -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)