Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Mar 21, 2023
0 parents commit 503f2ed
Show file tree
Hide file tree
Showing 20 changed files with 6,500 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
APP_ENV=dev
COOKIE_SECRET=vno64218hua
SUPERADMIN_USERNAME=superadmin
SUPERADMIN_PASSWORD=superadmin
DB_HOST=localhost
DB_PORT=5432
DB_NAME=v2-migration-testbed
DB_USERNAME=admin
DB_PASSWORD=secret
DB_SCHEMA=public
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
static/assets
static/email/test-emails
.idea
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:16

WORKDIR /usr/src/app

COPY package.json ./
COPY yarn.lock ./
RUN yarn --production
COPY . .
RUN yarn build
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Vendure v2 Migration Testbed

This repo is being used to test migration of a Vendure v1 project to v2.

## Setup

You'll need a local postgres instance running, with a database named `v2-migration-testbed`. Adjust the
credentials in the `.env` file as needed.

## Test Sequence

1. With v1.x installed, run `yarn populate`.
2. Run `yarn test` to run the tests against v1.x.
3. Now update all Vendure packages to v2.x.
4. Run `yarn migrate` to run the migrations.
5. Run `yarn test` to run the tests against v2.x.
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3"
services:
server:
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
command: ["yarn", "start:server"]
volumes:
- /usr/src/app
environment:
DB_HOST: database
DB_PORT: 5432
DB_NAME: vendure
DB_USERNAME: postgres
DB_PASSWORD: password
worker:
build:
context: .
dockerfile: Dockerfile
command: ["yarn", "start:worker"]
volumes:
- /usr/src/app
environment:
DB_HOST: database
DB_PORT: 5432
DB_NAME: vendure
DB_USERNAME: postgres
DB_PASSWORD: password
database:
image: postgres
volumes:
- /var/lib/postgresql/data
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: password
POSTGRES_DB: vendure
27 changes: 27 additions & 0 deletions migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { generateMigration, revertLastMigration, runMigrations } from '@vendure/core';
import program from 'commander';

import { config } from './src/vendure-config';

program
.command('generate <name>')
.description('Generate a new migration file with the given name')
.action(name => {
return generateMigration(config, { name, outputDir: './src/migrations' });
});

program
.command('run')
.description('Run all pending migrations')
.action(() => {
return runMigrations(config);
});

program
.command('revert')
.description('Revert the last applied migration')
.action(() => {
return revertLastMigration(config);
});

program.parse(process.argv);
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "v2-migration-testbed",
"version": "0.1.0",
"private": true,
"scripts": {
"dev:server": "ts-node ./src/index.ts",
"dev:worker": "ts-node ./src/index-worker.ts",
"dev": "concurrently yarn:dev:*",
"build": "tsc",
"start:server": "node ./dist/index.js",
"start:worker": "node ./dist/index-worker.js",
"start": "concurrently yarn:start:*",
"migration:generate": "ts-node migration generate",
"migration:run": "ts-node migration run",
"migration:revert": "ts-node migration revert",
"populate": "ts-node ./src/populate.ts"
},
"dependencies": {
"@vendure/admin-ui-plugin": "1.9.3",
"@vendure/asset-server-plugin": "1.9.3",
"@vendure/core": "1.9.3",
"@vendure/email-plugin": "1.9.3",
"dotenv": "16.0.3",
"pg": "8.10.0",
"typescript": "4.3.5"
},
"devDependencies": {
"@vendure/create": "^1.9.3",
"concurrently": "7.6.0",
"ts-node": "10.9.1"
}
}
20 changes: 20 additions & 0 deletions src/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export {};

// Here we declare the members of the process.env object, so that we
// can use them in our application code in a type-safe manner.
declare global {
namespace NodeJS {
interface ProcessEnv {
APP_ENV: string;
COOKIE_SECRET: string;
SUPERADMIN_USERNAME: string;
SUPERADMIN_PASSWORD: string;
DB_HOST: string;
DB_PORT: number;
DB_NAME: string;
DB_USERNAME: string;
DB_PASSWORD: string;
DB_SCHEMA: string;
}
}
}
8 changes: 8 additions & 0 deletions src/index-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { bootstrapWorker } from '@vendure/core';
import { config } from './vendure-config';

bootstrapWorker(config)
.then(worker => worker.startJobQueue())
.catch(err => {
console.log(err);
});
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { bootstrap, runMigrations } from '@vendure/core';
import { config } from './vendure-config';

runMigrations(config)
.then(() => bootstrap(config))
.catch(err => {
console.log(err);
});
Loading

0 comments on commit 503f2ed

Please sign in to comment.