prisma-laravel-migrate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.gitattributes +2 -0
  2. package/.vscode/launch.json +21 -0
  3. package/.vscode/settings.json +11 -0
  4. package/@types/cli/index.d.ts +1 -0
  5. package/@types/cli/models.index.d.ts +1 -0
  6. package/@types/generator/migrator/PrismaToLaravelMigrationGenerator.d.ts +29 -0
  7. package/@types/generator/migrator/actions-map.d.ts +6 -0
  8. package/@types/generator/migrator/column-definition-types.d.ts +60 -0
  9. package/@types/generator/migrator/column-definition.d.ts +17 -0
  10. package/@types/generator/migrator/column-maps.d.ts +71 -0
  11. package/@types/generator/migrator/index.d.ts +3 -0
  12. package/@types/generator/migrator/migration-generator.d.ts +3 -0
  13. package/@types/generator/migrator/migrationTypes.d.ts +62 -0
  14. package/@types/generator/migrator/rule-definition.d.ts +25 -0
  15. package/@types/generator/migrator/rules.d.ts +40 -0
  16. package/@types/generator/modeler/generator.d.ts +14 -0
  17. package/@types/generator/modeler/index.d.ts +6 -0
  18. package/@types/generator/modeler/types.d.ts +42 -0
  19. package/@types/generator/utils.d.ts +42 -0
  20. package/@types/global.d.ts +1 -0
  21. package/@types/migrations.d.ts +2 -0
  22. package/@types/models.d.ts +2 -0
  23. package/@types/printer/migrations.d.ts +10 -0
  24. package/@types/printer/models.d.ts +36 -0
  25. package/@types/test.d.ts +0 -0
  26. package/LICENSE +21 -0
  27. package/dist/cli/index.js +10 -0
  28. package/dist/cli/index.js.map +1 -0
  29. package/dist/cli/models.index.js +10 -0
  30. package/dist/cli/models.index.js.map +1 -0
  31. package/dist/generator/migrator/PrismaToLaravelMigrationGenerator.js +44 -0
  32. package/dist/generator/migrator/PrismaToLaravelMigrationGenerator.js.map +1 -0
  33. package/dist/generator/migrator/actions-map.js +18 -0
  34. package/dist/generator/migrator/actions-map.js.map +1 -0
  35. package/dist/generator/migrator/column-definition-types.js +2 -0
  36. package/dist/generator/migrator/column-definition-types.js.map +1 -0
  37. package/dist/generator/migrator/column-definition.js +98 -0
  38. package/dist/generator/migrator/column-definition.js.map +1 -0
  39. package/dist/generator/migrator/column-maps.js +84 -0
  40. package/dist/generator/migrator/column-maps.js.map +1 -0
  41. package/dist/generator/migrator/index.js +88 -0
  42. package/dist/generator/migrator/index.js.map +1 -0
  43. package/dist/generator/migrator/migrationTypes.js +63 -0
  44. package/dist/generator/migrator/migrationTypes.js.map +1 -0
  45. package/dist/generator/migrator/rule-definition.js +47 -0
  46. package/dist/generator/migrator/rule-definition.js.map +1 -0
  47. package/dist/generator/migrator/rules.js +227 -0
  48. package/dist/generator/migrator/rules.js.map +1 -0
  49. package/dist/generator/modeler/generator.js +130 -0
  50. package/dist/generator/modeler/generator.js.map +1 -0
  51. package/dist/generator/modeler/index.js +64 -0
  52. package/dist/generator/modeler/index.js.map +1 -0
  53. package/dist/generator/modeler/types.js +2 -0
  54. package/dist/generator/modeler/types.js.map +1 -0
  55. package/dist/generator/utils.js +239 -0
  56. package/dist/generator/utils.js.map +1 -0
  57. package/dist/global.js +2 -0
  58. package/dist/global.js.map +1 -0
  59. package/dist/migrations.js +3 -0
  60. package/dist/migrations.js.map +1 -0
  61. package/dist/models.js +3 -0
  62. package/dist/models.js.map +1 -0
  63. package/dist/printer/migrations.js +32 -0
  64. package/dist/printer/migrations.js.map +1 -0
  65. package/dist/printer/models.js +63 -0
  66. package/dist/printer/models.js.map +1 -0
  67. package/dist/test.js +2 -0
  68. package/dist/test.js.map +1 -0
  69. package/package.json +50 -0
  70. package/schema.prisma +203 -0
  71. package/scripts/gen-laravel.js +63 -0
  72. package/scripts/toCommons.cjs +18 -0
  73. package/src/cli/index.ts +11 -0
  74. package/src/cli/models.index.ts +10 -0
  75. package/src/generator/migrator/PrismaToLaravelMigrationGenerator.ts +64 -0
  76. package/src/generator/migrator/actions-map.ts +35 -0
  77. package/src/generator/migrator/column-definition-types.ts +70 -0
  78. package/src/generator/migrator/column-definition.ts +122 -0
  79. package/src/generator/migrator/column-maps.ts +92 -0
  80. package/src/generator/migrator/index.ts +130 -0
  81. package/src/generator/migrator/migrationTypes.ts +62 -0
  82. package/src/generator/migrator/rule-definition.ts +62 -0
  83. package/src/generator/migrator/rules.ts +290 -0
  84. package/src/generator/modeler/generator.ts +165 -0
  85. package/src/generator/modeler/index.ts +108 -0
  86. package/src/generator/modeler/types.ts +50 -0
  87. package/src/generator/utils.ts +328 -0
  88. package/src/global.ts +2 -0
  89. package/src/migrations.ts +2 -0
  90. package/src/models.ts +2 -0
  91. package/src/printer/migrations.ts +42 -0
  92. package/src/printer/models.ts +96 -0
  93. package/src/test.ts +0 -0
  94. package/stubs/enums.stub +10 -0
  95. package/stubs/migration.stub +28 -0
  96. package/stubs/model.stub +85 -0
  97. package/stubs/simple-model.stub +14 -0
  98. package/tsconfig.json +20 -0
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
@@ -0,0 +1,21 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+
8
+ {
9
+ "type": "node",
10
+ "request": "launch",
11
+ "name": "Launch Program",
12
+ "skipFiles": [
13
+ "<node_internals>/**"
14
+ ],
15
+ "program": "${workspaceFolder}\\scripts\\gen-laravel.js",
16
+ "outFiles": [
17
+ "${workspaceFolder}/**/*.js"
18
+ ]
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "files.exclude": {
3
+ ".gitattributes": true,
4
+ ".gitignore": true,
5
+ "LICENSE": true,
6
+ "node_modules": true,
7
+ "package-lock.json": true,
8
+ "tsconfig.json": true,
9
+ ".vscode": true
10
+ }
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { ColumnDefinition } from "./column-definition-types.js";
3
+ import { Rule } from "./rules.js";
4
+ /**
5
+ * The shape returned by the generator—pure data, no rendering.
6
+ */
7
+ export interface Migration {
8
+ /** Table name (from dbName or model name) */
9
+ tableName: string;
10
+ /** Fully resolved migration lines for that table */
11
+ statements: string[];
12
+ /** The ColumnDefinition objects used to produce those statements */
13
+ definitions: ColumnDefinition[];
14
+ }
15
+ export declare class PrismaToLaravelMigrationGenerator {
16
+ private dmmf;
17
+ private columnGen;
18
+ private ruleResolver;
19
+ constructor(dmmf: DMMF.Document, customRules?: Rule[]);
20
+ /**
21
+ * Given an array of ColumnDefinition, apply rules and return PHP snippets.
22
+ * Skips any definitions marked `ignore = true`.
23
+ */
24
+ private resolveColumns;
25
+ /**
26
+ * Generate a Migration object for each model, using per‐model definitions.
27
+ */
28
+ generateAll(): Migration[];
29
+ }
@@ -0,0 +1,6 @@
1
+ import { RelationshipOptions } from "./column-definition-types";
2
+ /**
3
+ * Convert a Prisma referential action into the corresponding Laravel action.
4
+ * Falls back to 'restrict' if you ever get an unexpected value.
5
+ */
6
+ export declare function mapPrismaActionToLaravel(action: string): Exclude<RelationshipOptions['onDelete'], undefined>;
@@ -0,0 +1,60 @@
1
+ import { DMMF } from '@prisma/generator-helper';
2
+ import { MigrationTypes } from './migrationTypes';
3
+ /**
4
+ * The union of all values in the MigrationTypes object.
5
+ */
6
+ export type MigrationType = typeof MigrationTypes[keyof typeof MigrationTypes];
7
+ /**
8
+ * Options for defining a foreign key relationship.
9
+ */
10
+ export interface RelationshipOptions {
11
+ /** The column this references (defaults to 'id') */
12
+ references?: string;
13
+ /** The table this references */
14
+ on: string;
15
+ /** Action on delete */
16
+ onDelete?: 'cascade' | 'restrict' | 'set null' | 'no action' | 'set default';
17
+ /** Action on update */
18
+ onUpdate?: 'cascade' | 'restrict' | 'set null' | 'no action' | 'set default';
19
+ /**Ignore for migrations */
20
+ ignore?: boolean;
21
+ }
22
+ /**
23
+ * Extra properties for Laravel migration column definitions.
24
+ */
25
+ export interface ColumnExtras {
26
+ /** The native DB type, e.g., "VarChar(255)" */
27
+ nativeType: string;
28
+ /** Parsed args from the nativeType, e.g. [255] or [10,2] */
29
+ args?: Array<number | string | any[]>;
30
+ /** The mapped Laravel migration type (strictly one of MigrationType) */
31
+ migrationType: MigrationType;
32
+ /** Marks the column as unsigned */
33
+ unsigned?: boolean;
34
+ /** Marks the column as nullable */
35
+ nullable?: boolean;
36
+ /** Column comment */
37
+ comment?: string;
38
+ /** Foreign key relationship options */
39
+ relationship?: RelationshipOptions;
40
+ /** Ignore definition */
41
+ ignore?: boolean;
42
+ }
43
+ /**
44
+ * Column definition when no default value is present.
45
+ */
46
+ export type ColumnDefinitionWithoutDefault = DMMF.Field & ColumnExtras & {
47
+ hasDefaultValue: false;
48
+ };
49
+ /**
50
+ * Column definition when a default value is present.
51
+ */
52
+ export type ColumnDefinitionWithDefault = DMMF.Field & ColumnExtras & {
53
+ hasDefaultValue: true;
54
+ /** Default value (string, number, boolean, or null) */
55
+ default: string | number | boolean | null;
56
+ };
57
+ /**
58
+ * A strict union of column definitions, discriminated by `hasDefaultValue`.
59
+ */
60
+ export type ColumnDefinition = ColumnDefinitionWithoutDefault | ColumnDefinitionWithDefault;
@@ -0,0 +1,17 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { ColumnDefinition } from "./column-definition-types";
3
+ /**
4
+ * Helper class to build ColumnDefinition objects from Prisma DMMF.Field.
5
+ */
6
+ export declare class ColumnDefinitionGenerator {
7
+ #private;
8
+ private dmmf;
9
+ constructor(dmmf: DMMF.Document);
10
+ getColumns(): Record<string, ColumnDefinition[]>;
11
+ getColumns(modelName: string): ColumnDefinition[];
12
+ /**
13
+ * Generate a ColumnDefinition from a DMMF.Field.
14
+ */
15
+ generate(field: DMMF.Field): ColumnDefinition;
16
+ private mapPrismaAction;
17
+ }
@@ -0,0 +1,71 @@
1
+ export declare const NativeToMigrationTypeMap: {
2
+ Text: "text";
3
+ TinyText: "tinyText";
4
+ MediumText: "mediumText";
5
+ LongText: "longText";
6
+ Char: "char";
7
+ NChar: "char";
8
+ CatalogSingleChar: "char";
9
+ VarChar: "string";
10
+ NVarChar: "string";
11
+ String: "string";
12
+ Xml: "text";
13
+ NText: "text";
14
+ Citext: "text";
15
+ Boolean: "boolean";
16
+ Bool: "boolean";
17
+ Bit: "boolean";
18
+ VarBit: "binary";
19
+ TinyInt: "tinyInteger";
20
+ UnsignedTinyInt: "unsignedTinyInteger";
21
+ SmallInt: "smallInteger";
22
+ UnsignedSmallInt: "unsignedSmallInteger";
23
+ MediumInt: "mediumInteger";
24
+ UnsignedMediumInt: "unsignedMediumInteger";
25
+ Int2: "smallInteger";
26
+ Int4: "integer";
27
+ Int8: "bigInteger";
28
+ Integer: "integer";
29
+ Int: "integer";
30
+ BigInt: "bigInteger";
31
+ Long: "bigInteger";
32
+ Oid: "integer";
33
+ UnsignedInt: "unsignedInteger";
34
+ UnsignedBigInt: "unsignedBigInteger";
35
+ Float4: "float";
36
+ Float8: "double";
37
+ Float: "float";
38
+ Double: "double";
39
+ DoublePrecision: "double";
40
+ Real: "double";
41
+ Decimal: "decimal";
42
+ Money: "decimal";
43
+ SmallMoney: "decimal";
44
+ Date: "date";
45
+ Time: "time";
46
+ Timetz: "timeTz";
47
+ Timestamp: "timestamp";
48
+ Timestamptz: "timestampsTz";
49
+ DateTime: "timestamp";
50
+ DateTime2: "dateTime";
51
+ SmallDateTime: "dateTime";
52
+ DateTimeOffset: "dateTimeTz";
53
+ Year: "year";
54
+ Json: "json";
55
+ JsonB: "jsonb";
56
+ ByteA: "binary";
57
+ Binary: "binary";
58
+ VarBinary: "binary";
59
+ TinyBlob: "binary";
60
+ Blob: "binary";
61
+ MediumBlob: "binary";
62
+ LongBlob: "binary";
63
+ BinData: "binary";
64
+ Image: "binary";
65
+ Bytes: "binary";
66
+ Uuid: "uuid";
67
+ UniqueIdentifier: "uuid";
68
+ ObjectId: "string";
69
+ Inet: "ipAddress";
70
+ };
71
+ export declare function getType(type: string): ValueOf<typeof NativeToMigrationTypeMap>;
@@ -0,0 +1,3 @@
1
+ import { GeneratorOptions } from "@prisma/generator-helper";
2
+ import { Migration } from "./PrismaToLaravelMigrationGenerator.js";
3
+ export declare function generateLaravelSchema(options: GeneratorOptions): Promise<Migration[]>;
@@ -0,0 +1,3 @@
1
+ import { GeneratorOptions } from "@prisma/generator-helper";
2
+ import { Migration } from "./PrismaToLaravelMigrationGenerator.js";
3
+ export declare function generateLaravelSchema(options: GeneratorOptions): Promise<Migration[]>;
@@ -0,0 +1,62 @@
1
+ export declare const MigrationTypes: {
2
+ readonly boolean: "boolean";
3
+ readonly char: "char";
4
+ readonly longText: "longText";
5
+ readonly mediumText: "mediumText";
6
+ readonly string: "string";
7
+ readonly text: "text";
8
+ readonly tinyText: "tinyText";
9
+ readonly bigIncrements: "bigIncrements";
10
+ readonly bigInteger: "bigInteger";
11
+ readonly decimal: "decimal";
12
+ readonly double: "double";
13
+ readonly float: "float";
14
+ readonly id: "id";
15
+ readonly increments: "increments";
16
+ readonly integer: "integer";
17
+ readonly mediumIncrements: "mediumIncrements";
18
+ readonly mediumInteger: "mediumInteger";
19
+ readonly smallIncrements: "smallIncrements";
20
+ readonly smallInteger: "smallInteger";
21
+ readonly tinyIncrements: "tinyIncrements";
22
+ readonly tinyInteger: "tinyInteger";
23
+ readonly unsignedBigInteger: "unsignedBigInteger";
24
+ readonly unsignedInteger: "unsignedInteger";
25
+ readonly unsignedMediumInteger: "unsignedMediumInteger";
26
+ readonly unsignedSmallInteger: "unsignedSmallInteger";
27
+ readonly unsignedTinyInteger: "unsignedTinyInteger";
28
+ readonly dateTime: "dateTime";
29
+ readonly dateTimeTz: "dateTimeTz";
30
+ readonly date: "date";
31
+ readonly time: "time";
32
+ readonly timeTz: "timeTz";
33
+ readonly timestamp: "timestamp";
34
+ readonly timestamps: "timestamps";
35
+ readonly timestampsTz: "timestampsTz";
36
+ readonly softDeletes: "softDeletes";
37
+ readonly softDeletesTz: "softDeletesTz";
38
+ readonly year: "year";
39
+ readonly binary: "binary";
40
+ readonly json: "json";
41
+ readonly jsonb: "jsonb";
42
+ readonly ulid: "ulid";
43
+ readonly ulidMorphs: "ulidMorphs";
44
+ readonly uuid: "uuid";
45
+ readonly uuidMorphs: "uuidMorphs";
46
+ readonly nullableUlidMorphs: "nullableUlidMorphs";
47
+ readonly nullableUuidMorphs: "nullableUuidMorphs";
48
+ readonly geography: "geography";
49
+ readonly geometry: "geometry";
50
+ readonly foreignId: "foreignId";
51
+ readonly foreignIdFor: "foreignIdFor";
52
+ readonly foreignUlid: "foreignUlid";
53
+ readonly foreignUuid: "foreignUuid";
54
+ readonly morphs: "morphs";
55
+ readonly nullableMorphs: "nullableMorphs";
56
+ readonly enum: "enum";
57
+ readonly set: "set";
58
+ readonly macAddress: "macAddress";
59
+ readonly ipAddress: "ipAddress";
60
+ readonly rememberToken: "rememberToken";
61
+ readonly vector: "vector";
62
+ };
@@ -0,0 +1,25 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { ColumnDefinition } from "./column-definition-types";
3
+ import { Render, Rule } from "./rules.js";
4
+ /**
5
+ * Encapsulates all special‐case column rendering rules.
6
+ * Needs access to the full DMMF document and the set of all column definitions
7
+ * in order to support rules that depend on other columns (e.g. composite keys).
8
+ */
9
+ export declare class RuleResolver {
10
+ private dmmf;
11
+ private customRules;
12
+ private definitions;
13
+ constructor(dmmf: DMMF.Document, customRules?: Rule[]);
14
+ /**
15
+ * Supply the full list of column definitions so that rules can inspect
16
+ * other columns (e.g. detect composite primary keys or multi‐column morphs).
17
+ */
18
+ setDefinitions(defs: ColumnDefinition[]): void;
19
+ private rules;
20
+ /**
21
+ * Returns the special‐case lines for this column,
22
+ * or an empty array if none of the rules match.
23
+ */
24
+ resolve(def: ColumnDefinition): Render;
25
+ }
@@ -0,0 +1,40 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { ColumnDefinition } from "./column-definition-types";
3
+ export interface Rule {
4
+ test(def: ColumnDefinition, allDefs: ColumnDefinition[], dmmf: DMMF.Document): boolean;
5
+ render(def: ColumnDefinition, allDefs: ColumnDefinition[], dmmf: DMMF.Document): Render;
6
+ }
7
+ export interface Render {
8
+ column: string;
9
+ snippet: string[];
10
+ }
11
+ /** ID primary key */
12
+ declare const idRule: Rule;
13
+ /** timezone‐aware timestamps → timestampsTz() */
14
+ declare const timestampsTzRule: Rule;
15
+ /** plain timestamps → timestamps() */
16
+ declare const timestampsRule: Rule;
17
+ /** timezone‐aware soft deletes → softDeletesTz() */
18
+ declare const softDeletesTzRule: Rule;
19
+ /** plain soft deletes → softDeletes() */
20
+ declare const softDeletesRule: Rule;
21
+ /** remember token */
22
+ declare const rememberTokenRule: Rule;
23
+ /** Foreign ID shorthand, plus ignore its related back‐reference */
24
+ declare const foreignIdRule: Rule;
25
+ /** morphs (non‐nullable polymorphic) */
26
+ declare const morphsRule: Rule;
27
+ /** nullableMorphs (nullable polymorphic) */
28
+ declare const nullableMorphsRule: Rule;
29
+ /** combine/_merge is handled via the two morphs rules above, skip the merge rule */
30
+ /**
31
+ * Fallback renderer: respects def.ignore
32
+ */
33
+ declare function defaultBuild(def: ColumnDefinition): {
34
+ column: string;
35
+ snippet: string[];
36
+ };
37
+ /** Merge `<base>_id` + `<base>_type` into one morphs call */
38
+ declare const morphsMergeRule: Rule;
39
+ export { idRule, timestampsTzRule, timestampsRule, softDeletesTzRule, softDeletesRule, rememberTokenRule, foreignIdRule, morphsMergeRule, // <— added back
40
+ morphsRule, nullableMorphsRule, defaultBuild, };
@@ -0,0 +1,14 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { ModelDefinition, EnumDefinition } from "./types";
3
+ /**
4
+ * Build ModelDefinition[] + EnumDefinition[] from your DMMF.
5
+ */
6
+ export declare class PrismaToLaravelModelGenerator {
7
+ private dmmf;
8
+ constructor(dmmf: DMMF.Document);
9
+ generateAll(): {
10
+ models: ModelDefinition[];
11
+ enums: EnumDefinition[];
12
+ };
13
+ private mapPrismaToPhpType;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { GeneratorOptions } from "@prisma/generator-helper";
2
+ import { ModelDefinition, EnumDefinition } from "./types";
3
+ export declare function generateLaravelModels(options: GeneratorOptions): Promise<{
4
+ models: ModelDefinition[];
5
+ enums: EnumDefinition[];
6
+ }>;
@@ -0,0 +1,42 @@
1
+ /** Reuse these from your model‐generator file */
2
+ export interface EnumDefinition {
3
+ name: string;
4
+ values: string[];
5
+ }
6
+ export interface RelationDefinition {
7
+ name: string;
8
+ type: 'belongsTo' | 'hasOne' | 'hasMany' | 'belongsToMany' | 'morphTo' | 'morphMany' | 'morphToMany';
9
+ modelClass: string;
10
+ foreignKey?: string;
11
+ localKey?: string;
12
+ pivotTable?: string;
13
+ morphType?: string;
14
+ }
15
+ export interface PropertyDefinition {
16
+ name: string;
17
+ phpType: string;
18
+ fillable: boolean;
19
+ hidden: boolean;
20
+ ignore: boolean;
21
+ cast?: string;
22
+ enumRef?: string;
23
+ relation?: RelationDefinition;
24
+ typeAnnotation?: {
25
+ import?: string;
26
+ type: string;
27
+ };
28
+ }
29
+ export interface ModelDefinition {
30
+ className: string;
31
+ tableName: string;
32
+ properties: PropertyDefinition[];
33
+ relations: RelationDefinition[];
34
+ enums: EnumDefinition[];
35
+ interfaces: Record<string, {
36
+ import?: string;
37
+ type: string;
38
+ }>;
39
+ /** NEW: list of fields to put in $guarded, if any */
40
+ guarded?: string[];
41
+ with?: string[];
42
+ }
@@ -0,0 +1,42 @@
1
+ import { DMMF } from "@prisma/generator-helper";
2
+ import { MigrationType } from "./migrator/column-definition-types.js";
3
+ import { Migration } from "./migrator/PrismaToLaravelMigrationGenerator.js";
4
+ import { ModelDefinition } from "./modeler/types.js";
5
+ /**
6
+ * Given a Prisma field default, return the PHP code fragment
7
+ * to append to your migration column definition.
8
+ *
9
+ * You’ll need to have `use Illuminate\Support\Facades\DB;`
10
+ * at the top of your migration stub for the `DB::raw()` calls.
11
+ */
12
+ export declare function formatDefault(field: DMMF.Field): string;
13
+ export declare function getType(field: DMMF.Field): MigrationType;
14
+ /**
15
+ * Reorders migrations so that any table with foreign‐key dependencies
16
+ * is always migrated *after* the tables it references.
17
+ *
18
+ * @param migrations Array of Migration objects (with tableName & definitions[])
19
+ * @returns New array sorted in dependency order
20
+ * @throws If there’s a cycle in the relationships
21
+ */
22
+ export declare function sortMigrations(migrations: Migration[]): Migration[];
23
+ export declare function buildModelContent(model: ModelDefinition): string;
24
+ /**
25
+ * Escape a stub’s contents so it can be safely wrapped in a JS template literal.
26
+ * This will:
27
+ * - Escape all backslashes
28
+ * - Escape all backticks
29
+ */
30
+ export declare function formatStub(stub: string): string;
31
+ /**
32
+ * Safely write or update a file by replacing the region between
33
+ * startMarker and endMarker if both exist, otherwise overwrite the whole file.
34
+ *
35
+ * @param filePath Path to the target file
36
+ * @param fullContent The full text to write if markers are missing
37
+ * @param generated The text to inject between the markers
38
+ * @param startMarker Literal string marking the region start
39
+ * @param endMarker Literal string marking the region end
40
+ * @param overwrite If false and file exists, do nothing
41
+ */
42
+ export declare function writeWithMarkers(filePath: string, fullContent: string, generated: string, startMarker: string, endMarker: string, overwrite: boolean): void;
@@ -0,0 +1 @@
1
+ type ValueOf<T> = T[keyof T];
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './generator/migrator/index.js';
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './cli/generator-models.js';
@@ -0,0 +1,10 @@
1
+ import { Migration } from '../generator/migrator/PrismaToLaravelMigrationGenerator.js';
2
+ export declare class StubMigrationPrinter {
3
+ private tmplFn;
4
+ constructor(stubFilePath: string);
5
+ printMigration(mig: Migration): {
6
+ fullContent: string;
7
+ columns: string;
8
+ };
9
+ printAll(migs: Migration[]): string;
10
+ }
@@ -0,0 +1,36 @@
1
+ import { ModelDefinition, EnumDefinition } from 'generator/modeler/types';
2
+ /**
3
+ * Loads JS‐based stubs for both models and enums, and evaluates
4
+ * their `${…}` placeholders at runtime.
5
+ *
6
+ * The model stub must include a `${content}` placeholder.
7
+ */
8
+ export declare class StubModelPrinter {
9
+ private modelTmpl;
10
+ private enumTmpl;
11
+ constructor(modelStubPath: string, enumStubPath: string);
12
+ /**
13
+ * Render a single enum class.
14
+ */
15
+ printEnum(enumDef: EnumDefinition): string;
16
+ /**
17
+ * Render multiple enum classes concatenated with two newlines.
18
+ */
19
+ printAllEnums(enums: EnumDefinition[]): string;
20
+ /**
21
+ * Render a single model class, injecting a pre-built `content` string.
22
+ */
23
+ printModel(model: ModelDefinition, enums: EnumDefinition[], content: string): string;
24
+ /**
25
+ * Render multiple model classes, each with its own `content`, concatenated.
26
+ *
27
+ * @param models Array of ModelDefinition
28
+ * @param enums Array of EnumDefinition
29
+ * @param contents Array of content strings matching each model
30
+ */
31
+ printAllModels(models: ModelDefinition[], enums: EnumDefinition[], contents: string[]): string;
32
+ /**
33
+ * Render enums first, then models (with their contents).
34
+ */
35
+ printAll(models: ModelDefinition[], enums: EnumDefinition[], contents: string[]): string;
36
+ }
File without changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 David Okpako
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import { generatorHandler } from "@prisma/generator-helper";
2
+ import { generateLaravelSchema } from "../generator/migrator/index.js";
3
+ generatorHandler({
4
+ onGenerate: generateLaravelSchema,
5
+ onManifest: () => ({
6
+ defaultOutput: './database/migrations',
7
+ prettyName: 'Laravel Schema',
8
+ }),
9
+ });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAGvE,gBAAgB,CAAC;IACd,UAAU,EAAE,qBAAqB;IACjC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAChB,aAAa,EAAE,uBAAuB;QACtC,UAAU,EAAE,gBAAgB;KAC9B,CAAC;CACJ,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { generatorHandler } from "@prisma/generator-helper";
2
+ import { generateLaravelModels } from "generator/modeler";
3
+ generatorHandler({
4
+ onGenerate: generateLaravelModels,
5
+ onManifest: () => ({
6
+ defaultOutput: './database/migrations',
7
+ prettyName: 'Laravel Schema',
8
+ }),
9
+ });
10
+ //# sourceMappingURL=models.index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.index.js","sourceRoot":"","sources":["../../src/cli/models.index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,gBAAgB,CAAC;IACd,UAAU,EAAE,qBAAqB;IACjC,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QAChB,aAAa,EAAE,uBAAuB;QACtC,UAAU,EAAE,gBAAgB;KAC9B,CAAC;CACJ,CAAC,CAAA"}
@@ -0,0 +1,44 @@
1
+ import { ColumnDefinitionGenerator } from "./column-definition.js";
2
+ import { RuleResolver } from "./rule-definition.js";
3
+ export class PrismaToLaravelMigrationGenerator {
4
+ dmmf;
5
+ columnGen;
6
+ ruleResolver;
7
+ constructor(dmmf, customRules = []) {
8
+ this.dmmf = dmmf;
9
+ this.columnGen = new ColumnDefinitionGenerator(dmmf);
10
+ this.ruleResolver = new RuleResolver(dmmf, customRules);
11
+ }
12
+ /**
13
+ * Given an array of ColumnDefinition, apply rules and return PHP snippets.
14
+ * Skips any definitions marked `ignore = true`.
15
+ */
16
+ resolveColumns(defs) {
17
+ this.ruleResolver.setDefinitions(defs);
18
+ return defs.flatMap(def => {
19
+ // Apply rules: may set def.ignore and return { column, snippet }
20
+ const { snippet } = this.ruleResolver.resolve(def);
21
+ // If the rule marked this column to ignore, skip its snippets
22
+ if (def.ignore) {
23
+ return [];
24
+ }
25
+ return snippet;
26
+ });
27
+ }
28
+ /**
29
+ * Generate a Migration object for each model, using per‐model definitions.
30
+ */
31
+ generateAll() {
32
+ return this.dmmf.datamodel.models.map(model => {
33
+ const tableName = model.dbName ?? model.name;
34
+ const definitions = this.columnGen.getColumns(tableName);
35
+ const statements = this.resolveColumns(definitions);
36
+ return {
37
+ tableName,
38
+ definitions,
39
+ statements,
40
+ };
41
+ });
42
+ }
43
+ }
44
+ //# sourceMappingURL=PrismaToLaravelMigrationGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismaToLaravelMigrationGenerator.js","sourceRoot":"","sources":["../../../src/generator/migrator/PrismaToLaravelMigrationGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAgBpD,MAAM,OAAO,iCAAiC;IAIvB;IAHZ,SAAS,CAA4B;IACrC,YAAY,CAAe;IAEnC,YAAoB,IAAmB,EAAE,cAAsB,EAAE;QAA7C,SAAI,GAAJ,IAAI,CAAe;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,yBAAyB,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,IAAwB;QAC5C,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACvB,iEAAiE;YACjE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAEnD,8DAA8D;YAC9D,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;gBACd,OAAO,EAAE,CAAC;YACb,CAAC;YAED,OAAO,OAAO,CAAC;QAClB,CAAC,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACI,WAAW;QACf,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC;YAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACzD,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;YAEpD,OAAO;gBACJ,SAAS;gBACT,WAAW;gBACX,UAAU;aACZ,CAAC;QACL,CAAC,CAAC,CAAC;IACN,CAAC;CACH"}