Skip to content

Commit

Permalink
Reuse type
Browse files Browse the repository at this point in the history
  • Loading branch information
colodenn committed Feb 13, 2025
1 parent 07d8ed6 commit 2c71407
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
14 changes: 4 additions & 10 deletions src/utils/field.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { MigrationOptions } from '@/src/utils/migration';
import { RONIN_SCHEMA_TEMP_SUFFIX } from '@/src/utils/misc';
import {
createFieldQuery,
Expand Down Expand Up @@ -30,9 +31,7 @@ const handleRequiredField = async (
modelSlug: string,
field: ModelField,
definedFields: Array<ModelField> | undefined,
options?: {
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
): Promise<{
defaultValue: string | boolean | undefined;
definedFields: Array<ModelField> | undefined;
Expand Down Expand Up @@ -94,10 +93,7 @@ export const diffFields = async (
modelSlug: string,
indexes: Array<ModelIndex>,
triggers: Array<ModelTrigger>,
options?: {
rename?: boolean;
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
): Promise<Array<string>> => {
const diff: Array<string> = [];

Expand Down Expand Up @@ -321,9 +317,7 @@ export const createFields = async (
fields: Array<ModelField>,
modelSlug: string,
definedFields?: Array<ModelField>,
options?: {
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
): Promise<Array<string>> => {
const diff: Array<string> = [];

Expand Down
18 changes: 10 additions & 8 deletions src/utils/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import {
import { confirm } from '@inquirer/prompts';
import type { Model } from '@ronin/compiler';

/**
* Options for migration operations.
*/
export type MigrationOptions = {
rename?: boolean;
requiredDefault?: boolean | string;
};

/**
* Fields to ignore.
* There are several fields that are not relevant for the migration process.
Expand Down Expand Up @@ -40,10 +48,7 @@ export const IGNORED_FIELDS = [
export const diffModels = async (
definedModels: Array<Model>,
existingModels: Array<Model>,
options?: {
rename?: boolean;
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
): Promise<Array<string>> => {
const diff: Array<string> = [];

Expand Down Expand Up @@ -97,10 +102,7 @@ export const diffModels = async (
const adjustModels = async (
definedModels: Array<Model>,
existingModels: Array<Model>,
options?: {
rename?: boolean;
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
): Promise<Array<string>> => {
const diff: Array<string> = [];

Expand Down
10 changes: 3 additions & 7 deletions tests/fixtures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { diffModels } from '@/src/utils/migration';
import { type MigrationOptions, diffModels } from '@/src/utils/migration';
import { type LocalPackages, getLocalPackages } from '@/src/utils/misc';
import { getModels } from '@/src/utils/model';
import { Protocol } from '@/src/utils/protocol';
Expand Down Expand Up @@ -66,8 +66,7 @@ export const prefillDatabase = async (
*
* @param definedModels - The new/updated model definitions to migrate to.
* @param existingModels - The current models in the database.
* @param enableRename - Whether to enable model renaming during migration
* (defaults to `false`).
* @param options - Optional configuration for migration operations.
* @param insertStatements - The statements that should be executed to insert records into
* the database.
*
Expand All @@ -81,10 +80,7 @@ export const prefillDatabase = async (
export const runMigration = async (
definedModels: Array<Model>,
existingModels: Array<Model>,
options?: {
rename?: boolean;
requiredDefault?: boolean | string;
},
options?: MigrationOptions,
insertStatements: Array<Statement> = [],
): Promise<{
db: Database;
Expand Down

0 comments on commit 2c71407

Please sign in to comment.