feat: database
This commit is contained in:
66
models/Link.js
Normal file
66
models/Link.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = (sequelize) => {
|
||||
const Link = sequelize.define('Link', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true
|
||||
},
|
||||
url: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
validate: {
|
||||
isUrl: true
|
||||
}
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
image: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: DataTypes.NOW,
|
||||
allowNull: false
|
||||
},
|
||||
created_by: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
modified_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true
|
||||
},
|
||||
modified_by: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
},
|
||||
archived: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'links',
|
||||
timestamps: false, // We're using created_at and modified_at manually
|
||||
underscored: true
|
||||
});
|
||||
|
||||
// Hook to set modified_at before update
|
||||
Link.beforeUpdate((link) => {
|
||||
link.modified_at = new Date();
|
||||
});
|
||||
|
||||
return Link;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user