Skip to content

Commit

Permalink
fix: migrations run on service bootstrap (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega authored Jul 24, 2024
1 parent a9b59fe commit e5e2510
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 425 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/manual-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Manual deployment

on:
workflow_dispatch:
inputs:
deployment-environment:
required: true
type: choice
options:
- prd
- dev
default: prd
description: Environment
tag:
required: true
default: "latest"
type: string
description: "Docker tag (quay.io)"

jobs:
deployment:
if: ${{ inputs.deployment-environment }}
name: "Deploy to: ${{ inputs.deployment-environment }}"
runs-on: ubuntu-latest
environment: ${{ inputs.deployment-environment }}
steps:
- name: Trigger deployment
id: deploy
uses: decentraland/dcl-deploy-action@main
with:
dockerImage: "quay.io/decentraland/events-notifier:${{ inputs.tag }}"
serviceName: "events-notifier"
env: ${{ inputs.deployment-environment }}
token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 18 additions & 1 deletion entrypoint.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ finish() {

trap finish SIGINT SIGQUIT SIGTERM

temp_migration_dir="./temp_migrations"
mkdir -p "$temp_migration_dir"

# Copy only .js migration files to the temporary directory
cp ./dist/migrations/*.js "$temp_migration_dir"

dbUser=$PG_COMPONENT_PSQL_USER
dbPassword=$PG_COMPONENT_PSQL_PASSWORD
dbHost=$PG_COMPONENT_PSQL_HOST
dbPort=$PG_COMPONENT_PSQL_PORT
dbDatabaseName=$PG_COMPONENT_PSQL_DATABASE

# Build the CONNECTION_STRING
export CONNECTION_STRING="postgres://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/${dbDatabaseName}"

echo "running migrations"
./node_modules/.bin/node-pg-migrate -m lib/migrations -d CONNECTION_STRING up
./node_modules/.bin/node-pg-migrate -m "$temp_migration_dir" -d CONNECTION_STRING up

rm -r "$temp_migration_dir"

echo "starting service..."
/usr/local/bin/node --trace-warnings --abort-on-uncaught-exception --unhandled-rejections=strict dist/index.js &
Expand Down
1 change: 1 addition & 0 deletions src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createLogComponent } from '@well-known-components/logger'
import { createSubgraphComponent } from '@well-known-components/thegraph-component'
import { createPgComponent } from '@well-known-components/pg-component'
import { createFetchComponent } from '@dcl/platform-server-commons'
import path from 'path'

Check warning on line 7 in src/components.ts

View workflow job for this annotation

GitHub Actions / build / validations

'path' is defined but never used. Allowed unused vars must match /^_/u

import { metricDeclarations } from './metrics'
import { AppComponents, GlobalContext } from './types'
Expand Down
14 changes: 0 additions & 14 deletions src/migrations/1720036664875_create_cursors_table.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/migrations/1721829390249_init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder } from 'node-pg-migrate'

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createTable('cursors', {
id: { type: 'varchar(255)', notNull: true, primaryKey: true },
last_successful_run_at: { type: 'bigint', notNull: false },
created_at: { type: 'bigint', notNull: true },
updated_at: { type: 'bigint', notNull: true }
})
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropTable('cursors')
}
Loading

0 comments on commit e5e2510

Please sign in to comment.