This commit is contained in:
Vakula Uladimir
2025-10-17 11:27:52 +03:00
commit 12f005e335
72 changed files with 14402 additions and 0 deletions
@@ -0,0 +1,26 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'auctions'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('auction_num', 255).notNullable().unique()
table.string('title', 500).notNullable()
table.text('description').nullable()
table.string('organization', 500).nullable()
table.string('status', 100).nullable()
table.decimal('price', 15, 2).nullable()
table.timestamp('deadline', { useTz: true }).nullable()
table.string('url', 1000).nullable()
table.json('raw_data').nullable()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,19 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'keywords'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('keyword', 255).notNullable().unique()
table.boolean('is_active').notNullable().defaultTo(true)
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,20 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'users'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('email', 255).notNullable().unique()
table.string('password', 180).notNullable()
table.string('telegram_chat_id', 255).nullable().unique()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,20 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'notifications'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.integer('auction_id').unsigned().notNullable().references('id').inTable('auctions').onDelete('CASCADE')
table.string('notification_type', 100).notNullable()
table.timestamp('sent_at', { useTz: true }).notNullable()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,23 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'parse_logs'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('parse_type', 100).notNullable()
table.string('status', 50).notNullable()
table.integer('items_found').notNullable().defaultTo(0)
table.text('errors').nullable()
table.timestamp('started_at', { useTz: true }).notNullable()
table.timestamp('completed_at', { useTz: true }).nullable()
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
@@ -0,0 +1,29 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'keywords'
async up() {
this.schema.alterTable(this.tableName, (table) => {
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE').nullable()
table.dropUnique(['keyword'])
})
// Add composite unique constraint for user_id + keyword
this.schema.alterTable(this.tableName, (table) => {
table.unique(['user_id', 'keyword'])
})
}
async down() {
this.schema.alterTable(this.tableName, (table) => {
table.dropUnique(['user_id', 'keyword'])
})
this.schema.alterTable(this.tableName, (table) => {
table.dropForeign(['user_id'])
table.dropColumn('user_id')
table.unique(['keyword'])
})
}
}
@@ -0,0 +1,55 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'notifications'
async up() {
this.schema.alterTable(this.tableName, (table) => {
// Add keyword_id foreign key
table
.integer('keyword_id')
.unsigned()
.notNullable()
.references('id')
.inTable('keywords')
.onDelete('CASCADE')
// Add status enum with default 'pending'
table.enum('status', ['pending', 'sent', 'failed']).notNullable().defaultTo('pending')
// Add error_message for failed notifications
table.text('error_message').nullable()
// Alter sent_at to be nullable (was NOT NULL before)
table.timestamp('sent_at', { useTz: true }).nullable().alter()
// Remove notification_type column as it's replaced by status
table.dropColumn('notification_type')
// Add composite index for auction_id + keyword_id to prevent duplicates
table.index(['auction_id', 'keyword_id'])
// Add index on status for filtering
table.index('status')
})
}
async down() {
this.schema.alterTable(this.tableName, (table) => {
// Drop indexes
table.dropIndex(['auction_id', 'keyword_id'])
table.dropIndex('status')
// Restore notification_type column
table.string('notification_type', 100).notNullable()
// Restore sent_at as NOT NULL
table.timestamp('sent_at', { useTz: true }).notNullable().alter()
// Remove new columns
table.dropColumn('error_message')
table.dropColumn('status')
table.dropColumn('keyword_id')
})
}
}
@@ -0,0 +1,18 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'keywords'
async up() {
this.schema.alterTable(this.tableName, (table) => {
// Add case_sensitive flag with default false
table.boolean('case_sensitive').notNullable().defaultTo(false)
})
}
async down() {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('case_sensitive')
})
}
}