Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup #1

Merged
merged 5 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
3 changes: 3 additions & 0 deletions .sampleenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BASE_PATH=http://localhost:3000
APP_PORT=3000
ENVIRONMENT=development
14 changes: 14 additions & 0 deletions db/migrations/20211218122321_create_user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Knex } from "knex";

export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable("users", (table) => {
table.increments();
table.string("first_name");
table.string("last_name");
table.timestamps(true, true);
});
}

export async function down(knex: Knex): Promise<void> {
return knex.schema.dropTableIfExists("users");
}
53 changes: 53 additions & 0 deletions knexfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Update with your config settings. Made with command "knex init -x ts"

export default {
development: {
client: "postgresql",
connection: {
database: "graphql_typed_db",
user: "graphql_typed_user",
password: "graphql_typed_password",
},
pool: {
min: 2,
max: 10,
},
migrations: {
directory: "./db/migrations",
},
},

staging: {
client: "postgresql",
connection: {
database: "my_db",
user: "username",
password: "password",
},
pool: {
min: 2,
max: 10,
},
migrations: {
directory: "./db/migrations",
// tableName: "knex_migrations",
},
},

production: {
client: "postgresql",
connection: {
database: "my_db",
user: "username",
password: "password",
},
pool: {
min: 2,
max: 10,
},
migrations: {
directory: "./db/migrations",
// tableName: "knex_migrations",
},
},
};
11 changes: 11 additions & 0 deletions models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Knex from "knex";
import { Model } from "objection";
import { Environment } from "types";
import knexConfig from "../knexfile";

const setUpDb = (environment: Environment) => {
const knex = Knex(knexConfig[environment]);
Model.knex(knex);
};

export default setUpDb;
Loading