forked from PluralFlux/PluralFlux
* clear out fluxer.net * basic discord.js bot with ping, and echo * added creation of webhook * simplifying webhook logic * sending messages as webhook * deleting orignal message * adding sequelize file * commented out pgadmin part while it's not working * adding member sort of working * changing names of values * updating names of values and adding new method in memberHelper * renamed messagehelper function * deleted proxyhelper * passed only channel id into webhook helper methods * added new functions and got update working * changed message match to better reducer * adjusted webhook helper to use actual data * refactored bot.js and removed unused methods
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import {DataTypes, Sequelize} from 'sequelize';
|
|
|
|
const password = process.env.POSTGRES_PASSWORD;
|
|
|
|
if (!password) {
|
|
console.error("Missing POSTGRES_PWD environment variable.");
|
|
process.exit(1);
|
|
}
|
|
|
|
const database = {};
|
|
|
|
const sequelize = new Sequelize('postgres', 'postgres', password, {
|
|
host: 'localhost',
|
|
dialect: 'postgres'
|
|
});
|
|
|
|
database.sequelize = sequelize;
|
|
database.Sequelize = Sequelize;
|
|
|
|
database.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,
|
|
}
|
|
});
|
|
|
|
database.check_connection = async function() {
|
|
await sequelize.authenticate().then(async (result) => {
|
|
console.log('Connection has been established successfully.');
|
|
await syncModels();
|
|
}).catch(err => {
|
|
console.error('Unable to connect to the database:', err);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
async function syncModels() {
|
|
await sequelize.sync({force:true}).then((result) => {
|
|
console.log('Models synced successfully.');
|
|
}).catch((err) => {
|
|
console.error('Syncing models did not work', err);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
export const db = database; |