mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1960 from gradido/1948-delete-settings-animationcoin-in-database
refactor: 🍰 Delete `user_setting` Table From DB
This commit is contained in:
commit
7860abb6ef
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0036-unique_previous_in_transactions',
|
||||
DB_VERSION: '0037-drop_server_user_table',
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
import { EntityRepository, Repository } from '@dbTools/typeorm'
|
||||
import { UserSetting } from '@entity/UserSetting'
|
||||
import { isStringBoolean } from '@/util/validate'
|
||||
|
||||
@EntityRepository(UserSetting)
|
||||
export class UserSettingRepository extends Repository<UserSetting> {
|
||||
async setOrUpdate(userId: number, value: string): Promise<UserSetting> {
|
||||
let entity = await this.findOne({ userId: userId })
|
||||
|
||||
if (!entity) {
|
||||
entity = new UserSetting()
|
||||
entity.userId = userId
|
||||
}
|
||||
entity.value = value
|
||||
return this.save(entity)
|
||||
}
|
||||
|
||||
async readBoolean(userId: number): Promise<boolean> {
|
||||
const entity = await this.findOne({ userId: userId })
|
||||
if (!entity || !isStringBoolean(entity.value)) {
|
||||
return true
|
||||
}
|
||||
return entity.value.toLowerCase() === 'true'
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,6 @@ const communityDbUser: dbUser = {
|
||||
isAdmin: null,
|
||||
publisherId: 0,
|
||||
passphrase: '',
|
||||
settings: [],
|
||||
hasId: function (): boolean {
|
||||
throw new Error('Function not implemented.')
|
||||
},
|
||||
|
||||
@ -1,32 +1,39 @@
|
||||
# database
|
||||
|
||||
## Project setup
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn install
|
||||
```
|
||||
|
||||
## Upgrade migrations production
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn up
|
||||
```
|
||||
|
||||
## Upgrade migrations development
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn dev_up
|
||||
```
|
||||
|
||||
## Downgrade migrations production
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn down
|
||||
```
|
||||
|
||||
## Downgrade migrations development
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn dev_down
|
||||
```
|
||||
|
||||
## Reset database
|
||||
```
|
||||
|
||||
```bash
|
||||
yarn dev_reset
|
||||
```
|
||||
|
||||
Runs all down migrations and after this all up migrations.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
// Moriz: I do not like the idea of having two user tables
|
||||
@Entity('state_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm'
|
||||
import { User } from '../User'
|
||||
import { User } from '../0034-drop_server_user_table/User'
|
||||
|
||||
@Entity()
|
||||
export class UserSetting extends BaseEntity {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('state_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('state_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('state_users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
OneToMany,
|
||||
DeleteDateColumn,
|
||||
} from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
OneToMany,
|
||||
DeleteDateColumn,
|
||||
} from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
@ -6,7 +6,7 @@ import {
|
||||
OneToMany,
|
||||
DeleteDateColumn,
|
||||
} from 'typeorm'
|
||||
import { UserSetting } from '../UserSetting'
|
||||
import { UserSetting } from '../0002-add_settings/UserSetting'
|
||||
|
||||
@Entity('users', { engine: 'InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' })
|
||||
export class User extends BaseEntity {
|
||||
|
||||
70
database/entity/0037-drop_server_user_table/User.ts
Normal file
70
database/entity/0037-drop_server_user_table/User.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { BaseEntity, Entity, PrimaryGeneratedColumn, Column, DeleteDateColumn } from 'typeorm'
|
||||
|
||||
@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
|
||||
|
||||
@DeleteDateColumn()
|
||||
deletedAt: Date | null
|
||||
|
||||
@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: 'is_admin', type: 'datetime', nullable: true, default: null })
|
||||
isAdmin: Date | null
|
||||
|
||||
@Column({ name: 'referrer_id', type: 'int', unsigned: true, nullable: true, default: null })
|
||||
referrerId?: number | null
|
||||
|
||||
@Column({ name: 'publisher_id', default: 0 })
|
||||
publisherId: number
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
name: 'passphrase',
|
||||
collation: 'utf8mb4_unicode_ci',
|
||||
nullable: true,
|
||||
default: null,
|
||||
})
|
||||
passphrase: string
|
||||
}
|
||||
@ -1 +1 @@
|
||||
export { User } from './0034-drop_server_user_table/User'
|
||||
export { User } from './0037-drop_server_user_table/User'
|
||||
|
||||
@ -1 +0,0 @@
|
||||
export { UserSetting } from './0002-add_settings/UserSetting'
|
||||
@ -4,7 +4,6 @@ import { Migration } from './Migration'
|
||||
import { Transaction } from './Transaction'
|
||||
import { TransactionLink } from './TransactionLink'
|
||||
import { User } from './User'
|
||||
import { UserSetting } from './UserSetting'
|
||||
import { AdminPendingCreation } from './AdminPendingCreation'
|
||||
|
||||
export const entities = [
|
||||
@ -15,5 +14,4 @@ export const entities = [
|
||||
Transaction,
|
||||
TransactionLink,
|
||||
User,
|
||||
UserSetting,
|
||||
]
|
||||
|
||||
19
database/migrations/0037-drop_server_user_table.ts
Normal file
19
database/migrations/0037-drop_server_user_table.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/* MIGRATION DROP user_setting TABLE */
|
||||
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn('DROP TABLE `user_setting`;')
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
await queryFn(`
|
||||
CREATE TABLE IF NOT EXISTS \`user_setting\` (
|
||||
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
\`userId\` int(11) NOT NULL,
|
||||
\`key\` varchar(255) NOT NULL,
|
||||
\`value\` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user