Skip to content

Commit

Permalink
Fixed migrations and added releases
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkBrines committed Nov 15, 2024
1 parent 39ab427 commit 04000d5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
11 changes: 9 additions & 2 deletions app/Models/App.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,6 +17,9 @@ export default class App extends BaseModel {
@column()
public userId: number

@belongsTo(() => User)
public author: BelongsTo<typeof User>

@column()
public name: string

Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions app/Models/Release.ts
Original file line number Diff line number Diff line change
@@ -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<typeof App>

@column()
public commitSha: string

@column()
public downloadLink: string

@column.dateTime({ autoCreate: true })
public createdAt: DateTime
}
2 changes: 1 addition & 1 deletion database/migrations/1698679914813_apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions database/migrations/1731662514979_apps_v2.ts
Original file line number Diff line number Diff line change
@@ -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')
})
}
}
25 changes: 25 additions & 0 deletions database/migrations/1731663175921_releases.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 04000d5

Please sign in to comment.