Skip to content

Commit

Permalink
Merge pull request #5 from pvcy/jc/run-migration
Browse files Browse the repository at this point in the history
Run Sequelize
  • Loading branch information
john-craft authored Oct 24, 2023
2 parents 704d1e8 + 6b71a4e commit 4ccba8c
Show file tree
Hide file tree
Showing 8 changed files with 1,255 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and Push Container Image
on:
pull_request:
push:
branches: [ main ]
jobs:
build-and-push:
Expand Down
27 changes: 18 additions & 9 deletions .github/workflows/test-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
env:
GCP_PROEJCT_ID: "database-migration-anonymized"
DB_HOST: "users-db"
POSTGRES_PASSWORD: "dMVZFeBWLOzYRV71"
DB_USERNAME: "postgres"
POSTGRES_DB: "postgres"
DB_BACKUP_URL: "https://storage.googleapis.com/anonymize-db-backups/us-west1/backup.sql"

steps:
- name: Checkout code
Expand All @@ -36,16 +40,20 @@ jobs:
docker pull gcr.io/$GCP_PROEJCT_ID/$DB_HOST:latest
- name: Start PostgreSQL container
env:
POSTGRES_PASSWORD: ${DB_PASSWORD:-dMVZFeBWLOzYRV71}
POSTGRES_DB: "postgres"
run: |
docker run -d --name $DB_HOST -e POSTGRES_PASSWORD=$DB_PASSWORD: -e POSTGRES_DB=$POSTGRES_DB -p 5432:5432 gcr.io/$GCP_PROEJCT_ID/$DB_HOST:latest
docker run -d --name $DB_HOST \
-e POSTGRES_USER=$DB_USERNAME \
-e POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
-e POSTGRES_DB=$POSTGRES_DB \
-e RESTORE_FROM_BACKUP=True \
-e DB_BACKUP_URL=$DB_BACKUP_URL \
-p 5432:5432 \
gcr.io/$GCP_PROEJCT_ID/$DB_HOST:latest
- name: Install Sequelize CLI and dependencies
run: |
npm install sequelize-cli
npm install # Assuming you have package.json with necessary dependencies
cd ./users-api/src
npm install
- name: Wait for Postgres to be ready
run: |
Expand All @@ -55,9 +63,10 @@ jobs:
sleep 10
done
# - name: Run Sequelize migrations
# run: |
# npx sequelize-cli db:migrate --config path-to-your-sequelize-config
- name: Run Sequelize migrations
run: |
cd ./users-api/src
npx sequelize-cli db:migrate
- name: Cleanup
run: docker stop $DB_HOST
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.env
9 changes: 9 additions & 0 deletions users-api/src/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
development: {
username: process.env.DB_USERNAME,
password: process.env.POSTGRES_PASSWORD,
database: process.env.POSTGRES_DB,
host: 'localhost', // process.env.DB_HOST ||
dialect: 'postgres',
},
};
23 changes: 0 additions & 23 deletions users-api/src/config/config.json

This file was deleted.

14 changes: 7 additions & 7 deletions users-api/src/migrations/20230921200634-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ module.exports = {
type: Sequelize.STRING
},
last_name: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
phone: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
city: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
state: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
zip: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
gender: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
},
age: {
type: DataTypes.INTEGER,
type: Sequelize.INTEGER,
allowNull: false,
}
});
Expand Down
Loading

0 comments on commit 4ccba8c

Please sign in to comment.