wooork
This commit is contained in:
parent
e7674d409e
commit
c2bd8a5a08
4 changed files with 77 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ COPY --from=builder /app/src ./src
|
|||
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
RUN chown -R nextjs:nodejs /app/public
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
|
@ -38,4 +39,4 @@ EXPOSE 3001
|
|||
ENV PORT=3001
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["sh", "-c", "node --import tsx/esm /app/node_modules/payload/dist/bin/index.js migrate && node server.js"]
|
||||
CMD ["node", "server.js"]
|
||||
21
scripts/README.md
Normal file
21
scripts/README.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# 1. Exec into the app container
|
||||
docker exec -it $(docker ps | grep portfolio-web | awk '{print $1}') sh
|
||||
|
||||
# 2. Write and run the migration
|
||||
cat > /tmp/migrate.ts << 'EOF'
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import pg from 'pg'
|
||||
|
||||
async function main() {
|
||||
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
||||
const { up } = await import('/app/src/migrations/20260521_173007.ts')
|
||||
console.log('running migration...')
|
||||
await up({ db: drizzle(pool) })
|
||||
console.log('done')
|
||||
await pool.end()
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
EOF
|
||||
|
||||
DATABASE_URL=postgresql://postgres:TrojanHero1@portfolio-portfoliodb-22lpk0:5432/postgres node_modules/.bin/tsx /tmp/migrate.ts
|
||||
33
scripts/migrate.sh
Normal file
33
scripts/migrate.sh
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
# Run this from the VPS when you need to manually run migrations
|
||||
# Usage: bash scripts/migrate.sh
|
||||
|
||||
NETWORK=$(docker inspect $(docker ps | grep portfoliodb | awk '{print $1}' | head -1) --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}}{{end}}')
|
||||
APP_IMAGE=$(docker images | grep portfolio-web | awk '{print $1}' | head -1)
|
||||
|
||||
docker run --rm \
|
||||
--network $NETWORK \
|
||||
-e DATABASE_URL=postgresql://postgres:TrojanHero1@portfolio-portfoliodb-22lpk0:5432/postgres \
|
||||
-e PAYLOAD_SECRET=n8Kj2vR5pL9mQx7tY3wE6bZ1aD4sF0hU9cV2xB5nM8pL1q \
|
||||
$APP_IMAGE \
|
||||
sh -c "cat > /tmp/migrate.ts << 'EOF'
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import pg from 'pg'
|
||||
|
||||
async function main() {
|
||||
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
||||
const migrations = await import('/app/src/migrations/index.ts')
|
||||
console.log('running migrations...')
|
||||
for (const [name, migration] of Object.entries(migrations)) {
|
||||
if (typeof migration === 'function') {
|
||||
console.log('running:', name)
|
||||
await migration({ db: drizzle(pool) })
|
||||
}
|
||||
}
|
||||
console.log('done')
|
||||
await pool.end()
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
EOF
|
||||
node_modules/.bin/tsx /tmp/migrate.ts"
|
||||
21
scripts/migrate.ts
Normal file
21
scripts/migrate.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import pg from 'pg'
|
||||
import * as migrations from './src/migrations/index.ts'
|
||||
|
||||
async function main() {
|
||||
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
||||
const db = drizzle(pool)
|
||||
|
||||
for (const [name, fn] of Object.entries(migrations)) {
|
||||
if (typeof fn === 'function' && name === 'up') continue
|
||||
if (typeof fn === 'function') {
|
||||
console.log(`running: ${name}`)
|
||||
await fn({ db })
|
||||
}
|
||||
}
|
||||
|
||||
console.log('all migrations done')
|
||||
await pool.end()
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Loading…
Add table
Reference in a new issue