Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ services:
- .env
volumes:
- pg_data:/var/lib/postgresql
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql:Z

valkey:
container_name: outfiter_valkey
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ services:
- .env
volumes:
- pg_data:/var/lib/postgresql
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql:Z

valkey:
container_name: valkey
Expand Down
6 changes: 2 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

set -e

# Import environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
# Since the DATABASE_URL en var is constructed using other en vars, we need to export it here to account for overrides from docker-compose
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"

mkdir -p /app/assets/{profile_pictures,clothing_item,publication}

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@types/colorthief": "^2.6.0",
"@types/jsonwebtoken": "^9.0.10",
"@types/nodemailer": "^7.0.5",
"@types/pg": "^8.16.0",
"@types/qrcode": "^1.5.6",
"@types/speakeasy": "^2.0.10",
"bits-ui": "^2.15.4",
Expand Down Expand Up @@ -80,7 +79,6 @@
"iovalkey": "^0.3.3",
"jsonwebtoken": "^9.0.3",
"nodemailer": "^7.0.12",
"pg": "^8.16.3",
"qrcode": "^1.5.4",
"sharp": "^0.34.5",
"speakeasy": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/db/makeAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// -- regular user into an admin --
// -----------------------------------

import pool from './pool.ts';
import { sql } from 'bun';

if (Bun.argv.length !== 3) {
throw new Error('Usage: bun run db:make-admin <USERNAME>');
}

const username = Bun.argv[2];

await pool.query("UPDATE users SET role = 'admin' WHERE username = $1", [username]);
await sql`UPDATE users SET role = 'admin' WHERE username = ${username}`;

console.log(`Made user ${username} an admin!`);
process.exit(0);
44 changes: 13 additions & 31 deletions scripts/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,31 @@
// -- already been done. --
// ---------------------------------------------------------

import pool from './pool.ts';
import { HERE } from '../shared.ts';
import { readdir, readFile } from 'node:fs/promises';
import { readdir } from 'node:fs/promises';
import { join } from 'node:path';
import { sql } from 'bun';

const getLastMigrationDate = async (): Promise<Date> => {
const { rows } = await pool.query<{ created_at: string }>(
'SELECT created_at FROM migrations ORDER BY created_at DESC LIMIT 1'
);
return rows.length > 0 ? new Date(rows[0].created_at) : new Date(0);
const initScriptPath = join(HERE, `../sql/migrations/init.sql`);
await sql.file(initScriptPath);

const getAppliedMigrations = async (): Promise<Set<string>> => {
const rows = await sql<{ name: string }[]>`SELECT name FROM migrations`;
return new Set(rows.map((row) => row.name));
};

async function applyMigration(name: string) {
const migrationPath = join(HERE, `../sql/migrations/${name}`);
const sql = await readFile(migrationPath, 'utf8');
if (!sql) {
throw new Error(`Migration file ${name} not found.`);
}
const migrationSQL = await pool.query(sql);
await sql.file(migrationPath);
const timeStamp = name.match(/migration\.(\d+)\.sql/);
const migrationTime = new Date(parseInt(timeStamp![1], 10));
// Update migrations table
await pool.query('INSERT INTO migrations (name, created_at) VALUES ($1, $2)', [
name,
migrationTime,
]);
await sql`INSERT INTO migrations (name, created_at) VALUES (${name}, ${migrationTime})`;
console.log(`Migration ${name} applied successfully.`);
return migrationSQL;
}

const lastMigrationDate = await getLastMigrationDate();
if (lastMigrationDate) {
console.log(`Last migration: ${lastMigrationDate}`);
} else {
console.log('No previous migrations found.');
}
const appliedMigrations = await getAppliedMigrations();
console.log(`Applied migrations: ${appliedMigrations.size}`);

const availableMigrations = (await readdir(join(HERE, '../sql/migrations')))
.filter((f) => f.match(/migration\.(\d+)\.sql/))
Expand All @@ -50,14 +39,7 @@ const availableMigrations = (await readdir(join(HERE, '../sql/migrations')))
return timeA - timeB;
});

const newMigrations = availableMigrations
.filter((file) => {
const timeStamp = file.match(/migration\.(\d+)\.sql/);
if (!timeStamp) return false;
const migrationTime = new Date(parseInt(timeStamp[1], 10));
return !lastMigrationDate || migrationTime > lastMigrationDate;
})
.sort();
const newMigrations = availableMigrations.filter((file) => !appliedMigrations.has(file));
console.log(`Available migrations: ${availableMigrations.length}`);
console.log(`New migrations to apply: ${newMigrations.length}`);

Expand Down
26 changes: 0 additions & 26 deletions scripts/db/pool.ts

This file was deleted.

Binary file removed sql/assets.zip
Binary file not shown.
Loading