-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made more progress on Knex migration-system setup.
Backup before switching from snowpack to tsc for Packages/server. (this issue keeps happening when I try to compile the server code: FredKSchott/snowpack#3468)
- Loading branch information
Showing
15 changed files
with
289 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {Knex} from "knex"; | ||
|
||
export async function up(knex: Knex) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {Knex} from "knex"; | ||
|
||
// doesn't work because this file's code runs *after* knex checks for the db's existence | ||
/*async function CreateDBIfNotExists(name: string) { | ||
const config = require("../knexfile"); | ||
let knex = new Knex.Client({ | ||
client: "postgresql", | ||
connection: { | ||
...config.development.connection, | ||
//host: "localhost", | ||
database: null, | ||
}, | ||
}) | ||
// Lets create our database if it does not exist | ||
await knex.raw("CREATE DATABASE IF NOT EXISTS ??", name) | ||
}*/ | ||
|
||
export async function up(knex: Knex) { | ||
console.log("Starting"); | ||
//CreateDBIfNotExists("debate-map"); | ||
knex.schema.createTable("users_draft", t=>{ | ||
t.text("id"); | ||
t.text("displayName"); | ||
t.text("photoURL"); | ||
t.bigInteger("joinDate"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require("dotenv").config({path: "../../.env"}); | ||
|
||
module.exports = { | ||
development: { | ||
client: "postgresql", | ||
connection: { | ||
database: "debate-map", | ||
user: process.env.LOCALDB_USERNAME, | ||
password: process.env.LOCALDB_PASSWORD, | ||
}, | ||
pool: { | ||
min: 2, | ||
max: 10, | ||
}, | ||
migrations: { | ||
tableName: "knex_migrations", | ||
directory: "./Migrations", | ||
}, | ||
acquireConnectionTimeout: 3000, | ||
}, | ||
/*production: { | ||
client: "postgresql", | ||
connection: { | ||
database: "debate-map", | ||
user: process.env.LOCALDB_USERNAME, | ||
password: process.env.LOCALDB_PASSWORD, | ||
}, | ||
pool: { | ||
min: 2, | ||
max: 10, | ||
}, | ||
migrations: { | ||
tableName: "knex_migrations", | ||
} | ||
},*/ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Knex from "knex"; | ||
//import config from "../Knex/knexfile"; | ||
import {createRequire} from "module"; | ||
const require = createRequire(import.meta.url); | ||
|
||
const dbName = "debate-map"; | ||
|
||
const config = require("../Knex/knexfile"); | ||
async function CreateDBIfNotExists(name: string) { | ||
console.log("Test1:"); | ||
/*let knex = new Knex.Client({ | ||
//client: "postgresql", | ||
client: "pg", | ||
//connection: `postgres://${process.env.PGUSER}:${process.env.PGPASSWORD}@localhost:5432/debate-map`, | ||
//connection: `postgres://${config.development.connection.user}:${config.development.connection.password}@localhost:5432/debate-map`, | ||
//connection: `postgres://${config.development.connection.user}:${config.development.connection.password}@localhost:5432`, | ||
connection: { | ||
...config.development.connection, | ||
//host: "localhost", port: 5432, | ||
host: "127.0.0.1", //port: 5432, | ||
//host: "localhost:5432", | ||
database: null, | ||
}, | ||
});*/ | ||
const config_final = JSON.parse(JSON.stringify(config.development)); | ||
delete config_final.connection.database; | ||
let knex = new Knex.Client(config_final); | ||
|
||
console.log("Creating"); | ||
await knex.raw("CREATE DATABASE IF NOT EXISTS ??", name); | ||
console.log("Created"); | ||
} | ||
|
||
async function Main() { | ||
await CreateDBIfNotExists(dbName); | ||
console.log("Created2"); | ||
|
||
// now that our database confirmed to exist, create another knex object (with db-name specified) so we can run our migrations | ||
const knex = new Knex.Client({ | ||
//client: "postgresql", | ||
client: "pg", | ||
connection: { | ||
...config.development.connection, | ||
//host: "localhost", | ||
database: dbName, | ||
}, | ||
}); | ||
|
||
await knex["migrate"].latest(); | ||
} | ||
|
||
Main().catch(console.log).then(()=>process.exit()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"compilerOptions": { | ||
// general | ||
"watch": true, | ||
"forceConsistentCasingInFileNames": true, // creates duplicates in import-helper plugins otherwise | ||
|
||
// modules/paths | ||
"module": "ESNext", | ||
//"module": "commonjs", // needed, since ts-node does not yet support imports from es2015-modules | ||
"moduleResolution": "node", | ||
//"rootDir": ".", | ||
//"baseUrl": ".", | ||
|
||
"resolveJsonModule": true, | ||
|
||
// compiler options | ||
"target": "ES2015", | ||
"jsx": "react", | ||
"noImplicitAny": false, | ||
"alwaysStrict": true, // alternative: "@babel/plugin-transform-strict-mode"; went with this since doesn't require another npm package | ||
|
||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true | ||
}, | ||
"include": [ | ||
"../Typings/**/*.d.ts", | ||
"../Scripts/**/*.ts", | ||
"../Scripts/**/*.tsx", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.