Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chukwuka-emi committed Sep 13, 2023
0 parents commit 25e9338
Show file tree
Hide file tree
Showing 54 changed files with 11,905 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
~/.env
~/node_modules
3 changes: 3 additions & 0 deletions Core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
build
5 changes: 5 additions & 0 deletions Core/COMMANDS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GENERATE MIGRATION - example
npx typeorm migration:generate src/migration/AddedNewTables -d build/ormconfig.js

RUN MIGRATION - example
npx typeorm migration:run -d build/ormconfig.js
35 changes: 35 additions & 0 deletions Core/ormconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DataSource } from "typeorm";
import { config } from "dotenv";
import { User } from "./src/Entities/User";
import { Topic } from "./src/Entities/Topic";
import { Subscription } from "./src/Entities/Subscription";

config();

// const { PGHOST, PGDATABASE, PGUSER, PGPASSWORD, ENDPOINT_ID } = process.env;
// const databaseUrl = `postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}/${PGDATABASE}?options=project%3D${ENDPOINT_ID}`;

const dataSource = new DataSource({
type: "postgres",
url: process.env.DATABASE_URL,
// url: databaseUrl,
synchronize: false,
logging: true,
migrationsRun: false,
entities: [User, Topic, Subscription],
migrations: ["build/src/migration/*.js"],
ssl: {
rejectUnauthorized: false,
},
});

if (!dataSource.isInitialized) {
dataSource
.initialize()
.then(() => console.log(`Database connected.`))
.catch((err) =>
console.log(`Error initializing database connection : ${err}`)
);
}

export default dataSource;
Loading

0 comments on commit 25e9338

Please sign in to comment.