mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
remove migration, update typeorm
This commit is contained in:
parent
1952844c80
commit
c9e04d1e6f
4712
backend/package-lock.json
generated
Normal file
4712
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@ import { isAuthorized } from './auth/auth'
|
||||
// TODO implement
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
|
||||
const DB_VERSION = '0002-update_user'
|
||||
const DB_VERSION = '0001-init_db'
|
||||
|
||||
const context = (args: any) => {
|
||||
const authorization = args.req.headers.authorization
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
|
||||
// import { Group } from "./Group"
|
||||
@Entity()
|
||||
@Entity('state_users')
|
||||
export class User extends BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
@ -9,16 +9,16 @@ export class User extends BaseEntity {
|
||||
// @ManyToOne(type => Group, group => group.users)
|
||||
// group: Group;
|
||||
|
||||
@Column({ type: 'binary', length: 32 })
|
||||
@Column({ type: 'binary', length: 32, name: 'public_key' })
|
||||
pubkey: Buffer
|
||||
|
||||
@Column()
|
||||
email: string
|
||||
|
||||
@Column()
|
||||
@Column({ name: 'first_name' })
|
||||
firstName: string
|
||||
|
||||
@Column()
|
||||
@Column({ name: 'last_name' })
|
||||
lastName: string
|
||||
|
||||
@Column()
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
/* FIRST MIGRATION
|
||||
*
|
||||
* This migration is special since it takes into account that
|
||||
* the database can be setup already but also may not be.
|
||||
* Therefore you will find all `CREATE TABLE` statements with
|
||||
* a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the
|
||||
* downgrade function all `DROP TABLE` with a `IF EXISTS`.
|
||||
* This ensures compatibility for existing or non-existing
|
||||
* databases.
|
||||
*/
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write upgrade logic as parameter of queryFn
|
||||
|
||||
// rename table
|
||||
await queryFn(`
|
||||
ALTER TABLE state_users
|
||||
RENAME TO user;
|
||||
`)
|
||||
// drop not used columns
|
||||
await queryFn(`
|
||||
ALTER TABLE user
|
||||
DROP COLUMN index_id;
|
||||
`)
|
||||
// rename from snake case to camel case (cakePHP standard to typeorm standard)
|
||||
await queryFn(`
|
||||
ALTER TABLE user
|
||||
CHANGE COLUMN group_id groupId int(10) unsigned NOT NULL DEFAULT '0',
|
||||
CHANGE COLUMN public_key pubkey binary(32) NOT NULL,
|
||||
CHANGE COLUMN first_name firstName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
CHANGE COLUMN last_name lastName varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL;
|
||||
`)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
// write downgrade logic as parameter of queryFn
|
||||
// rename table
|
||||
await queryFn(`
|
||||
ALTER TABLE user
|
||||
RENAME TO state_users;
|
||||
`)
|
||||
// put back dropped column
|
||||
await queryFn(`
|
||||
ALTER TABLE state_users
|
||||
ADD index_id smallint(6) NOT NULL DEFAULT '0';
|
||||
`)
|
||||
// rename from camel case to snake case (typeorm standard to cakePHP standard)
|
||||
await queryFn(`
|
||||
ALTER TABLE state_users
|
||||
CHANGE COLUMN groupId group_id int(10) unsigned NOT NULL DEFAULT '0',
|
||||
CHANGE COLUMN pubkey public_key binary(32) NOT NULL,
|
||||
CHANGE COLUMN firstName first_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
CHANGE COLUMN lastName last_name varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL;
|
||||
`)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user