Added migrations and disabled auto-migrations to better protect users' databases
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2022-12-13 18:58:14 -05:00
parent b8700c1ba3
commit 8119f49b4d
7 changed files with 921 additions and 200 deletions

20
config/config.json Normal file
View File

@ -0,0 +1,20 @@
{
"development": {
"storage": "./data/overseer.db",
"dialect": "sqlite"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}

View File

@ -8,12 +8,7 @@ const app = express();
const config = require('config'); const config = require('config');
// initialize database connection // initialize database connection
(async () => { const db = require('./src/models');
const db = require('./src/models');
await db.sequelize.sync({
alter: true,
});
})();
if (config.get('use_redis')) { if (config.get('use_redis')) {
// initialize Redis store for session data // initialize Redis store for session data

View File

@ -0,0 +1,28 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('items', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.DataTypes.STRING,
allowNull: false,
},
manufacturer: Sequelize.DataTypes.STRING,
serialNumber: Sequelize.DataTypes.STRING,
skuNumber: Sequelize.DataTypes.STRING,
type: Sequelize.DataTypes.STRING,
purchasedFrom: Sequelize.DataTypes.STRING,
purchasedAt: Sequelize.DataTypes.DATE,
createdAt: Sequelize.DataTypes.DATE,
updatedAt: Sequelize.DataTypes.DATE,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('items');
}
};

View File

@ -0,0 +1,37 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('licenses', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.DataTypes.STRING,
allowNull: false,
},
key: {
type: Sequelize.DataTypes.STRING,
allowNull: false,
},
manufacturer: Sequelize.DataTypes.STRING,
seatsUsed: {
type: Sequelize.DataTypes.NUMBER,
defaultValue: 0,
},
seatsTotal: {
type: Sequelize.DataTypes.NUMBER,
defaultValue: 1,
},
purchasedFrom: Sequelize.DataTypes.STRING,
purchasedAt: Sequelize.DataTypes.DATE,
createdAt: Sequelize.DataTypes.DATE,
updatedAt: Sequelize.DataTypes.DATE,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('licenses');
}
};

View File

@ -0,0 +1,30 @@
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('activities', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
user: {
type: Sequelize.STRING,
allowNull: false,
},
action: {
type: Sequelize.STRING,
allowNull: false,
},
itemId: {
type: Sequelize.NUMBER,
allowNull: false,
},
createdAt: Sequelize.DataTypes.DATE,
updatedAt: Sequelize.DataTypes.DATE,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('activities');
}
};

997
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
"start": "node index.js", "start": "node index.js",
"grunt": "grunt", "grunt": "grunt",
"nodemon": "nodemon index.js", "nodemon": "nodemon index.js",
"sequelize": "sequelize-cli",
"lint": "eslint index.js src/**/*.js", "lint": "eslint index.js src/**/*.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
@ -49,6 +50,7 @@
"pg-hstore": "^2.3.4", "pg-hstore": "^2.3.4",
"redis": "^4.4.0", "redis": "^4.4.0",
"sequelize": "^6.25.3", "sequelize": "^6.25.3",
"sequelize-cli": "^6.5.2",
"sqlite3": "^5.1.2", "sqlite3": "^5.1.2",
"twig": "^1.15.4" "twig": "^1.15.4"
} }