From d6fea26d17b1393671725196aed300d12ecd9862 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 22 Dec 2018 11:49:56 +0100 Subject: [PATCH] improving users db migration --- backend/model/sql/SQLConnection.ts | 12 +++++-- package.json | 51 ++++++++++++++---------------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/backend/model/sql/SQLConnection.ts b/backend/model/sql/SQLConnection.ts index 31b8aab0..20860251 100644 --- a/backend/model/sql/SQLConnection.ts +++ b/backend/model/sql/SQLConnection.ts @@ -28,7 +28,7 @@ export class SQLConnection { public static async getConnection(): Promise { if (this.connection == null) { const options: any = this.getDriver(Config.Server.database); - // options.name = 'main'; + // options.name = 'main'; options.entities = [ UserEntity, FileEntity, @@ -101,10 +101,18 @@ export class SQLConnection { } version.version = DataStructureVersion; - + const users = await connection.getRepository(UserEntity).find(); await connection.dropDatabase(); await connection.synchronize(); await connection.getRepository(VersionEntity).save(version); + try { + await connection.getRepository(UserEntity).save(users); + } catch (e) { + await connection.dropDatabase(); + await connection.synchronize(); + await connection.getRepository(VersionEntity).save(version); + Logger.warn('Could not move users to the new db scheme, deleting them. Details:' + e.toString()); + } } private static getDriver(config: DataBaseConfig): ConnectionOptions { diff --git a/package.json b/package.json index 3cf54143..ce5a6bf8 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,6 @@ "pretest": "tsc", "test": "ng test && mocha --recursive test/backend/unit && mocha --recursive test/backend/integration && mocha --recursive test/common/unit ", "start": "node ./backend/index", - "ng": "ng", - "lint": "ng lint", - "e2e": "ng e2e", "run-dev": "ng build --aot --watch --output-path=./dist --i18n-locale en --i18n-format xlf --i18n-file frontend/translate/messages.en.xlf --i18n-missing-translation warning", "update-translation": "gulp update-translation", "add-translation": "gulp add-translation" @@ -47,39 +44,39 @@ "winston": "2.4.2" }, "devDependencies": { - "@angular-devkit/build-angular": "0.11.2", - "@angular-devkit/build-optimizer": "0.11.2", - "@angular/animations": "7.1.2", - "@angular/cli": "7.1.2", - "@angular/common": "7.1.2", - "@angular/compiler": "7.1.2", - "@angular/compiler-cli": "7.1.2", - "@angular/core": "7.1.2", - "@angular/forms": "7.1.2", - "@angular/http": "7.1.2", - "@angular/language-service": "7.1.2", - "@angular/platform-browser": "7.1.2", - "@angular/platform-browser-dynamic": "7.1.2", - "@angular/router": "7.1.2", + "@angular-devkit/build-angular": "0.11.4", + "@angular-devkit/build-optimizer": "0.11.4", + "@angular/animations": "7.1.4", + "@angular/cli": "7.1.4", + "@angular/common": "7.1.4", + "@angular/compiler": "7.1.4", + "@angular/compiler-cli": "7.1.4", + "@angular/core": "7.1.4", + "@angular/forms": "7.1.4", + "@angular/http": "7.1.4", + "@angular/language-service": "7.1.4", + "@angular/platform-browser": "7.1.4", + "@angular/platform-browser-dynamic": "7.1.4", + "@angular/router": "7.1.4", "@ngx-translate/i18n-polyfill": "1.0.0", "@types/bcryptjs": "2.4.2", "@types/chai": "4.1.7", "@types/cookie-parser": "1.4.1", "@types/cookie-session": "2.0.36", - "@types/ejs": "2.6.0", + "@types/ejs": "2.6.1", "@types/express": "4.16.0", - "@types/fluent-ffmpeg": "2.1.8", + "@types/fluent-ffmpeg": "2.1.9", "@types/gm": "1.18.2", "@types/image-size": "0.0.29", - "@types/jasmine": "3.3.0", - "@types/node": "10.12.12", + "@types/jasmine": "3.3.5", + "@types/node": "10.12.18", "@types/sharp": "0.21.0", "@types/winston": "2.3.9", "@yaga/leaflet-ng2": "^1.0.0", - "bootstrap": "4.1.3", + "bootstrap": "4.2.1", "chai": "4.2.0", "codelyzer": "4.5.0", - "core-js": "2.6.0", + "core-js": "2.6.1", "ejs-loader": "0.3.1", "gulp": "3.9.1", "gulp-json-modify": "1.0.2", @@ -90,7 +87,7 @@ "jasmine-core": "3.3.0", "jasmine-spec-reporter": "4.2.1", "jw-bootstrap-switch-ng2": "2.0.2", - "karma": "3.1.3", + "karma": "3.1.4", "karma-chrome-launcher": "2.2.0", "karma-cli": "2.0.0", "karma-coverage-istanbul-reporter": "2.0.4", @@ -102,7 +99,7 @@ "mocha": "5.2.0", "ng2-cookies": "1.0.12", "ng2-slim-loading-bar": "4.0.0", - "ngx-bootstrap": "3.1.2", + "ngx-bootstrap": "3.1.3", "ngx-clipboard": "11.1.9", "ngx-toastr": "9.1.1", "open-iconic": "1.1.1", @@ -114,7 +111,7 @@ "rxjs-compat": "^6.3.3", "ts-helpers": "1.1.2", "ts-node": "7.0.1", - "tslint": "5.11.0", + "tslint": "5.12.0", "typescript": "3.1.6", "xlf-google-translate": "1.0.0-beta.12", "zone.js": "0.8.26" @@ -123,7 +120,7 @@ "natives": "1.1.3" }, "optionalDependencies": { - "@ffmpeg-installer/ffmpeg": "1.0.16", + "@ffmpeg-installer/ffmpeg": "1.0.17", "@ffprobe-installer/ffprobe": "1.0.9", "bcrypt": "3.0.2", "gm": "1.23.1",