Skip to content

Commit

Permalink
fix: correct migrations on fresh installations @anbraten (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Nov 6, 2023
1 parent 86099d2 commit 41e2493
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ type Subscription = {

export class MigrationSetNextPaymentForSubscriptions extends Migration {
async up(): Promise<void> {
if (await this.ctx?.schema.hasColumn('subscription', 'next_payment')) {
if (
!(await this.ctx?.schema.hasTable('subscription')) ||
(await this.ctx?.schema.hasColumn('subscription', 'next_payment'))
) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/migrations/003_update_payment_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type Payment = {

export class MigrationPaymentStatusFromPendingToProcessing extends Migration {
async up(): Promise<void> {
if (!(await this.ctx?.schema.hasTable('payment'))) {
return;
}

await this.ctx?.table<Payment>('payment').where({ status: 'pending' }).update({
status: 'processing',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ type Subscription = {

export class MigrationUpdateInvoiceAddCustomerAndAllowOptionalSubscription extends Migration {
async up(): Promise<void> {
if (await this.ctx?.schema.hasColumn('invoice', 'customer__id')) {
if (
!(await this.ctx?.schema.hasTable('invoice')) ||
(await this.ctx?.schema.hasColumn('invoice', 'customer__id'))
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ type Subscription = {

export class MigrationReplaceNextPaymentWithCurrentPeriod extends Migration {
async up(): Promise<void> {
if (await this.ctx?.schema.hasColumn('subscription', 'current_period_start')) {
if (
!(await this.ctx?.schema.hasTable('subscription')) ||
(await this.ctx?.schema.hasColumn('subscription', 'current_period_start'))
) {
return;
}

Expand Down

0 comments on commit 41e2493

Please sign in to comment.