2026-02-16 14:29:53 -05:00
|
|
|
const {DataTypes, sequelize, Sequelize} = require('sequelize');
|
|
|
|
|
const {env} = require('dotenv');
|
2026-02-16 11:07:43 -05:00
|
|
|
|
|
|
|
|
env.config();
|
2026-02-13 18:20:29 -05:00
|
|
|
|
|
|
|
|
const password = process.env.POSTGRES_PASSWORD;
|
|
|
|
|
|
|
|
|
|
if (!password) {
|
|
|
|
|
console.error("Missing POSTGRES_PWD environment variable.");
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
const database = {
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
sequelize: new Sequelize('postgres', 'postgres', password, {
|
|
|
|
|
host: 'localhost',
|
|
|
|
|
logging: false,
|
|
|
|
|
dialect: 'postgres'
|
|
|
|
|
}),
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
Sequelize: Sequelize,
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
members: sequelize.define('Member', {
|
|
|
|
|
userid: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
name: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
displayname: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
},
|
|
|
|
|
propic: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
},
|
|
|
|
|
proxy: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
}
|
|
|
|
|
}),
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
systems: sequelize.define('System', {
|
|
|
|
|
userid: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
},
|
|
|
|
|
fronter: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
grouptag: {
|
|
|
|
|
type: DataTypes.STRING
|
|
|
|
|
},
|
|
|
|
|
autoproxy: {
|
|
|
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
|
}
|
|
|
|
|
}),
|
2026-02-16 11:09:03 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
/**
|
|
|
|
|
* Checks Sequelize database connection.
|
|
|
|
|
*/
|
|
|
|
|
check_connection: async function () {
|
|
|
|
|
await sequelize.authenticate().then(async () => {
|
2026-02-13 18:20:29 -05:00
|
|
|
console.log('Connection has been established successfully.');
|
2026-02-16 14:29:53 -05:00
|
|
|
await this.syncModels();
|
2026-02-13 18:20:29 -05:00
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('Unable to connect to the database:', err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
2026-02-16 14:29:53 -05:00
|
|
|
},
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
/**
|
|
|
|
|
* Syncs Sequelize models.
|
|
|
|
|
*/
|
|
|
|
|
async syncModels() {
|
|
|
|
|
await this.sequelize.sync().then(() => {
|
|
|
|
|
console.log('Models synced successfully.');
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.error('Syncing models did not work', err);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-02-13 18:20:29 -05:00
|
|
|
|
2026-02-16 14:29:53 -05:00
|
|
|
module.exports = database;
|