Commit 2b766521 authored by Phạm Quang Bảo's avatar Phạm Quang Bảo

fix: deploy render

parent 21924786
EMAIL_USER = abc@gmail.com EMAIL_USER = abc@gmail.com
EMAIL_PASS = 1234 5678 9012 3456 EMAIL_PASS = password
JWT_SECRET = 0987654321 JWT_SECRET = secretkey
\ No newline at end of file HOSTNAMEDB = localhost
PORTDB = 5432
NAMEDB = mydatabase
USERNAMEDB = myuser
PASSWORDDB = example
\ No newline at end of file
import { Sequelize } from 'sequelize'; import { Sequelize } from 'sequelize';
import { config as loadEnv } from 'dotenv';
import { initModels } from '#models/init-models.js'; import { initModels } from '#models/init-models.js';
const sequelize = new Sequelize('challenge_db', 'postgres', '123456', { loadEnv({ override: true });
host: 'localhost',
port: 2550, const host = process.env.HOSTNAMEDB || 'localhost';
const useSsl = process.env.DB_SSL === 'true' || host.includes('render.com');
const sequelizeOptions: Record<string, unknown> = {
host,
port: Number(process.env.PORTDB) || 2550,
dialect: 'postgres', dialect: 'postgres',
logging: false, logging: false,
define: { define: {
underscored: true, underscored: true,
timestamps: false, timestamps: false,
}, },
}); };
if (useSsl) {
sequelizeOptions.dialectOptions = {
ssl: {
require: true,
rejectUnauthorized: false,
},
};
}
const sequelize = new Sequelize(
process.env.NAMEDB || 'mydatabase',
process.env.USERNAMEDB || 'myuser',
process.env.PASSWORDDB || 'example',
sequelizeOptions as any,
);
const models = initModels(sequelize); const models = initModels(sequelize);
......
...@@ -67,7 +67,8 @@ export class user_auth extends Model<user_authAttributes, user_authCreationAttri ...@@ -67,7 +67,8 @@ export class user_auth extends Model<user_authAttributes, user_authCreationAttri
}, },
active: { active: {
type: DataTypes.BOOLEAN, type: DataTypes.BOOLEAN,
allowNull: true allowNull: true,
defaultValue: false
} }
}, { }, {
tableName: 'user_auth', tableName: 'user_auth',
......
import { config as loadEnv } from 'dotenv';
import SequelizeAuto from 'sequelize-auto'; import SequelizeAuto from 'sequelize-auto';
const auto = new SequelizeAuto('challenge_db', 'postgres', '123456', { loadEnv({ override: true });
host: 'localhost',
port: 2550, const host = process.env.HOSTNAMEDB || 'localhost';
const useSsl = process.env.DB_SSL === 'true' || host.includes('render.com');
const autoOptions: any = {
host,
port: Number(process.env.PORTDB) || 2550,
dialect: 'postgres', dialect: 'postgres',
directory: './src/models', directory: './src/models',
lang: 'ts', lang: 'ts',
...@@ -15,7 +21,23 @@ const auto = new SequelizeAuto('challenge_db', 'postgres', '123456', { ...@@ -15,7 +21,23 @@ const auto = new SequelizeAuto('challenge_db', 'postgres', '123456', {
additional: { additional: {
timestamps: false, timestamps: false,
}, },
}); };
if (useSsl) {
autoOptions.dialectOptions = {
ssl: {
require: true,
rejectUnauthorized: false,
},
};
}
const auto = new SequelizeAuto(
process.env.NAMEDB || 'mydatabase',
process.env.USERNAMEDB || 'myuser',
process.env.PASSWORDDB || 'example',
autoOptions,
);
console.log('🔄 Đang tiến hành quét Database và sinh Model...'); console.log('🔄 Đang tiến hành quét Database và sinh Model...');
......
...@@ -39,6 +39,9 @@ CREATE TABLE user_auth ( ...@@ -39,6 +39,9 @@ CREATE TABLE user_auth (
id uuid DEFAULT gen_random_uuid() NOT NULL, id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid, user_id uuid,
password_hash text, password_hash text,
otp_code VARCHAR(6),
otp_expiry TIMESTAMP WITH TIME ZONE,
active BOOLEAN DEFAULT false,
created_at timestamp with time zone DEFAULT now() created_at timestamp with time zone DEFAULT now()
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment