sequelize, storage for userdata

This commit is contained in:
Felix Kaspar
2024-05-29 23:19:07 +02:00
parent 9d540d6aa2
commit 09a3d83dc5
12 changed files with 1493 additions and 51 deletions

View File

@@ -0,0 +1,87 @@
import { Sequelize, DataTypes } from "sequelize";
//TODO: Make this configurable
const sequelize = new Sequelize("sqlite::memory:");
import { User, AccessRule, APIKey, Password } from "../auth/user/user-model";
User.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
mail: {
type: DataTypes.STRING,
unique: true,
},
authenticationMethod: {
type: DataTypes.STRING,
allowNull: false,
},
createdAt: DataTypes.DATE,
updatedAt: DataTypes.DATE,
},
{ sequelize },
);
Password.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
password: DataTypes.STRING,
createdAt: DataTypes.DATE,
updatedAt: DataTypes.DATE,
},
{ sequelize },
);
Password.hasOne(User);
User.hasOne(Password);
AccessRule.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
grants: DataTypes.STRING,
createdAt: DataTypes.DATE,
updatedAt: DataTypes.DATE,
},
{ sequelize },
);
AccessRule.hasOne(User);
User.hasMany(AccessRule);
APIKey.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true
},
apikey: DataTypes.STRING,
createdAt: DataTypes.DATE,
updatedAt: DataTypes.DATE,
},
{ sequelize },
);
APIKey.hasOne(User);
User.hasMany(APIKey);
export default sequelize;
(async () => {
await sequelize.sync({ force: true });
console.log("Database synced!")
})();