I was started to learn a nestjs with typeorm
could somebody clarify
How to use an entity in migration
There is my case
in the src/entity, I was created 2 entities files named base.entity.ts and users.entity.ts
So
When I try to create the new migration file using a users.entity.ts I have seen this
Maybe somebody knows how to use a single entity users.entity.ts for next use a migration users file
Thanks
Related
Apologies in advance as I am unable to find a good solution regarding this.
Background: We are using Typeorm in express app and have too many migrations because its a little old project.
Question: Is there a good way to manage migrations? Ideally I would want to delete all migrations(generated till now) and have only single file for schema creation(updated automatically after every migration run) and another file for seeding master data. Using these two files any new developer can setup the database locally in no time.
I worked in Ruby on rails and there used to be a clean approach like ruby maintains the database schema all the time in schema.rb and database could be generated using that.
I researched a lot but couldn't find a maintainable solution. May be the experts here could help me.
Thanks in advance
All your schemas describe your data model at current time, you can just delete all migrations from code and database, it will be as if you had no migrations at all. The problem will be only with old versions of your database which needs to be migrated.
I am new in jhipster and I would like to know If I can create an entity for a view like the table with jhipster command ? And how to do it ?
I used jhipster entity command but I am not sure this is the right way to do it
JHipster does not support SQL views in Liquibase but JDL lets you flag an entity as read-only which will prevent generating code for creating or updating an entity.
You can then manually adapt generated code to replace table by view, it should be limited to Liquibase migration file.
See official JDL doc for examples: https://www.jhipster.tech/jdl/options
jhipster entity command also asks you whether new entity should be read-only.
I need to migrate the front-end of an application to angular. I want to use jhipster and reuse all existing java back-end and database. My questions are:
Is it possible to generate the front-end based on java model or i need to have the JDL files?
Is it possible to generate JDL files from the java model or from the database schema?
Thank you for your help.
No
No even though there has been some attempt like https://github.com/bastienmichaux/generator-jhipster-db-helper but I don't think it will go far enough for you
Thank you for your help.
I found another approach to generate the JDL files based on the database:
https://github.com/Blackdread/sql-to-jdl
I will try it.
I'm trying to create a Materialized view from my NestJS app using TypeORM.
The database is a Postgres.
View Entities unfortunately doesn't match requirements: https://www.bookstack.cn/read/TypeORM/view-entities.md
Wished behaviour: just like models, a materialized view is defined in the NestJS project, with the option 'synchronize:true' : the project creates the view on running if it doesn't exist, if it exist, it just sync with it (just like models).
Is there any leads that would help me achieving this?
What I ended up doing was defining the entity as a ViewEntity, setting {materialized:true}.
However, as you noted, typeorm doesn't handle this so well. I ended up disabling synchronization in the ormconfiguration and running migrations when I wanted to change things in the entity.
However, once the entity is created, typeorm works out of the box really well.
Is there any tool that works similar to Django South, but for Node?
Now I'm working with Sequelize. If I got it right, Sequelize does not have an option to create migration files based on existing models.
So, to create a new model/table, the steps are:
Create model with sequelize model:create <model meta>.
Edit generated migration file - add actual code for creating tables
in DB under up section.
Run migration with sequelize db:migrate.
I'm looking for something that can create migration files based on existing models, manage it similar to what South can do for Django.
Is there any option?
I have written a step-by-step guide on how to auto-create migrations with Sequelize in another post. Here is a summary...
The closest thing with Sequelize is
Sequelize Auto Migrations.
It allows you to have an iteration cycle like the following:
Create/update model -- by hand or with sequelize-cli)
Run makemigrations to auto-generate up and down migrations
Repeat as necessary
While this is very helpful, I've found it to be lacking in some critical areas:
The down migrations can be created incorrectly. So it may try to drop a table before its dependent tables have been dropped.
There are certain configurations around multi-field indexes that it has not correctly output.
There are currently 10 outstanding PRs, so it seems like a few additional contributors are attempting to make it more production-ready... but I've yet to find anything as clean and reliable as Django Migrations (formerly Django South).
TypeORM supports model based migrations. It can sync your db to your models directly, it can also create migration files too.
I think prisma is another option. It doesn't seem like that popular but it's a promising one.
Either way, it's just ridiculous that there are no solid tools for this. I've worked on django and .net projects in the last years and creating migrations is just easy with them. But when you try to use node.js for backend, you get stuck at a lot of points.
I was using sequelize and when I saw there was no official way to create automatic migrations from models, I've dropped using it. Maintaining your models with manually written migrations becomes very hard in my experience.
Now my only alternative is TypeORM and it just bugs me there is no other alternative in case TypeORM just goes unmaintained or if I want to use another library etc.
I'm seriously thinking dropping using node.js for backend. Yet, there are good tools to create projects integrated with modern front-end tools (like Next.js), finding a good orm is a big problem.
Take a look at https://typeorm.io/#/migrations/generating-migrations. I am in the same situation you was 4 years ago.
My options:
Waterline just for ORM and diff tool (like dbdiff) to make a file with differences from a new schema (generated by waterline migration with 'drop') vs production schema. With that output, you run query by query in a safe mode.
Prev option plus knex migrations. But you have to make your own migrations files. Knex doesnt have a schema file to compare but there is a request feature https://github.com/knex/knex/issues/1086.
Using sails but change waterline for sequalize and give a try at the #paulmest answer.
Use sails but change waterline for typeorm an use that auto generated.
Over the years, my team has tried Sequelize and TypeORM, but neither of them were great experiences. TypeORM had tons of cryptic problems and thousands of issues are unaddressed/open for years on end. Sequelize was generally fine, but lack of type support made it time-consuming to work with.
For the last 1.5 years, my team has been using Hasura. It's honestly been a breath of fresh air. Hasura's migration system is pretty barebones compared to Django South, but it is straight-forward and has a clean happy path.
You can use the Hasura Console (a localhost web editor) to create tables and add/remove columns. Those changes will be automatically distilled into schema changes stored in .sql files in a migration directory. You can modify these files. You can run a migration command from the command line to apply them when you want.
Since Hasura is a GraphQL engine, it also comes with a schematized SDK that is TypeScript compatible so you get incredible editor support.
All of this and much more is available in the open source version of their product. We have not needed to pay for any higher tier.
You can find more information here: https://hasura.io/docs/latest/graphql/core/migrations/index.html