add migration of users, user_contacts and email_opt_in

This commit is contained in:
Claus-Peter Hübner 2022-08-25 01:06:25 +02:00
parent ab1dd4a2c8
commit fde236aa43
6 changed files with 6 additions and 4 deletions

View File

@ -10,7 +10,7 @@ Decimal.set({
})
const constants = {
DB_VERSION: '0047-messages_tables',
DB_VERSION: '0048-add_user_contacts_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

View File

@ -1 +1 @@
export { User } from './0047-add_user_contacts_table/User'
export { User } from './0048-add_user_contacts_table/User'

View File

@ -1 +1 @@
export { UserContact } from './0047-add_user_contacts_table/UserContact'
export { UserContact } from './0048-add_user_contacts_table/UserContact'

View File

@ -63,8 +63,10 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// reconstruct the previous email back from contacts to users table
// this step comes after verification and test
await queryFn('ALTER TABLE users ADD COLUMN email varchar(255) NULL AFTER privkey;')
// reconstruct the previous email back from contacts to users table
const contacts = await queryFn(`SELECT c.id, c.email, c.user_id FROM user_contacts as c`)
for (const id in contacts) {
const contact = contacts[id]