Browse Source

changed dev and testing environments to sqlite3

main
suroh 5 months ago
parent
commit
248a0fb05a
  1. 3
      .gitignore
  2. 14
      backend/db/DB.js
  3. 14
      backend/db/migrations/20230908082728_migration_create_table.js
  4. 22
      backend/knexfile.js
  5. 1135
      backend/package-lock.json
  6. 3
      backend/package.json
  7. 24
      frontend/.gitignore
  8. 1
      frontend/package-lock.json
  9. 3
      frontend/package.json

3
.gitignore

@ -103,6 +103,9 @@ dist
# DynamoDB Local files
.dynamodb/
# sqliteDb files
**/db/*.db
# TernJS port file
.tern-port

14
backend/db/DB.js

@ -1,23 +1,13 @@
import knexConfig from '../knexfile.js'
import Knex from 'knex'
import { Model } from 'objection'
import { newDb } from 'pg-mem'
const environment = process.env.NODE_ENV || 'development'
// variable for exporting the db
let DB
if (environment == 'test') {
const mem = newDb()
DB = mem.adapters.createKnex(0, {
migrations: {
directory: './db/migrations'
},
})
Model.knex(DB)
} else {
DB = Knex(knexConfig[environment])
}
DB = Knex(knexConfig[environment])
Model.knex(DB)
export default DB

14
backend/db/migrations/20230908082728_migration_create_table.js

@ -17,7 +17,7 @@ const up = (knex) => {
table.point('location')
table.timestamp('created_at').defaultTo(knex.fn.now())
table.timestamp('updated_at').defaultTo(knex.fn.now())
table.integer('map_id').references('id').inTable('maps')
table.integer('map_id').references('id').inTable('maps').onDelete('CASCADE')
})
}
@ -26,9 +26,15 @@ const up = (knex) => {
* @returns { Promise<void> }
*/
const down = (knex) => {
return knex.schema
.raw('DROP TABLE maps CASCADE')
.dropTable('map_points')
if (knex.client.version === 'pg' || knex.client.version === 'pg-mem') {
return knex.schema
.raw('DROP TABLE maps CASCADE')
.dropTable('map_points')
} else {
return knex.schema
.dropTable('maps')
.dropTable('map_points')
}
}
export { up, down }

22
backend/knexfile.js

@ -10,13 +10,23 @@ const __dirname = dirname(fileURLToPath(import.meta.url))
*/
export default {
development: {
client: 'pg',
client: 'sqlite3',
connection: {
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASS,
host: process.env.DB_HOST,
port: process.env.DB_PORT
filename: './db/development.db'
},
migrations: {
directory: __dirname + '/db/migrations'
},
seeds: {
directory: __dirname + '/db/seeds'
}
},
test: {
client: 'sqlite3',
useNullAsDefault: true,
connection: {
filename: './db/testing.db'
},
migrations: {
directory: __dirname + '/db/migrations'

1135
backend/package-lock.json

File diff suppressed because it is too large

3
backend/package.json

@ -26,7 +26,8 @@
"knex": "^2.5.1",
"objection": "^3.1.1",
"pg": "^8.11.3",
"socket.io": "^4.7.2"
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6"
},
"devDependencies": {
"ava": "^5.3.1",

24
frontend/.gitignore

@ -1,24 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

1
frontend/package-lock.json

@ -7,6 +7,7 @@
"": {
"name": "ethermap.front",
"version": "0.0.0",
"license": "GPL-3.0-or-later",
"dependencies": {
"leaflet": "^1.9.4",
"leaflet-contextmenu": "^1.4.0",

3
frontend/package.json

@ -17,5 +17,6 @@
"leaflet-contextmenu": "^1.4.0",
"lit": "^2.8.0",
"socket.io-client": "^4.7.2"
}
},
"license": "GPL-3.0-or-later"
}

Loading…
Cancel
Save