{"id":13474933,"url":"https://github.com/jamiepine/prismix","last_synced_at":"2025-03-26T22:31:33.388Z","repository":{"id":37931385,"uuid":"388634172","full_name":"jamiepine/prismix","owner":"jamiepine","description":"The Prisma schema mixer 🍹","archived":true,"fork":false,"pushed_at":"2022-11-05T21:48:19.000Z","size":190,"stargazers_count":304,"open_issues_count":23,"forks_count":41,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-16T13:03:31.587Z","etag":null,"topics":["prisma"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamiepine.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-23T00:30:27.000Z","updated_at":"2025-03-07T00:39:46.000Z","dependencies_parsed_at":"2023-01-20T23:15:31.770Z","dependency_job_id":null,"html_url":"https://github.com/jamiepine/prismix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiepine%2Fprismix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiepine%2Fprismix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiepine%2Fprismix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiepine%2Fprismix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamiepine","download_url":"https://codeload.github.com/jamiepine/prismix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245747822,"owners_count":20665872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["prisma"],"created_at":"2024-07-31T16:01:16.054Z","updated_at":"2025-03-26T22:31:31.173Z","avatar_url":"https://github.com/jamiepine.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# `Prismix`\n \n### *The Prisma schema mixer 🍹*\n_Made for Prisma `^2.0`_\n\n[![Downloads](https://img.shields.io/npm/dt/prismix.svg?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/prismix)\n[![Downloads](https://img.shields.io/npm/v/prismix.svg?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/prismix)\n\n\nPrisma restricts your schema to a single file, Prismix allows you to write as many schema files as you'd like, wherever you like—all while supporting cross-file model relations 🤯\n\n\u003e Learn more about Prisma: [prisma.io](https://prisma.io)\n\n\nUnlike `prisma-merge`, Prismix allows model relations to exist between files by combining models and enums, allowing you to extend and override Models as you please. This is ideal when working in a monorepo where parts of your schema need to exist in separate modules.\n\n\n## Installation\n1. Install Prismix\n```\nyarn add prismix --dev\n```\nor NPM\n```\nnpm install prismix --dev\n```\n2. Create a `prismix.config.json` file in the root of your project. This allows you to define how you would like Prismix to merge your schemas. \n```json\n{\n  \"mixers\": [\n    {\n        \"input\": [\n            \"base.prisma\",\n            \"./modules/auth/auth.prisma\", \n            \"./modules/posts/posts.prisma\",\n        ],\n        \"output\": \"prisma/schema.prisma\"\n    }\n  ]\n}\n```\nThe order of your input files effects how overrides are considered, the later inputs take priority over the earlier inputs.\n\nThe default `output` value is `prisma/schema.prisma` (it can be omitted from the config) and Prisma encourages you to keep is as such, especially if you want to use `prisma format`.\n\n3. Add the `npx prismix` command as a prefix to your `package.json` scripts.\n```json\n{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"prismix\": \"npx prismix \u0026\u0026 prisma format\",\n    \"dev\": \"yarn prismix \u0026\u0026 ts-node server.ts\",\n  }\n}\n```\nOr just run `npx prismix` from within the repo that contains the Prismix config file. \n\nUsing `prisma format` is optional, but I like clean code.\n\nNote: If you are using a monorepo you won't be able to run this command from the root, if you add a script `\"prismix\": \"npx prismix\"` you could run `yarn workspace my-app prismix`.\n\n## Cross-file relations \n\nIn order to relate to a model defined in another file you **must create an alias model**. This is simply a model with only the `@id` field. \n\nThis is to ensure Prisma can parse the schema file, as Prismix uses the Prisma SDK to parse each file individually before merging models at field level.\n\n```prisma\nmodel Post {\n    id String @id @default(autoincrement())\n}\n```\nIn the above example `Post` would be a model defined in another schema, any fields added in this schema file will be merged with any `Post` model(s) in other schema files. The `@id` field is the only required field in an extended model, however you may add fields specific to a relation. (this is shown in greater detail below)\n\n## Example\nLet's go over how Prismix merges schemas. We'll keep it simple with two schemas that need to relate to each other.\n\n## `base.prisma`\n\n\n```prisma\ngenerator client {\n    provider = \"prisma-client-js\"\n}\n\ndatasource db {\n    provider = \"postgresql\"\n    url      = \"postgresql://...\"\n}\n\nmodel Account {\n    id       Int    @id @default(autoincrement())\n    username String\n    email    String\n    status   String\n\n    @@map(\"accounts\")\n}\n```\nWe've established our `generator` and `datasource`, as well as our first model, `Account`. It is required that these two definitions be present in at least one of your schemas.\n\n## `posts.prisma`\nNow we'll create the Posts schema in a different file. In order for posts to relate to accounts we can define an **empty model** to represent the account.\n\n```prisma\nmodel Post {\n    id         Int     @id @default(autoincrement())\n    title      String\n    content    String\n    account_id Int\n    account    Account @relation(fields: [account_id], references: [id])\n\n    @@map(\"posts\")\n}\n\nmodel Account {\n    id     Int @id\n    posts  Post[]\n}\n```\nWhen Prismix merges these two schemas the relations will be connected. \n\n## `schema.prisma`\nThis is the generated file, do not edit this file!\n\n```prisma\n// *** GENERATED BY PRISMIX :: DO NOT EDIT ***\n\ngenerator client {\n    provider = \"prisma-client-js\"\n}\n\ndatasource db {\n    provider = \"postgresql\"\n    url      = \"postgresql://...\"\n}\n\nmodel Account {\n    id       Int    @id @default(autoincrement())\n    username String\n    email    String\n    status   String\n    posts    Post[]\n}\n\nmodel Posts {\n    id         Int     @id @default(autoincrement())\n    title      String\n    content    String\n    account_id Int\n    account    Account @relation(fields: [account_id], references: [id])\n\n    @@map(\"posts\")\n}\n```\n\nAs you can see the property `posts` was added on to the original Account schema and the `account` relation on the Posts schema links to the original Account schema.\n\n\n\n## How it works\nUsing the Prisma SDK we parse the input schemas into a DMMF objects, then process the schema merge into a single DMMF object as per the config file, finally it is converted back into Prisma schema format using a custom deserializer, adapted from `@IBM/prisma-schema-transformer` and written to the output location.\n\n\n## To-do\n- [x] Make it work\n- [x] Add glob support for wildcard schema discovery\n- [ ] Make `prismix.config.json` optional\n- [ ] Add command flags\n\nCreated by [@jamiepine](https://twitter.com/jamiepine)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiepine%2Fprismix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamiepine%2Fprismix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiepine%2Fprismix/lists"}