migration 20

This commit is contained in:
Ulf Gebhardt 2022-02-07 04:56:19 +01:00
parent a1f73514dd
commit c0156d4a29
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
3 changed files with 108 additions and 1 deletions

View File

@ -0,0 +1,68 @@
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
import { UserSetting } from '../UserSetting'
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
export class User extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true })
id: number
@Column({ name: 'public_key', type: 'binary', length: 32, default: null, nullable: true })
pubKey: Buffer
@Column({ name: 'privkey', type: 'binary', length: 80, default: null, nullable: true })
privKey: Buffer
@Column({ length: 255, unique: true, nullable: false, collation: 'utf8mb4_unicode_ci' })
email: string
@Column({
name: 'first_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
firstName: string
@Column({
name: 'last_name',
length: 255,
nullable: true,
default: null,
collation: 'utf8mb4_unicode_ci',
})
lastName: string
@Column({ type: 'bool', default: false })
disabled: boolean
@Column({ type: 'bigint', default: 0, unsigned: true })
password: BigInt
@Column({ name: 'email_hash', type: 'binary', length: 32, default: null, nullable: true })
emailHash: Buffer
@Column({ name: 'created', default: () => 'CURRENT_TIMESTAMP', nullable: false })
createdAt: Date
@Column({ name: 'email_checked', type: 'bool', nullable: false, default: false })
emailChecked: boolean
@Column({ length: 4, default: 'de', collation: 'utf8mb4_unicode_ci', nullable: false })
language: string
@Column({ name: 'publisher_id', default: 0 })
publisherId: number
@Column({
type: 'text',
name: 'passphrase',
collation: 'utf8mb4_unicode_ci',
nullable: true,
default: null,
})
passphrase: string
@OneToMany(() => UserSetting, (userSetting) => userSetting.user)
settings: UserSetting[]
}

View File

@ -1 +1 @@
export { User } from './0019-replace_login_user_id_with_state_user_id/User'
export { User } from './0020-rename_and_clean_state_users/User'

View File

@ -0,0 +1,39 @@
/* MIGRATION TO CLEAN UP AND RENAME STATE_USERS
*
* This migration renames 'state_users` to `users`
* and removes columns with no meaningful value
*/
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// rename `state_users` table to `users`
await queryFn('RENAME TABLE `state_users` TO `users`;')
// Remove the column `index_id` from `users`, it only contains 0 as value
await queryFn('ALTER TABLE `users` DROP COLUMN `index_id`;')
// Remove the column `username` from `users`, it contains only '' or NULL
await queryFn('ALTER TABLE `users` DROP COLUMN `username`;')
// Remove the column `description` from `users`, it contains only '' or NULL
await queryFn('ALTER TABLE `users` DROP COLUMN `description`;')
// Remove the column `passphrase_shown` from `users`, it contains only 0 as value
await queryFn('ALTER TABLE `users` DROP COLUMN `passphrase_shown`;')
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(
'ALTER TABLE `users` ADD COLUMN `passphrase_shown` tinyint(4) NOT NULL DEFAULT 0 AFTER `email_checked`;',
)
await queryFn(
"ALTER TABLE `users` ADD COLUMN `description` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT '' AFTER `disabled`;",
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL AFTER `last_name`;',
)
await queryFn(
'ALTER TABLE `users` ADD COLUMN `index_id` smallint(6) NOT NULL DEFAULT 0 AFTER `id`;',
)
await queryFn('RENAME TABLE `users` TO `state_users`;')
}