import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-sqlite'

export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
  await db.run(sql`ALTER TABLE \`chapters\` ADD \`affiliate_unlock_url\` text;`)
  await db.run(sql`ALTER TABLE \`chapters\` ADD \`affiliate_unlock_label\` text DEFAULT 'Mở khóa chương';`)
  await db.run(sql`ALTER TABLE \`_chapters_v\` ADD \`version_affiliate_unlock_url\` text;`)
  await db.run(sql`ALTER TABLE \`_chapters_v\` ADD \`version_affiliate_unlock_label\` text DEFAULT 'Mở khóa chương';`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.run(sql`ALTER TABLE \`chapters\` DROP COLUMN \`affiliate_unlock_url\`;`)
  await db.run(sql`ALTER TABLE \`chapters\` DROP COLUMN \`affiliate_unlock_label\`;`)
  await db.run(sql`ALTER TABLE \`_chapters_v\` DROP COLUMN \`version_affiliate_unlock_url\`;`)
  await db.run(sql`ALTER TABLE \`_chapters_v\` DROP COLUMN \`version_affiliate_unlock_label\`;`)
}
