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

[legacy-framework] Fix blitz generate model to add fields to existing model instead of duplicating #1251

Merged
merged 2 commits into from Oct 10, 2020

Conversation

engelkes-finstreet
Copy link
Collaborator

@engelkes-finstreet engelkes-finstreet commented Oct 5, 2020

Updates the existing model only with missing fields.

Closes: blitz-js/legacy-framework#704

What are the changes and their implications?

Right now if a user generates a model that already exists a new model is added to the schema.prisma. This changes the behavior to update the existing model only with the fields that do not exist yet.

Checklist

  • [X ] Tests added for changes
  • [X ] PR submitted to blitzjs.com for any user facing changes - PR

@blitzjs-bot blitzjs-bot bot added this to In Review in Dashboard Oct 5, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2020

Size Change: +1.61 kB (0%)

Total Size: 189 kB

Filename Size Change
packages/core/dist/core.cjs.development.js 12.3 kB +215 B (1%)
packages/core/dist/core.cjs.production.min.js 6.75 kB +31 B (0%)
packages/core/dist/core.esm.js 12 kB +244 B (2%)
packages/display/dist/display.cjs.development.js 1.43 kB +22 B (1%)
packages/display/dist/display.cjs.production.min.js 819 B +17 B (2%)
packages/display/dist/display.esm.js 1.33 kB +21 B (1%)
packages/generator/dist/generator.cjs.development.js 15.6 kB +382 B (2%)
packages/generator/dist/generator.cjs.production.min.js 9.44 kB +154 B (1%)
packages/generator/dist/generator.esm.js 15.3 kB +378 B (2%)
packages/installer/dist/installer.cjs.development.js 7.71 kB +59 B (0%)
packages/installer/dist/installer.cjs.production.min.js 5.13 kB +33 B (0%)
packages/installer/dist/installer.esm.js 7.57 kB +58 B (0%)
ℹ️ View Unchanged
Filename Size Change
packages/blitz/dist/cli.js 15.7 kB 0 B
packages/blitz/dist/index.js 245 B 0 B
packages/config/dist/config.cjs.development.js 1.35 kB 0 B
packages/config/dist/config.cjs.production.min.js 916 B 0 B
packages/config/dist/config.esm.js 1.28 kB 0 B
packages/config/dist/index.js 143 B 0 B
packages/core/dist/index.js 141 B 0 B
packages/display/dist/index.js 144 B 0 B
packages/file-pipeline/dist/file-pipeline.cjs.development.js 5.9 kB 0 B
packages/file-pipeline/dist/file-pipeline.cjs.production.min.js 3.02 kB 0 B
packages/file-pipeline/dist/file-pipeline.esm.js 5.76 kB 0 B
packages/file-pipeline/dist/index.js 147 B 0 B
packages/generator/dist/index.js 145 B 0 B
packages/generator/dist/templates/app/babel.config.js 77 B 0 B
packages/generator/dist/templates/app/blitz.config.js 324 B 0 B
packages/generator/dist/templates/app/jest.config.js 662 B 0 B
packages/generator/dist/templates/app/test/__mocks__/fileMock.js 54 B 0 B
packages/installer/dist/index.js 145 B 0 B
packages/repl/dist/index.js 141 B 0 B
packages/repl/dist/repl.cjs.development.js 1.73 kB 0 B
packages/repl/dist/repl.cjs.production.min.js 1.02 kB 0 B
packages/repl/dist/repl.esm.js 1.61 kB 0 B
packages/server/dist/index.js 142 B 0 B
packages/server/dist/server.cjs.development.js 20.4 kB 0 B
packages/server/dist/server.cjs.production.min.js 11.8 kB 0 B
packages/server/dist/server.esm.js 20.5 kB 0 B

compressed-size-action

//replace all content with the newly added fields for the already existing model
this.fs.write(path.resolve("db/schema.prisma"), schema.replace(model, newModel))
}
}
}
log.success(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @engelkes-finstreet!! Works great!

One more tweak, let's switch this success message do say "created" or "updated" depending on whether it added the whole model or just updated it.

Tell the user if the model was created or updated.
@flybayer flybayer changed the title Checks if the model and the fields to generate exists. Fix blitz generate model to add fields to existing model instead of duplicating Oct 10, 2020
@flybayer flybayer merged commit 0199605 into canary Oct 10, 2020
Dashboard automation moved this from In Review to Done Oct 10, 2020
@flybayer flybayer deleted the update-existing-model-instead-of-creating-new-one branch October 10, 2020 20:01
wanjuntham pushed a commit to wanjuntham/blitz that referenced this pull request Oct 11, 2020
nahue added a commit to nahue/blitz that referenced this pull request Oct 13, 2020
…-ink

* 'canary' of github.com:blitz-js/blitz:
  docs: add alexnaiman as a contributor (blitz-js#1299)
  Fix circular dependencies in blitz core (blitz-js#1249)
  docs: add aaronfulkerson as a contributor (blitz-js#1295)
  Remove "--experimental" from "blitz db studio" (blitz-js#1272)
  Remove Simon Debbarma and Jack Clancy from L1 maintainers. (blitz-js#1290)
  Update @aericson as a contributor
  Add @Kosai106 as a contributor
  docs: add cajotafer as a contributor (blitz-js#1293)
  (newapp) Add yarn/npx to global install instructions in readme (blitz-js#1285)
  Fix to allow babel config modification in Recipes (blitz-js#1280)
  Fix all recipes to add their context providers above getLayout() (blitz-js#1279)
  docs: add aericson as a contributor (blitz-js#1292)
  (newapp) Fix validateDOMNesting error from default home page (blitz-js#1277)
  Fix `blitz generate model` to add fields to existing model instead of duplicating (blitz-js#1251)
  Fix to not run husky during new app creation (blitz-js#1270)
  Adds tests for useSession in core super tokens (blitz-js#1258)
ntgussoni added a commit to ntgussoni/blitz that referenced this pull request Feb 7, 2021
* upstream/canary: (70 commits)
  docs: add alexnaiman as a contributor (blitz-js#1299)
  Fix circular dependencies in blitz core (blitz-js#1249)
  docs: add aaronfulkerson as a contributor (blitz-js#1295)
  Remove "--experimental" from "blitz db studio" (blitz-js#1272)
  Remove Simon Debbarma and Jack Clancy from L1 maintainers. (blitz-js#1290)
  Update @aericson as a contributor
  Add @Kosai106 as a contributor
  docs: add cajotafer as a contributor (blitz-js#1293)
  (newapp) Add yarn/npx to global install instructions in readme (blitz-js#1285)
  Fix to allow babel config modification in Recipes (blitz-js#1280)
  Fix all recipes to add their context providers above getLayout() (blitz-js#1279)
  docs: add aericson as a contributor (blitz-js#1292)
  (newapp) Fix validateDOMNesting error from default home page (blitz-js#1277)
  Fix `blitz generate model` to add fields to existing model instead of duplicating (blitz-js#1251)
  Fix to not run husky during new app creation (blitz-js#1270)
  Adds tests for useSession in core super tokens (blitz-js#1258)
  Add Alexandru Stratulat as L1 Maintainer (blitz-js#1271)
  v0.24.1
  Fix page template to use useMutation (blitz-js#1269)
  update patch for release script (meta)
  ...
@dillondotzip dillondotzip changed the title Fix blitz generate model to add fields to existing model instead of duplicating [legacy-framework] Fix blitz generate model to add fields to existing model instead of duplicating Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Improve prisma generate behaviour for updating a model that already exists in the schema
2 participants