Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Sequelize #5

Merged
merged 1 commit into from
Oct 24, 2023
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
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