sudo npm install -g typeorm
module.exports = {
"type": "type", // postgres, mysql
"host": "localhost",
"port": 5432,
"username": "username",
"password": "password",
"database": "test",
"dropSchema" : false,
"entities": ["./src/domain/**/*.ts"], // path to domain classes
"migrationsTableName": "migrations",
"migrations": ["./src/migrations/**/*.ts"], // path to migrations directory
"cli": {
"migrationsDir": "./src/migrations"
}
}
example: adding a column to a pre existing class
// important check for @Entity , @Column attributes at start of entity
import {Column, Entity} from "typeorm";
@Entity('x')
export class X{
// pre existing code
...
...
...
// add new column
@Column({nullable: true, array: true, type: String})
newColumnName: string[];
}
On console
npx ts-node ./node_modules/.bin/typeorm migration:generate -n AddNewColumnToX
you should see this code
instance for a postgres db
import {MigrationInterface, QueryRunner} from "typeorm";
export class AddNewColumnToX1534491159669 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "X" ADD "newColumnName" character varying array`);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "X" DROP COLUMN "newColumnName"`);
}
}
on console
npx ts-node ./node_modules/.bin/typeorm migration:run
on first migration , this should result
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
query: CREATE TABLE "migrations" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY ("id"))
query: SELECT * FROM "migrations" "migrations"
0 migrations are already loaded in the database.
1 migrations were found in the source code.
1 migrations are new migrations that needs to be executed.
query: START TRANSACTION
query: ALTER TABLE "X" ADD "newColumnName" character varying array
query: INSERT INTO "migrations"("timestamp", "name") VALUES ($1, $2) -- PARAMETERS: [1534491159669,"AddNewColumnToX1534491159669"]
Migration AddNewColumnToX1534491159669 has been executed successfully.
query: COMMIT
run tsc
module.exports = {
"type": "type",
"host": config.get('db.host'),
"port": 5432,
"username": config.get('db.user'),
"password": config.get('db.password'),
"database": config.get('db.db'),
"dropSchema": config.get('db.dropSchema'),
"entities": ["./dist/domain/**/*.js"],
"migrationsTableName": "migrations",
"migrations": ["./dist/migrations/**/*.js"],
"cli": {
"migrationsDir": "./dist/migrations"
}
}
**– check for migration folder in dist folder and generated js files for migrations, only proceed if required migration files exist in dist folder **
typeorm migration:run
/* when document is ready, delegate an event, * even after the element is rendered * after the page is loaded */ $(document).ready(function() { $(document).on('mouseover', '.your-child-element', function() { $(this).focus(); // <- $(this) will return the current element }); });
May 28, 2023Build your docker Create a Dockerfile in your project Run the command docker build . -t "my-app/main" Create an a Private App Container and API key for CLI SideMenu-> Container Registry -> Create private container registry - give a name Go to API settings and create new personal access token with write access Copy the auth token
Sep 3, 2021Steps Create a file in root directory of the project Add in these contents Base Image FROM node:14 Create app working directory WORKDIR /usr/src/app
Jun 21, 2021Newer laptops wifi problem In BIOS, disabled secure boot and enable legacy mode. Install curl sudo apt intall curl Install snapcraft packages This will install following : - docker : sudo snap install docker - datagrip : sudo snap install datagrip --classic
Mar 18, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up