Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert model.fields to objects when applying migrations #57

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/commands/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path';
import { initializeDatabase } from '@/src/utils/database';
import type { MigrationFlags } from '@/src/utils/migration';
import { MIGRATIONS_PATH, getLocalPackages } from '@/src/utils/misc';
import { getModels } from '@/src/utils/model';
import { convertArrayToObject, getModels } from '@/src/utils/model';
import { Protocol } from '@/src/utils/protocol';
import { getOrSelectSpaceId } from '@/src/utils/space';
import { spinner as ora } from '@/src/utils/spinner';
Expand Down Expand Up @@ -51,7 +51,13 @@ export default async (
}));

const protocol = await new Protocol(packages).load(migrationPrompt);
const statements = protocol.getSQLStatements(existingModels);
const statements = protocol.getSQLStatements(
existingModels.map((model) => ({
...model,
// @ts-expect-error This will work once the types are fixed.
fields: convertArrayToObject(model.fields),
})),
);

// Create the migrations directory if it doesn't exist.
if (!fs.existsSync(MIGRATIONS_PATH)) {
Expand Down
Loading