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_PASS = 1234 5678 9012 3456
JWT_SECRET = 0987654321
\ No newline at end of file
EMAIL_USER = abc@gmail.com
EMAIL_PASS = password
JWT_SECRET = secretkey
HOSTNAMEDB = localhost
PORTDB = 5432
NAMEDB = mydatabase
USERNAMEDB = myuser
PASSWORDDB = example
\ No newline at end of file
import { Sequelize } from 'sequelize';
import { config as loadEnv } from 'dotenv';
import { initModels } from '#models/init-models.js';
const sequelize = new Sequelize('challenge_db', 'postgres', '123456', {
host: 'localhost',
port: 2550,
loadEnv({ override: true });
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',
logging: false,
define: {
underscored: true,
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);
......
......@@ -67,7 +67,8 @@ export class user_auth extends Model<user_authAttributes, user_authCreationAttri
},
active: {
type: DataTypes.BOOLEAN,
allowNull: true
allowNull: true,
defaultValue: false
}
}, {
tableName: 'user_auth',
......
import { config as loadEnv } from 'dotenv';
import SequelizeAuto from 'sequelize-auto';
const auto = new SequelizeAuto('challenge_db', 'postgres', '123456', {
host: 'localhost',
port: 2550,
loadEnv({ override: true });
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',
directory: './src/models',
lang: 'ts',
......@@ -15,7 +21,23 @@ const auto = new SequelizeAuto('challenge_db', 'postgres', '123456', {
additional: {
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...');
......
......@@ -39,6 +39,9 @@ CREATE TABLE user_auth (
id uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid,
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()
);
......
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