@@ -2,17 +2,35 @@ import { Knex } from "knex"
22
33import { DB_CONFIG } from "@/config"
44
5- export function up ( knex : Knex ) {
6- return knex . schema
7- . withSchema ( DB_CONFIG . defaultSchema )
8- . table ( "application_draft" , ( table ) => {
5+ export async function up ( knex : Knex ) {
6+ const schema = knex . schema . withSchema ( DB_CONFIG . defaultSchema )
7+
8+ // Check and add column for 'application_draft' table
9+ const hasApplicationIdOnApplicationDraft = await schema . hasColumn (
10+ "application_draft" ,
11+ "application_id"
12+ )
13+ await schema . table ( "application_draft" , ( table ) => {
14+ if ( ! hasApplicationIdOnApplicationDraft ) {
915 table . integer ( "application_id" ) . nullable ( )
10- } )
11- . table ( "application" , ( table ) => {
16+ }
17+ } )
18+
19+ // Check and add columns for 'application' table
20+ const hasLastTravelOnApplication = await schema . hasColumn ( "application" , "has_last_travel" )
21+ const hasLastYearOnApplication = await schema . hasColumn ( "application" , "last_travel_year" )
22+ const hasLastMonthOnApplication = await schema . hasColumn ( "application" , "last_travel_month" )
23+ await schema . table ( "application" , async ( table ) => {
24+ if ( ! hasLastTravelOnApplication ) {
1225 table . integer ( "has_last_travel" ) . nullable ( )
26+ }
27+ if ( ! hasLastYearOnApplication ) {
1328 table . integer ( "last_travel_year" ) . nullable ( )
29+ }
30+ if ( ! hasLastMonthOnApplication ) {
1431 table . integer ( "last_travel_month" ) . nullable ( )
15- } )
32+ }
33+ } )
1634}
1735
1836export function down ( knex : Knex ) {
0 commit comments