diff --git a/database/migrations/0049-add_user_contacts_table.ts b/database/migrations/0049-add_user_contacts_table.ts index 964285420..acdd1af61 100644 --- a/database/migrations/0049-add_user_contacts_table.ts +++ b/database/migrations/0049-add_user_contacts_table.ts @@ -41,13 +41,13 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis // merge values from login_email_opt_in table with users.email in new user_contacts table await queryFn(` - INSERT INTO \`user_contacts\` + INSERT INTO user_contacts (type, user_id, email, email_verification_code, email_opt_in_type_id, email_resend_count, email_checked, created_at, updated_at, deleted_at) - SELECT 'EMAIL', \`users\`.id, \`users\`.email, optin.\`verification_code\`, optin.\`email_opt_in_type_id\`, optin.\`resend_count\`, users.\`email_checked\`, users.created, null, users.deletedAt + SELECT 'EMAIL', users.id, users.email, optin.verification_code, optin.email_opt_in_type_id, optin.resend_count, users.email_checked, users.created, null, users.deletedAt FROM users LEFT JOIN (SELECT le.id, le.user_id, le.verification_code, le.email_opt_in_type_id, le.resend_count, le.created, le.updated, ROW_NUMBER() OVER (PARTITION BY le.user_id ORDER BY le.created DESC) AS row_num - FROM login_email_opt_in as le) AS optin ON users.id = optin.\`user_id\` AND row_num = 1;`) + FROM login_email_opt_in as le) AS optin ON users.id = optin.user_id AND row_num = 1;`) // insert in users table the email_id of the new created email-contacts const contacts = await queryFn(`SELECT c.id, c.user_id FROM user_contacts as c`)