Skip to content

Commit c4682ed

Browse files
authored
Merge pull request #1 from muhsinkamil/initial-setup
Initial setup
2 parents ead7b3b + d3de564 commit c4682ed

11 files changed

+2545
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

.sampleenv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BASE_PATH=http://localhost:3000
2+
APP_PORT=3000
3+
ENVIRONMENT=development
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Knex } from "knex";
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
return knex.schema.createTable("users", (table) => {
5+
table.increments();
6+
table.string("first_name");
7+
table.string("last_name");
8+
table.timestamps(true, true);
9+
});
10+
}
11+
12+
export async function down(knex: Knex): Promise<void> {
13+
return knex.schema.dropTableIfExists("users");
14+
}

knexfile.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Update with your config settings. Made with command "knex init -x ts"
2+
3+
export default {
4+
development: {
5+
client: "postgresql",
6+
connection: {
7+
database: "graphql_typed_db",
8+
user: "graphql_typed_user",
9+
password: "graphql_typed_password",
10+
},
11+
pool: {
12+
min: 2,
13+
max: 10,
14+
},
15+
migrations: {
16+
directory: "./db/migrations",
17+
},
18+
},
19+
20+
staging: {
21+
client: "postgresql",
22+
connection: {
23+
database: "my_db",
24+
user: "username",
25+
password: "password",
26+
},
27+
pool: {
28+
min: 2,
29+
max: 10,
30+
},
31+
migrations: {
32+
directory: "./db/migrations",
33+
// tableName: "knex_migrations",
34+
},
35+
},
36+
37+
production: {
38+
client: "postgresql",
39+
connection: {
40+
database: "my_db",
41+
user: "username",
42+
password: "password",
43+
},
44+
pool: {
45+
min: 2,
46+
max: 10,
47+
},
48+
migrations: {
49+
directory: "./db/migrations",
50+
// tableName: "knex_migrations",
51+
},
52+
},
53+
};

models/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Knex from "knex";
2+
import { Model } from "objection";
3+
import { Environment } from "types";
4+
import knexConfig from "../knexfile";
5+
6+
const setUpDb = (environment: Environment) => {
7+
const knex = Knex(knexConfig[environment]);
8+
Model.knex(knex);
9+
};
10+
11+
export default setUpDb;

0 commit comments

Comments
 (0)