Finish "new" command, and other stuff

This commit is contained in:
Isaac
2021-04-05 18:38:00 +01:00
parent 01519df0cf
commit 4b3ba238bd
15 changed files with 369 additions and 255 deletions

View File

@@ -6,7 +6,7 @@ const { path } = require('../utils/fs');
const config = require('../../user/config');
const types = require('./dialects');
module.exports = async (log) => {
module.exports = async (client) => {
const {
DB_TYPE,
@@ -22,7 +22,7 @@ module.exports = async (log) => {
const supported = Object.keys(types);
if (!supported.includes(type)) {
log.error(new Error(`DB_TYPE (${type}) is not a valid type`));
client.log.error(new Error(`DB_TYPE (${type}) is not a valid type`));
return process.exit();
}
@@ -30,35 +30,35 @@ module.exports = async (log) => {
types[type].packages.forEach(pkg => require(pkg));
} catch {
let required = types[type].packages.map(i => `"${i}"`).join(' and ');
log.error(new Error(`Please install the package(s) for your selected database type: ${required}`));
client.log.error(new Error(`Please install the package(s) for your selected database type: ${required}`));
return process.exit();
}
let sequelize;
if (type === 'sqlite') {
log.info('Using SQLite storage');
client.log.info('Using SQLite storage');
sequelize = new Sequelize({
dialect: types[type].dialect,
storage: path('./user/database.sqlite'),
logging: text => log.debug(text)
logging: text => client.log.debug(text)
});
} else {
log.info(`Connecting to ${types[type].name} database...`);
client.log.info(`Connecting to ${types[type].name} database...`);
sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASS, {
dialect: types[type].dialect,
host: DB_HOST,
port: DB_PORT,
logging: text => log.debug(text)
logging: text => client.log.debug(text)
});
}
try {
await sequelize.authenticate();
log.success('Connected to database successfully');
client.log.success('Connected to database successfully');
} catch (error) {
log.warn('Failed to connect to database');
log.error(error);
client.log.warn('Failed to connect to database');
client.log.error(error);
return process.exit();
}
@@ -92,6 +92,10 @@ module.exports = async (log) => {
type: DataTypes.BOOLEAN,
defaultValue: config.defaults.log_messages
},
footer: {
type: DataTypes.STRING,
defaultValue: 'Discord Tickets by eartharoid'
},
}, {
tableName: DB_TABLE_PREFIX + 'guilds'
});
@@ -160,6 +164,10 @@ module.exports = async (log) => {
key: 'id'
},
},
topic: {
type: DataTypes.STRING,
allowNull: true,
},
creator: {
type: DataTypes.CHAR(18),
allowNull: false,