Comments (18)
@leosuncin I wonder how I can migrate the database once I add more entities. and also when I changed the database name?
How to add more entities
- Create a new entity somewhere in your project
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Pet {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
- Register it the
data-source.ts
file
import { Pet } from './wherever/pet.entity';
export const dataSourceOptions: DataSourceOptions = {
// ...
entities: [ /* the other entities*/, Pet],
// ...
};
- Generate the new migration using TypeORM CLI
npm run typeorm migration:generate src/migrations/NameOfTheMigration
-
Review the generated migration and modified it as needed
-
Then add it to
data-source.ts
file
import { Pet } from './wherever/pet.entity';
import { NameOfTheMigration } from './migrations/name-of-the-migration';
export const dataSourceOptions: DataSourceOptions = {
// ...
entities: [ /* the other entities*/, Pet],
migrations: [
/* the other migrations, keep in mind that the order is important! */
NameOfTheMigration,
],
// ...
};
- Run the migrations
npm run typeorm migration:run
Check the documentation for further information https://orkhan.gitbook.io/typeorm/docs/migrations
Change the name of the database
The name of the database doesn't need to be "nestjs", it can be whatever you pick for, and set it in .env
.
If you want to change the name of an existing database google it and again change it in the .env
file
from nest-auth-example.
from nest-auth-example.
Replace the values in your connection connection string with the ones you're using
By example:
DATABASE_URL=postgres://user:password@postgres-host-name:5432/nestjs
Sorry, I'm writing from my phone, I can check it later if you need more help.
from nest-auth-example.
I run your docker container, so I guess, it's built-in setting?
from nest-auth-example.
from nest-auth-example.
The values in the .env.example
are examples values and they should be replaced with a more accurate ones.
The default ones should work when you run the following steps:
- Copy the default values:
cp .env.example .env
- Run the services with docker compose:
docker compose up -d
- Run the project with a local node.js installation:
npm run start:dev
This is because Docker Compose will run an instance of PostgreSQL listening on localhost:5432 with the user user
and password password
When the project run as a Docker container the PostgreSQL instance is not accessible through localhost:5432, you'll need to link both containers (the project and PostgreSQL) or run in the same network. Google it for more information
from nest-auth-example.
Yeah, that's exactly what I did (just followed steps in README)
from nest-auth-example.
But when I run yarn start:dev
, it shows the following error:
from nest-auth-example.
Hi @crazydevlegend, I updated the dependencies of the project, pull the changes and try again, please
from nest-auth-example.
@leosuncin I'm using windows 11, and am not sure if this template work on Windows either.
when i run npm run typeorm migration:run
, it said, NODE_OPTIONS
undefined.
So I installed wi-node-env
, and it shows another error.
from nest-auth-example.
oh, i just fixed this issue by installing ts-node
, .thanks 🙏
from nest-auth-example.
@leosuncin I'm using windows 11, and am not sure if this template work on Windows either. when i run
npm run typeorm migration:run
, it said,NODE_OPTIONS
undefined. So I installedwi-node-env
, and it shows another error.
Sorry, I'm not giving support for Windows since I don't use it anymore, but it should work with Bash for Windows or Windows Subsystem for Linux (WSL), due to this template heavily rely on environment variables as Bash define it. I haven't used wi-node-env
but I know that cross-env
works.
from nest-auth-example.
@leosuncin I wonder how I can migrate the database once I add more entities.
and also when I changed the database name?
from nest-auth-example.
You should take a look at your docker configuration, @salahawk
from nest-auth-example.
@leosuncin What if I want to remove an entity? (aka. TODO
entity)
I'm building my own app, and want to remove this TODO
entity, but when I run npm run typeorm migration:generate src/migrations/RemovedTODO
after removing TODO
in the entities
list in data-source.ts
, it says, no changes were found!!! (but actually, there's been changes - TODO
entity has been removed)
Do you have any ideas on this?
Thanks in advance
from nest-auth-example.
@leosuncin What if I want to remove an entity? (aka.
TODO
entity)
I'm building my own app, and want to remove thisTODO
entity, but when I runnpm run typeorm migration:generate src/migrations/RemovedTODO
after removingTODO
in theentities
list indata-source.ts
, it says, no changes were found!!! (but actually, there's been changes -TODO
entity has been removed)Do you have any ideas on this?
Thanks in advance
This is not related to this project, so I won't go deep but removing a entity from the data source doesn't necessary means that the table must be removed just ignored by the ORM, if you still need to remove the table create an empty migration and add the drop table statement
from nest-auth-example.
@leosuncin What if I want to remove an entity? (aka.
TODO
entity)
I'm building my own app, and want to remove thisTODO
entity, but when I runnpm run typeorm migration:generate src/migrations/RemovedTODO
after removingTODO
in theentities
list indata-source.ts
, it says, no changes were found!!! (but actually, there's been changes -TODO
entity has been removed)
Do you have any ideas on this?
Thanks in advanceThis is not related to this project, so I won't go deep but removing a entity from the data source doesn't necessary means that the table must be removed just ignored by the ORM, if you still need to remove the table create an empty migration and add the drop table statement
So you mean, typeorm does not automatically generate that DROP statement, right?
from nest-auth-example.
This is not proper place to ask questions about any other library if you have any technical questions ask them on stackoverflow, I will only respond to questions related to the functionality of this repository
from nest-auth-example.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest-auth-example.