Skip to content

Instantly share code, notes, and snippets.

@eropple
Created July 27, 2017 06:19
Show Gist options
  • Save eropple/9d557a8d6ef0516cd288a13ec8cebbcd to your computer and use it in GitHub Desktop.
Save eropple/9d557a8d6ef0516cd288a13ec8cebbcd to your computer and use it in GitHub Desktop.
{ driver:
{ type: 'postgres',
host: 'services.dev.vms',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'postgres' },
autoSchemaSync: true,
entities: [ '/home/ed/Development/testapp/api/dist/data/entities/*.js' ],
logging: { logSchemaCreation: true, logQueries: true } }
[2017-07-27T06:18:51.568Z] INFO: testapp-api/16083 on bigboss: Initializing server.
executing query: SELECT * FROM information_schema.tables WHERE table_catalog = 'postgres' AND table_schema = 'public' AND table_name IN ('projects')
executing query: SELECT * FROM information_schema.columns WHERE table_catalog = 'postgres' AND table_schema = 'public'
executing query: SELECT t.relname AS table_name, i.relname AS index_name, a.attname AS column_name FROM pg_class t, pg_class i, pg_index ix, pg_attribute a
WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid
AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' AND t.relname IN ('projects') ORDER BY t.relname, i.relname
executing query: SELECT table_name, constraint_name FROM information_schema.table_constraints WHERE table_catalog = 'postgres' AND constraint_type = 'FOREIGN KEY'
executing query: SELECT * FROM information_schema.table_constraints WHERE table_catalog = 'postgres' AND constraint_type = 'UNIQUE'
executing query: SELECT c.column_name, tc.table_name, tc.constraint_name FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name
where constraint_type = 'PRIMARY KEY' and tc.table_catalog = 'postgres'
executing query: START TRANSACTION
creating a new table: projects
executing query: CREATE SCHEMA IF NOT EXISTS "public";CREATE TABLE "projects" ("id" SERIAL NOT NULL PRIMARY KEY)
executing query: COMMIT
{ EntityMetadataAlreadySetError: Entity metadata for Function with projects table name has been already set to this Function
at new EntityMetadataAlreadySetError (/home/ed/Development/testapp/api/node_modules/typeorm/metadata/error/EntityMetadataAlreadySetError.js:19:28)
at TableMetadata.set [as entityMetadata] (/home/ed/Development/testapp/api/node_modules/typeorm/metadata/TableMetadata.js:51:23)
at _clone (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1210:18)
at _clone (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1210:20)
at _clone (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1210:20)
at _clone (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1210:20)
at _clone (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1210:20)
at Config.cloneDeep (/home/ed/Development/testapp/api/node_modules/config/lib/config.js:1217:10)
at /home/ed/Development/testapp/api/node_modules/config/lib/config.js:1477:32
at Array.forEach (native)
name: 'EntityMetadataAlreadySetError',
message: 'Entity metadata for Function with projects table name has been already set to this Function' }
import * as _ from 'lodash';
import 'reflect-metadata';
import { createConnection, Connection } from 'typeorm';
import { Config } from 'convict';
export async function buildDatabaseConnection(config: Config): Promise<Connection> {
const primaryConfig = config.get("db.primary");
const fullConfig =
_.merge(
{},
primaryConfig,
{
entities: [ __dirname + "/entities/*.js" ],
logging: {
logSchemaCreation: true,
logQueries: true
}
}
);
const connection = await createConnection(fullConfig);
return connection;
}
import {
Entity, Index,
PrimaryGeneratedColumn, Column,
OneToMany, ManyToOne, OneToOne, ManyToMany
} from "typeorm";
@Entity("projects")
export class Project {
@PrimaryGeneratedColumn({ type: "bigint" })
id: number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment