Add migrations

This commit is contained in:
Amit Jakubowicz 2019-08-01 09:53:33 +02:00
parent f154591130
commit 1b8f1b820c
16 changed files with 37 additions and 48 deletions

View file

@ -13,5 +13,5 @@ deploy_staging:
- apt-get update
- apt-get install -y node docker
- (cd server; yarn build)
- (cd client; yarn build)
- docker build -t registry.gitlab.com/amiiit/gcf-auth:$CI_COMMIT_SHA .
- docker build -t eu.gcr.io/qpa-staging-237606/qpa:$CI_COMMIT_TAG .
- docker push eu.gcr.io/qpa-staging-237606/qpa:$CI_COMMIT_TAG

0
client/Dockerfile.client Normal file
View file

View file

@ -48,7 +48,7 @@ spec:
spec:
containers:
- name: master
image: eu.gcr.io/qpa-staging-237606/qpa:0.0.1
image: eu.gcr.io/qpa-staging-237606/qpa:0.0.4
resources:
requests:
cpu: 100m

View file

@ -18,6 +18,7 @@
"codegen": "gql2ts ./schema.graphql -o ./@types/graphql.d.ts",
"ssr": "(cd client; yarn ssr)",
"server": "(cd server; yarn start)",
"server-build": "(rm -r ./server/lib; cd server; yarn build)",
"client": "(cd client; yarn start)",
"prod-server": "(cd server; yarn prod-server)"
},

View file

@ -15,15 +15,10 @@ RUN apt-get install -y nginx
# application
RUN mkdir /opt/server
RUN mkdir /opt/client
COPY ./server/lib ./opt/server
COPY ./server/package.json /opt/server
COPY ./lib ./opt/server
COPY ./package.json /opt/server
COPY ./client/dist ./opt/client
COPY ./client/package.json ./opt/client
RUN (cd /opt/client; npm install)
RUN (cd /opt/server; npm install)
WORKDIR /opt

View file

@ -1,20 +0,0 @@
// import {MigrationInterface, QueryRunner} from "typeorm"
// import {EventOccurrence} from "../src/Calendar/Event.entity"
//
// export class bla1556696716003 implements MigrationInterface {
//
// // public async up(queryRunner: QueryRunner): Promise<any> {
// // const ox = await EventOccurrence.find({take: 1})
// // console.log('ox', ox.length, ox)
// // ox.forEach(async occ => {
// // occ.during = `[${occ.utcStart.toISOString()},${occ.utcEnd.toISOString()}]`
// // console.log('will save during', occ.during)
// // await occ.save()
// // })
// // }
// //
// // public async down(queryRunner: QueryRunner): Promise<any> {
// // await queryRunner.query(`ALTER TABLE "event_occurrence" DROP COLUMN "during"`)
// // }
//
// }

View file

@ -1,11 +1,11 @@
import { createTestClient } from 'apollo-server-testing'
import {createServer } from "../../graphql"
import {Connection, createConnection} from "typeorm"
import {testConfig} from "../../../ormconfig"
import gql from "graphql-tag"
import {PostOffice, sendEmail} from "../../post_office"
import {User} from "../User.entity"
import {SessionInvite} from "../Session.entity"
import testConfig from "../../__tests__/testORMConfig"
jest.setTimeout(10000)

View file

@ -1,12 +1,12 @@
import {createTestClient} from 'apollo-server-testing'
import {createServer} from "../../graphql"
import {Connection, createConnection} from "typeorm"
import {testConfig} from "../../ormconfig"
import gql from "graphql-tag"
import {PostOffice, sendEmail} from "../../post_office"
import {User} from "../User.entity"
import {Session, SessionInvite} from "../Session.entity"
import SessionManager from "../SessionManager"
import testConfig from "../../__tests__/testORMConfig"
jest.setTimeout(10000)

View file

@ -1,8 +1,8 @@
import { testConfig } from "../../../ormconfig"
import { createConnection } from "typeorm"
import { User } from "../../Auth/User.entity"
import { Event, EventInformation, EventOccurrence } from "../Event.entity"
import { DateTime } from "luxon"
import testConfig from "../../__tests__/testORMConfig";
const toUTC = (isoTime: string, ianaTZ: string) => {
const parsed = DateTime.fromISO(isoTime, { zone: ianaTZ })

View file

@ -1,8 +1,8 @@
import gql from 'graphql-tag'
import eventResolvers from '../eventsResolvers'
import {testConfig} from "../../../ormconfig"
import {User} from "../../Auth/User.entity"
import { createConnection } from "typeorm"
import testConfig from "../../__tests__/testORMConfig"
const mutation = gql`
mutation {

View file

@ -1,4 +1,3 @@
import { testConfig } from "../../../ormconfig"
import { Connection, createConnection } from "typeorm"
import { createServer } from "../../graphql"
import { PostOffice } from "../../post_office"
@ -7,6 +6,7 @@ import { User } from "../../Auth/User.entity"
import { Session } from "../../Auth/Session.entity"
import { Event, EventInformation } from "../../Calendar/Event.entity"
import gql from "graphql-tag"
import testConfig from "../../__tests__/testORMConfig"
let testClient
let connection: Connection = null

View file

@ -2,8 +2,8 @@ import {User} from "../../Auth/User.entity"
import {Session} from "../../Auth/Session.entity"
import {Event, EventInformation, toUTC} from "../../Calendar/Event.entity"
import {Frequency, RRule} from 'rrule'
import {testConfig} from "../../../ormconfig"
import {Connection, createConnection} from "typeorm"
import testConfig from "../../__tests__/testORMConfig";
let connection: Connection = null

View file

@ -0,0 +1,10 @@
import config from '../ormconfig'
import {ConnectionOptions} from "typeorm"
export const testConfig: ConnectionOptions = {
...config,
database: 'qpa-test',
dropSchema: true
}
export default testConfig

View file

@ -14,8 +14,12 @@ const start = async () => {
})
console.log(`Starting with db: ${typeormConfig.database} and config:\n ${JSON.stringify(typeormConfig,null,'\t')}`)
const connection = await createConnection(typeormConfig)
console.log('Will look for migrations and run them')
await connection.runMigrations()
console.log('No more migrations to run')
const server = await createServer({
typeormConnection: await createConnection(typeormConfig),
typeormConnection: connection,
sendEmail,
domain: config.domain,
sessionManager

View file

@ -1,6 +1,6 @@
import {ConnectionOptions} from 'typeorm'
import {PostgresConnectionOptions} from "typeorm/driver/postgres/PostgresConnectionOptions"
const config: ConnectionOptions = {
const config: PostgresConnectionOptions = {
type: 'postgres',
host: process.env.POSTGRES_HOST || 'localhost',
port: Number(process.env.POSTGRES_PORT || 5432),
@ -8,15 +8,13 @@ const config: ConnectionOptions = {
username: process.env.DB_USER || null,
password: process.env.DB_PASSWORD || null,
entities: ["src/**/*.entity.ts"],
migrations: ["migrations/*.js"],
logging: true,
synchronize: true,
logger: 'debug'
logger: 'debug',
cli: {
migrationsDir: "migrations"
}
}
export const testConfig: ConnectionOptions = {
...config,
database: 'qpa-test',
dropSchema: true
}
export default config
export = config

View file

@ -15,7 +15,8 @@
},
"compileOnSave": true,
"include": [
"src"
"src",
"migrations"
],
"files": [
"../@types/index.d.ts", "../node_modules/@types/node/ts3.2/index.d.ts"