diff --git a/app/Models/App.ts b/app/Models/App.ts index 26bbd88..b8be740 100644 --- a/app/Models/App.ts +++ b/app/Models/App.ts @@ -1,5 +1,6 @@ import { DateTime } from 'luxon' -import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' +import { BaseModel, BelongsTo, belongsTo, column } from '@ioc:Adonis/Lucid/Orm' +import User from './User' export enum AppCategory { // If you want to add an app category, append to the bottom and add translation in language files PRODUCTIVITY, @@ -16,6 +17,9 @@ export default class App extends BaseModel { @column() public userId: number + @belongsTo(() => User) + public author: BelongsTo + @column() public name: string @@ -26,7 +30,10 @@ export default class App extends BaseModel { public source_url: string @column() - public path: string + public image: string + + @column() + public releases: string @column() public category: AppCategory diff --git a/app/Models/Release.ts b/app/Models/Release.ts new file mode 100644 index 0000000..ebd1b8c --- /dev/null +++ b/app/Models/Release.ts @@ -0,0 +1,23 @@ +import { DateTime } from 'luxon' +import { BaseModel, belongsTo, BelongsTo, column } from '@ioc:Adonis/Lucid/Orm' +import App from './App' + +export default class Release extends BaseModel { + @column({ isPrimary: true }) + public id: number + + @column() + public appId: number + + @belongsTo(() => App) + public author: BelongsTo + + @column() + public commitSha: string + + @column() + public downloadLink: string + + @column.dateTime({ autoCreate: true }) + public createdAt: DateTime +} diff --git a/database/migrations/1698679914813_apps.ts b/database/migrations/1698679914813_apps.ts index 2b03346..c61d171 100644 --- a/database/migrations/1698679914813_apps.ts +++ b/database/migrations/1698679914813_apps.ts @@ -17,7 +17,7 @@ export default class extends BaseSchema { table.string('desc', 350).nullable().defaultTo("") table.string('source_url', 300).nullable() table.string('image', 300).nullable() - table.string('path', 300).nullable() + table.string('releases', 300).nullable() table.smallint('category').notNullable() table.bigint("downloads").unsigned().notNullable().defaultTo(0) diff --git a/database/migrations/1731662514979_apps_v2.ts b/database/migrations/1731662514979_apps_v2.ts new file mode 100644 index 0000000..265e0e4 --- /dev/null +++ b/database/migrations/1731662514979_apps_v2.ts @@ -0,0 +1,20 @@ +import BaseSchema from '@ioc:Adonis/Lucid/Schema' + +export default class extends BaseSchema { + protected tableName = 'apps' + + public async up () { + this.schema.alterTable(this.tableName, (table) => { + table.dropColumns('image', 'releases') + table.string('source', 300).nullable() + }) + } + + public async down () { + this.schema.alterTable(this.tableName, (table) => { + table.string('image', 300).nullable() + table.string('releases', 300).nullable() + table.dropColumn('source') + }) + } +} diff --git a/database/migrations/1731663175921_releases.ts b/database/migrations/1731663175921_releases.ts new file mode 100644 index 0000000..b20b878 --- /dev/null +++ b/database/migrations/1731663175921_releases.ts @@ -0,0 +1,25 @@ +import BaseSchema from '@ioc:Adonis/Lucid/Schema' + +export default class extends BaseSchema { + protected tableName = 'releases' + + public async up () { + this.schema.createTable(this.tableName, (table) => { + table.increments('id') + + + table.integer('app_id') + .references('apps.id') + .onDelete('CASCADE') + + table.string('commit_sha', 40) + table.string('download_link').nullable() + + table.timestamp('created_at', { useTz: true }) + }) + } + + public async down () { + this.schema.dropTable(this.tableName) + } +}