Remove sequelize models

This commit is contained in:
Jorge Vargas 2024-11-13 22:45:40 -06:00
parent c49bcf070e
commit e8530f0f01
22 changed files with 0 additions and 506 deletions

View file

@ -1,16 +0,0 @@
import { Sequelize, type Options } from '@sequelize/core'
import { SEQUELIZE } from 'astro:env/server'
import Album from './models/album';
import Artist from './models/artist';
import Category from './models/category';
import Config from './models/config';
import User from './models/user';
const envOptions: Options = JSON.parse(SEQUELIZE)
envOptions.models = [Album, Artist, Category, Config, User]
const db = new Sequelize(envOptions)
export default db

View file

@ -1,48 +0,0 @@
import { DataTypes, Model, type BelongsToManyGetAssociationsMixin, type CreationOptional, type InferAttributes, type InferCreationAttributes, type NonAttribute } from '@sequelize/core';
import { Attribute, PrimaryKey, AutoIncrement, Default, BelongsToMany, Table } from '@sequelize/core/decorators-legacy';
import Category from './category';
import Artist from './artist';
Table({ tableName: 'albums' })
export default class Album extends Model<InferAttributes<Album>, InferCreationAttributes<Album>> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>
@Attribute(DataTypes.STRING)
declare title: string
@Attribute(DataTypes.TEXT)
declare subTitle: string
@Attribute(DataTypes.DATEONLY)
declare releaseDate: string
@Attribute(DataTypes.STRING)
declare label: string
@Attribute(DataTypes.STRING)
declare vgmdb: string
@Attribute(DataTypes.STRING)
declare description: string
@Attribute(DataTypes.STRING)
@Default('hidden')
declare status: CreationOptional<string>
@Attribute(DataTypes.STRING)
@Default('#ff7c12')
declare headerColor: CreationOptional<string>
@BelongsToMany(() => Category, { through: 'Album_Category', foreignKey: { onDelete: 'SET NULL' } })
declare categories?: NonAttribute<Category[]>
@BelongsToMany(() => Artist, { through: 'Album_Artist', foreignKey: { onDelete: 'SET NULL' } })
declare artists?: NonAttribute<Artist[]>
declare getArtists: BelongsToManyGetAssociationsMixin<Artist>
}

View file

@ -1,35 +0,0 @@
import { DataTypes } from 'sequelize'
import { PLACEHOLDER } from 'constants'
const animation = (sequelize) => {
sequelize.define(
'animation',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
title: { type: DataTypes.STRING, unique: true },
subTitle: { type: DataTypes.STRING },
releaseDate: DataTypes.DATEONLY,
placeholder: { type: DataTypes.TEXT, defaultValue: PLACEHOLDER },
headerColor: { type: DataTypes.STRING, defaultValue: '#ffffff' }
},
{ freezeTableName: true }
)
sequelize.define(
'studio',
{
slug: {
type: DataTypes.STRING,
primaryKey: true
},
name: DataTypes.STRING
},
{ freezeTableName: true }
)
}
export default animation

View file

@ -1,15 +0,0 @@
import { DataTypes, Model, type CreationOptional, type InferAttributes, type InferCreationAttributes, type NonAttribute } from '@sequelize/core';
import { Attribute, PrimaryKey, AutoIncrement, Default, BelongsToMany, Table, NotNull, HasMany } from '@sequelize/core/decorators-legacy';
import Album from './album';
@Table({ freezeTableName: true })
export default class Artist extends Model<InferAttributes<Artist>, InferCreationAttributes<Artist>> {
@PrimaryKey
@Attribute(DataTypes.STRING)
declare slug: string
@Attribute(DataTypes.STRING)
@NotNull
declare name: string
}

View file

@ -1,10 +0,0 @@
import { DataTypes, Model, type CreationOptional, type InferAttributes, type InferCreationAttributes } from '@sequelize/core';
import { Attribute, PrimaryKey, Table } from '@sequelize/core/decorators-legacy';
@Table({ freezeTableName: true })
export default class Category extends Model<InferAttributes<Category>, InferCreationAttributes<Category>> {
@PrimaryKey
@Attribute(DataTypes.STRING)
declare name: string
}

View file

@ -1,19 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Classification = sequelize.define(
'classification',
{
name: {
type: DataTypes.STRING,
primaryKey: true
}
},
{
freezeTableName: true
}
)
return Classification
}
export default model

View file

@ -1,12 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
sequelize.define('comment', {
text: DataTypes.STRING(300),
anon: DataTypes.BOOLEAN
})
sequelize.define('rating', { score: DataTypes.INTEGER })
}
export default model

View file

@ -1,13 +0,0 @@
import { DataTypes, Model, type CreationOptional, type InferAttributes, type InferCreationAttributes } from '@sequelize/core';
import { Attribute, PrimaryKey, AutoIncrement, Default, Table } from '@sequelize/core/decorators-legacy';
@Table({ tableName: 'config' })
export default class Config extends Model<InferAttributes<Config>, InferCreationAttributes<Config>> {
@Attribute(DataTypes.ENUM('banner', 'banner-position'))
@PrimaryKey
declare name: string
@Attribute(DataTypes.STRING)
declare value: string
}

View file

@ -1,11 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Disc = sequelize.define('disc', {
number: DataTypes.INTEGER,
body: DataTypes.TEXT
})
return Disc
}
export default model

View file

@ -1,11 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Download = sequelize.define('download', {
title: DataTypes.STRING,
small: DataTypes.BOOLEAN
})
return Download
}
export default model

View file

@ -1,27 +0,0 @@
import { DataTypes } from 'sequelize'
import { PLACEHOLDER } from 'constants'
const model = (sequelize) => {
const Game = sequelize.define(
'game',
{
slug: {
type: DataTypes.STRING,
primaryKey: true
},
name: {
type: DataTypes.STRING
},
releaseDate: DataTypes.DATEONLY,
placeholder: { type: DataTypes.TEXT, defaultValue: PLACEHOLDER },
headerColor: { type: DataTypes.STRING, defaultValue: '#ffffff' }
},
{
freezeTableName: true
}
)
return Game
}
export default model

View file

@ -1,13 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Link = sequelize.define('link', {
url: DataTypes.STRING,
directUrl: DataTypes.STRING,
provider: DataTypes.STRING,
custom: DataTypes.STRING
})
return Link
}
export default model

View file

@ -1,17 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
return sequelize.define('log', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
action: DataTypes.STRING,
data: {
type: DataTypes.TEXT,
allowNull: true
}
})
}
export default model

View file

@ -1,27 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Platform = sequelize.define(
'platform',
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING
},
type: {
type: DataTypes.STRING,
defaultValue: 'Game'
}
},
{
freezeTableName: true
}
)
return Platform
}
export default model

View file

@ -1,23 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Publisher = sequelize.define(
'publisher',
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
name: {
type: DataTypes.STRING
}
},
{
freezeTableName: true
}
)
return Publisher
}
export default model

View file

@ -1,21 +0,0 @@
import { DataTypes } from 'sequelize'
const request = (sequelize) =>
sequelize.define('request', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
title: DataTypes.STRING,
link: DataTypes.STRING,
user: DataTypes.STRING,
userID: DataTypes.STRING,
state: { type: DataTypes.STRING, allowNull: false },
donator: { type: DataTypes.BOOLEAN, allowNull: false },
reason: DataTypes.STRING,
comments: DataTypes.STRING,
message: DataTypes.STRING
})
export default request

View file

@ -1,14 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Role = sequelize.define('role', {
name: {
type: DataTypes.STRING,
primaryKey: true
},
permissions: DataTypes.JSON
})
return Role
}
export default model

View file

@ -1,24 +0,0 @@
import { DataTypes } from 'sequelize'
import { PLACEHOLDER } from 'constants'
const model = (sequelize) => {
const Series = sequelize.define(
'series',
{
slug: {
type: DataTypes.STRING,
primaryKey: true
},
name: { type: DataTypes.STRING },
placeholder: { type: DataTypes.TEXT, defaultValue: PLACEHOLDER },
headerColor: { type: DataTypes.STRING, defaultValue: '#ffffff' }
},
{
freezeTableName: true
}
)
return Series
}
export default model

View file

@ -1,10 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) => {
const Store = sequelize.define('store', {
url: DataTypes.STRING,
provider: DataTypes.STRING
})
return Store
}
export default model

View file

@ -1,26 +0,0 @@
import { DataTypes } from 'sequelize'
const model = (sequelize) =>
sequelize.define('submission', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
state: {
type: DataTypes.STRING,
defaultValue: 'pending'
},
title: DataTypes.STRING,
vgmdb: {
type: DataTypes.STRING,
allowNull: true
},
links: DataTypes.TEXT,
score: {
type: DataTypes.INTEGER,
defaultValue: 0
}
})
export default model

View file

@ -1,20 +0,0 @@
import { DataTypes, Model, type InferAttributes, type InferCreationAttributes } from '@sequelize/core'
import { Attribute, NotNull, PrimaryKey } from '@sequelize/core/decorators-legacy'
export default class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@PrimaryKey
@Attribute(DataTypes.STRING)
declare username: string
@Attribute(DataTypes.STRING)
@NotNull
declare email: string
@Attribute(DataTypes.STRING)
@NotNull
declare password: string
@Attribute(DataTypes.STRING)
@NotNull
declare imgId: string
}

View file

@ -1,94 +0,0 @@
export default function relations(sequelize) {
const {
album,
classification,
disc,
download,
link,
publisher,
game,
series,
platform,
artist,
category,
store,
animation,
studio,
user,
role,
forgor,
log,
comment,
rating,
submission,
request
} = sequelize.models
user.belongsToMany(role, { through: 'User_Role' })
log.belongsTo(user, { foreignKey: 'username' })
forgor.belongsTo(user, { foreignKey: 'username' })
submission.belongsTo(user)
submission.belongsTo(request)
user.hasMany(submission)
request.hasMany(submission)
classification.belongsToMany(album, { through: 'Album_Classification' })
disc.belongsTo(album)
download.hasMany(link)
link.belongsTo(download)
game.belongsToMany(publisher, { through: 'Publisher_Game' })
game.belongsToMany(album, { through: 'Album_Game' })
game.belongsToMany(series, { through: 'Series_Game' })
game.belongsToMany(platform, { through: 'Game_Platform' })
platform.belongsToMany(game, { through: 'Game_Platform' })
album.belongsToMany(artist, { onDelete: 'SET NULL', through: 'Album_Artist' })
album.belongsToMany(classification, {
onDelete: 'SET NULL',
through: 'Album_Classification'
})
// album.belongsToMany(category, { onDelete: 'SET NULL', through: 'Album_Category' })
album.belongsToMany(platform, {
onDelete: 'SET NULL',
through: 'Album_Platform'
})
album.belongsToMany(game, { onDelete: 'SET NULL', through: 'Album_Game' })
album.belongsToMany(animation, { through: 'Album_Animation' })
album.hasMany(disc, { onDelete: 'SET NULL' })
album.hasMany(download, { onDelete: 'SET NULL' })
album.hasMany(store, { onDelete: 'SET NULL' })
album.belongsToMany(album, {
onDelete: 'SET NULL',
through: 'related_album',
as: 'related'
})
platform.belongsToMany(album, { through: 'Album_Platform' })
publisher.belongsToMany(game, { through: 'Publisher_Game' })
series.belongsToMany(game, { through: 'Series_Game' })
animation.belongsToMany(studio, { through: 'Studio_Animation' })
studio.belongsToMany(animation, { through: 'Studio_Animation' })
animation.belongsToMany(album, { through: 'Album_Animation' })
album.hasMany(comment, { onDelete: 'SET NULL' })
comment.belongsTo(album)
user.hasMany(comment, { foreignKey: 'username' })
comment.belongsTo(user, { foreignKey: 'username' })
album.hasMany(rating)
rating.belongsTo(album)
user.hasMany(rating, { foreignKey: 'username' })
rating.belongsTo(user, { foreignKey: 'username' })
user.belongsToMany(album, { through: 'favorites', foreignKey: 'username' })
album.belongsToMany(user, { through: 'favorites' })
}