first commit
This commit is contained in:
11
db/db.js
Normal file
11
db/db.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import knex from "knex";
|
||||
import { development, production } from "./knexfile.cjs";
|
||||
|
||||
const env = process.env.ENVIRONMENT || "development";
|
||||
|
||||
console.log(env);
|
||||
console.log(development);
|
||||
|
||||
const db = env === "development" ? knex(development) : knex(production);
|
||||
|
||||
export default db;
|
98
db/knexfile.cjs
Normal file
98
db/knexfile.cjs
Normal file
@@ -0,0 +1,98 @@
|
||||
// Update with your config settings.
|
||||
|
||||
const dir = process.cwd();
|
||||
|
||||
const env = process.env.ENVIRONMENT || "";
|
||||
|
||||
const config =
|
||||
env === "development"
|
||||
? require("dotenv").config({ path: dir + "/.env" })
|
||||
: require("dotenv").config({ path: "../.env" });
|
||||
|
||||
//const config = require("dotenv").config({ path: dir + "/.env" });
|
||||
|
||||
console.log(config);
|
||||
|
||||
/**
|
||||
* @type { Object.<string, import("knex").Knex.Config> }
|
||||
*/
|
||||
|
||||
exports.development = {
|
||||
client: "postgresql",
|
||||
connection: {
|
||||
database: config.parsed.DEV_DB, // env var: PGDATABASE YOUR UEA username
|
||||
user: config.parsed.DEV_USER, // env var: PGUSER YOUR UEA username
|
||||
password: config.parsed.DEV_PASSWORD // env var: PGPASSWORD YOUR UEA password
|
||||
},
|
||||
pool: {
|
||||
min: 2,
|
||||
max: 10
|
||||
},
|
||||
migrations: {
|
||||
tableName: "knex_migrations"
|
||||
},
|
||||
seeds: {
|
||||
directory: "./seeds"
|
||||
}
|
||||
};
|
||||
|
||||
exports.production = {
|
||||
client: "postgresql",
|
||||
connection: {
|
||||
host: process.env.DEPLOYBOT_DB_HOST,
|
||||
database: process.env.DEPLOYBOT_DB_NAME,
|
||||
user: process.env.DEPLOYBOT_DB_USER,
|
||||
password: process.env.DEPLOYBOT_DB_PASS,
|
||||
port: process.env.DEPLOYBOT_DB_PORT
|
||||
},
|
||||
pool: {
|
||||
min: 2,
|
||||
max: 10
|
||||
},
|
||||
migrations: {
|
||||
tableName: "knex_migrations"
|
||||
}
|
||||
};
|
||||
|
||||
// module.exports = {
|
||||
// development: {
|
||||
// client: "postgresql",
|
||||
// connection: {
|
||||
// database: "6057", // env var: PGDATABASE YOUR UEA username
|
||||
// user: "postgres", // env var: PGUSER YOUR UEA username
|
||||
// password: "12345" // env var: PGPASSWORD YOUR UEA password
|
||||
// }
|
||||
// },
|
||||
|
||||
// staging: {
|
||||
// client: "postgresql",
|
||||
// connection: {
|
||||
// database: "my_db",
|
||||
// user: "username",
|
||||
// password: "password"
|
||||
// },
|
||||
// pool: {
|
||||
// min: 2,
|
||||
// max: 10
|
||||
// },
|
||||
// migrations: {
|
||||
// tableName: "knex_migrations"
|
||||
// }
|
||||
// },
|
||||
|
||||
// production: {
|
||||
// client: "postgresql",
|
||||
// connection: {
|
||||
// database: "my_db",
|
||||
// user: "username",
|
||||
// password: "password"
|
||||
// },
|
||||
// pool: {
|
||||
// min: 2,
|
||||
// max: 10
|
||||
// },
|
||||
// migrations: {
|
||||
// tableName: "knex_migrations"
|
||||
// }
|
||||
// }
|
||||
// };
|
21
db/migrations/20241021122628_create_subscribers_table.cjs
Normal file
21
db/migrations/20241021122628_create_subscribers_table.cjs
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable("subscribers", (table) => {
|
||||
table.increments("id");
|
||||
table.string("firstname", 50).notNullable().defaultTo("");
|
||||
table.string("lastname", 50).notNullable().defaultTo("");
|
||||
table.string("email", 100).notNullable().defaultTo("");
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.dropTable("subscribers");
|
||||
};
|
21
db/migrations/20241021123023_create_users_table.cjs
Normal file
21
db/migrations/20241021123023_create_users_table.cjs
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.createTable("users", (table) => {
|
||||
table.increments("id");
|
||||
table.string("firstname", 50).notNullable().defaultTo("");
|
||||
table.string("lastname", 50).notNullable().defaultTo("");
|
||||
table.string("email", 100).notNullable().defaultTo("");
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.dropTable("users");
|
||||
};
|
15
db/migrations/20241021130056_create_logins_table.cjs
Normal file
15
db/migrations/20241021130056_create_logins_table.cjs
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.up = function(knex) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.down = function(knex) {
|
||||
|
||||
};
|
13
db/seeds/01_subscribers_test_data.cjs
Normal file
13
db/seeds/01_subscribers_test_data.cjs
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.seed = async function (knex) {
|
||||
// Deletes ALL existing entries
|
||||
// Deletes ALL existing entries
|
||||
await knex("subscribers").del();
|
||||
await knex("subscribers").insert([
|
||||
{ firstname: "Jeannette", lastname: "Chin", email: "jc@jc.com" },
|
||||
{ firstname: "Jo", lastname: "Blog", email: "jo@blog.com" }
|
||||
]);
|
||||
};
|
Reference in New Issue
Block a user