save all before archival

This commit is contained in:
b1ek 2023-02-19 19:54:30 +10:00
parent d369f8b7d9
commit 8bad9f7c83
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 158 additions and 0 deletions

9
README.md Normal file
View File

@ -0,0 +1,9 @@
# homepage.js
This is a rewrite of my current website to Express.JS.
# This was aborted.
With focusing on code structure & performance, I decided
to rewrite the website into JavaScript, but as it turned out,
i can't provide enough for my satisfaction with ExpressJS.
I am re writing this to Go & atreugo

23
config/config.json Normal file
View File

@ -0,0 +1,23 @@
{
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"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

@ -0,0 +1,31 @@
'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Guestbooks', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
id: {
type: Sequelize.BIGINT
},
name: {
type: Sequelize.TEXT
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Guestbooks');
}
};

52
models/guestbook.js Normal file
View File

@ -0,0 +1,52 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Guestbook extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
Guestbook.init({
id: {
type: DataTypes.BIGINT(11),
primaryKey: true,
autoIncrement: true,
allowNull: false
},
name: {
type: DataTypes.TEXT,
allowNull: false
},
email: DataTypes.TEXT,
text: {
type: DataTypes.TEXT,
allowNull: false
},
hidemail: {
type: DataTypes.BOOLEAN,
allowNull: false
},
ip: {
type: DataTypes.TEXT,
allowNull: false
},
hidden: {
type: DataTypes.BOOLEAN,
allowNull: false
},
time: {
type: DataTypes.BIGINT
}
}, {
sequelize,
modelName: 'Guestbook',
});
return Guestbook;
};

43
models/index.js Normal file
View File

@ -0,0 +1,43 @@
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const process = require('process');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (
file.indexOf('.') !== 0 &&
file !== basename &&
file.slice(-3) === '.js' &&
file.indexOf('.test.js') === -1
);
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;