<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=TypeORM</id>
		<title>TypeORM - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=TypeORM"/>
		<link rel="alternate" type="text/html" href="https://logicwiki.co.uk/index.php?title=TypeORM&amp;action=history"/>
		<updated>2026-05-01T20:24:58Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>https://logicwiki.co.uk/index.php?title=TypeORM&amp;diff=2058&amp;oldid=prev</id>
		<title>AliIybar: /* Using TypeORM CLI */</title>
		<link rel="alternate" type="text/html" href="https://logicwiki.co.uk/index.php?title=TypeORM&amp;diff=2058&amp;oldid=prev"/>
				<updated>2021-01-03T00:12:14Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Using TypeORM CLI&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 00:12, 3 January 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l218&quot; &gt;Line 218:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 218:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;dev&amp;quot;: &amp;quot;ts-node ./src/server.ts&amp;quot;,&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;dev&amp;quot;: &amp;quot;ts-node ./src/server.ts&amp;quot;,&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;lint&amp;quot;: &amp;quot;tslint -p tsconfig.json -c tslint.json&amp;quot;,&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;lint&amp;quot;: &amp;quot;tslint -p tsconfig.json -c tslint.json&amp;quot;,&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;typeorm:cli&amp;quot;: &amp;quot;ts-node ./node_modules/typeorm/cli -f &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;./&lt;/del&gt;src/ormconfig.ts&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;quot;typeorm:cli&amp;quot;: &amp;quot;ts-node ./node_modules/typeorm/cli -f src/ormconfig.ts&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l240&quot; &gt;Line 240:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 240:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; ],&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; ],&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; cli: {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; cli: {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; migrationsDir: 'src/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;migrations&lt;/del&gt;',&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; &amp;#160; migrationsDir: 'src/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;migration&lt;/ins&gt;',&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160;&amp;#160; }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;};&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;};&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	<entry>
		<id>https://logicwiki.co.uk/index.php?title=TypeORM&amp;diff=2056&amp;oldid=prev</id>
		<title>AliIybar: Created page with &quot;Category:ORM Category:Node.js Category:TypeScript == Links == [https://typeorm.io https://typeorm.io]  [https://github.com/typeorm/typeorm https://github.com/typeo...&quot;</title>
		<link rel="alternate" type="text/html" href="https://logicwiki.co.uk/index.php?title=TypeORM&amp;diff=2056&amp;oldid=prev"/>
				<updated>2020-12-29T13:27:19Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php?title=Category:ORM&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:ORM (page does not exist)&quot;&gt;Category:ORM&lt;/a&gt; &lt;a href=&quot;/Category:Node.js&quot; title=&quot;Category:Node.js&quot;&gt;Category:Node.js&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:TypeScript&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:TypeScript (page does not exist)&quot;&gt;Category:TypeScript&lt;/a&gt; == Links == [https://typeorm.io https://typeorm.io]  [https://github.com/typeorm/typeorm https://github.com/typeo...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:ORM]]&lt;br /&gt;
[[Category:Node.js]]&lt;br /&gt;
[[Category:TypeScript]]&lt;br /&gt;
== Links ==&lt;br /&gt;
[https://typeorm.io https://typeorm.io]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/typeorm/typeorm https://github.com/typeorm/typeorm]&lt;br /&gt;
&lt;br /&gt;
[https://wanago.io/2019/01/28/typeorm-migrations-postgres/ https://wanago.io/2019/01/28/typeorm-migrations-postgres/]&lt;br /&gt;
&lt;br /&gt;
[https://medium.com/@shijin_nath/typescript-rest-api-with-express-js-mysql-and-typeorm-8331cea78b0c https://medium.com/@shijin_nath/typescript-rest-api-with-express-js-mysql-and-typeorm-8331cea78b0c]&lt;br /&gt;
&lt;br /&gt;
== What is TypeORM ==&lt;br /&gt;
TypeORM has a CLI tool that allow us to generate a base application already in TypeScript. To use this tool we need first to install typeORM as a global dependency:&lt;br /&gt;
== Installation ==&lt;br /&gt;
 npm install -g typeorm&lt;br /&gt;
Then go to the directory where you want to create a new project and run the command:&lt;br /&gt;
 typeorm init --name MyProject --database mysql&lt;br /&gt;
or if you want to apply it to an already existing app&lt;br /&gt;
 typeorm init&lt;br /&gt;
'''Important : this command changes tsconfig.json and scripts in package.json. Back it up before you run ''' &lt;br /&gt;
&lt;br /&gt;
and run &lt;br /&gt;
 npm install&lt;br /&gt;
While installation is in progress, edit the '''ormconfig.json''' file and put your own database connection configuration options in there:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
   &amp;quot;type&amp;quot;: &amp;quot;mysql&amp;quot;,&lt;br /&gt;
   &amp;quot;host&amp;quot;: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
   &amp;quot;port&amp;quot;: 3306,&lt;br /&gt;
   &amp;quot;username&amp;quot;: &amp;quot;test&amp;quot;,&lt;br /&gt;
   &amp;quot;password&amp;quot;: &amp;quot;test&amp;quot;,&lt;br /&gt;
   &amp;quot;database&amp;quot;: &amp;quot;test&amp;quot;,&lt;br /&gt;
   &amp;quot;synchronize&amp;quot;: true,&lt;br /&gt;
   &amp;quot;logging&amp;quot;: false,&lt;br /&gt;
   &amp;quot;entities&amp;quot;: [&lt;br /&gt;
      &amp;quot;src/entity/**/*.ts&amp;quot;&lt;br /&gt;
   ],&lt;br /&gt;
   &amp;quot;migrations&amp;quot;: [&lt;br /&gt;
      &amp;quot;src/migration/**/*.ts&amp;quot;&lt;br /&gt;
   ],&lt;br /&gt;
   &amp;quot;subscribers&amp;quot;: [&lt;br /&gt;
      &amp;quot;src/subscriber/**/*.ts&amp;quot;&lt;br /&gt;
   ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then run&lt;br /&gt;
 npm start&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Step-by-Step Guide ==&lt;br /&gt;
What are you expecting from ORM? First of all, you are expecting it will create database tables for you and find / insert / update / delete your data without the pain of having to write lots of hardly maintainable SQL queries. This guide will show you how to setup TypeORM from scratch and make it do what you are expecting from an ORM.&lt;br /&gt;
=== Create a model ===&lt;br /&gt;
Working with a database starts from creating tables. How do you tell TypeORM to create a database table? The answer is — through the models. Your models in your app are your database tables.&lt;br /&gt;
For example, you have a Photo model:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
export class Photo {&lt;br /&gt;
    id: number;&lt;br /&gt;
    name: string;&lt;br /&gt;
    description: string;&lt;br /&gt;
    filename: string;&lt;br /&gt;
    views: number;&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And you want to store photos in your database. To store things in the database, first you need a database table, and database tables are created from your models. Not all models, but only those you define as entities.&lt;br /&gt;
=== Create an entity ===&lt;br /&gt;
Entity is your model decorated by an @Entity decorator. A database table will be created for such models. You work with entities everywhere with TypeORM. You can load/insert/update/remove and perform other operations with them.&lt;br /&gt;
Let’s make our Photo model as an entity:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {Entity} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
@Entity()&lt;br /&gt;
export class Photo {&lt;br /&gt;
    id: number;&lt;br /&gt;
    name: string;&lt;br /&gt;
    description: string;&lt;br /&gt;
    filename: string;&lt;br /&gt;
    views: number;&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, a database table will be created for the Photo entity and we'll be able to work with it anywhere in our app. We have created a database table, however what table can exist without columns? Let's create a few columns in our database table.&lt;br /&gt;
=== Adding table columns ===&lt;br /&gt;
To add database columns, you simply need to decorate an entity’s properties you want to make into a column with a @Column decorator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {Entity, Column} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
@Entity()&lt;br /&gt;
export class Photo {&lt;br /&gt;
    @Column()&lt;br /&gt;
    id: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    name: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    description: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    filename: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    views: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Creating a primary column ===&lt;br /&gt;
Each entity must have at least one primary key column. This is a requirement and you can’t avoid it. To make a column a primary key, you need to use @PrimaryColumn decorator.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {Entity, Column, PrimaryColumn} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
@Entity()&lt;br /&gt;
export class Photo {&lt;br /&gt;
    @PrimaryColumn()&lt;br /&gt;
    id: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    name: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    description: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    filename: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    views: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Creating an auto generated column ===&lt;br /&gt;
Now, let’s say you want your id column to be auto-generated (this is known as auto-increment / sequence / serial / generated identity column). To do that, you need to change the @PrimaryColumn decorator to a @PrimaryGeneratedColumn decorator:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {Entity, Column, PrimaryGeneratedColumn} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
@Entity()&lt;br /&gt;
export class Photo {&lt;br /&gt;
    @PrimaryGeneratedColumn()&lt;br /&gt;
    id: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    name: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    description: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    filename: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    views: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Column data types ===&lt;br /&gt;
Next, let’s fix our data types. By default, string is mapped to a varchar(255)-like type (depending on the database type). Number is mapped to a integer-like type (depending on the database type). We don’t want all our columns to be limited varchars or integers. Let’s setup correct data types:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {Entity, Column, PrimaryGeneratedColumn} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
@Entity()&lt;br /&gt;
export class Photo {&lt;br /&gt;
    @PrimaryGeneratedColumn()&lt;br /&gt;
    id: number;&lt;br /&gt;
    @Column({&lt;br /&gt;
        length: 100&lt;br /&gt;
    })&lt;br /&gt;
    name: string;&lt;br /&gt;
    @Column(&amp;quot;text&amp;quot;)&lt;br /&gt;
    description: string;&lt;br /&gt;
    @Column()&lt;br /&gt;
    filename: string;&lt;br /&gt;
    @Column(&amp;quot;double&amp;quot;)&lt;br /&gt;
    views: number;&lt;br /&gt;
    @Column()&lt;br /&gt;
    isPublished: boolean;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Column types are database-specific. You can set any column type your database supports. More information on supported column types can be found [https://typeorm.io/#/entities/column-types here].&lt;br /&gt;
=== Creating a connection to the database&lt;br /&gt;
Now, when our entity is created, let’s create an index.ts (or app.ts whatever you call it) file and set up our connection there:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import &amp;quot;reflect-metadata&amp;quot;;&lt;br /&gt;
import {createConnection} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
import {Photo} from &amp;quot;./entity/Photo&amp;quot;;&lt;br /&gt;
createConnection({&lt;br /&gt;
    type: &amp;quot;mysql&amp;quot;,&lt;br /&gt;
    host: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
    port: 3306,&lt;br /&gt;
    username: &amp;quot;root&amp;quot;,&lt;br /&gt;
    password: &amp;quot;admin&amp;quot;,&lt;br /&gt;
    database: &amp;quot;test&amp;quot;,&lt;br /&gt;
    entities: [&lt;br /&gt;
        Photo&lt;br /&gt;
    ],&lt;br /&gt;
    synchronize: true,&lt;br /&gt;
    logging: false&lt;br /&gt;
}).then(connection =&amp;gt; {&lt;br /&gt;
    // here you can start to work with your entities&lt;br /&gt;
}).catch(error =&amp;gt; console.log(error));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We are using MySQL in this example, but you can use any other supported database. To use another database, simply change the type in the options to the database type you are using: mysql, mariadb, postgres, cockroachdb, sqlite, mssql, oracle, cordova, nativescript, react-native, expo, or mongodb. Also make sure to use your own host, port, username, password and database settings.&lt;br /&gt;
We added our Photo entity to the list of entities for this connection. Each entity you are using in your connection must be listed there.&lt;br /&gt;
&lt;br /&gt;
Setting synchronize makes sure your entities will be synced with the database, every time you run the application.&lt;br /&gt;
=== Loading all entities from the directory ===&lt;br /&gt;
Later, when we create more entities we need to add them to the entities in our configuration. This is not very convenient, so instead we can set up the whole directory, from where all entities will be connected and used in our connection:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import {createConnection} from &amp;quot;typeorm&amp;quot;;&lt;br /&gt;
createConnection({&lt;br /&gt;
    type: &amp;quot;mysql&amp;quot;,&lt;br /&gt;
    host: &amp;quot;localhost&amp;quot;,&lt;br /&gt;
    port: 3306,&lt;br /&gt;
    username: &amp;quot;root&amp;quot;,&lt;br /&gt;
    password: &amp;quot;admin&amp;quot;,&lt;br /&gt;
    database: &amp;quot;test&amp;quot;,&lt;br /&gt;
    entities: [&lt;br /&gt;
        __dirname + &amp;quot;/entity/*.js&amp;quot;&lt;br /&gt;
    ],&lt;br /&gt;
    synchronize: true,&lt;br /&gt;
}).then(connection =&amp;gt; {&lt;br /&gt;
    // here you can start to work with your entities&lt;br /&gt;
}).catch(error =&amp;gt; console.log(error));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But be careful with this approach. If you are using ts-node then you need to specify paths to .ts files instead. If you are using outDir then you'll need to specify paths to .js files inside outDir directory. If you are using outDir and when you remove or rename your entities make sure to clear outDir directory and re-compile your project again, because when you remove your source .ts files their compiled .js versions aren't removed from output directory and still are loaded by TypeORM because they are present in the outDir directory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using TypeORM CLI ==&lt;br /&gt;
We use the TypeORM CLI installed in the node_modules directory. To do this, we need an additional script in our package.json file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;scripts&amp;quot;: {&lt;br /&gt;
  &amp;quot;dev&amp;quot;: &amp;quot;ts-node ./src/server.ts&amp;quot;,&lt;br /&gt;
  &amp;quot;lint&amp;quot;: &amp;quot;tslint -p tsconfig.json -c tslint.json&amp;quot;,&lt;br /&gt;
  &amp;quot;typeorm:cli&amp;quot;: &amp;quot;ts-node ./node_modules/typeorm/cli -f ./src/ormconfig.ts&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can also install typeorm globally, but it won’t be able to read the typescript config file out of the box&lt;br /&gt;
&lt;br /&gt;
Due to some issues, we need to use ts-node here and export our CLI config in a CommonJS way.&lt;br /&gt;
&lt;br /&gt;
'''src/ormconfig.ts'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import { ConnectionOptions } from 'typeorm';&lt;br /&gt;
 &lt;br /&gt;
const config: ConnectionOptions = {&lt;br /&gt;
  type: 'postgres',&lt;br /&gt;
  host: process.env.POSTGRES_HOST,&lt;br /&gt;
  port: Number(process.env.POSTGRES_PORT),&lt;br /&gt;
  username: process.env.POSTGRES_USER,&lt;br /&gt;
  password: process.env.POSTGRES_PASSWORD,&lt;br /&gt;
  database: process.env.POSTGRES_DB,&lt;br /&gt;
  entities: [&lt;br /&gt;
    __dirname + '/../**/*.entity{.ts,.js}',&lt;br /&gt;
  ],&lt;br /&gt;
  cli: {&lt;br /&gt;
    migrationsDir: 'src/migrations',&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
export = config;&lt;br /&gt;
 &amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can run TypeORM CLI through NPM scripts. You can add any additional parameters after the  -- characters.&lt;br /&gt;
&lt;br /&gt;
=== Creating migrations ===&lt;br /&gt;
Let’s create our first migration:&lt;br /&gt;
&lt;br /&gt;
 npm run typeorm:cli -- migration:create -n UserFullName&lt;br /&gt;
It generates a file for us that contains the current timestamp when the migration was generated. It looks like this:&lt;br /&gt;
&lt;br /&gt;
src/migrations/1548548890100-UserFullName.ts&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import { MigrationInterface, QueryRunner } from 'typeorm';&lt;br /&gt;
 &lt;br /&gt;
export class UserFullName1548548890100 implements MigrationInterface {&lt;br /&gt;
 &lt;br /&gt;
  public async up(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
 &lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
  public async down(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
 &lt;br /&gt;
  }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can also create the migration files by hand&lt;br /&gt;
&lt;br /&gt;
There are two methods that we need to write:&lt;br /&gt;
&lt;br /&gt;
the up method performs the migration&lt;br /&gt;
&lt;br /&gt;
the down method reverts it&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When it comes to the QueryRunner, you can either build the query by hand or use the migration API. Let’s go with the first option for starters:&lt;br /&gt;
&lt;br /&gt;
'''src/migrations/1548548890100-UserFullName.ts'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import { MigrationInterface, QueryRunner } from 'typeorm';&lt;br /&gt;
 &lt;br /&gt;
export class UserFullName1548548890100 implements MigrationInterface {&lt;br /&gt;
  public async up(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.query(`ALTER TABLE &amp;quot;user&amp;quot; RENAME &amp;quot;name&amp;quot; to &amp;quot;fullName&amp;quot;`);&lt;br /&gt;
  }&lt;br /&gt;
  public async down(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.query(`ALTER TABLE &amp;quot;user&amp;quot; RENAME &amp;quot;fullName&amp;quot; to &amp;quot;name&amp;quot;`);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Running the migrations with the CLI&lt;br /&gt;
Once we got that down, we can execute it using the CLI:&lt;br /&gt;
&lt;br /&gt;
 npm run typeorm:cli -- migration:run&lt;br /&gt;
We are presented with the result in the console:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
query: SELECT * FROM &amp;quot;information_schema&amp;quot;.&amp;quot;tables&amp;quot; WHERE &amp;quot;table_schema&amp;quot; = current_schema() AND &amp;quot;table_name&amp;quot; = 'migrations'&lt;br /&gt;
query: SELECT * FROM &amp;quot;migrations&amp;quot; &amp;quot;migrations&amp;quot;&lt;br /&gt;
0 migrations are already loaded in the database.&lt;br /&gt;
1 migrations were found in the source code.&lt;br /&gt;
1 migrations are new migrations that needs to be executed.&lt;br /&gt;
query: START TRANSACTION&lt;br /&gt;
query: ALTER TABLE &amp;quot;user&amp;quot; RENAME &amp;quot;name&amp;quot; to &amp;quot;fullName&amp;quot;&lt;br /&gt;
query: INSERT INTO &amp;quot;migrations&amp;quot;(&amp;quot;timestamp&amp;quot;, &amp;quot;name&amp;quot;) VALUES ($1, $2) -- PARAMETERS: [1548548890100,&amp;quot;UserFullName1548548890100&amp;quot;]&lt;br /&gt;
Migration UserFullName1548548890100 has been executed successfully.&lt;br /&gt;
query: COMMIT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This runs the migrations in a sequence ordered by their timestamps. In this process, queries written in our up methods are executed.&lt;br /&gt;
&lt;br /&gt;
== Running the migrations in the code ==&lt;br /&gt;
Aside from running the migrations using the CLI, you can do it from within your application. Thanks to that, TypeORM always checks if there are any migrations that it needs to run at the start.&lt;br /&gt;
&lt;br /&gt;
'''src/server.ts'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import 'dotenv/config';&lt;br /&gt;
import 'reflect-metadata';&lt;br /&gt;
import { createConnection } from 'typeorm';&lt;br /&gt;
import AddressController from './address/address.controller';&lt;br /&gt;
import App from './app';&lt;br /&gt;
import AuthenticationController from './authentication/authentication.controller';&lt;br /&gt;
import CategoryController from './category/category.controller';&lt;br /&gt;
import * as config from './ormconfig';&lt;br /&gt;
import PostController from './post/post.controller';&lt;br /&gt;
import validateEnv from './utils/validateEnv';&lt;br /&gt;
 &lt;br /&gt;
validateEnv();&lt;br /&gt;
 &lt;br /&gt;
(async () =&amp;gt; {&lt;br /&gt;
  try {&lt;br /&gt;
    const connection = await createConnection(config);&lt;br /&gt;
    await connection.runMigrations();&lt;br /&gt;
  } catch (error) {&lt;br /&gt;
    console.log('Error while connecting to the database', error);&lt;br /&gt;
    return error;&lt;br /&gt;
  }&lt;br /&gt;
  const app = new App(&lt;br /&gt;
    [&lt;br /&gt;
      new PostController(),&lt;br /&gt;
      new AuthenticationController(),&lt;br /&gt;
      new AddressController(),&lt;br /&gt;
      new CategoryController(),&lt;br /&gt;
    ],&lt;br /&gt;
  );&lt;br /&gt;
  app.listen();&lt;br /&gt;
})();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are not doing that, make sure to run the migrations using the CLI when you are in the process of deployment.&lt;br /&gt;
&lt;br /&gt;
=== Reverting migrations ===&lt;br /&gt;
If you decide that you need to cancel the changes that are applied it, you can do so with the revert command:&lt;br /&gt;
&lt;br /&gt;
 npm run typeorm:cli -- migration:revert&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
query: SELECT * FROM &amp;quot;information_schema&amp;quot;.&amp;quot;tables&amp;quot; WHERE &amp;quot;table_schema&amp;quot; = current_schema() AND &amp;quot;table_name&amp;quot; = 'migrations'&lt;br /&gt;
query: SELECT * FROM &amp;quot;migrations&amp;quot; &amp;quot;migrations&amp;quot;&lt;br /&gt;
1 migrations are already loaded in the database.&lt;br /&gt;
UserFullName1548548890100 is the last executed migration. It was executed on Sun Jan 27 2019 01:28:10 GMT+0100 (CET).&lt;br /&gt;
Now reverting it...&lt;br /&gt;
query: START TRANSACTION&lt;br /&gt;
query: ALTER TABLE &amp;quot;user&amp;quot; RENAME &amp;quot;fullName&amp;quot; to &amp;quot;name&amp;quot;&lt;br /&gt;
query: DELETE FROM &amp;quot;migrations&amp;quot; WHERE &amp;quot;timestamp&amp;quot; = $1 AND &amp;quot;name&amp;quot; = $2 -- PARAMETERS: [1548548890100,&amp;quot;UserFullName1548548890100&amp;quot;]&lt;br /&gt;
Migration UserFullName1548548890100 has been reverted successfully.&lt;br /&gt;
query: COMMIT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The command above executes the down method in the latest performed migration. If you need to revert more than one migration, you need to call revert multiple times.&lt;br /&gt;
&lt;br /&gt;
The TypeORM knows the current state of migrations in your database thanks to the migrations table. It holds the data about migrations that are already completed. When we use the revert functionality, TypeORM knows what migration has been done last because of the timestamp that it holds in the migrations table.&lt;br /&gt;
&lt;br /&gt;
=== Generating migrations ===&lt;br /&gt;
Thankfully, TypeORM can automatically generate migration files with the changes to your schema. After reverting our migration in the previous paragraph, we can let the TypeORM handle the writing of the migration for us.&lt;br /&gt;
&lt;br /&gt;
 npm run typeorm:cli -- migration:generate -n UserFullName&lt;br /&gt;
src/migrations/1548598555048-UserFullName.ts&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import { MigrationInterface, QueryRunner } from 'typeorm';&lt;br /&gt;
 &lt;br /&gt;
export class UserFullName1548598555048 implements MigrationInterface {&lt;br /&gt;
  public async up(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.query('ALTER TABLE &amp;quot;user&amp;quot; RENAME COLUMN &amp;quot;name&amp;quot; TO &amp;quot;fullName&amp;quot;');&lt;br /&gt;
  }&lt;br /&gt;
  public async down(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.query('ALTER TABLE &amp;quot;user&amp;quot; RENAME COLUMN &amp;quot;fullName&amp;quot; TO &amp;quot;name&amp;quot;');&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you look closely, you can see that the query is slightly different than the one that we wrote. It is a good idea to check it out first before running it. To make the work of the TypeORM CLI easier, generate migrations after each change you made to your entities, so it would have to generate relatively simple queries.&lt;br /&gt;
&lt;br /&gt;
== Using migration API ==&lt;br /&gt;
When writing your migration by hand, you don’t have to create SQL queries necessarily. You can use the migration API, that has a set of functions that can make changes in the schema. Let’s implement our example using it.&lt;br /&gt;
&lt;br /&gt;
src/migrations/1548598555048-UserFullName.ts&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import { MigrationInterface, QueryRunner } from 'typeorm';&lt;br /&gt;
 &lt;br /&gt;
export class UserFullName1548600643971 implements MigrationInterface {&lt;br /&gt;
  public async up(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.renameColumn('user', 'name', 'fullName');&lt;br /&gt;
  }&lt;br /&gt;
  public async down(queryRunner: QueryRunner): Promise&amp;lt;any&amp;gt; {&lt;br /&gt;
    await queryRunner.renameColumn('user', 'fullName', 'name');&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 npm run typeorm:cli -- migration:run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
query: SELECT * FROM &amp;quot;information_schema&amp;quot;.&amp;quot;tables&amp;quot; WHERE &amp;quot;table_schema&amp;quot; = current_schema() AND &amp;quot;table_name&amp;quot; = 'migrations'&lt;br /&gt;
query: SELECT * FROM &amp;quot;migrations&amp;quot; &amp;quot;migrations&amp;quot;&lt;br /&gt;
0 migrations are already loaded in the database.&lt;br /&gt;
1 migrations were found in the source code.&lt;br /&gt;
1 migrations are new migrations that needs to be executed.&lt;br /&gt;
query: START TRANSACTION&lt;br /&gt;
query: SELECT * FROM current_schema()&lt;br /&gt;
query: SELECT * FROM &amp;quot;information_schema&amp;quot;.&amp;quot;tables&amp;quot; WHERE (&amp;quot;table_schema&amp;quot; = 'public' AND &amp;quot;table_name&amp;quot; = 'user')&lt;br /&gt;
query: SELECT *, (&amp;quot;udt_schema&amp;quot; || '.' || &amp;quot;udt_name&amp;quot;)::&amp;quot;regtype&amp;quot; AS &amp;quot;regtype&amp;quot; FROM &amp;quot;information_schema&amp;quot;.&amp;quot;columns&amp;quot; WHERE (&amp;quot;table_schema&amp;quot; = 'public' AND &amp;quot;table_name&amp;quot; = 'user')&lt;br /&gt;
query: SELECT &amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; AS &amp;quot;table_schema&amp;quot;, &amp;quot;t&amp;quot;.&amp;quot;relname&amp;quot; AS &amp;quot;table_name&amp;quot;, &amp;quot;cnst&amp;quot;.&amp;quot;conname&amp;quot; AS &amp;quot;constraint_name&amp;quot;, CASE &amp;quot;cnst&amp;quot;.&amp;quot;contype&amp;quot; WHEN 'x' THEN pg_get_constraintdef(&amp;quot;cnst&amp;quot;.&amp;quot;oid&amp;quot;, true) ELSE &amp;quot;cnst&amp;quot;.&amp;quot;consrc&amp;quot; END AS &amp;quot;expression&amp;quot;, CASE &amp;quot;cnst&amp;quot;.&amp;quot;contype&amp;quot; WHEN 'p' THEN 'PRIMARY' WHEN 'u' THEN 'UNIQUE' WHEN 'c' THEN 'CHECK' WHEN 'x' THEN 'EXCLUDE' END AS &amp;quot;constraint_type&amp;quot;, &amp;quot;a&amp;quot;.&amp;quot;attname&amp;quot; AS &amp;quot;column_name&amp;quot; FROM &amp;quot;pg_constraint&amp;quot; &amp;quot;cnst&amp;quot; INNER JOIN &amp;quot;pg_class&amp;quot; &amp;quot;t&amp;quot; ON &amp;quot;t&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;cnst&amp;quot;.&amp;quot;conrelid&amp;quot; INNER JOIN &amp;quot;pg_namespace&amp;quot; &amp;quot;ns&amp;quot; ON &amp;quot;ns&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;cnst&amp;quot;.&amp;quot;connamespace&amp;quot; LEFT JOIN &amp;quot;pg_attribute&amp;quot; &amp;quot;a&amp;quot; ON &amp;quot;a&amp;quot;.&amp;quot;attrelid&amp;quot; = &amp;quot;cnst&amp;quot;.&amp;quot;conrelid&amp;quot; AND &amp;quot;a&amp;quot;.&amp;quot;attnum&amp;quot; = ANY (&amp;quot;cnst&amp;quot;.&amp;quot;conkey&amp;quot;) WHERE &amp;quot;t&amp;quot;.&amp;quot;relkind&amp;quot; = 'r' AND ((&amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; = 'public' AND &amp;quot;t&amp;quot;.&amp;quot;relname&amp;quot; = 'user'))&lt;br /&gt;
query: SELECT &amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; AS &amp;quot;table_schema&amp;quot;, &amp;quot;t&amp;quot;.&amp;quot;relname&amp;quot; AS &amp;quot;table_name&amp;quot;, &amp;quot;i&amp;quot;.&amp;quot;relname&amp;quot; AS &amp;quot;constraint_name&amp;quot;, &amp;quot;a&amp;quot;.&amp;quot;attname&amp;quot; AS &amp;quot;column_name&amp;quot;, CASE &amp;quot;ix&amp;quot;.&amp;quot;indisunique&amp;quot; WHEN 't' THEN 'TRUE' ELSE'FALSE' END AS &amp;quot;is_unique&amp;quot;, pg_get_expr(&amp;quot;ix&amp;quot;.&amp;quot;indpred&amp;quot;, &amp;quot;ix&amp;quot;.&amp;quot;indrelid&amp;quot;) AS &amp;quot;condition&amp;quot;, &amp;quot;types&amp;quot;.&amp;quot;typname&amp;quot; AS &amp;quot;type_name&amp;quot; FROM &amp;quot;pg_class&amp;quot; &amp;quot;t&amp;quot; INNER JOIN &amp;quot;pg_index&amp;quot; &amp;quot;ix&amp;quot; ON &amp;quot;ix&amp;quot;.&amp;quot;indrelid&amp;quot; = &amp;quot;t&amp;quot;.&amp;quot;oid&amp;quot; INNER JOIN &amp;quot;pg_attribute&amp;quot; &amp;quot;a&amp;quot; ON &amp;quot;a&amp;quot;.&amp;quot;attrelid&amp;quot; = &amp;quot;t&amp;quot;.&amp;quot;oid&amp;quot;  AND &amp;quot;a&amp;quot;.&amp;quot;attnum&amp;quot; = ANY (&amp;quot;ix&amp;quot;.&amp;quot;indkey&amp;quot;) INNER JOIN &amp;quot;pg_namespace&amp;quot; &amp;quot;ns&amp;quot; ON &amp;quot;ns&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;t&amp;quot;.&amp;quot;relnamespace&amp;quot; INNER JOIN &amp;quot;pg_class&amp;quot; &amp;quot;i&amp;quot; ON &amp;quot;i&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;ix&amp;quot;.&amp;quot;indexrelid&amp;quot; INNER JOIN &amp;quot;pg_type&amp;quot; &amp;quot;types&amp;quot; ON &amp;quot;types&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;a&amp;quot;.&amp;quot;atttypid&amp;quot; LEFT JOIN &amp;quot;pg_constraint&amp;quot; &amp;quot;cnst&amp;quot; ON &amp;quot;cnst&amp;quot;.&amp;quot;conname&amp;quot; = &amp;quot;i&amp;quot;.&amp;quot;relname&amp;quot; WHERE &amp;quot;t&amp;quot;.&amp;quot;relkind&amp;quot; = 'r' AND &amp;quot;cnst&amp;quot;.&amp;quot;contype&amp;quot; IS NULL AND ((&amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; = 'public' AND &amp;quot;t&amp;quot;.&amp;quot;relname&amp;quot; = 'user'))&lt;br /&gt;
query: SELECT &amp;quot;con&amp;quot;.&amp;quot;conname&amp;quot; AS &amp;quot;constraint_name&amp;quot;, &amp;quot;con&amp;quot;.&amp;quot;nspname&amp;quot; AS &amp;quot;table_schema&amp;quot;, &amp;quot;con&amp;quot;.&amp;quot;relname&amp;quot; AS &amp;quot;table_name&amp;quot;, &amp;quot;att2&amp;quot;.&amp;quot;attname&amp;quot; AS &amp;quot;column_name&amp;quot;, &amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; AS &amp;quot;referenced_table_schema&amp;quot;, &amp;quot;cl&amp;quot;.&amp;quot;relname&amp;quot; AS &amp;quot;referenced_table_name&amp;quot;, &amp;quot;att&amp;quot;.&amp;quot;attname&amp;quot; AS &amp;quot;referenced_column_name&amp;quot;, &amp;quot;con&amp;quot;.&amp;quot;confdeltype&amp;quot; AS &amp;quot;on_delete&amp;quot;, &amp;quot;con&amp;quot;.&amp;quot;confupdtype&amp;quot; AS &amp;quot;on_update&amp;quot; FROM ( SELECT UNNEST (&amp;quot;con1&amp;quot;.&amp;quot;conkey&amp;quot;) AS &amp;quot;parent&amp;quot;, UNNEST (&amp;quot;con1&amp;quot;.&amp;quot;confkey&amp;quot;) AS &amp;quot;child&amp;quot;, &amp;quot;con1&amp;quot;.&amp;quot;confrelid&amp;quot;, &amp;quot;con1&amp;quot;.&amp;quot;conrelid&amp;quot;, &amp;quot;con1&amp;quot;.&amp;quot;conname&amp;quot;, &amp;quot;con1&amp;quot;.&amp;quot;contype&amp;quot;, &amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot;, &amp;quot;cl&amp;quot;.&amp;quot;relname&amp;quot;, CASE &amp;quot;con1&amp;quot;.&amp;quot;confdeltype&amp;quot; WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT' WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END as &amp;quot;confdeltype&amp;quot;, CASE &amp;quot;con1&amp;quot;.&amp;quot;confupdtype&amp;quot; WHEN 'a' THEN 'NO ACTION' WHEN 'r' THEN 'RESTRICT' WHEN 'c' THEN 'CASCADE' WHEN 'n' THEN 'SET NULL' WHEN 'd' THEN 'SET DEFAULT' END as &amp;quot;confupdtype&amp;quot; FROM &amp;quot;pg_class&amp;quot; &amp;quot;cl&amp;quot; INNER JOIN &amp;quot;pg_namespace&amp;quot; &amp;quot;ns&amp;quot; ON &amp;quot;cl&amp;quot;.&amp;quot;relnamespace&amp;quot; = &amp;quot;ns&amp;quot;.&amp;quot;oid&amp;quot; INNER JOIN &amp;quot;pg_constraint&amp;quot; &amp;quot;con1&amp;quot; ON &amp;quot;con1&amp;quot;.&amp;quot;conrelid&amp;quot; = &amp;quot;cl&amp;quot;.&amp;quot;oid&amp;quot; WHERE &amp;quot;con1&amp;quot;.&amp;quot;contype&amp;quot; = 'f' AND ((&amp;quot;ns&amp;quot;.&amp;quot;nspname&amp;quot; = 'public' AND &amp;quot;cl&amp;quot;.&amp;quot;relname&amp;quot; = 'user')) ) &amp;quot;con&amp;quot; INNER JOIN &amp;quot;pg_attribute&amp;quot; &amp;quot;att&amp;quot; ON &amp;quot;att&amp;quot;.&amp;quot;attrelid&amp;quot; = &amp;quot;con&amp;quot;.&amp;quot;confrelid&amp;quot; AND &amp;quot;att&amp;quot;.&amp;quot;attnum&amp;quot; = &amp;quot;con&amp;quot;.&amp;quot;child&amp;quot; INNER JOIN &amp;quot;pg_class&amp;quot; &amp;quot;cl&amp;quot; ON &amp;quot;cl&amp;quot;.&amp;quot;oid&amp;quot; = &amp;quot;con&amp;quot;.&amp;quot;confrelid&amp;quot; INNER JOIN &amp;quot;pg_namespace&amp;quot; &amp;quot;ns&amp;quot; ON &amp;quot;cl&amp;quot;.&amp;quot;relnamespace&amp;quot; = &amp;quot;ns&amp;quot;.&amp;quot;oid&amp;quot; INNER JOIN &amp;quot;pg_attribute&amp;quot; &amp;quot;att2&amp;quot; ON &amp;quot;att2&amp;quot;.&amp;quot;attrelid&amp;quot; = &amp;quot;con&amp;quot;.&amp;quot;conrelid&amp;quot; AND &amp;quot;att2&amp;quot;.&amp;quot;attnum&amp;quot; = &amp;quot;con&amp;quot;.&amp;quot;parent&amp;quot;&lt;br /&gt;
query: ALTER TABLE &amp;quot;user&amp;quot; RENAME COLUMN &amp;quot;name&amp;quot; TO &amp;quot;fullName&amp;quot;&lt;br /&gt;
query: INSERT INTO &amp;quot;migrations&amp;quot;(&amp;quot;timestamp&amp;quot;, &amp;quot;name&amp;quot;) VALUES ($1, $2) -- PARAMETERS: [1548600643971,&amp;quot;UserFullName1548600643971&amp;quot;]&lt;br /&gt;
Migration UserFullName1548600643971 has been executed successfully.&lt;br /&gt;
query: COMMIT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above code generates quite a big query, so you might be better off with writing your SQL query if the performance is one of your concerns.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Look also : [https://github.com/typeorm/typeorm/blob/master/docs/migrations.md#user-content-using-migration-api-to-write-migrations https://github.com/typeorm/typeorm/blob/master/docs/migrations.md#user-content-using-migration-api-to-write-migrations]&lt;/div&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	</feed>