Migrations are not run in order

I'm running through a problem (and I hope I'm writing in relevant channel). Context: I have an existing RDS Aurora Postgres Serverless v2 cluster & I'm able to run the migrations perfectly (as per git current head). Problem: I've cloned the cluster and for the newer cluster, migrations wouldn't accurately run and seems like they're being executed in random order that's causing SQL errors. Is there any clue you could provide to get out of it? Error:
ERROR: relation "userOtp" does not exist; SQLState: 42P01
ERROR: relation "userOtp" does not exist; SQLState: 42P01
Code:
import { IS_SANDBOX, checkEnvIsTruthy } from '@environment';
import { migrate } from 'drizzle-orm/aws-data-api/pg/migrator';
import { resetDatabaseFn } from 'src/debug/resetDatabase';
import logger from 'src/logger';
import { Resource } from 'sst';

export const handler = async ({
skipReset,
db,
}: {
skipReset?: boolean;
db: sst.aws.Postgres;
}) => {
if (
!skipReset &&
checkEnvIsTruthy(Resource.DB_SHOULD_RESET.value) &&
IS_SANDBOX
) {
await resetDatabaseFn();
}

await migrate(db, { migrationsFolder: 'packages/functions/drizzle' });
};
import { IS_SANDBOX, checkEnvIsTruthy } from '@environment';
import { migrate } from 'drizzle-orm/aws-data-api/pg/migrator';
import { resetDatabaseFn } from 'src/debug/resetDatabase';
import logger from 'src/logger';
import { Resource } from 'sst';

export const handler = async ({
skipReset,
db,
}: {
skipReset?: boolean;
db: sst.aws.Postgres;
}) => {
if (
!skipReset &&
checkEnvIsTruthy(Resource.DB_SHOULD_RESET.value) &&
IS_SANDBOX
) {
await resetDatabaseFn();
}

await migrate(db, { migrationsFolder: 'packages/functions/drizzle' });
};
1 Reply
jelderšŸ¦¾
jelderšŸ¦¾ā€¢5w ago
I've seen this as well.
Want results from more Discord servers?
Add your server