diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..b051c6c57 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +client diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..fcadb2cf9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.github/workflows/01-dockerize.yml b/.github/workflows/01-dockerize.yml index e6bec77c5..1ba8829a6 100644 --- a/.github/workflows/01-dockerize.yml +++ b/.github/workflows/01-dockerize.yml @@ -2,12 +2,35 @@ name: Dockerize on: pull_request: - branches: - - main jobs: + # run tests before dockerizing + test: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ github.head_ref }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: geovbot + password: ${{ secrets.GEOVBOT_READ_WRITE_PACKAGES }} + + # run database integration and unit tests + - name: run database tests + run: | + cd database + chmod -R 777 logs + export POSTGRES_PORT=5432 + bash test.sh -i -u -p + set-version: runs-on: ubuntu-latest + needs: [test] if: github.event_name == 'pull_request' outputs: version_tag: ${{steps.npm_version.outputs.tag}} @@ -31,8 +54,8 @@ jobs: if: always() with: webhook: ${{ secrets.DISCORD_GITHUB_CHANNEL_WEBHOOK }} - title: "Dockerize Toolbox Server and Client" - description: "PR: ${{ steps.pull_request.outputs.number }}" + title: 'Dockerize Toolbox Server and Client' + description: 'PR: ${{ steps.pull_request.outputs.number }}' color: 0xffed2b username: GitHub Actions @@ -46,8 +69,8 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: "16.13.2" - registry-url: "https://registry.npmjs.org" + node-version: '16.13.2' + registry-url: 'https://registry.npmjs.org' - name: Tag this commit with pr id: npm_version @@ -61,11 +84,11 @@ jobs: run: echo your tag is '${{steps.npm_version.outputs.tag}}' - name: Update Lock file - run: "npm i --package-lock-only" + run: 'npm i --package-lock-only' - uses: EndBug/add-and-commit@v5 with: - message: "chore(): update prerelease version" + message: 'chore(): update prerelease version' tag: v${{steps.npm_version.outputs.tag}} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -97,9 +120,9 @@ jobs: uses: docker/build-push-action@v3 with: # Location of Dockerfile, if not Dockerfile in root directory - file: server/webserver.dockerfile + file: webserver.dockerfile # Directory to run `docker build` from, if not project root - context: server + context: . push: true tags: ghcr.io/geovistory/toolbox-server:${{needs.set-version.outputs.version_tag}} @@ -108,8 +131,8 @@ jobs: if: always() with: webhook: ${{ secrets.DISCORD_GITHUB_CHANNEL_WEBHOOK }} - title: "Dockerize Toolbox Server > Done" - description: "Image Tag: ${{needs.set-version.outputs.version_tag}}" + title: 'Dockerize Toolbox Server > Done' + description: 'Image Tag: ${{needs.set-version.outputs.version_tag}}' color: 0x0000ff username: GitHub Actions @@ -125,12 +148,12 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: "16.13.2" - registry-url: "https://registry.npmjs.org" + node-version: '16.13.2' + registry-url: 'https://registry.npmjs.org' - name: Setup version info id: setup_version - run: "npm --prefix client run setup:version" + run: 'npm --prefix client run setup:version' - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -160,7 +183,7 @@ jobs: if: always() with: webhook: ${{ secrets.DISCORD_GITHUB_CHANNEL_WEBHOOK }} - title: "Dockerize Toolbox Client > Done" - description: "Image Tag: ${{needs.set-version.outputs.version_tag}}" + title: 'Dockerize Toolbox Client > Done' + description: 'Image Tag: ${{needs.set-version.outputs.version_tag}}' color: 0x0000ff username: GitHub Actions diff --git a/.vscode/settings.json b/.vscode/settings.json index aeadd0c1c..cd895ab6e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,12 @@ { "git.autofetch": true, - "editor.formatOnSave": true, + "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.organizeImports": "explicit", "source.fixAll": "explicit" }, + "sqltools.format": { + "linesBetweenQueries": 2, + "language": "pl/sql" + } } \ No newline at end of file diff --git a/client/apps/app-toolbox/src/app/components/editor/add-entity-or-value-dialog/add-entity-or-value-dialog.component.ts b/client/apps/app-toolbox/src/app/components/editor/add-entity-or-value-dialog/add-entity-or-value-dialog.component.ts index 4786120e4..0a5e2f439 100644 --- a/client/apps/app-toolbox/src/app/components/editor/add-entity-or-value-dialog/add-entity-or-value-dialog.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/add-entity-or-value-dialog/add-entity-or-value-dialog.component.ts @@ -139,7 +139,7 @@ export class AddEntityOrValueDialogComponent implements OnDestroy, OnInit { this.selectedInProject$ = this.state.data.war.entityPreview.getEntityPreview.byProjectIdPkEntity$(this.pkProject, d.pkEntity).pipe( filter(item => !!item), - map(item => item.project_id !== 0), + map(item => item.fk_project !== 0), startWith(false) ) diff --git a/client/apps/app-toolbox/src/app/components/editor/add-statement-dialog/add-statement-dialog.component.ts b/client/apps/app-toolbox/src/app/components/editor/add-statement-dialog/add-statement-dialog.component.ts index 76b9401d1..e057b775e 100644 --- a/client/apps/app-toolbox/src/app/components/editor/add-statement-dialog/add-statement-dialog.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/add-statement-dialog/add-statement-dialog.component.ts @@ -336,7 +336,7 @@ export class AddStatementDialogComponent implements OnInit, OnDestroy { this.ap.streamEntityPreview(d.pkEntity) this.selectedInProject$ = this.state.data.war.entityPreview.getEntityPreview.byProjectIdPkEntity$(this.pkProject, d.pkEntity).pipe( - map(item => item?.project_id !== 0), + map(item => item?.fk_project !== 0), startWith(false) ) diff --git a/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity-dialog/ctrl-entity-dialog.component.ts b/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity-dialog/ctrl-entity-dialog.component.ts index b20ae571a..1deec3c51 100644 --- a/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity-dialog/ctrl-entity-dialog.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity-dialog/ctrl-entity-dialog.component.ts @@ -157,7 +157,7 @@ export class CtrlEntityDialogComponent implements OnDestroy, OnInit { this.selectedInProject$ = this.state.data.war.entityPreview.getEntityPreview.byProjectIdPkEntity$(this.pkProject, d.pkEntity).pipe( filter(item => !!item), - map(item => item.project_id !== 0), + map(item => item.fk_project !== 0), startWith(false) ) diff --git a/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity.component.ts b/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity.component.ts index 4ed483cad..9115a99e9 100644 --- a/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/ctrl-entity/ctrl-entity.component.ts @@ -179,7 +179,7 @@ export class CtrlEntityComponent implements OnDestroy, class_label: label, entity_type: type, pk_entity: undefined, - project_id: undefined, + fk_project: undefined, } return e }) diff --git a/client/apps/app-toolbox/src/app/components/editor/search-existing-entity/search-existing-entity.component.ts b/client/apps/app-toolbox/src/app/components/editor/search-existing-entity/search-existing-entity.component.ts index a86973c22..8d80d82b6 100644 --- a/client/apps/app-toolbox/src/app/components/editor/search-existing-entity/search-existing-entity.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/search-existing-entity/search-existing-entity.component.ts @@ -147,7 +147,7 @@ export class SearchExistingEntityComponent implements OnInit, OnDestroy { map(([resp, selected]) => { const res: EntitySearchHit[] = resp.data; const hits: EntityAddExistingHit[] = res.map(r => { - const isInProject = r.project_id !== 0; + const isInProject = r.fk_project !== 0; const confirmBtnDisabled = (this.disableIfHasStatement && r.related_statements.length >= this.disableIfHasStatement.maxQuantity); const confirmBtnTooltip = confirmBtnDisabled ? `This ${r.class_label} can't be selected because it is already related to ${r.related_statements.length} ${this.disableIfHasStatement.sourceClassLabel} via '${this.disableIfHasStatement.propertyLabel}'.` diff --git a/client/apps/app-toolbox/src/app/components/editor/view-field-body/view-field-body.component.ts b/client/apps/app-toolbox/src/app/components/editor/view-field-body/view-field-body.component.ts index 6c722b077..8218dc64b 100644 --- a/client/apps/app-toolbox/src/app/components/editor/view-field-body/view-field-body.component.ts +++ b/client/apps/app-toolbox/src/app/components/editor/view-field-body/view-field-body.component.ts @@ -141,7 +141,7 @@ export class ViewFieldBodyComponent implements OnInit, OnDestroy { * For UX-Performance: trigger field load with limit 0 to get the total count of statements * in that field (without the need to query nested fields) */ - this.loadFieldCount(until$); + //this.loadFieldCount(until$); const page$ = pagination$.pipe( delay(0), diff --git a/client/apps/app-toolbox/src/app/components/editor/view-field-item-class-info/view-field-item-class-info.component.html b/client/apps/app-toolbox/src/app/components/editor/view-field-item-class-info/view-field-item-class-info.component.html index 70698f9d1..0cc32a997 100644 --- a/client/apps/app-toolbox/src/app/components/editor/view-field-item-class-info/view-field-item-class-info.component.html +++ b/client/apps/app-toolbox/src/app/components/editor/view-field-item-class-info/view-field-item-class-info.component.html @@ -1,11 +1,11 @@ - - - - - + + + + + diff --git a/client/apps/app-toolbox/src/app/components/misc/core-table/menu/menu.component.scss b/client/apps/app-toolbox/src/app/components/misc/core-table/menu/menu.component.scss index bc69fd95b..f637a8d6f 100755 --- a/client/apps/app-toolbox/src/app/components/misc/core-table/menu/menu.component.scss +++ b/client/apps/app-toolbox/src/app/components/misc/core-table/menu/menu.component.scss @@ -1,9 +1,9 @@ -:host { - display: flex; - align-items: center; - justify-content: space-between; -} - -mat-icon { - margin-top: -2px; -} +:host { + display: flex; + align-items: center; + justify-content: space-between; +} + +mat-icon { + margin-top: -2px; +} diff --git a/client/apps/app-toolbox/src/app/components/misc/core-table/table.scss b/client/apps/app-toolbox/src/app/components/misc/core-table/table.scss index 1c495fcf5..07286e64d 100755 --- a/client/apps/app-toolbox/src/app/components/misc/core-table/table.scss +++ b/client/apps/app-toolbox/src/app/components/misc/core-table/table.scss @@ -1,33 +1,33 @@ -@mixin base { - .mat-mdc-table { - width: 100%; - } - - .mat-mdc-header-cell:not(:last-of-type), - .mat-mdc-cell:not(:last-of-type) { - padding-right: 16px; - } -} - -@mixin progress { - .mat-mdc-header-row.core-table-progress { - border: none; - // height: 0; - min-height: 0; - - .mat-mdc-header-cell { - border: 0; - padding: 0; - } - mat-progress-bar { - bottom: 0; - position: absolute; - transition: height 0.3s, opacity 0.25s linear; - - &:not(.show) { - height: 0; - opacity: 0; - } - } - } -} +@mixin base { + .mat-mdc-table { + width: 100%; + } + + .mat-mdc-header-cell:not(:last-of-type), + .mat-mdc-cell:not(:last-of-type) { + padding-right: 16px; + } +} + +@mixin progress { + .mat-mdc-header-row.core-table-progress { + border: none; + // height: 0; + min-height: 0; + + .mat-mdc-header-cell { + border: 0; + padding: 0; + } + mat-progress-bar { + bottom: 0; + position: absolute; + transition: height 0.3s, opacity 0.25s linear; + + &:not(.show) { + height: 0; + opacity: 0; + } + } + } +} diff --git a/client/apps/app-toolbox/src/app/components/misc/entity-preview/entity-preview.component.html b/client/apps/app-toolbox/src/app/components/misc/entity-preview/entity-preview.component.html index 49814f988..56e950c3d 100644 --- a/client/apps/app-toolbox/src/app/components/misc/entity-preview/entity-preview.component.html +++ b/client/apps/app-toolbox/src/app/components/misc/entity-preview/entity-preview.component.html @@ -27,11 +27,11 @@ - - diff --git a/client/apps/app-toolbox/src/app/lib/converters/fieldPageToWarFieldChangeId.ts b/client/apps/app-toolbox/src/app/lib/converters/fieldPageToWarFieldChangeId.ts index 394fc70c0..c0d7e7f18 100644 --- a/client/apps/app-toolbox/src/app/lib/converters/fieldPageToWarFieldChangeId.ts +++ b/client/apps/app-toolbox/src/app/lib/converters/fieldPageToWarFieldChangeId.ts @@ -8,7 +8,6 @@ export function fieldPageToWarFieldChangeId(fieldPage: GvFieldPage): WarFieldCha fk_source_tables_cell: fieldPage.source.fkTablesCell, fk_project: fieldPage.scope.inProject, fk_property: fieldPage.property.fkProperty, - fk_property_of_property: fieldPage.property.fkPropertyOfProperty, is_outgoing: fieldPage.isOutgoing }; } diff --git a/client/apps/app-toolbox/src/app/lib/converters/fieldToWarFieldChangeId.ts b/client/apps/app-toolbox/src/app/lib/converters/fieldToWarFieldChangeId.ts index 78f92e5bd..66a715e23 100644 --- a/client/apps/app-toolbox/src/app/lib/converters/fieldToWarFieldChangeId.ts +++ b/client/apps/app-toolbox/src/app/lib/converters/fieldToWarFieldChangeId.ts @@ -13,7 +13,6 @@ export function fieldToWarFieldChangeId( fk_source_tables_cell: source.fkTablesCell, fk_project: pkProject, fk_property: property.fkProperty, - fk_property_of_property: property.fkPropertyOfProperty, is_outgoing: isOutgoing }; } diff --git a/client/apps/app-toolbox/src/app/services/pagination.service.ts b/client/apps/app-toolbox/src/app/services/pagination.service.ts index a35bc9035..885e18b1e 100644 --- a/client/apps/app-toolbox/src/app/services/pagination.service.ts +++ b/client/apps/app-toolbox/src/app/services/pagination.service.ts @@ -1,6 +1,14 @@ import { Injectable } from '@angular/core'; import { Field, StateFacade, subfieldIdToString } from '@kleiolab/lib-redux'; -import { GvFieldPageReq, GvFieldPageScope, GvFieldSourceEntity, WarFieldChange, WarFieldChangeAddToStream, WarFieldChangeId } from '@kleiolab/lib-sdk-lb4'; +import { + GvFieldPage, + GvFieldPageReq, + GvFieldPageScope, + GvFieldSourceEntity, + WarFieldChange, + WarFieldChangeAddToStream, + WarFieldChangeId, +} from '@kleiolab/lib-sdk-lb4'; import { FieldChangeSocket } from '@kleiolab/lib-sockets'; import { indexBy } from 'ramda'; import { Observable, Subject, interval } from 'rxjs'; @@ -9,7 +17,6 @@ import { fieldPageToWarFieldChangeId } from '../lib/converters/fieldPageToWarFie import { fieldToFieldPage } from '../lib/converters/fieldToFieldPage'; import { fieldToGvFieldTargets } from '../lib/converters/fieldToGvFieldTargets'; - interface Loader { refCount: number; // the number of references / subscribers that currently watch the page until$: Subject; // an observable for that emits, as soon as the page loader is not needed anymore @@ -19,34 +26,41 @@ interface Loader { } @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class PaginationService { - - /** * pageLoaders maps pageIdString (crteated form GvFieldId + limit + offset) * to an object holding information about the state of the pageLoader */ - private pageLoaders = new Map() + private pageLoaders = new Map(); /** - * fieldChangeListeners maps a fieldChangeIdString (created from WarFieldChangeId) - * to an array of pageIdString (crteated form GvFieldId + limit + offset) - * - * The reason behind is: - * a field change can make trigger multiple page loaders to (re-)load - */ - private fieldChangeListeners = new Map() + * fieldChangeListeners maps a fieldChangeIdString (created from WarFieldChangeId) + * to an array of pageIdString (crteated form GvFieldId + limit + offset) + * + * The reason behind is: + * a field change can make trigger multiple page loaders to (re-)load + */ + private fieldChangeListeners = new Map< + string, + { + fieldChangeId: WarFieldChangeId; + pageIds: string[]; + } + >(); - addLoader$ = new Subject<{ loader: Loader, pageIdString: string, takeUntil$: Observable }>() - loadQueue$: Observable<{ loader: Loader, pageIdString: string, takeUntil$: Observable }[]> + addLoader$ = new Subject<{ + loader: Loader; + pageIdString: string; + takeUntil$: Observable; + }>(); + loadQueue$: Observable< + { loader: Loader; pageIdString: string; takeUntil$: Observable }[] + >; - addReloader$ = new Subject<{ loader: Loader, pageIdString: string }>() - reloadQueue$: Observable<{ loader: Loader, pageIdString: string }[]> + addReloader$ = new Subject<{ loader: Loader; pageIdString: string }>(); + reloadQueue$: Observable<{ loader: Loader; pageIdString: string }[]>; constructor( private state: StateFacade, @@ -57,46 +71,49 @@ export class PaginationService { .pipe( bufferWhen(() => interval(0)), filter((events) => events.length > 0) - ) + ); this.reloadQueue$ = this.addReloader$ // .pipe(map(x => [x])) .pipe( // map(r => [r]) bufferWhen(() => interval(0)), filter((events) => events.length > 0) - ) - this.subscribeToPageLoadRequests() - this.subscribeToPageReloadRequests() + ); + this.subscribeToPageLoadRequests(); + this.subscribeToPageReloadRequests(); // listen to field changes - this.fieldChangeSocket.fromEvent('fieldChange') - .subscribe(fieldChange => { - + this.fieldChangeSocket + .fromEvent('fieldChange') + .subscribe((fieldChange) => { // is there a fieldChangeListener for the current fieldChange? const fcId = this.fieldChangeToStringId(fieldChange); - const fieldChangedDate = new Date(fieldChange.tmsp_last_modification) + const fieldChangedDate = new Date(fieldChange.tmsp_last_modification); this._reloadPagesOfField(fcId, fieldChangedDate); }); // get all FieldChangeIds and send them to the // server so that they will be streamed. This is important for // when connection was lost. - this.fieldChangeSocket.fromEvent('reconnect').subscribe(disconnect => { - this.state.pkProject$.pipe(first()).subscribe(pkProject => { + this.fieldChangeSocket.fromEvent('reconnect').subscribe((disconnect) => { + this.state.pkProject$.pipe(first()).subscribe((pkProject) => { const addMsg: WarFieldChangeAddToStream = { pkProject, - fieldIds: [] - } - this.fieldChangeListeners.forEach(i => { - addMsg.fieldIds.push(i.fieldChangeId) - }) - fieldChangeSocket.emit(`${FieldChangeSocket.NAMESPACE}::addToStream`, addMsg) - }) - }) + fieldIds: [], + }; + this.fieldChangeListeners.forEach((i) => { + addMsg.fieldIds.push(i.fieldChangeId); + }); + fieldChangeSocket.emit( + `${FieldChangeSocket.NAMESPACE}::addToStream`, + addMsg + ); + }); + }); } reloadPagesOfField(id: WarFieldChangeId, fieldChangedDate?: Date) { - this._reloadPagesOfField(this.fieldChangeToStringId(id), fieldChangedDate) + this._reloadPagesOfField(this.fieldChangeToStringId(id), fieldChangedDate); } /** @@ -105,20 +122,22 @@ export class PaginationService { * @param fieldChangedDate */ private _reloadPagesOfField(fieldChangeId: string, fieldChangedDate?: Date) { - const fcListener = this.fieldChangeListeners.get(fieldChangeId) + const fcListener = this.fieldChangeListeners.get(fieldChangeId); if (fcListener && fcListener.pageIds.length) { // iterate over all pageLoaders that are affected by the fieldChangeDate - fcListener.pageIds.forEach(pageIdString => { + fcListener.pageIds.forEach((pageIdString) => { const loader = this.pageLoaders.get(pageIdString); - if (loader && ( + if ( + loader && // is there no date on the page loader, or (!loader.isUpToDateUntil || // is ther no fieldChangeDate, or !fieldChangedDate || // is the date of the page loader older than the fieldChangeDate? - loader.isUpToDateUntil < fieldChangedDate))) { + loader.isUpToDateUntil < fieldChangedDate) + ) { // load page if (loader && loader.req) { - this.addReloader$.next({ loader, pageIdString }) + this.addReloader$.next({ loader, pageIdString }); } } }); @@ -133,9 +152,9 @@ export class PaginationService { */ public listenToPageUpdates( fieldPageReq: GvFieldPageReq, - takeUntil$: Observable, + takeUntil$: Observable ) { - return this.addPageLoader(fieldPageReq, takeUntil$, false) + return this.addPageLoader(fieldPageReq, takeUntil$, false); } /** @@ -149,82 +168,103 @@ export class PaginationService { takeUntil$: Observable, loadOnInit = true ) { - const { pageIdString, fieldPage, pkProject } = this.parseFieldPageRequest(fieldPageReq); - + const { pageIdString, fieldPage, pkProject } = + this.parseFieldPageRequest(fieldPageReq); if (!this.pageLoaders.has(pageIdString)) { - - - const warFieldChangeId: WarFieldChangeId = fieldPageToWarFieldChangeId(fieldPage) + const warFieldChangeId: WarFieldChangeId = + fieldPageToWarFieldChangeId(fieldPage); // extend stream of fieldChange this.extendFieldChangeStream(pkProject, warFieldChangeId); // add pageIdString to fieldChangeListener - const fcIdString = this.addFieldChangeListener(warFieldChangeId, pageIdString); + const fcIdString = this.addFieldChangeListener( + warFieldChangeId, + pageIdString + ); // add to internal list of field loaders this.addFieldLoader(pageIdString, fcIdString, fieldPageReq); // load the page - if (loadOnInit) this.loadPageAndAddSubfieldListeners(pageIdString, takeUntil$); - + if (loadOnInit) + this.loadPageAndAddSubfieldListeners(pageIdString, takeUntil$); } else { this.increaseFieldLoaderRefCount(pageIdString); } const sub = takeUntil$.subscribe(() => { - const loader = this.pageLoaders.get(pageIdString) + const loader = this.pageLoaders.get(pageIdString); if (loader.refCount === 1) { - this.removeFieldLoaderAndFieldChangeListener(loader, pageIdString, pkProject); + this.removeFieldLoaderAndFieldChangeListener( + loader, + pageIdString, + pkProject + ); } else { this.decreaseFieldLoaderRefCount(pageIdString, loader); } - sub.unsubscribe() - }) - return this.pageLoaders.get(pageIdString) - + sub.unsubscribe(); + }); + return this.pageLoaders.get(pageIdString); } - - private decreaseFieldLoaderRefCount(pageIdString: string, loader: { - refCount: number; // the number of references / subscribers that currently watch the page - // the number of references / subscribers that currently watch the page - until$: Subject; // an observable for that emits, as soon as the page loader is not needed anymore - // an observable for that emits, as soon as the page loader is not needed anymore - req: GvFieldPageReq; - fieldChangeId: string; - isUpToDateUntil?: Date; // the date, for which the loaded page data is valid (this is a date returned by the backend) - }) { + private decreaseFieldLoaderRefCount( + pageIdString: string, + loader: { + refCount: number; // the number of references / subscribers that currently watch the page + // the number of references / subscribers that currently watch the page + until$: Subject; // an observable for that emits, as soon as the page loader is not needed anymore + // an observable for that emits, as soon as the page loader is not needed anymore + req: GvFieldPageReq; + fieldChangeId: string; + isUpToDateUntil?: Date; // the date, for which the loaded page data is valid (this is a date returned by the backend) + } + ) { this.pageLoaders.set(pageIdString, { ...loader, until$: loader.until$, - refCount: loader.refCount - 1 + refCount: loader.refCount - 1, }); } - private removeFieldLoaderAndFieldChangeListener(loader: { - refCount: number; // the number of references / subscribers that currently watch the page - // the number of references / subscribers that currently watch the page - until$: Subject; // an observable for that emits, as soon as the page loader is not needed anymore - // an observable for that emits, as soon as the page loader is not needed anymore - req: GvFieldPageReq; - fieldChangeId: string; - isUpToDateUntil?: Date; // the date, for which the loaded page data is valid (this is a date returned by the backend) - }, pageIdString: string, pkProject: number) { + private removeFieldLoaderAndFieldChangeListener( + loader: { + refCount: number; // the number of references / subscribers that currently watch the page + // the number of references / subscribers that currently watch the page + until$: Subject; // an observable for that emits, as soon as the page loader is not needed anymore + // an observable for that emits, as soon as the page loader is not needed anymore + req: GvFieldPageReq; + fieldChangeId: string; + isUpToDateUntil?: Date; // the date, for which the loaded page data is valid (this is a date returned by the backend) + }, + pageIdString: string, + pkProject: number + ) { loader.until$.next(undefined); // remove the page from the fieldChangeListener const fcListener = this.fieldChangeListeners.get(loader.fieldChangeId); - const pageIds = fcListener.pageIds.filter(pageId => pageId !== pageIdString); + const pageIds = fcListener.pageIds.filter( + (pageId) => pageId !== pageIdString + ); if (pageIds.length === 0) { // remove the fieldChangeListener this.fieldChangeListeners.delete(loader.fieldChangeId); // remove fieldChangeListerner from stream - const msg: WarFieldChangeAddToStream = { pkProject, fieldIds: [fcListener.fieldChangeId] }; - this.fieldChangeSocket.emit(`${FieldChangeSocket.NAMESPACE}::removeFromStream`, msg); - } - else { - this.fieldChangeListeners.set(loader.fieldChangeId, { ...fcListener, pageIds }); + const msg: WarFieldChangeAddToStream = { + pkProject, + fieldIds: [fcListener.fieldChangeId], + }; + this.fieldChangeSocket.emit( + `${FieldChangeSocket.NAMESPACE}::removeFromStream`, + msg + ); + } else { + this.fieldChangeListeners.set(loader.fieldChangeId, { + ...fcListener, + pageIds, + }); } this.pageLoaders.delete(pageIdString); } @@ -234,39 +274,51 @@ export class PaginationService { this.pageLoaders.set(pageIdString, { ...loader, until$: loader.until$, - refCount: loader.refCount + 1 + refCount: loader.refCount + 1, }); } - private addFieldLoader(pageIdString: string, fcIdString: string, fieldPageReq: GvFieldPageReq) { + private addFieldLoader( + pageIdString: string, + fcIdString: string, + fieldPageReq: GvFieldPageReq + ) { this.pageLoaders.set(pageIdString, { fieldChangeId: fcIdString, refCount: 1, until$: new Subject(), - req: fieldPageReq + req: fieldPageReq, }); } - private addFieldChangeListener(warFieldChangeId: WarFieldChangeId, pageIdString: string) { + private addFieldChangeListener( + warFieldChangeId: WarFieldChangeId, + pageIdString: string + ) { const fcIdString = this.fieldChangeToStringId(warFieldChangeId); const fcListener = this.fieldChangeListeners.get(fcIdString); const pageIds = fcListener ? fcListener.pageIds : []; this.fieldChangeListeners.set(fcIdString, { fieldChangeId: warFieldChangeId, - pageIds: [...pageIds, pageIdString] + pageIds: [...pageIds, pageIdString], }); return fcIdString; } - private extendFieldChangeStream(pkProject: number, warFieldChangeId: WarFieldChangeId) { + private extendFieldChangeStream( + pkProject: number, + warFieldChangeId: WarFieldChangeId + ) { const addMsg: WarFieldChangeAddToStream = { pkProject, - fieldIds: [warFieldChangeId] + fieldIds: [warFieldChangeId], }; - this.fieldChangeSocket.emit(`${FieldChangeSocket.NAMESPACE}::extendStream`, addMsg); + this.fieldChangeSocket.emit( + `${FieldChangeSocket.NAMESPACE}::extendStream`, + addMsg + ); } - /** * Flattens the fieldPageReq and returns individual parameters that are easier to consume * than from the nested object. @@ -279,62 +331,83 @@ export class PaginationService { const offset = fieldPage.offset; const scope = fieldPage.scope; const source = fieldPage.source; - const subfieldIdString = subfieldIdToString(fieldPage); - const pageIdString = subfieldIdString + '_' + limit + '_' + offset; + const pageIdString = this.getFieldPageId(fieldPage); - return { pageIdString, fieldPage, pkProject, fieldTargets, source, scope, limit, offset }; + return { + pageIdString, + fieldPage, + pkProject, + fieldTargets, + source, + scope, + limit, + offset, + }; + } + + /** + * Gets the field page id string to identify a field page + * @param page + */ + private getFieldPageId(page: GvFieldPage): string { + const limit = page.limit; + const offset = page.offset; + const fieldId = subfieldIdToString(page); + return fieldId + '_' + limit + '_' + offset; } subscribeToPageReloadRequests() { this.reloadQueue$.subscribe((items) => { - const reqs = items.map(item => item.loader.req) - const options = indexBy((i) => i.pageIdString, items) - this.state.data.loadFieldPage(reqs).pipe(first()).subscribe( - res => { - res.subfieldPages.forEach(fieldpage => { - const { pageIdString } = this.parseFieldPageRequest(fieldpage.req) - const item = options[pageIdString] + const reqs = items.map((item) => item.loader.req); + const options = indexBy((i) => i.pageIdString, items); + this.state.data + .loadFieldPage(reqs) + .pipe(first()) + .subscribe((res) => { + res.subfieldPages.forEach((fieldpage) => { + const pageIdString = this.getFieldPageId(fieldpage.page); + const item = options[pageIdString]; // set the isUpToDateUntil of the loader if (item) { this.pageLoaders.set(pageIdString, { ...item.loader, - isUpToDateUntil: new Date(res.subfieldPages[0].validFor) - }) + isUpToDateUntil: new Date(res.subfieldPages[0].validFor), + }); } - }) - - } - ); - }) + }); + }); + }); } subscribeToPageLoadRequests() { this.loadQueue$.subscribe((items) => { - const reqs = items.map(item => item.loader.req) - const options = indexBy((i) => i.pageIdString, items) - this.state.data.loadFieldPage(reqs).pipe(first()).subscribe( - res => { - res.subfieldPages.forEach(fieldpage => { - const { pageIdString } = this.parseFieldPageRequest(fieldpage.req) - const item = options[pageIdString] + const reqs = items.map((item) => item.loader.req); + const options = indexBy((i) => i.pageIdString, items); + this.state.data + .loadFieldPage(reqs) + .pipe(first()) + .subscribe((res) => { + res.subfieldPages.forEach((fieldpage) => { + const pageIdString = this.getFieldPageId(fieldpage.page); + const item = options[pageIdString]; if (item) { // set the isUpToDateUntil of the loader this.pageLoaders.set(pageIdString, { ...item.loader, - isUpToDateUntil: new Date(res.subfieldPages[0].validFor) - }) + isUpToDateUntil: new Date(res.subfieldPages[0].validFor), + }); } - }) - - } - ); - }) + }); + }); + }); } - private loadPageAndAddSubfieldListeners(pageIdString: string, takeUntil$: Observable) { - const loader = this.pageLoaders.get(pageIdString) + private loadPageAndAddSubfieldListeners( + pageIdString: string, + takeUntil$: Observable + ) { + const loader = this.pageLoaders.get(pageIdString); if (loader && loader.req) { - this.addLoader$.next({ loader, pageIdString, takeUntil$ }) + this.addLoader$.next({ loader, pageIdString, takeUntil$ }); } - } public addPageLoaderFromField( @@ -344,18 +417,18 @@ export class PaginationService { limit, offset, takeUntil$: Observable, - scope: GvFieldPageScope, + scope: GvFieldPageScope ) { const req: GvFieldPageReq = { pkProject, targets: fieldToGvFieldTargets(field), page: fieldToFieldPage(field, source, scope, limit, offset), - } - return this.addPageLoader(req, takeUntil$) + }; + return this.addPageLoader(req, takeUntil$); } - private fieldChangeToStringId(i: WarFieldChangeId): string { - return `${i.fk_project || 0}_${i.fk_source_info || 0}_${i.fk_source_tables_cell || 0}_${i.fk_property || 0}_${i.fk_property_of_property || 0}_${i.is_outgoing}` + return `${i.fk_project || 0}_${i.fk_source_info || 0}_${i.fk_source_tables_cell || 0 + }_${i.fk_property || 0}_${i.is_outgoing}`; } } diff --git a/client/apps/app-toolbox/src/assets/favicon/android-chrome-192x192.png b/client/apps/app-toolbox/src/assets/favicon/android-chrome-192x192.png index 1fc87bc92..ca6c6eff6 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/android-chrome-192x192.png and b/client/apps/app-toolbox/src/assets/favicon/android-chrome-192x192.png differ diff --git a/client/apps/app-toolbox/src/assets/favicon/android-chrome-512x512.png b/client/apps/app-toolbox/src/assets/favicon/android-chrome-512x512.png index fcdcc2c7e..bdb3d9f42 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/android-chrome-512x512.png and b/client/apps/app-toolbox/src/assets/favicon/android-chrome-512x512.png differ diff --git a/client/apps/app-toolbox/src/assets/favicon/apple-touch-icon.png b/client/apps/app-toolbox/src/assets/favicon/apple-touch-icon.png index aeb9a58c9..374b5f9ba 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/apple-touch-icon.png and b/client/apps/app-toolbox/src/assets/favicon/apple-touch-icon.png differ diff --git a/client/apps/app-toolbox/src/assets/favicon/favicon-16x16.png b/client/apps/app-toolbox/src/assets/favicon/favicon-16x16.png index 1d802cd26..8f9dbe76b 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/favicon-16x16.png and b/client/apps/app-toolbox/src/assets/favicon/favicon-16x16.png differ diff --git a/client/apps/app-toolbox/src/assets/favicon/favicon-32x32.png b/client/apps/app-toolbox/src/assets/favicon/favicon-32x32.png index 688d1d3dc..9df6f731f 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/favicon-32x32.png and b/client/apps/app-toolbox/src/assets/favicon/favicon-32x32.png differ diff --git a/client/apps/app-toolbox/src/assets/favicon/mstile-150x150.png b/client/apps/app-toolbox/src/assets/favicon/mstile-150x150.png index 237579ec2..f825649b4 100644 Binary files a/client/apps/app-toolbox/src/assets/favicon/mstile-150x150.png and b/client/apps/app-toolbox/src/assets/favicon/mstile-150x150.png differ diff --git a/client/apps/app-toolbox/src/assets/images/positron_no_labels.png b/client/apps/app-toolbox/src/assets/images/positron_no_labels.png index c296b63cf..0220bfa30 100644 Binary files a/client/apps/app-toolbox/src/assets/images/positron_no_labels.png and b/client/apps/app-toolbox/src/assets/images/positron_no_labels.png differ diff --git a/client/apps/app-toolbox/src/assets/images/time-span.png b/client/apps/app-toolbox/src/assets/images/time-span.png index bd412574e..3178f6ebc 100644 Binary files a/client/apps/app-toolbox/src/assets/images/time-span.png and b/client/apps/app-toolbox/src/assets/images/time-span.png differ diff --git a/client/apps/app-toolbox/src/assets/images/visibility-status.png b/client/apps/app-toolbox/src/assets/images/visibility-status.png index 989cefe77..8ec65d562 100644 Binary files a/client/apps/app-toolbox/src/assets/images/visibility-status.png and b/client/apps/app-toolbox/src/assets/images/visibility-status.png differ diff --git a/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.eot b/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.eot index bc997a875..4042d5068 100755 Binary files a/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.eot and b/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.eot differ diff --git a/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.ttf b/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.ttf index 0ed92bae8..7b3c6d587 100755 Binary files a/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.ttf and b/client/apps/app-toolbox/src/assets/scss/glyphter-font/fonts/geovistory-font.ttf differ diff --git a/client/geovistory-font/gv-icons.ai b/client/geovistory-font/gv-icons.ai index 3d68c6692..6bc7d08bb 100644 --- a/client/geovistory-font/gv-icons.ai +++ b/client/geovistory-font/gv-icons.ai @@ -1,5 +1,5 @@ -%PDF-1.5 % -1 0 obj <>/OCGs[5 0 R 6 0 R 7 0 R 46 0 R 47 0 R 48 0 R 81 0 R 82 0 R 83 0 R 116 0 R 117 0 R 118 0 R 153 0 R 154 0 R 155 0 R 195 0 R 196 0 R 197 0 R 234 0 R 235 0 R 236 0 R 277 0 R 278 0 R 279 0 R]>>/Pages 3 0 R/Type/Catalog>> endobj 2 0 obj <>stream +%PDF-1.5 % +1 0 obj <>/OCGs[5 0 R 6 0 R 7 0 R 46 0 R 47 0 R 48 0 R 81 0 R 82 0 R 83 0 R 116 0 R 117 0 R 118 0 R 153 0 R 154 0 R 155 0 R 195 0 R 196 0 R 197 0 R 234 0 R 235 0 R 236 0 R 277 0 R 278 0 R 279 0 R]>>/Pages 3 0 R/Type/Catalog>> endobj 2 0 obj <>stream @@ -688,12 +688,12 @@ - endstream endobj 3 0 obj <> endobj 238 0 obj <> endobj 239 0 obj <> endobj 14 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 866.0 1000.0]/Type/Page>> endobj 120 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 914.0 1000.0]/Type/Page>> endobj 157 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 828.057 1000.0]/Type/Page>> endobj 158 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 1000.0 1000.0]/Type/Page>> endobj 159 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 891.0 1000.0]/Type/Page>> endobj 240 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 1000.0 1000.0]/Type/Page>> endobj 289 0 obj <>stream + endstream endobj 3 0 obj <> endobj 238 0 obj <> endobj 239 0 obj <> endobj 14 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 866.0 1000.0]/Type/Page>> endobj 120 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 914.0 1000.0]/Type/Page>> endobj 157 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 828.057 1000.0]/Type/Page>> endobj 158 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 1000.0 1000.0]/Type/Page>> endobj 159 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 891.0 1000.0]/Type/Page>> endobj 240 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 1000.0 1000.0]/Type/Page>> endobj 289 0 obj <>stream HdM1 u _<-bbZAė TY><'yYw<= kKb)}$I"HO^n\KMrZJ7 k^~lVռ^4.zXč)wmhn]j4-u?[)'ymƻa Msc\%sfY7 =1ծnJ9C ;EY>5FJˤ>1Z5S]2iT~yfѵ@CY3GhLb1(ߓLS˄)Ku"Ir0[/͖9;MD r!0^f-5^_xG|EO8͍JF> endobj 278 0 obj <> endobj 279 0 obj <> endobj 294 0 obj [/View/Design] endobj 295 0 obj <>>> endobj 292 0 obj [/View/Design] endobj 293 0 obj <>>> endobj 290 0 obj [/View/Design] endobj 291 0 obj <>>> endobj 284 0 obj <> endobj 283 0 obj [/ICCBased 296 0 R] endobj 296 0 obj <>stream +ytn۷7G endstream endobj 277 0 obj <> endobj 278 0 obj <> endobj 279 0 obj <> endobj 294 0 obj [/View/Design] endobj 295 0 obj <>>> endobj 292 0 obj [/View/Design] endobj 293 0 obj <>>> endobj 290 0 obj [/View/Design] endobj 291 0 obj <>>> endobj 284 0 obj <> endobj 283 0 obj [/ICCBased 296 0 R] endobj 296 0 obj <>stream HuTKtKKJI,t(݋4K%ҹH4J#Ғ(H wqyy~3̙g<3Y9El @ ]!O-@\+BVKK :OX~WCaiHKL0qY `5ck @@ -733,7 +733,7 @@ p vě92 w u煼ת#{P6+Dq3HIi%BCb!kc5&U ):X$܎[b2*@PkcӘdoTB_L1Uwi")=2#pI9,RO>T@>;bnDPuCfk^^\G~ oLRcHqܮ=-8^5Ońy*9:-\g8:T<?*C;[yX+I;lRL߭$DvYTQ6DyVmfy%/sIsmXP1Lռȭvow)QBb_LVwupeėO*|+](uHװ4WU.{ 4\m.QwR~MAiRz+%BKz?'{ k҉aa{H]sX}da~3_auQz VM\ĵv5I0LM)DŽp1:5,&4 %!$}ocޤA]R^xT◬M&/B:DwA24?cd&g]5b4a?iǐ Ĉ.OA 6vfvsd(5yTH/P=(a;zUs bWxDa)Eʼ $sgPJreY3w`cFo0|U[j5k.5J&eTor È´}I lpjC8c5J=g%Uo|L58E" ِ[Ak]J͆VBM"{NrQihЦ@Y?6^߫ZWٯ]ذc؋hKSLj:>O ɲ.ݰQ{5mm<ٷ?^v"}ъw9O&vX7km[ ,70nΒ7|eP\I;sx9||񐊵n.5YMAJ"KA 5 *#pL6#-pͶz7ӦJWn]Rc&S٥";H+,%p jHVJbe)Qa^b(,D y)|Z)qn3כ X)a zmVoRG,K)kȫvٕɎ|3LV&V%XU?@Uw(1ſ!1Ő(ZeW0Wi x6}=A{a.'M6eKȞ&!>6!$.ݙ[+tOfUUFW#ȑWy{R"wypьÝs8>Zﵡ7"fi-hgMoKKiIuHl7Iz7QCi +ڮȃZu(9O!͗d)2eA:r.RS4>5YMAJ"KA 5 *#pL6#-pͶz7ӦJWn]Rc&S٥";H+,%p jHVJbe)Qa^b(,D y)|Z)qn3כ X)a zmVoRG,K)kȫvٕɎ|3LV&V%XU?@Uw(1ſ!1Ő(ZeW0Wi x6}=A{a.'M6eKȞ&!>6!$.ݙ[+tOfUUFW#ȑWy{R"wypьÝs8>Zﵡ7"fi-hgMoKKiIuHl7Iz7QCi n \+k{'B>p6?7{qevCd]@?ߓv> eЛbw8Gv廝xw{S;|)W[E?r/~V迒g9jfjk`s@=aSN3w1_3"ܑН]QM^i@AH ,!!   aȢ ѶNjkkGfܵ"hE .qj3/s{{sfW/=4rl4:&eUԉU'br(PV_}P#>NW8,9u >K~i]ԅ܋/a坟ÝyDUD^Rj NOD{Z\oO#"V7ЊwXN)iQOͿjr˹jʺZ\25/$7'6}&o 7}״Gm:i=ic l:;wP^Ս Ϳ㌊|QMD[}fpNۊ<zǷ1tmk|cm_blԶݜǸv ?6OvwP;;ye*pALdRԩ3vΰOJuvuO*vt/v^^ٳK޳[s.=͐^cHzak=U>GhùwK[w@9(+JcԾ"_L+)qZ;@U=h̦E;ȇ#J$ëpKi נZV7n7ˁp;8]~QBi8 c>H7'""zBJ*'T"}kC]dR!EBXd/48pܑ~p֑ ͎,xx5quoC('u"4c )d $L.9t?$\0Q ‚̷C|n Pݠ}f>g#Ѕf!8w @@ -1647,7 +1647,7 @@ SM N!Mhon6\[b6R\wϑc*=Vc=?jCZyF+n{>@NZ5/bF*#r#7i{YQǍԨ+ƌG(HyNd7xg{=Ê6Wvg"7*l.an ZЭ跔=Js'jvLbR53fg̈YaT2c?5b/ScSbM#I̯\%gˌ\}2|))enE1>=*U)@=Da)fn$[IcuhuX&L;by7q3qFzWhD{o͌ qڽ]iVK4+>B =5#>4`%ۆ)6ZSmD{d[1ѶИ`+UXj,m\Fλݳ 1g$b>ã0{ KHe K"I&L2IfLB&$$C!"ITBR, @!(}cVVc] B_Hg3s9|/>X$E ҐcU8E5IsT@U-wdґ -G@2#Xa:Ŏ;BGYn;[ycq9.YK$_mqg.j]L,kc acSUU +G@2#Xa:Ŏ;BGYn;[ycq9.YK$_mqg.j]L,kc acSUU TE<',ݩӣgFsQ3Lw[,q+'+yN+fNj?g8IK+MuJ,Ty]̈Qif3ȝ;KnEFk\mǽvo[Vr_\GF9ƱlMԀxꉧ,'r`fE8;J9SU3GK= qɔϛ\o@^o1Mfg<`9={4cVy+󱕒c}fCV?8+/n-xBRgT7\c_-or}'w*Q?_n0#b&w[I^+Z\xm&}$=o%PF0 7f|>xhA,BeVVQ2#*RzTVj|&)ԥ`- @@ -2133,9 +2133,9 @@ p`+gQ d *>7 8PW% \ h`3^l:93cM|;egA :܂8XJ[7XI|0|N7w[{EkvcJȬi%J-Q#u|FBѵ<~ԠVTw|_JvV{J,͓ɯ)l/` R|Vxfm 96pL1c3Y0ߜ,/NP[@Qt+eKTe9ۏ-p -Ȯ|BpW$ %IHO޿y:~0?_(gD,rE}KcШ+)J_*=I,?!4l=Å[Pծ=Ğ [ }g OZO$o!xL=5dbBC) Oմ>RIr\r"#;@V2[kclzi5a#*Xm?;62.#:ĉ֙Li_8L+ endstream endobj 282 0 obj <> endobj 297 0 obj <> endobj 298 0 obj <>stream -%!PS-Adobe-3.0 %%Creator: Adobe Illustrator(R) 16.0 %%AI8_CreatorVersion: 16.0.0 %%For: (Jonas Schneider2) () %%Title: (gv-icons.ai) %%CreationDate: 07.06.19 15:52 %%Canvassize: 16383 %%BoundingBox: -7823 -2389 7872 2992 %%HiResBoundingBox: -7822.3218 -2388.1592 7871.748 2991.9224 %%DocumentProcessColors: Cyan Magenta Yellow Black %AI5_FileFormat 12.0 %AI12_BuildNumber: 682 %AI3_ColorUsage: Color %AI7_ImageSettings: 0 %%CMYKProcessColor: 1 1 1 1 ([Registration]) %AI3_Cropmarks: -5093 -590.6807 -4093 409.3193 %AI3_TemplateBox: 155.5 -50.5 155.5 -50.5 %AI3_TileBox: -4872.5 -470.6807 -4313.5 312.3193 %AI3_DocumentPreview: None %AI5_ArtSize: 14400 14400 %AI5_RulerUnits: 6 %AI9_ColorModel: 2 %AI5_ArtFlags: 0 0 0 1 0 0 1 0 0 %AI5_TargetResolution: 800 %AI5_NumLayers: 3 %AI9_OpenToView: -5589 418 1.25 2509 1297 18 1 0 6 134 0 0 0 1 1 0 1 1 0 0 %AI5_OpenViewLayers: 773 %%PageOrigin:-151 -446 %AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9 %AI9_Flatten: 1 %AI12_CMSettings: 00.MS %%EndComments endstream endobj 299 0 obj <>stream -%%BoundingBox: -7823 -2389 7872 2992 %%HiResBoundingBox: -7822.3218 -2388.1592 7871.748 2991.9224 %AI7_Thumbnail: 128 44 8 %%BeginData: 4146 Hex Bytes %0000330000660000990000CC0033000033330033660033990033CC0033FF %0066000066330066660066990066CC0066FF009900009933009966009999 %0099CC0099FF00CC0000CC3300CC6600CC9900CCCC00CCFF00FF3300FF66 %00FF9900FFCC3300003300333300663300993300CC3300FF333300333333 %3333663333993333CC3333FF3366003366333366663366993366CC3366FF %3399003399333399663399993399CC3399FF33CC0033CC3333CC6633CC99 %33CCCC33CCFF33FF0033FF3333FF6633FF9933FFCC33FFFF660000660033 %6600666600996600CC6600FF6633006633336633666633996633CC6633FF %6666006666336666666666996666CC6666FF669900669933669966669999 %6699CC6699FF66CC0066CC3366CC6666CC9966CCCC66CCFF66FF0066FF33 %66FF6666FF9966FFCC66FFFF9900009900339900669900999900CC9900FF %9933009933339933669933999933CC9933FF996600996633996666996699 %9966CC9966FF9999009999339999669999999999CC9999FF99CC0099CC33 %99CC6699CC9999CCCC99CCFF99FF0099FF3399FF6699FF9999FFCC99FFFF %CC0000CC0033CC0066CC0099CC00CCCC00FFCC3300CC3333CC3366CC3399 %CC33CCCC33FFCC6600CC6633CC6666CC6699CC66CCCC66FFCC9900CC9933 %CC9966CC9999CC99CCCC99FFCCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF %CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFFFF0033FF0066FF0099FF00CC %FF3300FF3333FF3366FF3399FF33CCFF33FFFF6600FF6633FF6666FF6699 %FF66CCFF66FFFF9900FF9933FF9966FF9999FF99CCFF99FFFFCC00FFCC33 %FFCC66FFCC99FFCCCCFFCCFFFFFF33FFFF66FFFF99FFFFCC110000001100 %000011111111220000002200000022222222440000004400000044444444 %550000005500000055555555770000007700000077777777880000008800 %000088888888AA000000AA000000AAAAAAAABB000000BB000000BBBBBBBB %DD000000DD000000DDDDDDDDEE000000EE000000EEEEEEEE0000000000FF %00FF0000FFFFFF0000FF00FFFFFF00FFFFFF %524C45FDAAFFA8AEA8AEA8AEA8AEA8FFA8FD76FFA8AEA8AEA8AE84FD78FF %A8AEA8AE83AEA8A8A8FFA8FD76FFA8AEA8AEA8AEA8FD78FFA8AEA8AE84AE %A8AEA8FD77FFAEA8AEA8AEA8AEA8FD78FFA8A883AEA8AE83AEA8FFA8FD75 %FFAEA8AEA8AEA8AEA8FD78FFAEAEA8FFA8AEA8FFAEFFA8FDFCFFFD13FF7D %FD7EFF777777FD7CFF77A2A97E77FD7BFFA27EFFFFA277FD7AFFA277A8FF %A277A8FD0DFF7EA8FD6AFF78A2FFCB78A2FD0DFF7E7E77A8FD69FFA27EA2 %78A2FD0EFFA27E7E7EFD6AFFA277A2FD0FFFA8A27EFD6CFFCBFDD3FFA97E %53A2FD0AFFA8FFA9FFA8FD07FFA9FD12FFA27EFD06FF7E777E5377A2FD04 %FFA8777853A8FD07FF777EFD07FF7E777EFD0EFFA8A8FD18FF7E53294D28 %77A8FD07FFA8A8A2A9A2A8A2FD05FFA2A27EFD07FFA8A8FD06FFA8784D77 %77FD04FFA9294D537E4D7EFFFFFFA94DA27EA24DA9FD05FFA24D78FD06FF %7E4D294DA2FF7E7E777E77A2FFFFFF7E7E784D77A9FD16FFA84D22787753 %2253FD07FFA8A2A8A8A9A2A2FD04FF77774C777DFD05FF7EFFA8A9A2FFFF %FFA2774DA2775353A9FFFF7E4D4D534D53A8FFFFFF7778FFFFFF7E53FFFF %FF777753FF77774DA8FFFFFF77224D2278FFA2537753777EFFA87E53A828 %A24DA8FD16FFA828787878534D4DFD07FFA8CBA8FFA9CBA8FFFFFFA87E4D %714DA2CBFD05FFA2A8A9FD04FFA94DA9FFFF7E77A8FFFFA9777E4D7E77FD %04FF77A8FFFFFFA978FFFFFFA94DFFFFFF7778FFFF7E7E534D4D4DA2FF7E %7E777E77A8FFFF537EFF784D4D7EFD16FF7E4D4D784DA2224DA9FD06FFA9 %A8A8A8A97EA8FFFFFFCB7771467177FFFFFFA8A2A8A27EA2A2A8FFFF7E53 %77FFFF7E53A9FFFFA27777535377FD04FF4DCBFD04FF4DFD04FF7E77FFA8 %78FFFF7E4D28787E53A2FFFFA2777853787EFFFF7E53A9FFFF7E53FD16FF %A94D4D77A2534D4DFD07FFA8A9A8FFA8CBA8FD04FFA2777877A9FD06FFA2 %A2A8FD05FF77787EA2537EA8FFFFA94D784D774D78FFFFFFA24DA9FFA94D %7EFD04FF7E77777853FFFFA94C4DA8A94DFFFFFF7E77537EFD04FF7E7878 %7E77A2FD18FF78224D4D4D28A2FD08FFA2A977A8A2FD06FFA8A2CBFD05FF %CB7EFFA8A87EFD04FFA84D534D53A2FFFFFFA84D2253534D4DFD04FFA84D %534DA2FD05FF7E53FF7E77A8FFFFA9A2FF774DA8FFFFA87DA2A2FD05FF53 %774D5353FD19FFA94D4D77FD0CFFA2CBFD11FFA9A9FD08FF7EA9FD06FF77 %78787E7EFD07FF7EFD13FFA9FD0DFFA9A2FD1DFFA8FD8FFFA9A2A27EA9FD %7AFF774C7777714DFD7AFF777777A271A2FD79FFA877A8FFA877FD7BFF77 %FFFFFF77FD7AFFA8777DA2777177FD1BFFCBFD0BFFA8FFA8CBFD4FFF7777 %77784C77FD0EFFA2A27EA277CBFFFFA8A9A2A2A8FFFFA27EA2A8FD05FF77 %A8A2A277A9FD4EFFA24DA2777EA2FD0DFFA8714CA2774D77FF4D4D777877 %77FF78537753537EFFFFFFA2777DA8A27EA8FD61FFCB7778777777FFFF77 %4D78777777A94DFFFFFF7E78FFFFFFCBA2A87ECBA2FD62FFA278777777A2 %FFFF4D784D7E4DFF537EFD04FF4DFFFFFFA8A2777EA8A2A8FD61FFCB77A2 %7778A2FFA9787E777778FF78A8FD04FF78A2FFFFFFA2787EFFA8CBFD61FF %A27777774D717EFF4D7E4D774CA27E53A8FFFF784DFFFFFFA8A2A8A9A8A2 %A2FD61FFCB4C7778774CA2FF774D7E77774DFF7E53777853FD05FF77A2A2 %A27EA2FD62FFA277A27EA8FFFF774D4D7777A2FFFFA87777FD06FFA277A8 %7EA2A8FD24FFFF %%EndData endstream endobj 300 0 obj <>stream +Ȯ|BpW$ %IHO޿y:~0?_(gD,rE}KcШ+)J_*=I,?!4l=Å[Pծ=Ğ [ }g OZO$o!xL=5dbBC) Oմ>RIr\r"#;@V2[kclzi5a#*Xm?;62.#:ĉ֙Li_8L+ endstream endobj 282 0 obj <> endobj 297 0 obj <> endobj 298 0 obj <>stream +%!PS-Adobe-3.0 %%Creator: Adobe Illustrator(R) 16.0 %%AI8_CreatorVersion: 16.0.0 %%For: (Jonas Schneider2) () %%Title: (gv-icons.ai) %%CreationDate: 07.06.19 15:52 %%Canvassize: 16383 %%BoundingBox: -7823 -2389 7872 2992 %%HiResBoundingBox: -7822.3218 -2388.1592 7871.748 2991.9224 %%DocumentProcessColors: Cyan Magenta Yellow Black %AI5_FileFormat 12.0 %AI12_BuildNumber: 682 %AI3_ColorUsage: Color %AI7_ImageSettings: 0 %%CMYKProcessColor: 1 1 1 1 ([Registration]) %AI3_Cropmarks: -5093 -590.6807 -4093 409.3193 %AI3_TemplateBox: 155.5 -50.5 155.5 -50.5 %AI3_TileBox: -4872.5 -470.6807 -4313.5 312.3193 %AI3_DocumentPreview: None %AI5_ArtSize: 14400 14400 %AI5_RulerUnits: 6 %AI9_ColorModel: 2 %AI5_ArtFlags: 0 0 0 1 0 0 1 0 0 %AI5_TargetResolution: 800 %AI5_NumLayers: 3 %AI9_OpenToView: -5589 418 1.25 2509 1297 18 1 0 6 134 0 0 0 1 1 0 1 1 0 0 %AI5_OpenViewLayers: 773 %%PageOrigin:-151 -446 %AI7_GridSettings: 72 8 72 8 1 0 0.8 0.8 0.8 0.9 0.9 0.9 %AI9_Flatten: 1 %AI12_CMSettings: 00.MS %%EndComments endstream endobj 299 0 obj <>stream +%%BoundingBox: -7823 -2389 7872 2992 %%HiResBoundingBox: -7822.3218 -2388.1592 7871.748 2991.9224 %AI7_Thumbnail: 128 44 8 %%BeginData: 4146 Hex Bytes %0000330000660000990000CC0033000033330033660033990033CC0033FF %0066000066330066660066990066CC0066FF009900009933009966009999 %0099CC0099FF00CC0000CC3300CC6600CC9900CCCC00CCFF00FF3300FF66 %00FF9900FFCC3300003300333300663300993300CC3300FF333300333333 %3333663333993333CC3333FF3366003366333366663366993366CC3366FF %3399003399333399663399993399CC3399FF33CC0033CC3333CC6633CC99 %33CCCC33CCFF33FF0033FF3333FF6633FF9933FFCC33FFFF660000660033 %6600666600996600CC6600FF6633006633336633666633996633CC6633FF %6666006666336666666666996666CC6666FF669900669933669966669999 %6699CC6699FF66CC0066CC3366CC6666CC9966CCCC66CCFF66FF0066FF33 %66FF6666FF9966FFCC66FFFF9900009900339900669900999900CC9900FF %9933009933339933669933999933CC9933FF996600996633996666996699 %9966CC9966FF9999009999339999669999999999CC9999FF99CC0099CC33 %99CC6699CC9999CCCC99CCFF99FF0099FF3399FF6699FF9999FFCC99FFFF %CC0000CC0033CC0066CC0099CC00CCCC00FFCC3300CC3333CC3366CC3399 %CC33CCCC33FFCC6600CC6633CC6666CC6699CC66CCCC66FFCC9900CC9933 %CC9966CC9999CC99CCCC99FFCCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF %CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFFFF0033FF0066FF0099FF00CC %FF3300FF3333FF3366FF3399FF33CCFF33FFFF6600FF6633FF6666FF6699 %FF66CCFF66FFFF9900FF9933FF9966FF9999FF99CCFF99FFFFCC00FFCC33 %FFCC66FFCC99FFCCCCFFCCFFFFFF33FFFF66FFFF99FFFFCC110000001100 %000011111111220000002200000022222222440000004400000044444444 %550000005500000055555555770000007700000077777777880000008800 %000088888888AA000000AA000000AAAAAAAABB000000BB000000BBBBBBBB %DD000000DD000000DDDDDDDDEE000000EE000000EEEEEEEE0000000000FF %00FF0000FFFFFF0000FF00FFFFFF00FFFFFF %524C45FDAAFFA8AEA8AEA8AEA8AEA8FFA8FD76FFA8AEA8AEA8AE84FD78FF %A8AEA8AE83AEA8A8A8FFA8FD76FFA8AEA8AEA8AEA8FD78FFA8AEA8AE84AE %A8AEA8FD77FFAEA8AEA8AEA8AEA8FD78FFA8A883AEA8AE83AEA8FFA8FD75 %FFAEA8AEA8AEA8AEA8FD78FFAEAEA8FFA8AEA8FFAEFFA8FDFCFFFD13FF7D %FD7EFF777777FD7CFF77A2A97E77FD7BFFA27EFFFFA277FD7AFFA277A8FF %A277A8FD0DFF7EA8FD6AFF78A2FFCB78A2FD0DFF7E7E77A8FD69FFA27EA2 %78A2FD0EFFA27E7E7EFD6AFFA277A2FD0FFFA8A27EFD6CFFCBFDD3FFA97E %53A2FD0AFFA8FFA9FFA8FD07FFA9FD12FFA27EFD06FF7E777E5377A2FD04 %FFA8777853A8FD07FF777EFD07FF7E777EFD0EFFA8A8FD18FF7E53294D28 %77A8FD07FFA8A8A2A9A2A8A2FD05FFA2A27EFD07FFA8A8FD06FFA8784D77 %77FD04FFA9294D537E4D7EFFFFFFA94DA27EA24DA9FD05FFA24D78FD06FF %7E4D294DA2FF7E7E777E77A2FFFFFF7E7E784D77A9FD16FFA84D22787753 %2253FD07FFA8A2A8A8A9A2A2FD04FF77774C777DFD05FF7EFFA8A9A2FFFF %FFA2774DA2775353A9FFFF7E4D4D534D53A8FFFFFF7778FFFFFF7E53FFFF %FF777753FF77774DA8FFFFFF77224D2278FFA2537753777EFFA87E53A828 %A24DA8FD16FFA828787878534D4DFD07FFA8CBA8FFA9CBA8FFFFFFA87E4D %714DA2CBFD05FFA2A8A9FD04FFA94DA9FFFF7E77A8FFFFA9777E4D7E77FD %04FF77A8FFFFFFA978FFFFFFA94DFFFFFF7778FFFF7E7E534D4D4DA2FF7E %7E777E77A8FFFF537EFF784D4D7EFD16FF7E4D4D784DA2224DA9FD06FFA9 %A8A8A8A97EA8FFFFFFCB7771467177FFFFFFA8A2A8A27EA2A2A8FFFF7E53 %77FFFF7E53A9FFFFA27777535377FD04FF4DCBFD04FF4DFD04FF7E77FFA8 %78FFFF7E4D28787E53A2FFFFA2777853787EFFFF7E53A9FFFF7E53FD16FF %A94D4D77A2534D4DFD07FFA8A9A8FFA8CBA8FD04FFA2777877A9FD06FFA2 %A2A8FD05FF77787EA2537EA8FFFFA94D784D774D78FFFFFFA24DA9FFA94D %7EFD04FF7E77777853FFFFA94C4DA8A94DFFFFFF7E77537EFD04FF7E7878 %7E77A2FD18FF78224D4D4D28A2FD08FFA2A977A8A2FD06FFA8A2CBFD05FF %CB7EFFA8A87EFD04FFA84D534D53A2FFFFFFA84D2253534D4DFD04FFA84D %534DA2FD05FF7E53FF7E77A8FFFFA9A2FF774DA8FFFFA87DA2A2FD05FF53 %774D5353FD19FFA94D4D77FD0CFFA2CBFD11FFA9A9FD08FF7EA9FD06FF77 %78787E7EFD07FF7EFD13FFA9FD0DFFA9A2FD1DFFA8FD8FFFA9A2A27EA9FD %7AFF774C7777714DFD7AFF777777A271A2FD79FFA877A8FFA877FD7BFF77 %FFFFFF77FD7AFFA8777DA2777177FD1BFFCBFD0BFFA8FFA8CBFD4FFF7777 %77784C77FD0EFFA2A27EA277CBFFFFA8A9A2A2A8FFFFA27EA2A8FD05FF77 %A8A2A277A9FD4EFFA24DA2777EA2FD0DFFA8714CA2774D77FF4D4D777877 %77FF78537753537EFFFFFFA2777DA8A27EA8FD61FFCB7778777777FFFF77 %4D78777777A94DFFFFFF7E78FFFFFFCBA2A87ECBA2FD62FFA278777777A2 %FFFF4D784D7E4DFF537EFD04FF4DFFFFFFA8A2777EA8A2A8FD61FFCB77A2 %7778A2FFA9787E777778FF78A8FD04FF78A2FFFFFFA2787EFFA8CBFD61FF %A27777774D717EFF4D7E4D774CA27E53A8FFFF784DFFFFFFA8A2A8A9A8A2 %A2FD61FFCB4C7778774CA2FF774D7E77774DFF7E53777853FD05FF77A2A2 %A27EA2FD62FFA277A27EA8FFFF774D4D7777A2FFFFA87777FD06FFA277A8 %7EA2A8FD24FFFF %%EndData endstream endobj 300 0 obj <>stream |XhW֓۰>arޓ2V"g~< 9U]9t|Y "ةfx6*y>[Km/OGo0 ۛe1 %W{B5S{w 0Z=?guzO}BI5f eǥȅ0;$\/a_bKlOA3ΝYeU5}`[T쎫}(*ĽRb+?Aub^ya^VkPNwN&^8^~`V.a1my~7p3Kc:^_{e;^R ccReI*l!ۯa4R^(˳0IE~P*=(f/^UKUz]ۃE騸+v {\uҝl4DGa;t@jRwaSϋzDZʳ 2ʸ2{23V 욟tei>{J5U"JazUJ :b%ADK zȥցq_AQ8*U\@;xq"s^ZX k2]s 8VhqU9~\Y >vm&mq 9 @@ -2200,7 +2200,7 @@ nmkr iDk72Q`3Ӓ/[l jccwee|7t#dפ1'#X; I Σkv0ljڈO#K8Ǩu~wlDae^DFެ$3h7{5lD^T_r!sW6m"=ǯ ?OWדL9%ic e4Q s>±_pUwKݠ݁<;v$(5< KveWdi"[ >׶6bTŎ`0 }2WBuĈȭ:CמN6KkMVNϬ!n[u=gtegN"E &={ȕKT*˒2q(C^q {bN)"zkLU*xeX\ם2;Lpo>)*Z'ޟ: W0O.=^ 3Zn.SpYBC"8X2Qdt)ӽ{x$wlpl[lQὕu?٦;1a*zjQnQfCl[*+=R+x k`xU}ř,I! M_f^o݁ܮtƋF=ڳq{ḥ![D̲Tn<ʆ0DV9{ewjtgŜs@k1=>i*9٨'tO! ۶rgׯ@7%&|&OGvKd*h 54':ÝZhRgnۨs%*0/ԅi8C:af(]MV\7r¦QzG^+?Xu*3LJlIts> -6m7Tklu&]z>j7z}B1y#1#q6w>d7 ⑺ج:تш2z;I[>yUcWL1TG+gR.{;]*vWhp/?>:d=}#1RK]t~&Ժ{L݁N1FtG7 aLeJz1=Y>LU$OVb9o xuȯ(KIL|NjcBkm) fP  +6m7Tklu&]z>j7z}B1y#1#q6w>d7 ⑺ج:تш2z;I[>yUcWL1TG+gR.{;]*vWhp/?>:d=}#1RK]t~&Ժ{L݁N1FtG7 aLeJz1=Y>LU$OVb9o xuȯ(KIL|NjcBkm) fP  {Ei@}3r+g'VL~ߡucۋ~˻b.HRKbPCRINo7"adK"~q9ܤK|.s] =_-pqz[;>2~ݷ3Ti*ڱM oV p+]7D\^~qgG-3mVCT_g87/fĨr6ZӴ*|>jJ))oe+ $XB 68D2#ɣft.@i˻#? K mc] voiqxGԀrP0.v@'eX!ĹaYjJ#4<@-@ @@ -2211,7 +2211,7 @@ p+ cK=v`keo[6N`$dzr/yy[? hPmen> F =;ٻL_ZKo> ze>|<7u6]}v:_<$ݥv{s˧:zdOz;jvrjwh9׹`l9 񈿋XrgULHcw#7kE]FPjZ? "A:xؔtC3(fZHê&~q[_~ßofu!F ſg(3uQ̝^dJ_E"_d*Ա:I&uq3YC㲎Z>FD%wtӦf\{g/<;e> >dVixxUF<u'@Ĭ*NF_u}^B 6hocJʻ@k#Q#o _`ok@)wk+X_ wxc&Zϖw_N=B%Z0zm:?ñ>.SHx|Ў3|%\rMڞ7z1֯6Sۄ~]-.8 #~$>/8LY۫*r+}Od# ֻK xEImeo`QPafȳ)B*k6Vh 2=͐(,7%.{6OdcP9l-xSe:%s6Sɼא@ B^,qC'aOsx\[JwԶ!K$ ?ۥF4q.Xyd ]XߐU&]8y}]3̀\2ӑ f dnƕb5KIx۸eѺesR4ן'{^ړCXmҼ E7A -ܡVؙ>j3R\dN[%W_nM [O7~Ev̻~) l7_Q~uzn] `N݃kǭ*jg%vV&%RY?SӖ{'+؏6ҤGum-Jg#oqg ;;"yZF<=U35m79F,QO=~}npDb\kAN7~pFٍQ3Ml,بgÈڐԼt㮾Oe8 3VݴM,Y]wi~ $ň)4:kR K}vOyj3R\dN[%W_nM [O7~Ev̻~) l7_Q~uzn] `N݃kǭ*jg%vV&%RY?SӖ{'+؏6ҤGum-Jg#oqg ;;"yZF<=U35m79F,QO=~}npDb\kAN7~pFٍQ3Ml,بgÈڐԼt㮾Oe8 3VݴM,Y]wi~ $ň)4:kR K}vOyUN("{(   @@ -2357,7 +2357,7 @@ o+ ţ3;ѵnT%amͬFi@^n= ,. wC}v,ܓ3E5tyCn2dj"J.rdV,2 n\X\qO/{]'zMԡ_) V[]t|7b "(x\r9 ƧMC첕3b3ۖ fAۚTC&vuhO8X5WфѶR5T5?im޻5Tr͒'h]_v>>_~׎0sbf*˚Yd3ȬN *miR̶(k#Iwl|[|F|X}Q>3~Rrt8KXCWs_3z+.&A\Y1xf0wFTRQM+ɳivI~O͈[w&'⁁5p >-x ?x@]ĉͩE-&L3-i5l.9MW+i"|o)pf$ћnB.tr5\:86l|X1\,CqjQˣV}G\-z<߭ rvUaabjj*ћbl Sc}/mM aJg][Wm9A2rQ ryvn+KH3*jL{2tceK7\9K -/8Kw(PmfXoݭvSRp bUD:J03kh&3]MKg31eT0iq\;w 8"w~ "s22+)u 4pVNt@sLᆏ[Mn= 'ٛB5O!Z;Vh1.o%]T 0ځeּ~s:fLۉOFrR>stream +/8Kw(PmfXoݭvSRp bUD:J03kh&3]MKg31eT0iq\;w 8"w~ "s22+)u 4pVNt@sLᆏ[Mn= 'ٛB5O!Z;Vh1.o%]T 0ځeּ~s:fLۉOFrR>stream j_gFA?s--<%J1V qDrͮ/LOY{\oa}3ނCrPi{  n2 Be@vJvn Hlz,{+7? uƨ{Ea+V52c)pNrz}u [(uNyV\.PnG v@'`@]dJ${x5tO_G PzOuǀZ+E@m>&a-5$kb)]쵰!/|luhDW-eO…@^;j;`[v$T9u*/*f^i'8(rp<ŧ;.!]? 0,@^\Nj \'%/ Yy .OGk1U{.8s_*ZSn`.sַzTxR\B:w0c+"oI;9 T < ?0S@e ![<l W~DRnVc&"wetv{n 1ajRO TQ5 @@ -2371,7 +2371,7 @@ A ɋPuz.ZSZ㥦@vi?>Zq>N{yA?N+ȭSgN>\!Ѓ8sLHkw%WHB,p3;z_1]W2oRMeA>ϔ;4`aihd1^tD;b1zX:{v˜Y\e̡qgV"IqP1 9`5d FiΕ>^_ccs_hEMX$srDDG,ػE{\.w2I2Az) - kl&Ed=h? h?ȲҧL@O˖ 4}3O?-D/A qLSG~)_a`ulXMgԩ?J 6)s;ERS!uڌ' kP8- nJO/vW[G<'\nb_o*0h*(X)`rgc:S$˯kg)T8EBxqrkR%}; 0|\`@Z%bɕ*_+p/oeo[{c&iua-}5 u;4q΀+8 .mTviAA#gfp_0DdS(6 `#]_^19o=ńw(d^?d/A`7X.^Z~ g wF#CI'P+ u/zsW-I^zTr/V=w@,$1@b<8$ 2)"tY*y'^Z{:Jh9gU-k ELdaJ e|U%~-_pʸv[uJye@_}*4@Gu""zUK]a[ıitura4WMokE'/Omm46Z#rݙ~^@' {}z4P_|7[hG<¤AS݆F7lE-quCx?7ዯuծy^r+h|C7- j._Z5QyQkoQd Ms-'"3FImrfbW<*G%ZiFKw܊&&j1nGv^aYZ{ ;GX1-QD}-1h|9P*^IԈP])_1- .zv=/G]Жu3jF@Q}CaC׈洢)0 p*bv k })r9lHD|Z;37:J9p߉hQbwh1{G0d>E\A#mGVD|(<ᙳb#&WѨ3v*GS0Ȗf!qUM"xަ,*s>}Kh\2LRbɿ -'&+:SC>WqɒR#.GE_HO |3s(4;{\mhog endstream endobj 302 0 obj <>stream +'&+:SC>WqɒR#.GE_HO |3s(4;{\mhog endstream endobj 302 0 obj <>stream _pTî'ӘYi%f KmywC*Ge$(,(ѫ1mD'I'y$BTeVڑEX7my~UQ#${<;BOp=+~\ HO9чb xJlӈK[ڇR8T >*RHD"q e$4Fև3)H<7`C˜!o Ap^Mi{Tqڙ*SusRamD8JnI=⯳jg%eZF"Dکb5PLJ*«=Q3 ?F')x*~iHhs)   8$DD\L`cSҌЫaG.Zt:R᳣8)n- ,,RlfGޒоB7<阃՝A?G‘nZ ٯJiSy_iYƫ*K6ѩ(&@Cec=6sa5 ZsB:\q Uh;ȱ8>|sdC%)V%K$ؚ=j}P`,X!· Br^ yD3e=(w. Fs!i£a W& 7<(> >57}rh8U8bDllBC= @@ -2716,7 +2716,7 @@ i U}̴pbі'U'CᬑU]ҙ38("w {MI,'w@BB;R4LUаş(05 (ˏ&7{RJ%X/dY/e0_f.ӻʢ=eqG8hjS&m3}C\} RC:OvG$IWqt(Ac#;acWS* ` :e7\K8 w.)v"sO kY@P2`Gd=j`Ư77$\mv5Xdc {0{O,"m‡ KAiu.`Ư77$\mv5Xdc {0{O,"m‡ KAiu."U-!d'솹 =s`UMAj lgK{GG'ƴ9S(j*CHgb}Ȧ,bVDv+8=Z1؇kitmZ?.GL^% 䃐BYI!$+ 405LqA |-CjLZ65yRcGZXA ]wӁ{J4A=ngPg|TbN)?UK>չ>j~Ѫ4/vلM"?&6 k6MyM޷&mYd߽llb7B;t%7{ E(-qow:76xȅU(UJ 1lGtAz=G'HU6L*bc ,yrbb#%*ĦI1 7L\ â q^/ dNYU @@ -2788,7 +2788,7 @@ h. vY?l/< bVN(|;ۨTjO>޾r,{X\zXs6*z:M8opg"NX"~d:5|}3}u3qQ魟5 '}; =jA\6566>XGuEw(S/B"Ġul-OAe.+d9Yɵ-ʃT-η=9,zYo}Hũ͎ގieh#3:I\!dh G:q[*C!oOثssYŵПea \sq'?z'uj`Ge(Bp˿dyRH%\B&sR;LZT|K޷r4PD=k| }t:$4nZ PuId,f3f _ 8<,Ϳw|My@]}2;D\ΐlh "SlLFod gi)n7MUZzIfc?8۶VJ@F[~"S 8Ȣ"C-H_"uE O8sͿm>&q_̉$zl/Ē0bis8 ti_@Q=>=o\<x:6Cãb(LvA 6)ms2s&KP2#{`WnkwtvxmsP<[eyfa@fK4 ŤI\A볳v{o(/Bj2kNrWzg*;" 6Sh27Vn C?}4F;Z9uOw&S}RRHfȻid::mZ~|sfvu$r!5bߌv(*Az{M{>K _H$7^ɤ➄G+X9feUOgT48v~ّ]!ۃs~5 W=Q\OX R`ѠQ%n6K:z64zf(Gt4ȴnAM_@&`j-}c0*a@R%Qq풽D(͡V{כozzPJVpTg9wxȤ5|cRbx>z^Ja!X1idkTmTXo&ļ&qL| !FBrj=H댮~:8 A:fqЕ\lC݋F˕NA"YGdHuZN=@ :@ܒ[)lynXw{o̓S\XXq?ak[mKĞ݃?#8Se )̫FVus'w!g)BlXm>9FJuSҮHX+ʂg"<r>ٍfbuw痁d!Xm]CdW]2Q#`Q!*@i S'aOY%׭7W[V7<`'F(lx};1m D&؋Stנ K"iƟfg#:;+zJ`ʛr"jMFu<%UZ)z +wuJGHGm<3٨#rΪ$AĂ$ɀЭ8>xȤ5|cRbx>z^Ja!X1idkTmTXo&ļ&qL| !FBrj=H댮~:8 A:fqЕ\lC݋F˕NA"YGdHuZN=@ :@ܒ[)lynXw{o̓S\XXq?ak[mKĞ݃?#8Se )̫FVus'w!g)BlXm>9FJuSҮHX+ʂg"<r>ٍfbuw痁d!Xm]CdW]2Q#`Q!*@i S'aOY%׭7W[V7<`'F(lx};1m D&؋Stנ K"iƟfg#:;+zJ`ʛr"jMFu<%UZ)z `tluOFCj 6i]U%s,nhyC6v]@(\pgoLbouHxs+o;Vjtvtl+}PaKz7yb7 pb׃js>?hk& Ons%x$UV^hԎFg*̪\?4*rʿU9j[7K2XwG6&S[T>߳nr>%2Uz Ă5eg']9j]⦩a,`v&& qok$h>eDl/ U*GJ=C8?=VYXc5TİF0,vLe81Wa]R7U}mw ųӄtyyFu˕ILw&T[3JqQ;B_y7LႨkk+F2RFgfsuEFpA/1sX -n,;OY (;;Cq)1aR@]]_֮i&~aI^|YbqyUB!)lc43RY;u~@`0]qr ˥>k;ϫ@ϊEϫJuX2/)WK56ʒmX\+ק9 `|>͍3cerg.+xh9 > uN"-CekpYXuYk5w+}װe%7i)ɇ۠=  Ϗ69?%]W2SQonL2TwV[Hxxyކɫp=CN=Rj? }^8efW&ZuDZE?&=Jb…7 'eSqL Dn<+\Jp@ +n,;OY (;;Cq)1aR@]]_֮i&~aI^|YbqyUB!)lc43RY;u~@`0]qr ˥>k;ϫ@ϊEϫJuX2/)WK56ʒmX\+ק9 `|>͍3cerg.+xh9 > uN"-CekpYXuYk5w+}װe%7i)ɇ۠=  Ϗ69?%]W2SQonL2TwV[Hxxyކɫp=CN=Rj? }^8efW&ZuDZE?&=Jb…7 'eSqL Dn<+\Jp@ hjky77zUɜH¡R ,kGҹ==H°TVl Q DU4ĹyЌ"zV?U1Y%bA^, {>"4 кe<ftdƈnj1'V /]Qw #+(p+[{>^+'i319M&,VcH[@ !*y]G:#g(_9ᔎ%cc+MQ8H{0H ~[,]0_mק_uiL T@HPFm/^@q(d] p\t/"2s 0[C.hY2h!wknfNޮ`dP-{9p(ZIEjQH7L3! Q/% -9Ɂ!Q\5"9GĄS/e B?bY@wӂlrU]ӐC%N2gǖ}b\MDWW-.RdmEʝ{ 5w7El`AB[d -'cEs4=%NxgfC#AX1b}vt}FAԵ#虑.VF\HA CPkYFGf@<#t~X::#l%Vh].؊*~uT(d-s^iwkIcߴo>M_߿o9O}__oO_oӗ_藷o~|?@z~_+2 endstream endobj 303 0 obj <>stream +9Ɂ!Q\5"9GĄS/e B?bY@wӂlrU]ӐC%N2gǖ}b\MDWW-.RdmEʝ{ 5w7El`AB[d -'cEs4=%NxgfC#AX1b}vt}FAԵ#虑.VF\HA CPkYFGf@<#t~X::#l%Vh].؊*~uT(d-s^iwkIcߴo>M_߿o9O}__oO_oӗ_藷o~|?@z~_+2 endstream endobj 303 0 obj <>stream %AI12_CompressedDataxmsq. ? twU:sx+i&4#ZǍ pp4<ϓYU;4"KuUV|ͫwzUwxbų/on>ǩ_nNqg1nE %$pIzXS>|jCbklʸ8ɷWa좥p̶Ӷ_qB-}Ѐ[nJk+ T-w Z`/s$ -bj4bJҞJiշ5L Z˽W:X3 `}d.r;fjx]߄TVu)2B[.S(ﺒgMGlGK*R)X򷰴z{/<NS%9Ɣ(UXѺȤW@cͻw5$=U|˘0Ok,:g$z>stream +bj4bJҞJiշ5L Z˽W:X3 `}d.r;fjx]߄TVu)2B[.S(ﺒgMGlGK*R)X򷰴z{/<NS%9Ɣ(UXѺȤW@cͻw5$=U|˘0Ok,:g$z>stream luh [X)3INvþXi)ިʢ%0,4śN.tMâZ(<.ݛXXܡM:11H֮"RWb>+qfISө3l%nniĽmN/)b*&Ta^jkg+ 8ms*)<}ݗ^yeN͹ZzXŜVՅ8Z[UG37N>E'>^Bo)eRí1:hIe^Ĭ\7 ,KkOӾ̇-id<!N<[l:;kz$H\u*OqZ2 O޽e"mE8KeS *da\ej7tVÜ(j)ցk|YAum)%VRՒo38@^aݑK!8jP2:Z\#[t)#gt|B08RW8Cؐ>=e^J9V2SO7*4Ӫ~,[S7V6edaͩ5SӸ"ik ߥ8ʼ3^&ZT֦.DSD8P"2eR; գKB Ws,$8ӲGbK >&JY|qqTy_;; dL?|dz\ lmF܍A/cLʢtI&3y:OݔCg5OYLMvT^ vic53*S!<j?>>޹7cǴmv"F+W' @@ -3244,7 +3244,7 @@ W Iw;y|^Lz-;Ih6U,ʄBaչS տ}4JMۃoN"AW˸~6L.:TDǴO>XfASܷ51fMxfͰR۬)PTkvvPp NMW*,O*=q{p[:WlD*O58ַkҒXx -KqP +KqP 暥T+?eG>q7)s1Ӓ$xX;Ԟ}̓8Eȵ6/%>vRa&m=3!GERD/3# duɴ%jZd>qje\|tU_`x}]֧^PIuYUmnoNq/jM=4p8se ]P=ԓ-hv/) u"m40Zwr5êk$=5~`žcy٨@NZMMPx]n/敂A@I?ʽUr\פ.ENvfیC:^) }5b ؞r *sn9EYz},nwmbNe[]SaNJ^3[KHr/}GIpc7 ȫءċ"K]."?6Uypȍ;|=g.eUp^2%ʎ8Ԓ:r6ol蚩cg#2W#J.)lsD{NMOERJsF_ bBOz%rMT'h4;$Gxg*2.ztӭeKxnly3ַ!47:y!.C"@-}m5]hf(h*m2 n,:S/}EhZDiu1o;w[[;ME2UT\dt3ͺ0l-JܮPkŦ ȡbP>&ߺ oYvDf`<'N7֗tP)1t)̘r@迉UȅT蘡E^q:tC7âJ7(dXMfȊw>.R"b' :)myZMNDq9p+1̐NJ۩=.<:SQhS><[-SnW$εxٱ]Dغ[%5KRi|}[ zxFXPO4ɪj +DcJuwێpIwRGxg*2.ztӭeKxnly3ַ!47:y!.C"@-}m5]hf(h*m2 n,:S/}EhZDiu1o;w[[;ME2UT\dt3ͺ0l-JܮPkŦ ȡbP>&ߺ oYvDf`<'N7֗tP)1t)̘r@迉UȅT蘡E^q:tC7âJ7(dXMfȊw>.R"b' :)myZMNDq9p+1̐NJ۩=.<:SQhS><[-SnW$εxٱ]Dغ[%5KRi|}[ zxFXPO4ɪj tݻzWf]뚸}AS IVF^,)^hkN|2F̧ Sǚ=b@1Ԩh@dh {\9uVUbG!F}o~2!b)'r*{bYb VQqL6#[+I?8ŲT܌ͣs, gR(2i)324CCUx.=[N_N% CU\%fd\< X>v֟Ysvd=vԾPIR lU}k?xvPӷ͕33+m}Y+˺q\hG\EmED<;>ح4;^fG(JrI;H!M޶5{H3fT)cR84 עP<;-tcUqP kY M챸r3S֕W*lTٙzZ'[mѣB]ѧ @@ -3389,7 +3389,7 @@ n < 'KEn~~Xυμɒ*8]Hْ3[ǥ($K,BdQ]z7'N~ۻ_>\Dd?;u/<_7g{}_]<\ݞ}:Ӻ__~zx⛫?oƿ%su?/t{uQ_qo6WyÐLl>ߟ󊾹7[/5}//>{{ﳻooч7[rΓ/_wߜ]#k3O[?::n}t |x{ۋmB^r7;O*bn.m\{[Ow{xWx{#x\>ǫpΓWn_y{=Ƿ@{7s Sd{vS~s_xvu xW_ݟaU򼺻wǘm/>>T |&*`<rP? 3׿z/)[:A}tttV/:`U>o_\hGLW06l_=|ssxάΧ?eW) <%y_"L~syKD^|$?<GO+gX퀌2B^l|;:c=|{>/0n3xyɼ"w]mkb|Ԗu#bhڏ_\tiO!sv͍-h;`3[_CwV;j{g_8+δU\r.>VC>^jk,"v&bO/.//vH_|Eak7ч.rGcG endstream endobj 305 0 obj <>stream +[?z{c]s'jw_񛱿w\kH.yTřr\oomԧx/.wY'ˋ߽} (S[_]Wwoo_ŏun/?`Tum7鿶ޕe-\N;,_G(nv108/ƞt;|{vGU>\hGLW06l_=|ssxάΧ?eW) <%y_"L~syKD^|$?<GO+gX퀌2B^l|;:c=|{>/0n3xyɼ"w]mkb|Ԗu#bhڏ_\tiO!sv͍-h;`3[_CwV;j{g_8+δU\r.>VC>^jk,"v&bO/.//vH_|Eak7ч.rGcG endstream endobj 305 0 obj <>stream _7O9CmN];;^tۮbL(;l7LlZ{ Bo ϑplOR6 zE?x.띂%x#9x{qdUW|mq^WWﰸGH<:t7wۇ?O^x=[OQxD2xD%>}Tz==ɶ^WٷOD~^,=~}w=I39فH9*]fwf_ѾDa3m=ۿ}A9rg.^\+޴ρ3[K8r=b/^\+:g3;O pTgv ϝW/^p8]DQJC>QqU=,~y|9YWK/,u{sXKVR@߶oL߶^ہ} 8o/]L@ԍ ہKnSї9_z^y hK/֋?\%@wi@@Yv"O~y|[> 7w-ٯ4W/}%4w(1y#ja͝7ߡζ+ۧ;[r}/㶯rs/Bc]I]I񏞏QԖ <Qv^|Z-Cwh/'0}7i;]gN/n{S߽}p G" lG6"~grx&~Ht!c[/%OlOᛛˇYA?'QV?:ڽ C:d!{,ϻ\<ui/|?//7';!=ok|9|Obwo_}s_{O\^_:CnkO/YlM]uݐt&Ϝxi\kew0LpʶBw|}_^~RO*'_]_>|rSW$bzy]-kS#} ޞh֟ϯ}ؙEM9SRnp[ƞ2|wyQHxrHitsj:wU[U/9cs0̖v0,`9sƜ-9L7bQm:ceƜƘ1KKzF/TO_K.Ҋ?psEg[ ♗~!ϼw]9ξpCeUjc=Ty|9V?O_|svߡX`:^K@dہ~NWPllV>܉_|͸|7*;'#|`e~P^bm;Oofۯ]bOPbr֨x1]V#k `Og奘?_Q`xNt`8?SwZ{/ί{w}ۗx]?^г-sw0!zn]7q^^l8,z}ppxjSg<5&/_ѡҡҡҡF{//?Vӭ;r=m=o93ޗjJ?%oz{])u`&ncOLv0þvX! @@ -3642,8 +3642,8 @@ Z kܰ137&ȼ1T;4)^Ø1,e8.VZ}Wk[>'}="z|E ҰzT.c: ai1vx$lPeԿD5vCowjI#F+dpo?駨vK}9k7їAD Vaf-.JrBT\Q-S? =a==X* c5v `G+ 4${ HnҫǶȵ? d*#Lj;ҨZ їr]'/ȼ ljPtf^ⱿАwC.P_]fOH녲1l']9yKY;}(٭G`f- GiB+}nnkxhC\#/׋ Ł Ny -#K#.M]R(u|׮@|#cK7AZ5['2W]|@:8ִhΝċj%:l ?[sU[szvTHi endstream endobj 306 0 obj <>stream -ݕGwF咲6py}Ro]ޑu,BxZ JV<ƚt:*NfX匯`a%c<ݯa>|JEf#1tkH^-'T +#K#.M]R(u|׮@|#cK7AZ5['2W]|@:8ִhΝċj%:l ?[sU[szvTHi endstream endobj 306 0 obj <>stream +ݕGwF咲6py}Ro]ޑu,BxZ JV<ƚt:*NfX匯`a%c<ݯa>|JEf#1tkH^-'T jfj1 y W*;i3槼^kUJNEڻM&`bCK8+ t&7 sny [׊sڢuzLR,+kTn<:]R 1d3Z%eigL5#<҉+ز0#Px͔Uj @@ -3654,7 +3654,7 @@ W b3qN@?߰[9ǝ&!CnU r i3G;{wr+Wj+4Ea3ۑnE<*l47"^QuO%sH|gتKnOlGQ^3`L`)|K'`UiNqSGH\Wp,~pa}Avɢ1_pȠlMߞw1iUNZx8G@~nH\4A?~|r6_Y*h &ɏ{Se~EaXF+ϥ` Ly q)_=)~ @Kv}į? MŌ*b;(Ct/զ5rǘM5;-+ 8ʨ@+/ b99&wv6ܞm})+uQ7e_e PFnCcӀo"7 bAd\qjyZqBhm)]csp%y &jutqjk UNbk -Y()쬏N7 ;?$D x t&;-^}_^>I..f?|$B>&6 \VUHiQԒ{Pc93:Q$L& zUՇu8s**6uP ďn L +Y()쬏N7 ;?$D x t&;-^}_^>I..f?|$B>&6 \VUHiQԒ{Pc93:Q$L& zUՇu8s**6uP ďn L v 䏦%?vY?ox M X1Sbr.&io"l@$>Ap/|R fE[ۋlze`ԱquoEtRP i0롺оԳ3ˠXѻǫLakP+=GN`%Ҽa e՞/.c sP7h a<=;5^ΠpQw)N"p59nkkPԲ W~(C[%Ey`*Ptn4IyZ c+ʃF3Sn7& -m.ԝ?z;VAr*C)壘QU>Z\~zs0F|eueޞn6i%@yİ";gA\/:7Ax+O` -Y!DB`.S '4 4KϘ= ̎ޝx0W¦Ëm9k{xi 2 z8DbX5/Q7%=?1j2ɳYkjڕ ![N |nYw_*zɛ@ ܏2 ?wgS6PmњnR<7ր]v ;zm(SF =7.:ELh蜲Zىu(4T سy5k1owIt95ƺ4Gu9O_.Όe?1V^9EzƾqMc#3 Ά f&=R.Ce3gk\Q!,w>d 'T@*BKR޿6_^z $V~Onլ5@jױ\+IzlPޕtZI֦.ʏifmI4oN'Z_K/J8KVz*5&<ygjFza֨f2G:إw bHY}7,ﻩJJz/xkYW5PR"3كϺjb',~Lf=_= ~UM7;NED,OQ˻bd=q!+>5to޳V~$#:^6ʶc4 R>a|n@ლon<3,@mv?@96~,;]'^C2bƾ=~^yƬI]0O.u.7;?2H_X<焐N#Q֟Hr1Ac2Ž3>ТoEco*q]ʇIЧFCηͳ c\bgw`WH2Z=`@< dzPީY9+IEUqگUB /pE jgi}Pܴvיs4hIkP[ uP-opBDANRj@E_sX.XW\%{f]?dPg#ef>/y59616}vy\}^xhԧ|v 䊯"]$i@]#%!C5<#E?yBTe_S{0H-cWӎoE@9km݃H[Nu /q3Rmڍ:P5 wRȟ(YdUu~ ~xzP,D9Ұ`?yt«õ#҉Pp]IUseu (P Z9a m,e @@ -3828,7 +3828,7 @@ i~ I0 ZUx'"x]螧Jsy>6QC0T9:/rҡ$yiOLǟDovĢkh6i^u) VYߒu3kAK0y'& !m'Y`*RQ"BFߤڰ,b!41<>ӳKx_-81bo/c}=)8. "ɬK4ZJBƳ򖥵׍K[qܲfx; bM2`@.WTOr@7 WK\+\1Sb̀FIa49=l,x^#\ܯ5Y I?G q0N*W δZ#%w5hAk1r -H,fe ؂O=Sc0ㆽf6( o~ LD5{a-Prಇ endstream endobj 307 0 obj <>stream +H,fe ؂O=Sc0ㆽf6( o~ LD5{a-Prಇ endstream endobj 307 0 obj <>stream fss'M㸴N)'j;3ZUP7Z%mGUxM!'! M#'l~r.f eOh[ؿs {gq^17s Mߢ41* ZéȔu ۘgY!-i B@!O,&?_5}^Rؗe.`6eTOZxf)4k 6'i%gGfeP^R]'>qMxmBIK'ѳ,Y j`uCh-GR;[iAzDžWM1MbPxu.mubw Lk7錞umc'9#*]RS(w6uᯢ/u^([p:y'%?mםaS["~a04Z # a`R/;5SԹ>kg(1cD 0B_>Pu" xv괳M|ip:cMGf;KmNALEEu ƖF׼^eZfl&R]JX(Fʻ3n"]_V5o6N8uəj~2W"Q aH"r~fB/& ΥJПʃM^aewQwDaV 2s)'KҖ'hMm9hcĕ8H~[FgNbמ52m*"21|/d @@ -3863,13 +3863,13 @@ R B7r|<SI,kt6.'?o M{ygcN _'xaPC%| lzpIS q#2XĔH*4 k7&( Õb܋\p~"#_K! " LϘ%a6W1wz%򳙍)NFX ?9 ;X6u]c7xyM2nǃ[{oܠ&5êB|+Ue6~!4@b*N^Divk3+ ӟG?X,>JVQ:hWeO霏v8DY>Q%m .hP>10f*$H jO"Zo&jU۰a 5<܌Fӥvxi>^&wsƴnʺx'~- T VNPoAQiC -TvwJ'GF|"bjȷ '8CG\k{Q23mD߳;s̙ekӵav~au&?E|i; (,;CXWPtlWyz UbߡݷsL7Ͼ5->Ԟ;UߵoM ners߀'- \h3.~O7|ߕA\; O|¤;N{~w딏Z;e۹'lǩVi vuW-7r xU5Y #aZt8̞FG-ryY=,]u +TvwJ'GF|"bjȷ '8CG\k{Q23mD߳;s̙ekӵav~au&?E|i; (,;CXWPtlWyz UbߡݷsL7Ͼ5->Ԟ;UߵoM ners߀'- \h3.~O7|ߕA\; O|¤;N{~w딏Z;e۹'lǩVi vuW-7r xU5Y #aZt8̞FG-ryY=,]u aW_y~&Ք(V$nq>#dz, 7g}{e~MԞO X+ՌN뢖--砙 -Zˬa IR lC_1 w/ 1#z$o/f޹W㳽wVq脫93ϛy[$ST(_MV#isG'?hQ[r(o{:$I(ήN=4a=~ڟʴ6QgqcM̭vt{^\uu4Wl)4Ә3dkvf E+gv|%ynqNzGa%aDɢԾ$O,]Hchi SYM^Z{q ϤtU[C% +IyA=f{;$(&Qev뎳f={Ph[ݖUo_խLpLV?tP:;Ti0. 1?x(p/!(zң[4q[lftE^eO呶Rn3ϛy[$ST(_MV#isG'?hQ[r(o{:$I(ήN=4a=~ڟʴ6QgqcM̭vt{^\uu4Wl)4Ә3dkvf E+gv|%ynqNzGa%aDɢԾ$O,]Hchi SYM^Z{q ϤtU[C% 9I5 mM{#uj]:bytIس6c]?w@Ѹ AWq:DNv~fz9팆m LYLqYkcUiƜS<+RsW*h7wS?yyL‚:wB} .FѠwOYhvu{z~+fYF [Z) IRS_?Ұ#;씣ɤm6l;Y?v[i~'wEo|LzYa.9lkn= $6cblT&?sGtHvKD*=BR?_Yh]v c9m*k`BhIe lH٦?(z^҅Az!usky/ӡ<:w7֝'d'T\+ )cN;tOJmh-Gi?H |V, uj C$v̮6 é쩱 @@ -3887,7 +3887,7 @@ b `(E``̠څ 31qàw$uui6^Cc̽0"RrwqQk=xMُ{( lAM5uDx}82@WY!rt ?K3Y:(|aJyS ')dKGX?C&cinZ>ҵF=@>b`<ǽEsZ`n՟$T\xdm9:dA`-ߧah6D?uy?̱SNǃ_(>@`z.BQZB9D}}ָxċyj>5$&  &c\K<^oKΌȏa/@kGw7ϣ6k*>t>K08Je66p=nQ(x K:skP. dߪ퓰u t~80vkJ {`kZ4ƚeLEvח3sж[K.gޗ޵kqQ3@.:Sg?򯱵yQ};k-烿DzEa(C]meMS]E2wwmMj$Fu<鋽SW_3pk]gWoAKt7~O!agށ"3 Dȹ' #{89ZXT""6CiU;%#g0b˥Tםpɣ75尓 KlCxvA߳8>#kbWէK˸Dkhn^}j#V^^pF 4_*gl;-V4.^NZTe~#pDO&IP CY xzdZk@s->Rio[ei<< g/mܙR,f4V}YAa!B9m%vܡw˃ʎo+}eln@FfI7ÊaeoЦwr,Tup -n7-_PN&[Us5M5-ZúGuv뱜kw|yHE5hﲍ.yL*RP(Rbk6'@ӑe ኘ'Z#b#q#׾_]6>> z\rZ/(|=k{8tpkcM@aݴ#DD\|bjtIjqKyiN^bTzICySa8<RjXГML(MgSA~b[ w׌`a ʹt6 FX`!z;3tb-V7t~Bn٘@G 9vq@Zp[`ѧ]rl7է0>stream +{}=nld`ܺ9iR3u[Gm1[̞Pl endstream endobj 308 0 obj <>stream $lؤAmTAm'5 /a ^gV_>!ȽWČ:'uʈteϏVM*׏)C&M87IgWmg[d=zk@*sz*jie)v\Rc;1YYeqN~z3>vGkrڽL]l#hmXӸʯY}jp֪ׄ˫zrj#RzvVگSRϵ|hњted3{\e.YrX` n K]۷-S+xJ{1K|ׄ@W:ao ibZ~XZ^2Yƚ',%R2ƽD\D"02lG7ȊZ,5:x@?e_+Ų`|k lu?K)'ֱI{Uk B hWg1wa2"G*~YxCo᯵l5>3b1fj_=*)#*R@kZ JK]*qM"222Ȭ5Pѭpw[6*w & / >Syu @@ -4140,7 +4140,7 @@ h cFL˪U~W1vWS:T:e@V~A mYifO}.2ͩ+=> :h2'q᏷"%j> w]25٢ 2-ju3ֺ*1]7kq }:c.-^V?YC#A;(u>QeE!ez`6lvΙ)ޖuj {;Q] JRB߳nД0ޛNY?eɗඓ[[Gq6IT6;{vhC즇Wp䉺ڼ5t#U5_ClJЮDACnsXoqUzxϙ Ǖ>k`,MC'-A9-NbWoOõ}8iK8N7!t,n'Nl] 1k#8>PKGS"']-İj^O{/}r˹qN8TIJᐷKM'+{1}17֠{j$zZU IpqpsmrrASyx-Z.U'|8׾ ~:.S{Q}5ZCi^ 3;C5MZxԤe]!E"}1Z4VݢyHPw7?TW83*XK.عxҽ:kq;f(D[ī'fGsK2g,.=ld[H^w}IGHG^FG\K! _$CT: %7kNWۙܤ8KMg\mDžS/ 5x[Ζ-vdaG>AAYGRS2DC7y}дJ( -J1~e)]J308h;g燫"6?rڴ[jBd*W[̋4D(o}'KG6_sL TWkWvZZUGS8!]\ĔڹYGjd'&/VIUFIGR^ W?Sow벼w̞jv +J1~e)]J308h;g燫"6?rڴ[jBd*W[̋4D(o}'KG6_sL TWkWvZZUGS8!]\ĔڹYGjd'&/VIUFIGR^ W?Sow벼w̞jv @ +ni 4Ұu9|g$œ|L_n R[}Ib4ӸUx K1хi m=Mv8. 2#!$YlN(S9i7ߊ_na }whnNPio)sװYW+bn6dp+]n͈.›i. 2zIۻu͌l (} ;,^tmP |$̠Px W/iUK*77PҟHH,>z,jn!^"E(̇X4n?Pw2Ûjp+#\6arKKPW[{])S4h_WOOվ (7HJ$cGύ*5%Jrkg^q\uОtlfmdϕlΡp-ággd102h3tWu- SCI74\.hFV˃'BV:ȑJKՊj4lQ\W0+;}DZ\) z @@ -4282,7 +4282,7 @@ M ÆPEjYFPHbi2)QԕS ǚWOIIڄcS>B&z-#{kvWwǐؑ*?4+0Oj2nxD놰W%C}-v,j] eVᕹIcgws1' 2;r s0gfOpo~) 2xhyܐH|VmZsMxSr)3|y_^yi B ^=Od(|!|Sca7e(.a뿵g?nҡb}ێ/*+Z2Z}ʪ=O2eƤ5GUy/?6e8 Qg(R ) lMΘi \xۓC[WUhX՛j%gKy쯷CWBD᏶EUY ѾHzk_bgжsAQ5soQHᲳ 䩾(5Y=ja,gDǿn;zOG&z&r !duTg8Lޢɦv 򹦝Z3.iYDh\HEw;gRKL<L崅QSU9T9Ktׇ유@nMz52MxG'ܤzEkhNfBáh73ҵ.vƇinkw*6ZqgbO~~mv`<;"~GEUZ}BxjmbR;o{7GpjCSf^wG#6N+ѷKӼ&{%ϒ.lx8ĀWQE\H'9AVhշc燴9~[E0~u#iͻ4(*vgjm GK(@Mi5Yj1^Y>^!k{s` -9k]:cfDvzuS߹ŝl]OZ6fkT S(*)/Jy(>ʏ < tYUOf'r1ưcgv[ւ&SܓW"~-7i37(-U%4|w&]epFhfi㣊DuHb{eYڶipd}\7qSލ.JϷE:rS)p1^ora(SŸ#Ơ#K_#LDĐ^"0F'SnFc][z;QyXNG1.nw3+ endstream endobj 309 0 obj <>stream +9k]:cfDvzuS߹ŝl]OZ6fkT S(*)/Jy(>ʏ < tYUOf'r1ưcgv[ւ&SܓW"~-7i37(-U%4|w&]epFhfi㣊DuHb{eYڶipd}\7qSލ.JϷE:rS)p1^ora(SŸ#Ơ#K_#LDĐ^"0F'SnFc][z;QyXNG1.nw3+ endstream endobj 309 0 obj <>stream P]zJ-Fr {&C 3(cWDĝ0u4\&kSj g_ȊQeoJg??Na~f\dXk/~jˠU˴u>''=,qewpyˮ:Tb0#s1 gI;cZ_3%zM.=v`@~ γ (=ֶv4L iAq5ʏwXy &HjjBj|~-pcrxgJ<:jc\{(7QK{#zyԚICky&Gs@~}_%>jh}?.υhGYlJԚOj}1?j286|pr+zO;5?N!?HؗK^;IÃ@GE~h%ug:9~Ͷ%>9(2f8Wh> LJ}g|W ޒb]=Q_Hw_|phX,O{[ϫ bNqy/,glB7H]?z4=-6n:hu跩((7_cPn(((qRT|֚"lfJXܛ``!YDx2&@BFh\u]>F>ui=ZI8~ӄWTp@ E _?Jkƭo'(SPs\Fk̨'y"ITL5{]:٬]~Cb2 ^8:m|jz>XWmtZӊ(xxc) $WBƛ(oP6([uPr6{Jd4p@Z}kg&/<ݸ!񝓮l"Q-zk4t5@4_m^2C7z?@\m 7\C=:ed@\'5!+IޥBkes i 郙dY@KY @@ -4320,7 +4320,7 @@ G mS/ab8j#K̨ `=m6궽# X+<^eh2!ZǬJZOVm^G{L؝TW֢wa{&yB7 /  _,.avAlA~^E7zV(ҝ>k͚"v6Bw|K ֓D:![)'皭e MJw&?B~A΃/}!Q4ά۹=^_OB Sڅ`եyQ &gVT=4j+jP@:H9b +D2UWiσlY>/}!Q4ά۹=^_OB Sڅ`եyQ &gVT=4j+jP@:H9b HUfC 1O̭$7:֠q^h/|R$Z  gIT)[޵rM,\|}ёP(50AQ,n@a:# G?g(2uk{X с^7~Voo*Dj&"8{Lk!WqA|yndzaM(xZrO_ @@ -4333,7 +4333,7 @@ k du"&z0!B{խLGD3e}AV+FsӬظKWi@*r{0kEٍb+Z)wŤ8Z{ΤM:CKZZzᏼCez j:?KFcXrARkE,("h;͹~/ e5]̓+d?W@ϰ>ȩ0Or!d(+uSXB7V{ ròH%)Yv! $?]l3oW>L^ET|-A?*7Di\S^(í`y@rsO{璾$ƭA41"pwv>>-PN1Y3O&4QX>@ֻyUk@K(Sz~р@RMNLðd_Vi1Vvoks8.eNp8\/ܜkci{sGB)sѣ)tz<~-P: dɩI:?BFHjILuNL|sovi5K & Ԫ//R_(wڤٳ[܆j) S֞/$Z/!Qa m%&U+ C?4ԷXoҗ)VjkW:Azz~?1j EjKm1sԠlR_9(DWq@ k~b6e էz/; FoƾXFƖ 1s[\9' -P#5t9[ d0(tNk̮:ӛөW}w" M;&OUfz  w/hŜB@j,4f[eﶶ$D=6S%L +P#5t9[ d0(tNk̮:ӛөW}w" M;&OUfz  w/hŜB@j,4f[eﶶ$D=6S%L =sxˎzU[lWC'XքyyF!/O搟@s1`69]Ay|7 %wq͎/fG]EoR氖>]s}͘3+}і&Ǧ*N/v5<#UoVn5A9}ܾUƑx{y~Iv+͍QvsXc@=:;+42Okm\sJ&)~\,HŵtPUYSNs WJ w]_~MEbG,[ %3\UozɰشÞ5Oݕv*9=d.74s, Dpkpv[V @e1ҁ^|nsN)yy׼n?lPf&F7g-L6&[u?x$}r+iZ՚}VP^׍@~]}r6c5V~Y@~vu#Pn1*F~#?cnTb =)SzL|\)Xt!P*Vl'SLWX]oҟ̨f <*/s߅px c#`ZnJyu+m3󴩎ަʭޙӚbܖIGNŸjцj`qan74}c&;)VI:_3ŒCq}4T=}tY})C|TΠ-lKJY1 j!7Xj:?f|V(̈́ݻo.awPJkZ0-oH z z _ۑ Irn3;g SmPԞN9PakhlEL|Wy#ȁ<WJ:l\x.'H[iKMT;? H$Tp[mYLX+ei+'7F&-%VZrWӊ36>-fP]3:zx;ԃ%zjk$?q*8S䠣sY=39oOt.S\D_rY|cj,2.5R/=F3|^u^waL{ϖ7YѧjY;S=Ca_)(QW2VRyp\+\|*d&dHhp:,9IqU3-@62[uZyt<I2u%`K~nh/@^Qd?JWMsMJ5_l &Ô*HO`Sp8i8bƼ{F? 6 arBF^Oj~Y6Ҵ_Nez3=ҫXo8hCTժ @@ -4523,7 +4523,7 @@ _B Fumα6=wZZWsU6ӀwuS#ɶ46a<{ J;$1O/+dk\/{ T.+~yw钸0A:-Z/pBKj5S6{!~1q'Gϓײ׉׳~ ƭ !GV|˙گ_Kn#.ŝS%KF}Ίm`ZEjtZNS] h߈Δk͕N/o~AP$W_ܖ-yT!l1U.>j}:@{u B*"Zw.;H [Z7ߍٹv7NCLc؋gT<7t2;7GUֶ3֝b]K#Yz!_J!J.pgI;'m~1 ʛbWwz̑ZT%74jT/`7zKhcevvY}_ϸ $̞kegc42,5.njSQȇg+J %5m[s ֫4⚓a\f΍m'W-5So]}GP%_/sģZhhT Y9ّadvVբqei*NWh{PrТ|Zߒʢ|8L^4xWt8V\;WfKk%[=tWrIT!K Bh-"PKUaU;%7>nz9?K {hߢUuwzg= rf" -%lqU{^K}&:=t_[_gڐ VLʋ*hn[Z[LZ?mUO5|q-&}iUz\,&1IbP!C逅q^髼*o97je$QrWDr9ɚ&טmO=\϶_\n1b>Ϗ~aڴBms=L2JL&*8=H Fl;>1L]C3;rd28qHNyl)z= NO(L_}nXpvZ3;; N. >ž/iсV]7 :l>S3C V7]|#$g4n[8`FVؖe9$jH!ju"6Sݥp:j/lr9.(yݜv};kf* ϙ113qNfʍ M1p1q2jF'H//KrrT}kOiŦRE:h3 5LG g3 Sz_,M'% j=4VMFCGi.ZYn[cfT5+UT+ɶ|IDR̆;b|>27ĊUN9.:~-GC%3 ݆TN#wFlpD86:q4qTqd!I %sexZىZL4a)'H wЍcv2J#,syfY&#*xj9tzwB ?'6'qʼ JūD:E~4%^ VBП Aq` =u% endstream endobj 310 0 obj <>stream +%lqU{^K}&:=t_[_gڐ VLʋ*hn[Z[LZ?mUO5|q-&}iUz\,&1IbP!C逅q^髼*o97je$QrWDr9ɚ&טmO=\϶_\n1b>Ϗ~aڴBms=L2JL&*8=H Fl;>1L]C3;rd28qHNyl)z= NO(L_}nXpvZ3;; N. >ž/iсV]7 :l>S3C V7]|#$g4n[8`FVؖe9$jH!ju"6Sݥp:j/lr9.(yݜv};kf* ϙ113qNfʍ M1p1q2jF'H//KrrT}kOiŦRE:h3 5LG g3 Sz_,M'% j=4VMFCGi.ZYn[cfT5+UT+ɶ|IDR̆;b|>27ĊUN9.:~-GC%3 ݆TN#wFlpD86:q4qTqd!I %sexZىZL4a)'H wЍcv2J#,syfY&#*xj9tzwB ?'6'qʼ JūD:E~4%^ VBП Aq` =u% endstream endobj 310 0 obj <>stream b3YJ;Px T<{C ^2߻,iAMS+W}PN ^E&?HAWc)_a3&>(7C\ͫ]mKssj\ma6`<5N߸)ЯY/ ;PfX>N䄧-KAvl]b `$c2뤙iaDq<[s+h'PX#/U@%5}2@G/Fy;Z46 +mEŐ K+P9Jw^)8B`+A ;Z:`qe7yjۀĞZe ݚ'Yn0ㄔx +g@e/NH=te|[})'+Ep[j asS\u\v<O3ݥ mxoh=CS>&1KG,pHp?&'_ն9Y5-{uaӀP qA@&on_\,/<[ڡ@wFK C;FpܲOx#7o&|d<I w8E || - -wMxyUG`զsA:~enoh~4P.}/8I2!G: +wMxyUG`զsA:~enoh~4P.}/8I2!G: E-T%*fBf[5c;"l/=L~wn܆:ܶaFBh:i(^ם5"1 uc[$n4VZSd˽Ck}_p҅cN÷6LhkC_pFICZ#Sa$^O:hRBK/4gfeĆ[m|gf[?mDVWoIV&̨k<R1Iez97W. ¥BN_JhUL砇ʧ-ǒzpG ؝됹k?^WqtvBT)*5l7vגz8&b$u_W ;?NE,܆N~ }oʡwΪ4'rh6p\ S8|_NMԾ1sagɿy|+\׺ʓՏwf4K*pt۷M9W']X0f5ʡN1OC64]dE0m D]vAM{NP+huLA&nkIy^;}m8p7 S4$'m`{lֆB}➈ "~àt yYZgʅp[{eE,#0eĖRev뜋j ən/ʓWI[fiEz)-f5\B=P YLjmk{L~SjUE>8gJ閲yZ[ZTeyB\s^9C,_13keìuRnT+q4jaiI @@ -4715,7 +4715,7 @@ K7p|=x 1b> g?M*kf۝X :cz7uɯyn O>+HXGf{uVpALI>!TYp6(d5 q|>#'4tfx V4DMMErH/b-񢗺[nGpEf9Oc̆={,Q|K>1ל ^FQ\3;XQa0ƻMaxbX1.X=6W,Tk{]klM\0P*$ >N"f>C v>OWj> Hũ|ٵZCT/*VOTqٍXjlŢ]xʘb>)d޴K?@oan)5vpr}bIg`E wk4:dt?n!*˂|&QaǸFf/n⒣<3) r!?aTe::=[Ђ}[~ vT U vv7ݣÆI!3j#enY]G+j~׮|˭1íҙy8.23TG6NdI!vbUn%K|B  9b6rwYzwEfJļJd-lfb&36ܴ P{x8)xj;j۹u׭Y5s:.ďZW88?t:zM l#1.ncToLWIWi>$j>RNN=$c}^W)zN^nn֙5jahH|=rbJx|ѺxpHT?)!Rm ^5;R~68Gq`r܉.E (W]oη!-TUNU5*k.ٶ6}Őϑ򯡴?J1"ǙhS챖UfIϩo @},&ZDŽ} -\[&쒚I轳.v**pmHV)Ë[}:da"?ytU +\[&쒚I轳.v**pmHV)Ë[}:da"?ytU &"Nx<|U_C/hКSHعYDgj\M'߀ 0=#c©ea6[m2 kP~UIVzl./9>gL2!vM J얔'ŕjlT{T?3ά 7~te-idbLa<4E*b>b8m7ҷhΗT`]o)-?-}`2A5eLD1 tj;NY'`\h|&NZ SGkE\~-*\zBzFrtH-yiL@ӅND?Lm @@ -4732,7 +4732,7 @@ Y pp |WAA^ E\o@N ڽe/zlDM.犺~$,ٓ&ij^8 ;!a'4 #ף;K|(5q i$ )M1cG&wٰ0o' 9}ƨ?y?IXL8ykYA ^_ߍŲй-D!rY.d"`UGnWj8 o y&H{eU%n -EHTTDA*90p]=[{oU(9ь4@IPthVHNz xF4 c/>=Fwm32Oyv3RG>uz7:g 'nmUg^+S +EHTTDA*90p]=[{oU(9ь4@IPthVHNz xF4 c/>=Fwm32Oyv3RG>uz7:g 'nmUg^+S o]VS:ۗ>>aЇ(.]?)3S0WҜY?un[;x{n7H5>Sl6^ m9y<ݿ٭_PB,P[43. (z /LiףMJ 2Qۖʶ@j}Z|-Ytԗ=uٷ)NǷ"~ I¦߲`._bsvc3l /TN{tj\3qߴr-%'(WuF =sM[Vxo*?Lwrj = ŏ\5W{V-?v@^zO K @@ -4755,24 +4755,24 @@ WU m __<_ἇm Mwql+Ez+I^ mˤ%^cfVtVę6&|~QfGDθ6N!Ztڮ?ž<_;9^je›vo9 g䱏SnѮm5G9Ϫi]55l[ B{F -z:9Y{AމJεuܨ̀h%fֻRXاf;w<٤˱HQO'e.W5R귐eT(|-wj:wz: 飰~DiݥFf<fquL;$#1 endstream endobj 288 0 obj <>stream +z:9Y{AމJεuܨ̀h%fֻRXاf;w<٤˱HQO'e.W5R귐eT(|-wj:wz: 飰~DiݥFf<fquL;$#1 endstream endobj 288 0 obj <>stream HdUK8 _ڦ*HH@*Wu7 ([?#s{ۧmO?z{۾~~lOvymR7u_{l؍z:e+˶H.2 AyW#ý8B<٠ѹ]Τ>[2e?fdcMrɒpWⴖB$4d4xqD+o]큨 K@S]xoonҳ)xV.IJȕl(lw"Č@+OQ#yg!w Dw!dg XA1%q(ĵNҡGY)R\} M3`2*։z>эQ8y3~liT :ȤhOt - Jњ$M C5_zlzQgvC~'v.4~":$Z3~L*LQY7`(0ǣ?A*TQ78Q 9ZJ„\ /k1l_`yoMfsb0H^QG% lⱆqBf1M/ J|Y O\3_u]b'7/6ѱ'+i `dj )17s+}1Gj\LmVoEI<=ajޓ@"oQmO;B"51p<ߞn"LhKcAkooW,?~U?FA,` Mv~?>8JϬ\;Jގ˱/lɛ)xUTu09vxjjBTDpR; '>;AVچ>#Xoo^ qI endstream endobj 287 0 obj <>stream + Jњ$M C5_zlzQgvC~'v.4~":$Z3~L*LQY7`(0ǣ?A*TQ78Q 9ZJ„\ /k1l_`yoMfsb0H^QG% lⱆqBf1M/ J|Y O\3_u]b'7/6ѱ'+i `dj )17s+}1Gj\LmVoEI<=ajޓ@"oQmO;B"51p<ߞn"LhKcAkooW,?~U?FA,` Mv~?>8JϬ\;Jގ˱/lɛ)xUTu09vxjjBTDpR; '>;AVچ>#Xoo^ qI endstream endobj 287 0 obj <>stream HdSKN0 @Sl)Xp H_Ic'0OO]_6XODe= s*ϻzon P'穖V3 mt`" 01hKUZ]hd:$'"EEtL 3ru?>&0wow{Q\iqU%LVSvNFgPz l1Y1,BPD9'n_nծ.w:iXC2$ĴuKRɴ+ dZ͌P,ҞJ!| m? :Vpv|ΐ7 -0Dt86{pW||g+)M endstream endobj 286 0 obj <>stream +0Dt86{pW||g+)M endstream endobj 286 0 obj <>stream HdSˎ0 +f%tE l@:vыCrH]\kY^p\6Ht.\Kh{/}Vޖ+۽0u8>stream -HdVIF -ۆOc x9GàBŌ T}y/O?/_vǐ][ٵ">4nnoᅲ؋4{qx}Gu^>ZHѷnǐj.ȔԞ . 'LJx2*hŃ(DW&E#(1 cT/Ъ#q2f*Y:U7`ICt`ETPC6FHP;D"Sљc .Z$h9T&~UOF8+A!y}2X? y*KGk*9ecғWW13t(&)%%ZM+rc H^y.Ll7wOiWq9Ďx20'a8a G2JC`rFVO4eRXPLkA"]ቱN&3}!dLM˵y?m *ܬ\lSkv9S3=ӗ}/g#YbJV 5w0X}98Ȟ<1Kq,4̠q6BO';:!s GymZsT GFؚQqege+ywjk%8ztܳ7L] Z/h:kgK)R";m-׆<0R.e(&2?!n\ya@ GKvPN[*TABA\Ѯwlqt)PeêXs$gMsA5N!(B f̀aȉή஘L(;c!(㈍{L-UE2>m؉{Wϙ4:˥E5Ï(jB"p٪XA Fz4C]QLS%?_#h#{7qFZ|MZI҂4}ex.[P!29__ L endstream endobj 281 0 obj <>stream +B[zb$uQjZc:VlCIR5Ԭ`SMR8}G Lΰ%ͱzlftyѨfS{'X![6$ێލJp|DX<ܖX_ +a endstream endobj 285 0 obj <>stream +HdVIF -ۆOc x9GàBŌ T}y/O?/_vǐ][ٵ">4nnoᅲ؋4{qx}Gu^>ZHѷnǐj.ȔԞ . 'LJx2*hŃ(DW&E#(1 cT/Ъ#q2f*Y:U7`ICt`ETPC6FHP;D"Sљc .Z$h9T&~UOF8+A!y}2X? y*KGk*9ecғWW13t(&)%%ZM+rc H^y.Ll7wOiWq9Ďx20'a8a G2JC`rFVO4eRXPLkA"]ቱN&3}!dLM˵y?m *ܬ\lSkv9S3=ӗ}/g#YbJV 5w0X}98Ȟ<1Kq,4̠q6BO';:!s GymZsT GFؚQqege+ywjk%8ztܳ7L] Z/h:kgK)R";m-׆<0R.e(&2?!n\ya@ GKvPN[*TABA\Ѯwlqt)PeêXs$gMsA5N!(B f̀aȉή஘L(;c!(㈍{L-UE2>m؉{Wϙ4:˥E5Ï(jB"p٪XA Fz4C]QLS%?_#h#{7qFZ|MZI҂4}ex.[P!29__ L endstream endobj 281 0 obj <>stream HdSK0 @(r۴jP ~IiɎAv$C\rB  !۠"""N՟.WN£ٕ?/͟Fd5U -^+-2nPN4NUز7NZp 3tPc PlRqlrmB&ˆ N3A:y,!B F5w1i6wIQĴrbv:~prkա!=җ4{v2sd&T#KU2F,pVԓ{H)`L×5E)0rف[kW]&[qsw[+٬ӄ: 8`ZmN' RvUAU\`-%Kqׂ\19~1Hߑ-!8f3xg/GyݾWx endstream endobj 9 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 785.0 1000.0]/Type/Page>> endobj 10 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 615.0 1000.0]/Type/Page>> endobj 11 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 780.0 1000.0]/Type/Page>> endobj 12 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 892.0 1000.0]/Type/Page>> endobj 13 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 736.0 1000.0]/Type/Page>> endobj 315 0 obj <>stream +^+-2nPN4NUز7NZp 3tPc PlRqlrmB&ˆ N3A:y,!B F5w1i6wIQĴrbv:~prkա!=җ4{v2sd&T#KU2F,pVԓ{H)`L×5E)0rف[kW]&[qsw[+٬ӄ: 8`ZmN' RvUAU\`-%Kqׂ\19~1Hߑ-!8f3xg/GyݾWx endstream endobj 9 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 785.0 1000.0]/Type/Page>> endobj 10 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 615.0 1000.0]/Type/Page>> endobj 11 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 780.0 1000.0]/Type/Page>> endobj 12 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 892.0 1000.0]/Type/Page>> endobj 13 0 obj <>/Resources<>/ExtGState<>/Properties<>>>/TrimBox[0.0 0.0 736.0 1000.0]/Type/Page>> endobj 315 0 obj <>stream H|WA$ )EIYAE؋{䑬zt.E|$o_ǗxD?>*G>(rp?ׯ?s4:2_?8!4ћ=Lɉk9JMP03^RϖS55rNI@%^Xxri{*Rq<+nIjndzx,"IDR d>2۔.g<(z)x61%wӍj%-T%16qY~x>{k ]Ɉ D*EQ*[THqf"̏@dG"xQpI-q /o2+8׊+F=it) zx\nԊ|22ˡSc׳4D,êvge^Cpַz(G$ e|Zh|SVxL!$ תI^,U!DjqAI؍oK<ʂ>YR3 v}~,ݽ/}זڰuX!DH$:-ϘVy~+NK _xkg^9 c,YQٌQX{֖0%3-:;st9ChfDBK2kl{tS݃ݿ0e*`6i'+I?ung b )SE;])FAV< &'W[60qDE`LY(nFQʖEMO;Bam\0:9 FӶ @@ -4832,14 +4832,14 @@ A iC di i&q#$'|0ݙfXK (hM<*H չ|pZ9.;~+hM_r`L1mU⛶)v|Ywaȣ '$C M|11SjtBSdf.)ؚq0XW6!h$%#BsOP}301@_D>ٖ), }t.[ Aنu,]1w - NH6cuyeĢ40 %H.H"Қ ,2e駨R ߠ2_YaBbGd"JA8eQ'R1S:S&X,y*m "0 j: |"_{.2<L/oLp&5]0YQuh{/0YO2'ɱVT픀#bbۃQ0QĚLx8YPK8.bֈ.}b}K\ Yoɋ$tKU턜]J'"-(~ w{΋s^мh-E\Me5 5F'Kp$Gk2B]& r="p$u%hk#u6]S-s|_KL~ endstream endobj 314 0 obj <>stream + NH6cuyeĢ40 %H.H"Қ ,2e駨R ߠ2_YaBbGd"JA8eQ'R1S:S&X,y*m "0 j: |"_{.2<L/oLp&5]0YQuh{/0YO2'ɱVT픀#bbۃQ0QĚLx8YPK8.bֈ.}b}K\ Yoɋ$tKU턜]J'"-(~ w{΋s^мh-E\Me5 5F'Kp$Gk2B]& r="p$u%hk#u6]S-s|_KL~ endstream endobj 314 0 obj <>stream HlKn6:/ 7q G ;d䫖˙ X쮮_~y /^Sװ/ǒ}/[ R)0W߷)<G\B_ϼ%8r{^o8޶=8LT^j/3>yd3`V3ֺQ-X*F # gh4/ZARΩn:G }mkcIƹT-ڤȞbO+m42h18yRm.Z(x-*e+9/jW*=Gk̛9yJveW=*ҬnڌƳ9ArbBZJO.jTkW\)H5p)d ?)Y3;3yG6g\d{m,+y`@e or΁ ɾ2 ϜhIZ8W J Z}[s bVVk#LgJr*}#ыgq8U:ϻv/-I3tę #&;  La^dz(:W 6H\ιcV}Ep+Л1Be2y"d\  kTb nR@~bBzdbL^M ^Jn4C٭{ی4C&%'wqu( (G*yJU0q9MIӊPNioQ9tUD9Պ-I%o\쒣*rHRUA/k 娥@1Ð=2m-d.iU_I({3tKuhmyݕ5A ?y. D>4O.w"}`@w< eti ɟ/'-*,z@z v]W;f&Oah2H rl*]ck_r'.*|7Rfghz?/;,lկvǖI|U >stream +,~ẽNgeJ&UbA]_qa/v״G׍fw|][0taxYIKן즌0eDvc{|7WYM endstream endobj 313 0 obj <>stream HWK# uUuj`^? ?S齶+3$o}O7}? ۼsnw.m:qcs{{_~~\~߼[lm/<ۯ^hwm{weKwa{,|uO-mCs-^ އ0`[Pw҃N.W1U+W\+?UW_^ _*7Zc͇SɧT;E #[qu_^KwҞ.- &=źN{ n&̳ҝݷ 3z~N^b[|F^7n/N|\ܰlq.˘-e 8N)jk @@ -4855,330 +4855,330 @@ a 1CbP\JՆ7P$)|i2 {jڰ^@9zXaqRFIȳެS3ՕӏS2օӥ,<__Bv R8($w/NkzI(#nJ(T`wL?)@5@s>A߱oA9@&Q jCXwH)Uc.D/V -{.z؇(ȡ{9(|KPs!cxSp>QTL-RlZWPXh1^ӯ?_O endstream endobj 312 0 obj <>stream +{.z؇(ȡ{9(|KPs!cxSp>QTL-RlZWPXh1^ӯ?_O endstream endobj 312 0 obj <>stream HlKN0 9/v[ b5B# V4NZ'HJ9vY_6X/"z @w@h=D ݼYWe*g ~!dbf7"7/$‰l!IJ4Aߙw6Ki -D%hu_!Ecc, >wr үdGFZNK䷐\RJTVPS~5߄.r#":$#|Tf92f8i4PsgH함%AG -I:FSGuՔx endstream endobj 311 0 obj <>stream +I:FSGuՔx endstream endobj 311 0 obj <>stream HVˎ6 +H.rZ<=6@%4`ebE_~yu/^ë;>~e@k.x]ɝ}oWSJ Ƹx3~|qܨJLpruC eɉj.㞶8•J zB9,"eN;|`d1$HV̔Xmlİ @K?C8S&ԟ]ҨT,J\bk-L焗SU( vT\c/j,Lj4."a6&M}AtDsD}$6>PVdK%Fl;[D~3RXeg*y-Pd`^}ۺ3{ 9 Z̞bm/,ww3N\݊7뾥n@W[ްڈ 6͂I"SDZba+*gZnDeE#PjN.T@l{,A{eϑD{A{Л!(. h 7E yQKP>:YK"jQ_wma:^(Iı|{7O bCX*1S2[cLmyoqq|Z%~ %9g]l( ˒PFQͨ BLm2롟TI}VJ5 f̴?ߥc%)nZ!ƞ -xZ}T`QcǸTMsFMgD3'qVlvڌŮzbd'rK|aSzc'o4 ;.;;;ɛdC?d/rjv ZP4sq;Ԧ5| );C:#~.OmO,\Wt-F _I>|QbݔPŌ.upvgt wvp[>!ԷeC5aDZə\W $q6d`'I endstream endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 46 0 obj <> endobj 47 0 obj <> endobj 48 0 obj <> endobj 81 0 obj <> endobj 82 0 obj <> endobj 83 0 obj <> endobj 116 0 obj <> endobj 117 0 obj <> endobj 118 0 obj <> endobj 153 0 obj <> endobj 154 0 obj <> endobj 155 0 obj <> endobj 195 0 obj <> endobj 196 0 obj <> endobj 197 0 obj <> endobj 234 0 obj <> endobj 235 0 obj <> endobj 236 0 obj <> endobj 254 0 obj [/View/Design] endobj 255 0 obj <>>> endobj 252 0 obj [/View/Design] endobj 253 0 obj <>>> endobj 250 0 obj [/View/Design] endobj 251 0 obj <>>> endobj 216 0 obj [/View/Design] endobj 217 0 obj <>>> endobj 214 0 obj [/View/Design] endobj 215 0 obj <>>> endobj 212 0 obj [/View/Design] endobj 213 0 obj <>>> endobj 177 0 obj [/View/Design] endobj 178 0 obj <>>> endobj 175 0 obj [/View/Design] endobj 176 0 obj <>>> endobj 173 0 obj [/View/Design] endobj 174 0 obj <>>> endobj 135 0 obj [/View/Design] endobj 136 0 obj <>>> endobj 133 0 obj [/View/Design] endobj 134 0 obj <>>> endobj 131 0 obj [/View/Design] endobj 132 0 obj <>>> endobj 98 0 obj [/View/Design] endobj 99 0 obj <>>> endobj 96 0 obj [/View/Design] endobj 97 0 obj <>>> endobj 94 0 obj [/View/Design] endobj 95 0 obj <>>> endobj 63 0 obj [/View/Design] endobj 64 0 obj <>>> endobj 61 0 obj [/View/Design] endobj 62 0 obj <>>> endobj 59 0 obj [/View/Design] endobj 60 0 obj <>>> endobj 28 0 obj [/View/Design] endobj 29 0 obj <>>> endobj 26 0 obj [/View/Design] endobj 27 0 obj <>>> endobj 24 0 obj [/View/Design] endobj 25 0 obj <>>> endobj 280 0 obj [279 0 R 278 0 R 277 0 R] endobj 316 0 obj <> endobj xref 0 317 0000000004 65535 f -0000000016 00000 n -0000000494 00000 n -0000048511 00000 n -0000000008 00000 f -0001188931 00000 n -0001189000 00000 n -0001189070 00000 n -0000000015 00000 f -0001162692 00000 n -0001163070 00000 n -0001163453 00000 n -0001163838 00000 n -0001164222 00000 n -0000048774 00000 n -0000000016 00000 f -0000000017 00000 f -0000000018 00000 f -0000000019 00000 f -0000000020 00000 f -0000000021 00000 f -0000000022 00000 f -0000000023 00000 f -0000000030 00000 f -0001192778 00000 n -0001192809 00000 n -0001192662 00000 n -0001192693 00000 n -0001192546 00000 n -0001192577 00000 n -0000000031 00000 f -0000000032 00000 f -0000000033 00000 f -0000000034 00000 f -0000000035 00000 f -0000000036 00000 f -0000000037 00000 f -0000000038 00000 f -0000000039 00000 f -0000000040 00000 f -0000000041 00000 f -0000000042 00000 f -0000000043 00000 f -0000000044 00000 f -0000000045 00000 f -0000000049 00000 f -0001189138 00000 n -0001189208 00000 n -0001189279 00000 n -0000000050 00000 f -0000000051 00000 f -0000000052 00000 f -0000000053 00000 f -0000000054 00000 f -0000000055 00000 f -0000000056 00000 f -0000000057 00000 f -0000000058 00000 f -0000000065 00000 f -0001192430 00000 n -0001192461 00000 n -0001192314 00000 n -0001192345 00000 n -0001192198 00000 n -0001192229 00000 n -0000000066 00000 f -0000000067 00000 f -0000000068 00000 f -0000000069 00000 f -0000000070 00000 f -0000000071 00000 f -0000000072 00000 f -0000000073 00000 f -0000000074 00000 f -0000000075 00000 f -0000000076 00000 f -0000000077 00000 f -0000000078 00000 f -0000000079 00000 f -0000000080 00000 f -0000000084 00000 f -0001189348 00000 n -0001189418 00000 n -0001189489 00000 n -0000000085 00000 f -0000000086 00000 f -0000000087 00000 f -0000000088 00000 f -0000000089 00000 f -0000000090 00000 f -0000000091 00000 f -0000000092 00000 f -0000000093 00000 f -0000000100 00000 f -0001192082 00000 n -0001192113 00000 n -0001191966 00000 n -0001191997 00000 n -0001191850 00000 n -0001191881 00000 n -0000000101 00000 f -0000000102 00000 f -0000000103 00000 f -0000000104 00000 f -0000000105 00000 f -0000000106 00000 f -0000000107 00000 f -0000000108 00000 f -0000000109 00000 f -0000000110 00000 f -0000000111 00000 f -0000000112 00000 f -0000000113 00000 f -0000000114 00000 f -0000000115 00000 f -0000000119 00000 f -0001189558 00000 n -0001189631 00000 n -0001189705 00000 n -0000000121 00000 f -0000049159 00000 n -0000000122 00000 f -0000000123 00000 f -0000000124 00000 f -0000000125 00000 f -0000000126 00000 f -0000000127 00000 f -0000000128 00000 f -0000000129 00000 f -0000000130 00000 f -0000000137 00000 f -0001191732 00000 n -0001191764 00000 n -0001191614 00000 n -0001191646 00000 n -0001191496 00000 n -0001191528 00000 n -0000000138 00000 f -0000000139 00000 f -0000000140 00000 f -0000000141 00000 f -0000000142 00000 f -0000000143 00000 f -0000000144 00000 f -0000000145 00000 f -0000000146 00000 f -0000000147 00000 f -0000000148 00000 f -0000000149 00000 f -0000000150 00000 f -0000000151 00000 f -0000000152 00000 f -0000000156 00000 f -0001189777 00000 n -0001189850 00000 n -0001189924 00000 n -0000000160 00000 f -0000049545 00000 n -0000049937 00000 n -0000050326 00000 n -0000000161 00000 f -0000000162 00000 f -0000000163 00000 f -0000000164 00000 f -0000000165 00000 f -0000000166 00000 f -0000000167 00000 f -0000000168 00000 f -0000000169 00000 f -0000000170 00000 f -0000000171 00000 f -0000000172 00000 f -0000000179 00000 f -0001191378 00000 n -0001191410 00000 n -0001191260 00000 n -0001191292 00000 n -0001191142 00000 n -0001191174 00000 n -0000000180 00000 f -0000000181 00000 f -0000000182 00000 f -0000000183 00000 f -0000000184 00000 f -0000000185 00000 f -0000000186 00000 f -0000000187 00000 f -0000000188 00000 f -0000000189 00000 f -0000000190 00000 f -0000000191 00000 f -0000000192 00000 f -0000000193 00000 f -0000000194 00000 f -0000000198 00000 f -0001189996 00000 n -0001190069 00000 n -0001190143 00000 n -0000000199 00000 f -0000000200 00000 f -0000000201 00000 f -0000000202 00000 f -0000000203 00000 f -0000000204 00000 f -0000000205 00000 f -0000000206 00000 f -0000000207 00000 f -0000000208 00000 f -0000000209 00000 f -0000000210 00000 f -0000000211 00000 f -0000000218 00000 f -0001191024 00000 n -0001191056 00000 n -0001190906 00000 n -0001190938 00000 n -0001190788 00000 n -0001190820 00000 n -0000000219 00000 f -0000000220 00000 f -0000000221 00000 f -0000000222 00000 f -0000000223 00000 f -0000000224 00000 f -0000000225 00000 f -0000000226 00000 f -0000000227 00000 f -0000000228 00000 f -0000000229 00000 f -0000000230 00000 f -0000000231 00000 f -0000000232 00000 f -0000000233 00000 f -0000000000 00000 f -0001190215 00000 n -0001190288 00000 n -0001190362 00000 n -0000000000 00000 f -0000048573 00000 n -0000048667 00000 n -0000050712 00000 n -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0001190670 00000 n -0001190702 00000 n -0001190552 00000 n -0001190584 00000 n -0001190434 00000 n -0001190466 00000 n -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000000000 00000 f -0000051844 00000 n -0000051917 00000 n -0000051991 00000 n -0001192894 00000 n -0001162151 00000 n -0000442402 00000 n -0000052531 00000 n -0000052417 00000 n -0001161031 00000 n -0001160493 00000 n -0001160047 00000 n -0001159108 00000 n -0000051101 00000 n -0000052299 00000 n -0000052331 00000 n -0000052181 00000 n -0000052213 00000 n -0000052063 00000 n -0000052095 00000 n -0000052568 00000 n -0000442478 00000 n -0000442890 00000 n -0000443951 00000 n -0000448310 00000 n -0000513899 00000 n -0000579488 00000 n -0000634396 00000 n -0000699985 00000 n -0000765574 00000 n -0000831163 00000 n -0000896752 00000 n -0000962341 00000 n -0001027930 00000 n -0001093519 00000 n -0001187870 00000 n -0001187479 00000 n -0001183631 00000 n -0001181990 00000 n -0001164607 00000 n -0001192937 00000 n +xZ}T`QcǸTMsFMgD3'qVlvڌŮzbd'rK|aSzc'o4 ;.;;;ɛdC?d/rjv ZP4sq;Ԧ5| );C:#~.OmO,\Wt-F _I>|QbݔPŌ.upvgt wvp[>!ԷeC5aDZə\W $q6d`'I endstream endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 46 0 obj <> endobj 47 0 obj <> endobj 48 0 obj <> endobj 81 0 obj <> endobj 82 0 obj <> endobj 83 0 obj <> endobj 116 0 obj <> endobj 117 0 obj <> endobj 118 0 obj <> endobj 153 0 obj <> endobj 154 0 obj <> endobj 155 0 obj <> endobj 195 0 obj <> endobj 196 0 obj <> endobj 197 0 obj <> endobj 234 0 obj <> endobj 235 0 obj <> endobj 236 0 obj <> endobj 254 0 obj [/View/Design] endobj 255 0 obj <>>> endobj 252 0 obj [/View/Design] endobj 253 0 obj <>>> endobj 250 0 obj [/View/Design] endobj 251 0 obj <>>> endobj 216 0 obj [/View/Design] endobj 217 0 obj <>>> endobj 214 0 obj [/View/Design] endobj 215 0 obj <>>> endobj 212 0 obj [/View/Design] endobj 213 0 obj <>>> endobj 177 0 obj [/View/Design] endobj 178 0 obj <>>> endobj 175 0 obj [/View/Design] endobj 176 0 obj <>>> endobj 173 0 obj [/View/Design] endobj 174 0 obj <>>> endobj 135 0 obj [/View/Design] endobj 136 0 obj <>>> endobj 133 0 obj [/View/Design] endobj 134 0 obj <>>> endobj 131 0 obj [/View/Design] endobj 132 0 obj <>>> endobj 98 0 obj [/View/Design] endobj 99 0 obj <>>> endobj 96 0 obj [/View/Design] endobj 97 0 obj <>>> endobj 94 0 obj [/View/Design] endobj 95 0 obj <>>> endobj 63 0 obj [/View/Design] endobj 64 0 obj <>>> endobj 61 0 obj [/View/Design] endobj 62 0 obj <>>> endobj 59 0 obj [/View/Design] endobj 60 0 obj <>>> endobj 28 0 obj [/View/Design] endobj 29 0 obj <>>> endobj 26 0 obj [/View/Design] endobj 27 0 obj <>>> endobj 24 0 obj [/View/Design] endobj 25 0 obj <>>> endobj 280 0 obj [279 0 R 278 0 R 277 0 R] endobj 316 0 obj <> endobj xref 0 317 0000000004 65535 f +0000000016 00000 n +0000000494 00000 n +0000048511 00000 n +0000000008 00000 f +0001188931 00000 n +0001189000 00000 n +0001189070 00000 n +0000000015 00000 f +0001162692 00000 n +0001163070 00000 n +0001163453 00000 n +0001163838 00000 n +0001164222 00000 n +0000048774 00000 n +0000000016 00000 f +0000000017 00000 f +0000000018 00000 f +0000000019 00000 f +0000000020 00000 f +0000000021 00000 f +0000000022 00000 f +0000000023 00000 f +0000000030 00000 f +0001192778 00000 n +0001192809 00000 n +0001192662 00000 n +0001192693 00000 n +0001192546 00000 n +0001192577 00000 n +0000000031 00000 f +0000000032 00000 f +0000000033 00000 f +0000000034 00000 f +0000000035 00000 f +0000000036 00000 f +0000000037 00000 f +0000000038 00000 f +0000000039 00000 f +0000000040 00000 f +0000000041 00000 f +0000000042 00000 f +0000000043 00000 f +0000000044 00000 f +0000000045 00000 f +0000000049 00000 f +0001189138 00000 n +0001189208 00000 n +0001189279 00000 n +0000000050 00000 f +0000000051 00000 f +0000000052 00000 f +0000000053 00000 f +0000000054 00000 f +0000000055 00000 f +0000000056 00000 f +0000000057 00000 f +0000000058 00000 f +0000000065 00000 f +0001192430 00000 n +0001192461 00000 n +0001192314 00000 n +0001192345 00000 n +0001192198 00000 n +0001192229 00000 n +0000000066 00000 f +0000000067 00000 f +0000000068 00000 f +0000000069 00000 f +0000000070 00000 f +0000000071 00000 f +0000000072 00000 f +0000000073 00000 f +0000000074 00000 f +0000000075 00000 f +0000000076 00000 f +0000000077 00000 f +0000000078 00000 f +0000000079 00000 f +0000000080 00000 f +0000000084 00000 f +0001189348 00000 n +0001189418 00000 n +0001189489 00000 n +0000000085 00000 f +0000000086 00000 f +0000000087 00000 f +0000000088 00000 f +0000000089 00000 f +0000000090 00000 f +0000000091 00000 f +0000000092 00000 f +0000000093 00000 f +0000000100 00000 f +0001192082 00000 n +0001192113 00000 n +0001191966 00000 n +0001191997 00000 n +0001191850 00000 n +0001191881 00000 n +0000000101 00000 f +0000000102 00000 f +0000000103 00000 f +0000000104 00000 f +0000000105 00000 f +0000000106 00000 f +0000000107 00000 f +0000000108 00000 f +0000000109 00000 f +0000000110 00000 f +0000000111 00000 f +0000000112 00000 f +0000000113 00000 f +0000000114 00000 f +0000000115 00000 f +0000000119 00000 f +0001189558 00000 n +0001189631 00000 n +0001189705 00000 n +0000000121 00000 f +0000049159 00000 n +0000000122 00000 f +0000000123 00000 f +0000000124 00000 f +0000000125 00000 f +0000000126 00000 f +0000000127 00000 f +0000000128 00000 f +0000000129 00000 f +0000000130 00000 f +0000000137 00000 f +0001191732 00000 n +0001191764 00000 n +0001191614 00000 n +0001191646 00000 n +0001191496 00000 n +0001191528 00000 n +0000000138 00000 f +0000000139 00000 f +0000000140 00000 f +0000000141 00000 f +0000000142 00000 f +0000000143 00000 f +0000000144 00000 f +0000000145 00000 f +0000000146 00000 f +0000000147 00000 f +0000000148 00000 f +0000000149 00000 f +0000000150 00000 f +0000000151 00000 f +0000000152 00000 f +0000000156 00000 f +0001189777 00000 n +0001189850 00000 n +0001189924 00000 n +0000000160 00000 f +0000049545 00000 n +0000049937 00000 n +0000050326 00000 n +0000000161 00000 f +0000000162 00000 f +0000000163 00000 f +0000000164 00000 f +0000000165 00000 f +0000000166 00000 f +0000000167 00000 f +0000000168 00000 f +0000000169 00000 f +0000000170 00000 f +0000000171 00000 f +0000000172 00000 f +0000000179 00000 f +0001191378 00000 n +0001191410 00000 n +0001191260 00000 n +0001191292 00000 n +0001191142 00000 n +0001191174 00000 n +0000000180 00000 f +0000000181 00000 f +0000000182 00000 f +0000000183 00000 f +0000000184 00000 f +0000000185 00000 f +0000000186 00000 f +0000000187 00000 f +0000000188 00000 f +0000000189 00000 f +0000000190 00000 f +0000000191 00000 f +0000000192 00000 f +0000000193 00000 f +0000000194 00000 f +0000000198 00000 f +0001189996 00000 n +0001190069 00000 n +0001190143 00000 n +0000000199 00000 f +0000000200 00000 f +0000000201 00000 f +0000000202 00000 f +0000000203 00000 f +0000000204 00000 f +0000000205 00000 f +0000000206 00000 f +0000000207 00000 f +0000000208 00000 f +0000000209 00000 f +0000000210 00000 f +0000000211 00000 f +0000000218 00000 f +0001191024 00000 n +0001191056 00000 n +0001190906 00000 n +0001190938 00000 n +0001190788 00000 n +0001190820 00000 n +0000000219 00000 f +0000000220 00000 f +0000000221 00000 f +0000000222 00000 f +0000000223 00000 f +0000000224 00000 f +0000000225 00000 f +0000000226 00000 f +0000000227 00000 f +0000000228 00000 f +0000000229 00000 f +0000000230 00000 f +0000000231 00000 f +0000000232 00000 f +0000000233 00000 f +0000000000 00000 f +0001190215 00000 n +0001190288 00000 n +0001190362 00000 n +0000000000 00000 f +0000048573 00000 n +0000048667 00000 n +0000050712 00000 n +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0001190670 00000 n +0001190702 00000 n +0001190552 00000 n +0001190584 00000 n +0001190434 00000 n +0001190466 00000 n +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000000000 00000 f +0000051844 00000 n +0000051917 00000 n +0000051991 00000 n +0001192894 00000 n +0001162151 00000 n +0000442402 00000 n +0000052531 00000 n +0000052417 00000 n +0001161031 00000 n +0001160493 00000 n +0001160047 00000 n +0001159108 00000 n +0000051101 00000 n +0000052299 00000 n +0000052331 00000 n +0000052181 00000 n +0000052213 00000 n +0000052063 00000 n +0000052095 00000 n +0000052568 00000 n +0000442478 00000 n +0000442890 00000 n +0000443951 00000 n +0000448310 00000 n +0000513899 00000 n +0000579488 00000 n +0000634396 00000 n +0000699985 00000 n +0000765574 00000 n +0000831163 00000 n +0000896752 00000 n +0000962341 00000 n +0001027930 00000 n +0001093519 00000 n +0001187870 00000 n +0001187479 00000 n +0001183631 00000 n +0001181990 00000 n +0001164607 00000 n +0001192937 00000 n trailer <<7098E6806FAC4ACA8CA4F17F11E72072>]>> startxref 1193122 %%EOF \ No newline at end of file diff --git a/client/geovistory-font/svg/gv-icons_circles.svg b/client/geovistory-font/svg/gv-icons_circles.svg index 64a6f81df..867132db9 100644 --- a/client/geovistory-font/svg/gv-icons_circles.svg +++ b/client/geovistory-font/svg/gv-icons_circles.svg @@ -1,23 +1,23 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_entity.svg b/client/geovistory-font/svg/gv-icons_entity.svg index 7609dc7bb..de6e5917d 100644 --- a/client/geovistory-font/svg/gv-icons_entity.svg +++ b/client/geovistory-font/svg/gv-icons_entity.svg @@ -1,70 +1,70 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_geovistory-logo.svg b/client/geovistory-font/svg/gv-icons_geovistory-logo.svg index 3f200aae5..27643b347 100644 --- a/client/geovistory-font/svg/gv-icons_geovistory-logo.svg +++ b/client/geovistory-font/svg/gv-icons_geovistory-logo.svg @@ -1,31 +1,31 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_information.svg b/client/geovistory-font/svg/gv-icons_information.svg index b26596af3..118efe729 100644 --- a/client/geovistory-font/svg/gv-icons_information.svg +++ b/client/geovistory-font/svg/gv-icons_information.svg @@ -1,198 +1,198 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_persistent-entity.svg b/client/geovistory-font/svg/gv-icons_persistent-entity.svg index 2c78b787b..8777900b7 100644 --- a/client/geovistory-font/svg/gv-icons_persistent-entity.svg +++ b/client/geovistory-font/svg/gv-icons_persistent-entity.svg @@ -1,23 +1,23 @@ - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_presentation.svg b/client/geovistory-font/svg/gv-icons_presentation.svg index 0c803a134..681dff8a0 100644 --- a/client/geovistory-font/svg/gv-icons_presentation.svg +++ b/client/geovistory-font/svg/gv-icons_presentation.svg @@ -1,47 +1,47 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_query.svg b/client/geovistory-font/svg/gv-icons_query.svg index 19ad829c6..f172a41f5 100644 --- a/client/geovistory-font/svg/gv-icons_query.svg +++ b/client/geovistory-font/svg/gv-icons_query.svg @@ -1,45 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_source.svg b/client/geovistory-font/svg/gv-icons_source.svg index 6a2162c61..0d8efb42c 100644 --- a/client/geovistory-font/svg/gv-icons_source.svg +++ b/client/geovistory-font/svg/gv-icons_source.svg @@ -1,835 +1,835 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_story.svg b/client/geovistory-font/svg/gv-icons_story.svg index a507755d4..004e91dcb 100644 --- a/client/geovistory-font/svg/gv-icons_story.svg +++ b/client/geovistory-font/svg/gv-icons_story.svg @@ -1,25 +1,25 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_temporal-entity.svg b/client/geovistory-font/svg/gv-icons_temporal-entity.svg index a5fa16625..4ec1f2c75 100644 --- a/client/geovistory-font/svg/gv-icons_temporal-entity.svg +++ b/client/geovistory-font/svg/gv-icons_temporal-entity.svg @@ -1,48 +1,48 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/client/geovistory-font/svg/gv-icons_visual.svg b/client/geovistory-font/svg/gv-icons_visual.svg index 75f6e1d21..0a7ffbd73 100644 --- a/client/geovistory-font/svg/gv-icons_visual.svg +++ b/client/geovistory-font/svg/gv-icons_visual.svg @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/api-responses/GvPaginationObjectMock.ts b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/api-responses/GvPaginationObjectMock.ts index f9247a5a7..4de1b3aa4 100644 --- a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/api-responses/GvPaginationObjectMock.ts +++ b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/api-responses/GvPaginationObjectMock.ts @@ -1,55 +1,68 @@ -import {GvFieldPageReq, GvPaginationObject, InfAppellation, InfDimension, InfLangString, InfLanguage, InfPlace, InfResource, InfStatement, InfTimePrimitive, ProInfoProjRel, WarEntityPreview} from '@kleiolab/lib-sdk-lb4'; -import {TrueEnum} from '../enums/TrueEnum'; -import {StatementWithTarget} from '@kleiolab/lib-sdk-lb4'; -import {SatementTarget} from '@kleiolab/lib-sdk-lb4'; -import {GvFieldPageReqMock} from '../api-requests/GvFieldPageReq' -import {DfhApiClassMock} from '../gvDB/DfhApiClassMock' -import {DfhApiPropertyMock} from '../gvDB/DfhApiPropertyMock' -import {InfAppellationMock} from '../gvDB/InfAppellationMock' -import {InfDimensionMock} from '../gvDB/InfDimensionMock' -import {InfLangStringMock} from '../gvDB/InfLangStringMock' -import {InfLanguageMock} from '../gvDB/InfLanguageMock' -import {InfPlaceMock} from '../gvDB/InfPlaceMock' -import {InfResourceMock} from '../gvDB/InfResourceMock' -import {InfStatementMock} from '../gvDB/InfStatementMock' -import {DEFAULT_DURATION, InfTimePrimitiveMock} from '../gvDB/InfTimePrimitiveMock' -import {NewDfhApiProperty, OmitEntity} from '../gvDB/local-model.helpers' -import {ProInfoProjRelMock} from '../gvDB/ProInfoProjRelMock' -import {ProProjectMock} from '../gvDB/ProProjectMock' -import {PubAccountMock} from '../gvDB/PubAccountMock' -import {WarEntityPreviewMock} from '../gvDB/WarEntityPreviewMock' +import { + GvFieldPage, + GvPaginationObject, + InfAppellation, + InfDimension, + InfLangString, + InfLanguage, + InfPlace, + InfResource, + InfStatement, + InfTimePrimitive, + ProInfoProjRel, + SatementTarget, + StatementWithTarget, + WarEntityPreview, +} from '@kleiolab/lib-sdk-lb4'; +import { GvFieldPageReqMock } from '../api-requests/GvFieldPageReq'; +import { DfhApiPropertyMock } from '../gvDB/DfhApiPropertyMock'; +import { InfAppellationMock } from '../gvDB/InfAppellationMock'; +import { InfDimensionMock } from '../gvDB/InfDimensionMock'; +import { InfLangStringMock } from '../gvDB/InfLangStringMock'; +import { InfLanguageMock } from '../gvDB/InfLanguageMock'; +import { InfPlaceMock } from '../gvDB/InfPlaceMock'; +import { InfResourceMock } from '../gvDB/InfResourceMock'; +import { InfStatementMock } from '../gvDB/InfStatementMock'; +import { + DEFAULT_DURATION, + InfTimePrimitiveMock, +} from '../gvDB/InfTimePrimitiveMock'; +import { NewDfhApiProperty, OmitEntity } from '../gvDB/local-model.helpers'; +import { ProInfoProjRelMock } from '../gvDB/ProInfoProjRelMock'; +import { ProProjectMock } from '../gvDB/ProProjectMock'; +import { PubAccountMock } from '../gvDB/PubAccountMock'; +import { WarEntityPreviewMock } from '../gvDB/WarEntityPreviewMock'; - -export function createStatementWithTarget(statement: OmitEntity, accountId = 1001, target: SatementTarget, isOutgoing: boolean, projRel?: OmitEntity): StatementWithTarget { - - let targetLabel = '' +export function createStatementWithTarget( + statement: OmitEntity, + accountId = 1001, + target: SatementTarget, + isOutgoing: boolean, + projRel?: OmitEntity +): StatementWithTarget { + let targetLabel = ''; if (target.appellation) { - targetLabel = target.appellation?.string ?? '' - } - else if (target.dimension) { - targetLabel = `${target.dimension.dimension.numeric_value} ${target.dimension?.unitPreview?.entity_label}` // todo add ${unitPreview.entity_label} - } - else if (target.langString) { - targetLabel = `${target.langString.langString.string} (${target.langString.language.iso6391})` // todo add - } - else if (target.language) { - targetLabel = `${target.language.notes ?? target.language.iso6391}` // todo add (${language.iso6391}) - } - else if (target.entity) { - targetLabel = `${target.entity.entityPreview?.entity_label}` - } - else if (target.timePrimitive) { - targetLabel = `todo` // todo - } - else if (target.place) { - targetLabel = `WGS84: ${target.place.lat}°, ${target.place.long}°` // todo + targetLabel = target.appellation?.string ?? ''; + } else if (target.dimension) { + targetLabel = `${target.dimension.dimension.numeric_value} ${target.dimension?.unitPreview?.entity_label}`; // todo add ${unitPreview.entity_label} + } else if (target.langString) { + targetLabel = `${target.langString.langString.string} (${target.langString.language.iso6391})`; // todo add + } else if (target.language) { + targetLabel = `${target.language.notes ?? target.language.iso6391}`; // todo add (${language.iso6391}) + } else if (target.entity) { + targetLabel = `${target.entity.entityPreview?.entity_label}`; + } else if (target.timePrimitive) { + targetLabel = `todo`; // todo + } else if (target.place) { + targetLabel = `WGS84: ${target.place.lat}°, ${target.place.long}°`; // todo } return { isOutgoing, ordNum: isOutgoing ? projRel?.ord_num_of_range : projRel?.ord_num_of_domain, statement, target, - targetClass: target.appellation?.fk_class ?? + targetClass: + target.appellation?.fk_class ?? target.dimension?.dimension.fk_class ?? target.entity?.resource.fk_class ?? target.langString?.langString?.fk_class ?? @@ -58,63 +71,62 @@ export function createStatementWithTarget(statement: OmitEntity, a target.timePrimitive?.infTimePrimitive.fk_class ?? -1, targetLabel, - projRel - } + projRel, + }; } const appeTeEnHasAppeVt: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnRefersToName, + page: GvFieldPageReqMock.appeTeEnRefersToName.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE + ), ], - } - ] -} + }, + ], +}; const appeTeEnHasAppeVtEmpty: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnRefersToName, + page: GvFieldPageReqMock.appeTeEnRefersToName.page, count: 0, paginatedStatements: [], - } - ] -} + }, + ], +}; const appeTeEnUsedInLanguage: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnUsedInLanguage, + page: GvFieldPageReqMock.appeTeEnUsedInLanguage.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_LANG, PubAccountMock.GAETAN_VERIFIED.id, { - language: InfLanguageMock.ENGLISH as InfLanguage + language: InfLanguageMock.ENGLISH as InfLanguage, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_LANG, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_LANG + ), ], - } + }, ], - -} +}; const appeTeEnIsAppeOfPerson: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnIsAppeOfPerson, + page: GvFieldPageReqMock.appeTeEnIsAppeOfPerson.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -123,20 +135,20 @@ const appeTeEnIsAppeOfPerson: GvPaginationObject = { { entity: { resource: InfResourceMock.PERSON_1 as InfResource, - entityPreview: WarEntityPreviewMock.PERSON_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.PERSON_1 as WarEntityPreview, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON + ), ], - } + }, ], -} +}; const madridsPresenceWasAtPlace: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.madridsPresenceWasAtPlace, + page: GvFieldPageReqMock.madridsPresenceWasAtPlace.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -146,16 +158,16 @@ const madridsPresenceWasAtPlace: GvPaginationObject = { place: InfPlaceMock.PLACE_123 as InfPlace, }, true, - ProInfoProjRelMock.PROJ_1_STMT_MADRIDS_PRESENCE_WAS_AT_PLACE_123, - ) + ProInfoProjRelMock.PROJ_1_STMT_MADRIDS_PRESENCE_WAS_AT_PLACE_123 + ), ], - } + }, ], -} +}; const journeyHasDuration: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.journyeHasDuration, + page: GvFieldPageReqMock.journyeHasDuration.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -164,20 +176,22 @@ const journeyHasDuration: GvPaginationObject = { { dimension: { dimension: InfDimensionMock.ONE_MONTH as InfDimension, - unitPreview: WarEntityPreviewMock.TIME_UNIT_ONE_MONTH as WarEntityPreview - } + unitPreview: + WarEntityPreviewMock.TIME_UNIT_ONE_MONTH as WarEntityPreview, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_ACCOUNT_OF_JOURNEY_HAS_DURATION, - )], - } + ProInfoProjRelMock.PROJ_1_STMT_ACCOUNT_OF_JOURNEY_HAS_DURATION + ), + ], + }, ], -} +}; const manifSingletonHasShortTitleMurderer: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.manifSingletonHasShortTitleMurderer, + page: GvFieldPageReqMock.manifSingletonHasShortTitleMurderer.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -185,21 +199,23 @@ const manifSingletonHasShortTitleMurderer: GvPaginationObject = { PubAccountMock.GAETAN_VERIFIED.id, { langString: { - langString: InfLangStringMock.EN_SHORT_TITLE_THE_MURDERER as InfLangString, - language: InfLanguageMock.ENGLISH as InfLanguage - } + langString: + InfLangStringMock.EN_SHORT_TITLE_THE_MURDERER as InfLangString, + language: InfLanguageMock.ENGLISH as InfLanguage, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_MANIF_SINGLETON_HAS_SHORT_TITLE_MURDERER, - )], - } - ] -} + ProInfoProjRelMock.PROJ_1_STMT_MANIF_SINGLETON_HAS_SHORT_TITLE_MURDERER + ), + ], + }, + ], +}; const shipVoyageAtSomeTimeWithin: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.shipVoyageAtSomeTimeWithin, + page: GvFieldPageReqMock.shipVoyageAtSomeTimeWithin.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -209,23 +225,24 @@ const shipVoyageAtSomeTimeWithin: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_2 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_2.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_2.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_2.julian_day, calendar: InfTimePrimitiveMock.TP_2.calendar, - } - } + }, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_AT_SOME_TIME_WITHIN_TP_2, - ) + ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_AT_SOME_TIME_WITHIN_TP_2 + ), ], - } + }, ], -} +}; const shipVoyageHasTimeSpan: GvPaginationObject = { subfieldPages: [ { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_71_ONGOING_THROUGHOUT ), @@ -233,7 +250,7 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_72_AT_SOME_TIME_WITHIN ), @@ -241,7 +258,7 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_152_BEGIN_OF_THE_BEGIN ), @@ -255,19 +272,20 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_5 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_5.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_5.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_5.julian_day, - calendar: InfTimePrimitiveMock.TP_5.calendar - } - } + calendar: InfTimePrimitiveMock.TP_5.calendar, + }, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_BEGIN_TP_5, - ) + ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_BEGIN_TP_5 + ), ], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_150_END_OF_THE_BEGIN ), @@ -275,7 +293,7 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_151_BEGIN_OF_THE_END ), @@ -288,19 +306,20 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_4 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_4.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_4.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_4.julian_day, - calendar: InfTimePrimitiveMock.TP_4.calendar - } - } + calendar: InfTimePrimitiveMock.TP_4.calendar, + }, + }, }, true, - ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_END_TP_4, - ) + ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_END_TP_4 + ), ], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, DfhApiPropertyMock.EN_153_END_OF_THE_END ), @@ -308,15 +327,14 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { paginatedStatements: [], }, ], - -} +}; const personHasAppeTeEn: GvPaginationObject = { subfieldPages: [ { - req: { - ...GvFieldPageReqMock.person1HasAppeTeEn, - page: {...GvFieldPageReqMock.person1HasAppeTeEn.page, isOutgoing: false}, + page: { + ...GvFieldPageReqMock.person1HasAppeTeEn.page, + isOutgoing: false, }, count: 1, paginatedStatements: [ @@ -326,18 +344,18 @@ const personHasAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_1 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview, + }, }, false, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEnRefersToName, - page: {...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1}, + page: { + ...GvFieldPageReqMock.appeTeEnRefersToName.page, + limit: 1, }, count: 1, paginatedStatements: [ @@ -345,21 +363,21 @@ const personHasAppeTeEn: GvPaginationObject = { InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE + ), ], }, ], -} +}; const personHasTwoAppeTeEn: GvPaginationObject = { subfieldPages: [ { - req: { - ...GvFieldPageReqMock.person1HasAppeTeEn, - page: {...GvFieldPageReqMock.person1HasAppeTeEn.page, isOutgoing: false}, + page: { + ...GvFieldPageReqMock.person1HasAppeTeEn.page, + isOutgoing: false, }, count: 2, paginatedStatements: [ @@ -369,11 +387,11 @@ const personHasTwoAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_1 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview, + }, }, false, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON ), createStatementWithTarget( InfStatementMock.NAME_2_TO_PERSON, @@ -381,56 +399,50 @@ const personHasTwoAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_2 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_2 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_2 as WarEntityPreview, + }, }, false, - ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_PERSON, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_PERSON + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEnRefersToName, - page: {...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1}, - }, + page: { ...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1 }, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEn2RefersToName, - page: {...GvFieldPageReqMock.appeTeEn2RefersToName.page, limit: 1}, - }, + page: { ...GvFieldPageReqMock.appeTeEn2RefersToName.page, limit: 1 }, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_2_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK as InfAppellation + appellation: InfAppellationMock.JACK as InfAppellation, }, true, - ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_APPE, - ) + ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_APPE + ), ], }, ], -} +}; // const statementOfStatementHasExactReference: GvPaginationObject = { // subfieldPages: [ // { -// req: GvFieldPageReqMock.statementOfStatementHasExactReference, +// page: GvFieldPageReqMock.statementOfStatementHasExactReference.page, // count: 1, // paginatedStatements: [ // createStatementWithTarget( @@ -449,26 +461,25 @@ const personHasTwoAppeTeEn: GvPaginationObject = { // ] // } - const definitionHasValueVersion: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.definitionHasValueVersion, + page: GvFieldPageReqMock.definitionHasValueVersion.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.DEFINITION_1_HAS_VALUE_VERSION_2, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.VALUE_VERSION_2 as InfAppellation + appellation: InfAppellationMock.VALUE_VERSION_2 as InfAppellation, }, true, - ProInfoProjRelMock.PROJ_1_STMT_DEFINITION_1_HAS_VALUE_VERSION_2, - )], - } + ProInfoProjRelMock.PROJ_1_STMT_DEFINITION_1_HAS_VALUE_VERSION_2 + ), + ], + }, ], -} - +}; export const GvPaginationObjectMock = { appeTeEnHasAppeVt, @@ -483,25 +494,19 @@ export const GvPaginationObjectMock = { personHasAppeTeEn, personHasTwoAppeTeEn, definitionHasValueVersion, -} +}; - -export function createTimeSpanSubPage(sourceEntity: number, property: NewDfhApiProperty): GvFieldPageReq { +export function createTimeSpanSubPage( + sourceEntity: number, + property: NewDfhApiProperty +): GvFieldPage { return { - pkProject: ProProjectMock.PROJECT_1.pk_entity, - targets: { - [DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class]: { - timePrimitive: TrueEnum.true - } - }, - page: { - source: {fkInfo: sourceEntity}, - property: {fkProperty: property.dfh_pk_property}, - isOutgoing: true, - // targetClass: DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class, - scope: {inProject: ProProjectMock.PROJECT_1.pk_entity as number}, - limit: 1, - offset: 0 - } - } + source: { fkInfo: sourceEntity }, + property: { fkProperty: property.dfh_pk_property }, + isOutgoing: true, + // targetClass: DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class, + scope: { inProject: ProProjectMock.PROJECT_1.pk_entity as number }, + limit: 1, + offset: 0, + }; } diff --git a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarEntityPreviewMock.ts b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarEntityPreviewMock.ts index 597563656..18d5728f2 100644 --- a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarEntityPreviewMock.ts +++ b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarEntityPreviewMock.ts @@ -1,12 +1,12 @@ -import {WarEntityPreview} from '@kleiolab/lib-sdk-lb4'; -import {CalendarType} from '../enums/CalendarType'; -import {Granularity} from '../enums/Granularity'; -import {DfhApiClassMock} from './DfhApiClassMock' -import {InfAppellationMock} from './InfAppellationMock' -import {InfLangStringMock} from './InfLangStringMock' -import {InfResourceMock} from './InfResourceMock' -import {OmitEntity} from './local-model.helpers' -import {ProProjectMock} from './ProProjectMock' +import { WarEntityPreview } from '@kleiolab/lib-sdk-lb4'; +import { CalendarType } from '../enums/CalendarType'; +import { Granularity } from '../enums/Granularity'; +import { DfhApiClassMock } from './DfhApiClassMock'; +import { InfAppellationMock } from './InfAppellationMock'; +import { InfLangStringMock } from './InfLangStringMock'; +import { InfResourceMock } from './InfResourceMock'; +import { ProProjectMock } from './ProProjectMock'; +import { OmitEntity } from './local-model.helpers'; /** * pk_entity prefix: depends on entity type. If peIt, 200, if teEn 400 @@ -14,7 +14,7 @@ import {ProProjectMock} from './ProProjectMock' export namespace WarEntityPreviewMock { export const GEO_PLACE_BASEL: OmitEntity = ({ pk_entity: 1000, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_363_GEO_PLACE.dfh_pk_class, class_label: 'Geographical Place', entity_label: 'Basel', @@ -25,7 +25,7 @@ export namespace WarEntityPreviewMock { export const BIRTH_OEKOLOMBAD: OmitEntity = ({ pk_entity: 1002, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_61_BIRTH.dfh_pk_class, class_label: 'Birth', entity_label: 'Johannes Oekolampad', @@ -41,7 +41,7 @@ export namespace WarEntityPreviewMock { export const BIRTH_ZWINGLI: OmitEntity = ({ pk_entity: 1003, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_61_BIRTH.dfh_pk_class, class_label: 'Birth', entity_label: 'Ulrich Zwingli', @@ -58,7 +58,7 @@ export namespace WarEntityPreviewMock { export const TIME_UNIT_ONE_MONTH: OmitEntity = ({ pk_entity: 2017, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_690_TIME_UNIT.dfh_pk_class, class_label: DfhApiClassMock.EN_690_TIME_UNIT.dfh_class_label, entity_label: InfLangStringMock.EN_SHORT_TITLE_MONTH.string, @@ -67,7 +67,7 @@ export namespace WarEntityPreviewMock { export const PERSON_1: OmitEntity = ({ pk_entity: 2001, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_21_PERSON.dfh_pk_class, class_label: DfhApiClassMock.EN_21_PERSON.dfh_class_label, entity_label: InfAppellationMock.JACK_THE_FOO.string, @@ -77,7 +77,7 @@ export namespace WarEntityPreviewMock { export const EXPRESSION_PORTION_HABS_EMP_CHAPTER_1: OmitEntity = ({ pk_entity: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_1.pk_entity, fk_class: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_503_EXPRESSION_PORTION.dfh_class_label, entity_label: 'Chapter 1', entity_type: 'peIt', @@ -85,7 +85,7 @@ export namespace WarEntityPreviewMock { export const EXPRESSION_PORTION_HABS_EMP_CHAPTER_2: OmitEntity = ({ pk_entity: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_2.pk_entity, fk_class: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_2.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_503_EXPRESSION_PORTION.dfh_class_label, entity_label: 'Chapter 2', entity_type: 'peIt', @@ -94,7 +94,7 @@ export namespace WarEntityPreviewMock { export const APPE_IN_LANG_TYPE_FIRST_NAME: OmitEntity = ({ pk_entity: InfResourceMock.APPE_IN_LANG_TYPE_FIRST_NAME.pk_entity, fk_class: InfResourceMock.APPE_IN_LANG_TYPE_FIRST_NAME.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_630_APPELLATION_IN_A_LANGUAGE_TYPE.dfh_class_label, entity_label: 'First Name', entity_type: 'peIt', @@ -103,7 +103,7 @@ export namespace WarEntityPreviewMock { export const APPE_IN_LANG_TYPE_LAST_NAME: OmitEntity = ({ pk_entity: InfResourceMock.APPE_IN_LANG_TYPE_LAST_NAME.pk_entity, fk_class: InfResourceMock.APPE_IN_LANG_TYPE_LAST_NAME.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_630_APPELLATION_IN_A_LANGUAGE_TYPE.dfh_class_label, entity_label: 'Last Name', entity_type: 'peIt', @@ -112,7 +112,7 @@ export namespace WarEntityPreviewMock { export const VOLUME_UNIT_CUBIC_METER: OmitEntity = ({ pk_entity: InfResourceMock.VOLUME_UNIT_CUBIC_METER.pk_entity, fk_class: InfResourceMock.VOLUME_UNIT_CUBIC_METER.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_715_VOLUME_MEASUREMENT_UNIT.dfh_class_label, entity_label: 'Cubic Meter', entity_type: 'peIt', @@ -121,7 +121,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_TYPE_CITY: OmitEntity = ({ pk_entity: InfResourceMock.GEO_PLACE_TYPE_CITY.pk_entity, fk_class: InfResourceMock.GEO_PLACE_TYPE_CITY.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_364_GEO_PLACE_TYPE.dfh_class_label, entity_label: 'City', entity_type: 'peIt', @@ -130,7 +130,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_TYPE_VILLAGE: OmitEntity = ({ pk_entity: InfResourceMock.GEO_PLACE_TYPE_VILLAGE.pk_entity, fk_class: InfResourceMock.GEO_PLACE_TYPE_VILLAGE.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_364_GEO_PLACE_TYPE.dfh_class_label, entity_label: 'Village', entity_type: 'peIt', @@ -139,7 +139,7 @@ export namespace WarEntityPreviewMock { export const NAMING_1: OmitEntity = ({ pk_entity: InfResourceMock.NAMING_1.pk_entity, fk_class: InfResourceMock.NAMING_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_365_NAMING.dfh_class_label, entity_label: 'Jack the foo', entity_type: 'teEn', @@ -148,7 +148,7 @@ export namespace WarEntityPreviewMock { export const NAMING_2: OmitEntity = ({ pk_entity: InfResourceMock.NAMING_2.pk_entity, fk_class: InfResourceMock.NAMING_2.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_365_NAMING.dfh_class_label, entity_label: 'Jack', entity_type: 'teEn', @@ -157,7 +157,7 @@ export namespace WarEntityPreviewMock { export const HABS_EMP_EXPR: OmitEntity = ({ pk_entity: InfResourceMock.HABS_EMP_EXPR.pk_entity, fk_class: InfResourceMock.HABS_EMP_EXPR.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_218_EXPRESSION.dfh_class_label, entity_label: 'Expression of Habs-Empire', entity_type: 'peIt', @@ -165,7 +165,7 @@ export namespace WarEntityPreviewMock { export const DEFINITION_1: OmitEntity = ({ pk_entity: InfResourceMock.DEFINITION_1.pk_entity, fk_class: InfResourceMock.DEFINITION_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: 'Definition', // todo: use DfhApiClassMock when available entity_label: 'This person is the famous jack the foo, invented by KleioLab and used in Geovistory mock data.', entity_type: 'peIt', @@ -174,7 +174,7 @@ export namespace WarEntityPreviewMock { export const TYPE_OF_MANIF_PROD_TYPE_BOOK: OmitEntity = ({ pk_entity: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_BOOK.pk_entity, fk_class: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_BOOK.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_452_TYPE_OF_MANIFESTATION_PRODUCT_TYPE.dfh_class_label, entity_label: 'Book', entity_type: 'peIt', @@ -182,7 +182,7 @@ export namespace WarEntityPreviewMock { export const TYPE_OF_MANIF_PROD_TYPE_JOURNAL: OmitEntity = ({ pk_entity: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_JOURNAL.pk_entity, fk_class: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_JOURNAL.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_452_TYPE_OF_MANIFESTATION_PRODUCT_TYPE.dfh_class_label, entity_label: 'Journal', entity_type: 'peIt', @@ -190,7 +190,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_ZURICH: OmitEntity = ({ pk_entity: 1001, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_363_GEO_PLACE.dfh_pk_class, class_label: 'Geographical Place', entity_label: 'Zürich', diff --git a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarFieldChangeMock.ts b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarFieldChangeMock.ts index 90b3c4858..ca110f211 100644 --- a/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarFieldChangeMock.ts +++ b/client/libs/lib-redux/src/lib/_helpers/data/auto-gen/gvDB/WarFieldChangeMock.ts @@ -10,7 +10,6 @@ export namespace WarFieldChangeMock { export const FIELD_1: OmitEntity = { fk_project: 1, fk_property: 2, - fk_property_of_property: 0, fk_source_info: 3, fk_source_tables_cell: 0, is_outgoing: true, @@ -18,8 +17,8 @@ export namespace WarFieldChangeMock { } export function toFieldId(f: OmitEntity): WarFieldChangeId { - const {fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing} = f; - return {fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing} + const {fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing} = f; + return {fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing} } } diff --git a/client/libs/lib-redux/src/lib/_helpers/mock-services/MockPaginationControllerForSandboxes.ts b/client/libs/lib-redux/src/lib/_helpers/mock-services/MockPaginationControllerForSandboxes.ts index 5a9d21178..993942d9e 100644 --- a/client/libs/lib-redux/src/lib/_helpers/mock-services/MockPaginationControllerForSandboxes.ts +++ b/client/libs/lib-redux/src/lib/_helpers/mock-services/MockPaginationControllerForSandboxes.ts @@ -1,4 +1,23 @@ -import { GvFieldPage, GvFieldPageReq, GvPaginationObject, GvSubfieldPageInfo, InfAppellation, InfDimension, InfLangString, InfLanguage, InfPlace, InfResource, InfStatement, InfTimePrimitive, ProInfoProjRel, StatementTargetDimension, StatementTargetEntity, StatementTargeTimePrimitive, StatementTargetLangString, StatementWithTarget } from '@kleiolab/lib-sdk-lb4'; +import { + GvFieldPage, + GvFieldPageReq, + GvPaginationObject, + GvSubfieldPageInfo, + InfAppellation, + InfDimension, + InfLangString, + InfLanguage, + InfPlace, + InfResource, + InfStatement, + InfTimePrimitive, + ProInfoProjRel, + StatementTargetDimension, + StatementTargetEntity, + StatementTargeTimePrimitive, + StatementTargetLangString, + StatementWithTarget, +} from '@kleiolab/lib-sdk-lb4'; import { concat, keys, mergeDeepWith, values } from 'ramda'; import { Observable, of } from 'rxjs'; import { createStatementWithTarget } from '../data/auto-gen/api-responses/GvPaginationObjectMock'; @@ -23,14 +42,15 @@ export class MockPaginationControllerForSandboxes { infTemporalEntitySerial: number; infAppellationSerial: number; infPlaceSerial: number; - infDimensionSerial: number + infDimensionSerial: number; infTimePrimitiveSerial: number; - subfieldPageControllerLoadSubfieldPages(gvLoadSubfieldPageReqs?: GvFieldPageReq[]): Observable { + subfieldPageControllerLoadSubfieldPages( + gvLoadSubfieldPageReqs?: GvFieldPageReq[] + ): Observable { this.resetIdBase(); - console.log('REST API called: subfieldPageControllerLoadSubfieldPage') - return of(this.handleRequests(gvLoadSubfieldPageReqs)) - + console.log('REST API called: subfieldPageControllerLoadSubfieldPage'); + return of(this.handleRequests(gvLoadSubfieldPageReqs)); } private resetIdBase() { this.warEntityPreviewSerial = 1000; @@ -41,22 +61,23 @@ export class MockPaginationControllerForSandboxes { this.infPlaceSerial = 7000; this.infDimensionSerial = 8000; this.infTimePrimitiveSerial = 9000; - } private increaseIdBase(amount = 100000) { this.warEntityPreviewSerial += amount; this.proInfoProjRelSerial += amount; this.infStatementSerial += amount; - this.infTemporalEntitySerial += amount + this.infTemporalEntitySerial += amount; this.infAppellationSerial += amount; this.infPlaceSerial += amount; this.infDimensionSerial += amount; this.infTimePrimitiveSerial += amount; } - handleRequests(gvLoadSubfieldPageReqs?: GvFieldPageReq[]): GvPaginationObject { - const results = gvLoadSubfieldPageReqs.map(req => this.generateData(req)) + handleRequests( + gvLoadSubfieldPageReqs?: GvFieldPageReq[] + ): GvPaginationObject { + const results = gvLoadSubfieldPageReqs.map((req) => this.generateData(req)); let result: GvPaginationObject = { subfieldPages: [] }; for (const obj of results) { result = mergeDeepWith(concat, result, obj); @@ -65,415 +86,455 @@ export class MockPaginationControllerForSandboxes { } generateData(gvLoadSubfieldPageReq?: GvFieldPageReq): GvPaginationObject { - // generate response with emtpy field for some properties - if ([1842, 1499, 1429, 133, 188, 1344, 1409].includes(gvLoadSubfieldPageReq?.page?.property.fkProperty)) { - return this.generateEmptyField(gvLoadSubfieldPageReq) + if ( + [1842, 1499, 1429, 133, 188, 1344, 1409].includes( + gvLoadSubfieldPageReq?.page?.property.fkProperty + ) + ) { + return this.generateEmptyField(gvLoadSubfieldPageReq.page); } if (values(gvLoadSubfieldPageReq.targets)[0].appellation) { - return this.generateDataForAppe(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].place) { - return this.generateDataForPlace(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].dimension) { - return this.generateDataForDimension(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].langString) { - return this.generateDataForLangString(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].language) { - return this.generateDataForLanguage(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].nestedResource) { + return this.generateDataForAppe(gvLoadSubfieldPageReq.page); + } else if (values(gvLoadSubfieldPageReq.targets)[0].place) { + return this.generateDataForPlace(gvLoadSubfieldPageReq.page); + } else if (values(gvLoadSubfieldPageReq.targets)[0].dimension) { + return this.generateDataForDimension(gvLoadSubfieldPageReq.page); + } else if (values(gvLoadSubfieldPageReq.targets)[0].langString) { + return this.generateDataForLangString(gvLoadSubfieldPageReq.page); + } else if (values(gvLoadSubfieldPageReq.targets)[0].language) { + return this.generateDataForLanguage(gvLoadSubfieldPageReq.page); + } else if (values(gvLoadSubfieldPageReq.targets)[0].nestedResource) { return this.generateDataForEntity(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].entityPreview) { + } else if (values(gvLoadSubfieldPageReq.targets)[0].entityPreview) { return this.generateDataForEntity(gvLoadSubfieldPageReq); - } - else if (values(gvLoadSubfieldPageReq.targets)[0].timePrimitive) { - return this.generateDataForTimePrimitive(gvLoadSubfieldPageReq); + } else if (values(gvLoadSubfieldPageReq.targets)[0].timePrimitive) { + return this.generateDataForTimePrimitive(gvLoadSubfieldPageReq.page); } throw new Error('mock not implemented for this request'); - } - - generateEmptyField(req: GvFieldPageReq) { + generateEmptyField(page: GvFieldPage) { const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: 0, - paginatedStatements: [] - } - ] - } - return paginationObject + paginatedStatements: [], + }, + ], + }; + return paginationObject; } - generateDataForAppe(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForAppe(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] + const paginatedStatements: StatementWithTarget[] = []; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const appellation: OmitEntity = { pk_entity: this.infAppellationSerial + i, fk_class: DfhApiClassMock.EN_40_APPELLATION.dfh_pk_class, string: 'Jack the foo ' + (this.infAppellationSerial + i), - } + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, fk_property: DfhApiPropertyMock.EN_1113_REFERS_TO_NAME.dfh_pk_property, fk_object_info: appellation.pk_entity, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } + is_in_project: true, + }; paginatedStatements.push( - createStatementWithTarget(statement, 1, { appellation }, page.isOutgoing, projRel) - ) + createStatementWithTarget( + statement, + 1, + { appellation }, + page.isOutgoing, + projRel + ) + ); } const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } - ] - } - return paginationObject + paginatedStatements, + }, + ], + }; + return paginationObject; } - - generateDataForPlace(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForPlace(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] - const statements: OmitEntity[] = [] - const places: OmitEntity[] = [] + const paginatedStatements: StatementWithTarget[] = []; + const statements: OmitEntity[] = []; + const places: OmitEntity[] = []; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const place: OmitEntity = { pk_entity: this.infPlaceSerial + i, fk_class: DfhApiClassMock.EN_51_PLACE.dfh_pk_class, lat: i + 1, - long: 47.1221 - } - places.push(place) + long: 47.1221, + }; + places.push(place); const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, fk_property: DfhApiPropertyMock.EN_148_WAS_AT.dfh_pk_property, fk_object_info: place.pk_entity, - } - statements.push(statement) + }; + statements.push(statement); const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { place }, page.isOutgoing, projRel)) + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { place }, + page.isOutgoing, + projRel + ) + ); } - const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } - ] - } - return paginationObject + paginatedStatements, + }, + ], + }; + return paginationObject; } - - generateDataForTimePrimitive(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForTimePrimitive(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] - function isOdd(num: number) { return num % 2; } - for (let i = offset; i < (offset + limit); i++) { - const tp = isOdd(i) ? InfTimePrimitiveMock.TP_1 : InfTimePrimitiveMock.TP_2; + const paginatedStatements: StatementWithTarget[] = []; + function isOdd(num: number) { + return num % 2; + } + for (let i = offset; i < offset + limit; i++) { + const tp = isOdd(i) + ? InfTimePrimitiveMock.TP_1 + : InfTimePrimitiveMock.TP_2; const infTimePrimitive: OmitEntity = { ...tp, pk_entity: this.infTimePrimitiveSerial + i, - - } + }; const timePrimitive: StatementTargeTimePrimitive = { infTimePrimitive, timePrimitive: { julianDay: infTimePrimitive.julian_day, duration: infTimePrimitive.duration, - calendar: CalendarType.gregorian - } - } + calendar: CalendarType.gregorian, + }, + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, fk_property: page.property.fkProperty, fk_object_info: infTimePrimitive.pk_entity, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { timePrimitive }, page.isOutgoing, projRel)) + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { timePrimitive }, + page.isOutgoing, + projRel + ) + ); } - const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } - ] - } - return paginationObject + paginatedStatements, + }, + ], + }; + return paginationObject; } - generateDataForDimension(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForDimension(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] - + const paginatedStatements: StatementWithTarget[] = []; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const infDimension: OmitEntity = { pk_entity: this.infDimensionSerial + i, fk_class: DfhApiClassMock.EN_689_DURATION.dfh_pk_class, numeric_value: i + 1, - fk_measurement_unit: InfResourceMock.TIME_UNIT_MONTH.pk_entity - } + fk_measurement_unit: InfResourceMock.TIME_UNIT_MONTH.pk_entity, + }; const dimension: StatementTargetDimension = { dimension: infDimension, - } + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, fk_property: DfhApiPropertyMock.EN_1613_HAS_DURATION.dfh_pk_property, fk_object_info: infDimension.pk_entity, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { dimension }, page.isOutgoing, projRel)) + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { dimension }, + page.isOutgoing, + projRel + ) + ); } - const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } - ] - } - return paginationObject + paginatedStatements, + }, + ], + }; + return paginationObject; } - generateDataForLangString(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForLangString(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] + const paginatedStatements: StatementWithTarget[] = []; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const infLangString: OmitEntity = { pk_entity: 9000 + i, fk_class: DfhApiClassMock.EN_689_DURATION.dfh_pk_class, fk_language: InfLanguageMock.ENGLISH.pk_entity, - string: `«The Murderer» ${i + 1}` - } + string: `«The Murderer» ${i + 1}`, + }; const langString: StatementTargetLangString = { langString: infLangString, - language: InfLanguageMock.ENGLISH - } + language: InfLanguageMock.ENGLISH, + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, - fk_property: DfhApiPropertyMock.EN_1761_MANIFESTATION_SINGLETON_HAS_SHORT_TITLE.dfh_pk_property, + fk_property: + DfhApiPropertyMock.EN_1761_MANIFESTATION_SINGLETON_HAS_SHORT_TITLE + .dfh_pk_property, fk_object_info: infLangString.pk_entity, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { langString }, page.isOutgoing, projRel)) + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { langString }, + page.isOutgoing, + projRel + ) + ); } - const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } + paginatedStatements, + }, ], - - } - return paginationObject + }; + return paginationObject; } - generateDataForLanguage(req: GvFieldPageReq): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForLanguage(page: GvFieldPage): GvPaginationObject { + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] + const paginatedStatements: StatementWithTarget[] = []; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const language: OmitEntity = { pk_entity: 99000 + i, fk_class: DfhApiClassMock.EN_54_LANGUAGE.dfh_pk_class, notes: `Language ${i + 1}`, - iso6391: `L${i + 1}` - } + iso6391: `L${i + 1}`, + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: page.source.fkInfo, - fk_property: DfhApiPropertyMock.EN_1112_USED_IN_LANGUAGE.dfh_pk_property, + fk_property: + DfhApiPropertyMock.EN_1112_USED_IN_LANGUAGE.dfh_pk_property, fk_object_info: language.pk_entity, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { language }, page.isOutgoing, projRel)) + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { language }, + page.isOutgoing, + projRel + ) + ); } - const paginationObject: GvPaginationObject = { subfieldPages: [ { - req, + page, count: count, - paginatedStatements - } - ] - } - return paginationObject + paginatedStatements, + }, + ], + }; + return paginationObject; } - - generateDataForEntity( - req: GvFieldPageReq, - ): GvPaginationObject { - const page = req.page - const limit = page.limit - const offset = page.offset + generateDataForEntity(req: GvFieldPageReq): GvPaginationObject { + const page = req.page; + const limit = page.limit; + const offset = page.offset; const count = 46; - const paginatedStatements: StatementWithTarget[] = [] + const paginatedStatements: StatementWithTarget[] = []; const subfieldPages: GvSubfieldPageInfo[] = [ { - req, + page, count: count, - paginatedStatements - } - ] + paginatedStatements, + }, + ]; - let paginationObject: GvPaginationObject = { subfieldPages } + let paginationObject: GvPaginationObject = { subfieldPages }; - for (let i = offset; i < (offset + limit); i++) { + for (let i = offset; i < offset + limit; i++) { const resource: OmitEntity = { pk_entity: this.infTemporalEntitySerial + i, - fk_class: parseInt(keys(req.targets)[0].toString()) + fk_class: parseInt(keys(req.targets)[0].toString()), // fk_class: DfhApiClassMock.EN_365_NAMING.dfh_pk_class, - } + }; const entity: StatementTargetEntity = { resource: resource, entityPreview: { ...resource, - project_id: ProProjectMock.PROJECT_1.pk_entity, - entity_label: 'Label of entity ' + resource.pk_entity - } - } + fk_project: ProProjectMock.PROJECT_1.pk_entity, + entity_label: 'Label of entity ' + resource.pk_entity, + }, + }; const statement: OmitEntity = { pk_entity: this.infStatementSerial + i, fk_subject_info: resource.pk_entity, - fk_property: req.page.property.fkProperty, + fk_property: page.property.fkProperty, // fk_property: DfhApiPropertyMock.EN_1111_IS_APPE_OF_PERSON.dfh_pk_property, fk_object_info: page.source.fkInfo, - } + }; const projRel: OmitEntity = { pk_entity: this.proInfoProjRelSerial + i, fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_entity: statement.pk_entity, fk_last_modifier: PubAccountMock.GAETAN_VERIFIED.id, - is_in_project: true - } - paginatedStatements.push(createStatementWithTarget(statement, 1, { entity }, page.isOutgoing, projRel)) - - + is_in_project: true, + }; + paginatedStatements.push( + createStatementWithTarget( + statement, + 1, + { entity }, + page.isOutgoing, + projRel + ) + ); } // Do the subfields - for (const resource of paginatedStatements.filter(s => s.target.entity).map(s => s.target.entity.resource)) { - const nestedResource = req.targets[resource.fk_class]?.nestedResource ?? [] + for (const resource of paginatedStatements + .filter((s) => s.target.entity) + .map((s) => s.target.entity.resource)) { + const nestedResource = + req.targets[resource.fk_class]?.nestedResource ?? []; for (const teEnSubfield of nestedResource) { // increase the id base for subfields - this.increaseIdBase(100000 + offset) + this.increaseIdBase(100000 + offset); const p: GvFieldPage = { ...teEnSubfield.page, source: { fkInfo: resource.pk_entity }, - scope: page.scope - } + scope: page.scope, + }; const subReq: GvFieldPageReq = { pkProject: req.pkProject, page: p, - targets: teEnSubfield.targets - } - const subPagObject = this.generateData(subReq) - paginationObject = mergeDeepWith(concat, paginationObject, subPagObject) + targets: teEnSubfield.targets, + }; + const subPagObject = this.generateData(subReq); + paginationObject = mergeDeepWith( + concat, + paginationObject, + subPagObject + ); } } - return paginationObject + return paginationObject; } - } diff --git a/client/libs/lib-redux/src/lib/redux-store/data/data.effects.ts b/client/libs/lib-redux/src/lib/redux-store/data/data.effects.ts index 24752bffc..5dc6a0586 100644 --- a/client/libs/lib-redux/src/lib/redux-store/data/data.effects.ts +++ b/client/libs/lib-redux/src/lib/redux-store/data/data.effects.ts @@ -5,20 +5,30 @@ import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects'; import { Store } from '@ngrx/store'; import { FluxStandardAction } from 'flux-standard-action'; import { of } from 'rxjs'; -import { catchError, filter, map, mergeMap, startWith, tap } from 'rxjs/operators'; +import { + catchError, + filter, + map, + mergeMap, + startWith, + tap, +} from 'rxjs/operators'; import { StateFacade } from '../state.facade'; import { IAppState } from '../state.model'; import { getActiveProjectId } from '../ui/active-project/active-project.selectors'; import { LoadingBarActions } from '../ui/loading-bar/loading-bar.actions'; import { notificationActions } from '../ui/notification/notification.actions'; -import { paginationObjectActions, schemaModifierActions, schemaObjectActions } from './data.actions'; +import { + paginationObjectActions, + schemaModifierActions, + schemaObjectActions, +} from './data.actions'; import { paginationActions } from './inf/statement/pagination/pagination.actions'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class DataEffects { - constructor( private actions$: Actions>, private store: Store, @@ -32,105 +42,133 @@ export class DataEffects { * - on success it stores the GvSchemaObject * - else it toasts an error message */ - loadSchemaObject$ = createEffect(() => this.actions$.pipe( - ofType(schemaObjectActions.load), - mergeMap((action) => action.payload.pipe( - mergeMap(data => of( - schemaModifierActions.succeeded({ payload: { positive: data } }), - LoadingBarActions.REMOVE_JOB() - )), - catchError((error: HttpErrorResponse) => of(...this.errorActions(error))), - startWith(LoadingBarActions.ADD_JOB()), - )) - )) + loadSchemaObject$ = createEffect(() => + this.actions$.pipe( + ofType(schemaObjectActions.load), + mergeMap((action) => + action.payload.pipe( + mergeMap((data) => + of( + schemaModifierActions.succeeded({ payload: { positive: data } }), + LoadingBarActions.REMOVE_JOB() + ) + ), + catchError((error: HttpErrorResponse) => + of(...this.errorActions(error)) + ), + startWith(LoadingBarActions.ADD_JOB()) + ) + ) + ) + ); /** * Epic for loading GvSchemaModifiers * - it subscribes to the given observable (payload), which usually triggers a REST API call * - on success it stores the GvSchemaObject * - else it toasts an error message */ - loadSchemaModifier$ = createEffect(() => this.actions$.pipe( - ofType(schemaModifierActions.load), - mergeMap((action) => action.payload.pipe( - mergeMap(data => of( - schemaModifierActions.succeeded({ payload: data }), - LoadingBarActions.REMOVE_JOB() - )), - catchError((error: HttpErrorResponse) => of(...this.errorActions(error))), - startWith(LoadingBarActions.ADD_JOB()), - )) - )) + loadSchemaModifier$ = createEffect(() => + this.actions$.pipe( + ofType(schemaModifierActions.load), + mergeMap((action) => + action.payload.pipe( + mergeMap((data) => + of( + schemaModifierActions.succeeded({ payload: data }), + LoadingBarActions.REMOVE_JOB() + ) + ), + catchError((error: HttpErrorResponse) => + of(...this.errorActions(error)) + ), + startWith(LoadingBarActions.ADD_JOB()) + ) + ) + ) + ); /** - * Epic for loading GvSchemaModifiers - * - it subscribes to the given observable (payload), which usually triggers a REST API call - * - on success it stores the GvSchemaObject - * - else it toasts an error message - */ - loadSchemaModifierWithMapper$ = createEffect(() => this.actions$.pipe( - ofType(schemaModifierActions.loadWithMapper), - mergeMap((action) => action.data$.pipe( - mergeMap(data => { - const schemaModifier = action.mapper(data); - return of( - schemaModifierActions.succeeded({ payload: schemaModifier }), - LoadingBarActions.REMOVE_JOB() + * Epic for loading GvSchemaModifiers + * - it subscribes to the given observable (payload), which usually triggers a REST API call + * - on success it stores the GvSchemaObject + * - else it toasts an error message + */ + loadSchemaModifierWithMapper$ = createEffect(() => + this.actions$.pipe( + ofType(schemaModifierActions.loadWithMapper), + mergeMap((action) => + action.data$.pipe( + mergeMap((data) => { + const schemaModifier = action.mapper(data); + return of( + schemaModifierActions.succeeded({ payload: schemaModifier }), + LoadingBarActions.REMOVE_JOB() + ); + }), + catchError((error: HttpErrorResponse) => + of(...this.errorActions(error)) + ), + startWith(LoadingBarActions.ADD_JOB()) ) - }), - catchError((error: HttpErrorResponse) => of(...this.errorActions(error))), - startWith(LoadingBarActions.ADD_JOB()), - )) - )) - + ) + ) + ); /** - * Epic for loading GvPaginationObjects - * - it subscribes to the given observable (payload), which usually triggers a REST API call - * - on success it stores the GvPaginationObject - * - else it toasts an error message - */ - loadPaginationObject$ = createEffect(() => this.actions$.pipe( - ofType(paginationObjectActions.load), - mergeMap((action) => action.payload.pipe( - concatLatestFrom(() => this.store.select(getActiveProjectId)), - mergeMap(([data, pkProject]) => { - const pages = data.subfieldPages.map(p => ({ statements: p.paginatedStatements, count: p.count, page: p.req.page, pk: pkProject })) - const pagesLoadedAction = paginationActions.loadPagesSucceeded({ pages }) - return of( - pagesLoadedAction, - LoadingBarActions.REMOVE_JOB() + * Epic for loading GvPaginationObjects + * - it subscribes to the given observable (payload), which usually triggers a REST API call + * - on success it stores the GvPaginationObject + * - else it toasts an error message + */ + loadPaginationObject$ = createEffect(() => + this.actions$.pipe( + ofType(paginationObjectActions.load), + mergeMap((action) => + action.payload.pipe( + concatLatestFrom(() => this.store.select(getActiveProjectId)), + mergeMap(([data, pkProject]) => { + const pages = data.subfieldPages.map((p) => ({ + statements: p.paginatedStatements, + count: p.count, + page: p.page, + pk: pkProject, + })); + const pagesLoadedAction = paginationActions.loadPagesSucceeded({ + pages, + }); + return of(pagesLoadedAction, LoadingBarActions.REMOVE_JOB()); + }), + catchError((error: HttpErrorResponse) => + of(...this.errorActions(error)) + ), + startWith(LoadingBarActions.ADD_JOB()) ) - }), - catchError((error: HttpErrorResponse) => of(...this.errorActions(error))), - startWith(LoadingBarActions.ADD_JOB()), - )) - )) - - + ) + ) + ); /** * Epic for extending stream of entity previews when new entity previews are * successfully loaded into the store */ extendEntityPreviewStream$ = createEffect( - () => this.actions$.pipe( - ofType(schemaModifierActions.succeeded), - map(a => a.payload?.positive?.war?.entity_preview), - filter(items => !!items?.length), - concatLatestFrom(() => this.facade.ui.activeProject.projectId$), - tap(([entityPreviews, pkProject]) => { - this.entityPreviewSocket.emit('extendStream', { - pkProject, - pks: entityPreviews.map(p => p.project_id + '_' + p.pk_entity) + () => + this.actions$.pipe( + ofType(schemaModifierActions.succeeded), + map((a) => a.payload?.positive?.war?.entity_preview), + filter((items) => !!items?.length), + concatLatestFrom(() => this.facade.ui.activeProject.projectId$), + tap(([entityPreviews, pkProject]) => { + this.entityPreviewSocket.emit('extendStream', { + pkProject, + pks: entityPreviews.map((p) => p.fk_project + '_' + p.pk_entity), + }); }) - }), - - ), + ), { dispatch: false, } - ) - + ); errorActions(error: HttpErrorResponse) { return [ @@ -140,12 +178,10 @@ export class DataEffects { type: 'error', options: { title: error.name, - msg: error.message - } - } - }) - ] + msg: error.message, + }, + }, + }), + ]; } - } - diff --git a/client/libs/lib-redux/src/lib/redux-store/data/war/entity_preview/war-entity-preview.reducer.ts b/client/libs/lib-redux/src/lib/redux-store/data/war/entity_preview/war-entity-preview.reducer.ts index 1142ef8e1..0d0cd84b3 100644 --- a/client/libs/lib-redux/src/lib/redux-store/data/war/entity_preview/war-entity-preview.reducer.ts +++ b/client/libs/lib-redux/src/lib/redux-store/data/war/entity_preview/war-entity-preview.reducer.ts @@ -6,7 +6,7 @@ export const warEntityPreviewFeature = 'entity_preview' export const warEntityPreviewReducerConfig: ReducerConfig = { indexBy: { keyInStore: 'project_id__pk_entity', - indexByFn: (item: WarEntityPreview) => item.project_id + '_' + item.pk_entity + indexByFn: (item: WarEntityPreview) => item.fk_project + '_' + item.pk_entity } } diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/.openapi-generator/FILES b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/.openapi-generator/FILES index cb0a7201e..da8809ba4 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/.openapi-generator/FILES +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/.openapi-generator/FILES @@ -156,6 +156,7 @@ model/proTableConfig.ts model/proTextProperty.ts model/profileActivationReport.ts model/profileDeactivationReport.ts +model/projectClassConfig.ts model/projectPongRequest.ts model/projectVisibilityOptions.ts model/pubAccount.ts diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/account.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/account.service.ts index cecf6ac29..6bec13eb3 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/account.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/account.service.ts @@ -35,7 +35,7 @@ import { Configuration } from '../configurat }) export class AccountService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/accountData.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/accountData.service.ts index af13868bf..4509bfe9a 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/accountData.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/accountData.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class AccountDataService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/analysis.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/analysis.service.ts index 556edbbb3..9f3ce47bf 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/analysis.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/analysis.service.ts @@ -39,7 +39,7 @@ import { Configuration } from '../configurat }) export class AnalysisService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/backoffice.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/backoffice.service.ts index e1bed1f52..1fc951843 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/backoffice.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/backoffice.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class BackofficeService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/communityVisibility.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/communityVisibility.service.ts index 8e73d028a..8736dee6e 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/communityVisibility.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/communityVisibility.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class CommunityVisibilityService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/contentTree.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/contentTree.service.ts index a08417042..1d4e3a6c2 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/contentTree.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/contentTree.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class ContentTreeService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/datChunkController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/datChunkController.service.ts index 3a3e511d4..e522abe4e 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/datChunkController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/datChunkController.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class DatChunkControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/dataModel.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/dataModel.service.ts index 4571672d9..90159b8ee 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/dataModel.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/dataModel.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class DataModelService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/factoidController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/factoidController.service.ts index 7d611f3da..3fe98b4b8 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/factoidController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/factoidController.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class FactoidControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/importTableController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/importTableController.service.ts index fae79c78a..1b076fff4 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/importTableController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/importTableController.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class ImportTableControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/languages.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/languages.service.ts index 22d411069..2d0906b66 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/languages.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/languages.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class LanguagesService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ontoMeController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ontoMeController.service.ts index 1ecfb8b8c..ee2593c4e 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ontoMeController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ontoMeController.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class OntoMeControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/pingController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/pingController.service.ts index d0c47c734..44260a009 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/pingController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/pingController.service.ts @@ -21,6 +21,7 @@ import { ClassConfig } from '../model/models'; import { CommunityVisibilityOptionsWithRelations } from '../model/models'; import { GvFieldTargetViewType } from '../model/models'; import { PingResponse } from '../model/models'; +import { ProjectClassConfig } from '../model/models'; import { ProjectPongRequest } from '../model/models'; import { ProjectVisibilityOptions } from '../model/models'; import { PubRoleMapping } from '../model/models'; @@ -40,7 +41,7 @@ import { Configuration } from '../configurat }) export class PingControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; @@ -449,6 +450,54 @@ export class PingControllerService { ); } + /** + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public pingControllerXProjectClassConfig(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable; + public pingControllerXProjectClassConfig(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable>; + public pingControllerXProjectClassConfig(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json'}): Observable>; + public pingControllerXProjectClassConfig(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json'}): Observable { + + let headers = this.defaultHeaders; + + let credential: string | undefined; + // authentication (jwt) required + credential = this.configuration.lookupCredential('jwt'); + if (credential) { + headers = headers.set('Authorization', 'Bearer ' + credential); + } + + let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (httpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); + } + + + let responseType: 'text' | 'json' = 'json'; + if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) { + responseType = 'text'; + } + + return this.httpClient.post(`${this.configuration.basePath}/ProjectClassConfig`, + null, + { + responseType: responseType, + withCredentials: this.configuration.withCredentials, + headers: headers, + observe: observe, + reportProgress: reportProgress + } + ); + } + /** * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectConfiguration.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectConfiguration.service.ts index f28139916..d4f64605a 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectConfiguration.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectConfiguration.service.ts @@ -35,7 +35,7 @@ import { Configuration } from '../configurat }) export class ProjectConfigurationService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectData.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectData.service.ts index 0e08f30b1..91210db39 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectData.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/projectData.service.ts @@ -36,7 +36,7 @@ import { Configuration } from '../configurat }) export class ProjectDataService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ramList.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ramList.service.ts index 717c6fefb..0dd4e43d8 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ramList.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/ramList.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class RamListService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/subfieldPageController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/subfieldPageController.service.ts index bf71ead6b..655c969d0 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/subfieldPageController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/subfieldPageController.service.ts @@ -30,7 +30,7 @@ import { Configuration } from '../configurat }) export class SubfieldPageControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemConfiguration.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemConfiguration.service.ts index 3bacf5754..b162fd8a3 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemConfiguration.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemConfiguration.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class SystemConfigurationService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemTypes.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemTypes.service.ts index 000c9edd0..ea721d91c 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemTypes.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/systemTypes.service.ts @@ -29,7 +29,7 @@ import { Configuration } from '../configurat }) export class SystemTypesService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/table.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/table.service.ts index 87014a02f..3ce2bf3a1 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/table.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/table.service.ts @@ -40,7 +40,7 @@ import { Configuration } from '../configurat }) export class TableService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/warEntityPreviewController.service.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/warEntityPreviewController.service.ts index 11e622800..2f0581ff7 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/warEntityPreviewController.service.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/api/warEntityPreviewController.service.ts @@ -32,7 +32,7 @@ import { Configuration } from '../configurat }) export class WarEntityPreviewControllerService { - protected basePath = 'http://0.0.0.0:3000'; + protected basePath = 'http://localhost:3000'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); public encoder: HttpParameterCodec; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/entitySearchHit.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/entitySearchHit.ts index 3309eb879..fa33c21d7 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/entitySearchHit.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/entitySearchHit.ts @@ -14,9 +14,8 @@ import { WarEntityPreviewTimeSpan } from './warEntityPreviewTimeSpan'; export interface EntitySearchHit { - key?: string; pk_entity?: number; - project_id: number; + fk_project: number; fk_class: number; class_label?: string; entity_label?: string; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/gvSubfieldPageInfo.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/gvSubfieldPageInfo.ts index 6fec56491..ad219f107 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/gvSubfieldPageInfo.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/gvSubfieldPageInfo.ts @@ -3,20 +3,18 @@ * Geovistory – Platform for Digital History * * The version of the OpenAPI document: 1.0.0 - * + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ +import { GvFieldPage } from './gvFieldPage'; import { StatementWithTarget } from './statementWithTarget'; -import { GvFieldPageReq } from './gvFieldPageReq'; - -export interface GvSubfieldPageInfo { - req: GvFieldPageReq; - count: number; - paginatedStatements: Array; - validFor?: string; +export interface GvSubfieldPageInfo { + page: GvFieldPage; + count: number; + paginatedStatements: Array; + validFor?: string; } - diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/models.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/models.ts index 6494f5429..63735bb9c 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/models.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/models.ts @@ -125,6 +125,7 @@ export * from './proTableConfig'; export * from './proTextProperty'; export * from './profileActivationReport'; export * from './profileDeactivationReport'; +export * from './projectClassConfig'; export * from './projectPongRequest'; export * from './projectVisibilityOptions'; export * from './pubAccount'; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/projectClassConfig.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/projectClassConfig.ts new file mode 100644 index 000000000..0c23509c4 --- /dev/null +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/projectClassConfig.ts @@ -0,0 +1,20 @@ +/** + * geovistory + * Geovistory – Platform for Digital History + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { CommunityVisibilityOptions } from './communityVisibilityOptions'; +import { ProjectVisibilityOptions } from './projectVisibilityOptions'; + + +export interface ProjectClassConfig { + communityVisibilityDefault?: CommunityVisibilityOptions; + projectVisibilityDefault?: ProjectVisibilityOptions; +} + diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreview.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreview.ts index 2b1257f2e..279af836f 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreview.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreview.ts @@ -13,9 +13,8 @@ import { WarEntityPreviewTimeSpan } from './warEntityPreviewTimeSpan'; export interface WarEntityPreview { - key?: string; pk_entity?: number; - project_id: number; + fk_project: number; fk_class: number; class_label?: string; entity_label?: string; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreviewWithFulltext.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreviewWithFulltext.ts index d540a687e..26d54db9a 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreviewWithFulltext.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warEntityPreviewWithFulltext.ts @@ -13,9 +13,8 @@ import { WarEntityPreviewTimeSpan } from './warEntityPreviewTimeSpan'; export interface WarEntityPreviewWithFulltext { - key?: string; pk_entity?: number; - project_id: number; + fk_project: number; fk_class: number; class_label?: string; entity_label?: string; diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChange.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChange.ts index eed6276e6..4da3167de 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChange.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChange.ts @@ -16,7 +16,6 @@ export interface WarFieldChange { fk_source_info: number; fk_source_tables_cell: number; fk_property: number; - fk_property_of_property: number; is_outgoing: boolean; tmsp_last_modification: string; } diff --git a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChangeId.ts b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChangeId.ts index e1b95524b..dc52f5341 100644 --- a/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChangeId.ts +++ b/client/libs/lib-sdk-lb4/src/lib/sdk-lb4/model/warFieldChangeId.ts @@ -16,7 +16,6 @@ export interface WarFieldChangeId { fk_source_info: number; fk_source_tables_cell: number; fk_property: number; - fk_property_of_property: number; is_outgoing: boolean; } diff --git a/database/.env.example b/database/.env.example new file mode 100644 index 000000000..5b45d81b8 --- /dev/null +++ b/database/.env.example @@ -0,0 +1,8 @@ +# postgres port used when running bash dev.sh +POSTGRES_PORT_DEV=15432 + +# postgres port used when running bash dev.sh +POSTGRES_PORT_TEST=25432 + +# Set it to "ARM" on Apple Computers with Silicon chip (M1+) +DOCKER_PLATFORM=ARM \ No newline at end of file diff --git a/database/.gitattributes b/database/.gitattributes new file mode 100644 index 000000000..07764a78d --- /dev/null +++ b/database/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/database/.gitignore b/database/.gitignore new file mode 100644 index 000000000..582390bd1 --- /dev/null +++ b/database/.gitignore @@ -0,0 +1,3 @@ +/logs/postgres/**.log + +.env \ No newline at end of file diff --git a/database/README.md b/database/README.md new file mode 100644 index 000000000..b689c8b45 --- /dev/null +++ b/database/README.md @@ -0,0 +1,151 @@ +# Database + +This folder contains all code to develop and test the postgres database of geovistory. + + +## Start a Dev-DB + +To start a local DB for development, do the following steps. + +### Prepare env + +First Copy `.env.example` to `.env` and adjust the `POSTGRES_PORT_DEV` in case you have already a process listinging on this port. + +On Mac M1+ set `DOCKER_PLATFORM=ARM`. + +### Login to ghcr.io + +In order to access the docker image with the dev-database you need to login with a user that has permissions to pull the image. Since the database in this image may contain sensible data, we cannot share the image publicly. + +[Login to ghcr.io](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic). + + +### Start docker container + +```bash +bash dev.sh +``` + +This should do the following: +- pull the docker image with a development database +- start postgres +- run the db migrations +- expose postgres on the port specified in `POSTGRES_PORT_DEV` + +Then you can connect with the server to this port, as specified in `/server/.env`. + +### Start the cron jobs + +This schedules the cron jobs that periodically update pgwar tables. + +```bash +bash pgwar-start-cron-jobs.sh +``` + + +## Add a database migration + +Whenever you modify the database schema, create a migration file. + +```bash +# Change into server directory +cd ../server +# Install node modules (if not yet done) +npm i +# create .env (if not yet done) +cp .env.example .env +# create migration +npm run db:cm name-of-migration +# this will create a *-up.sql and a *-down.sql +# - in *-up.sql, add your modifications +# - in *-down.sql, revert your modifications +``` + +If the create migration command fails with these errors +``` +/home/username/toolbox/server/db-migrate/create.sh: 2: Bad substitution + +/home/username/toolbox/toolbox/server/db-migrate/create.sh: 6: [[: not found + +/home/username/toolbox/server/db-migrate/create.sh: 6: ==: not found + +/home/username/toolbox/server/db-migrate/create.sh: 6: ==: not found +/home/username/toolbox/server/db-migrate/create.sh: 11: +Syntax error: redirection unexpected +``` + +it could mean your bash interpreter is not "/bin/bash" but another one, like "dash" which come in distributions like Ubuntu. +To solve the issue, check first what really is your interpreter with: +```bash +ls -l /bin/sh +``` +If the output gives a similar result to +``` +lrwxrwxrwx 1 root root 4 May 1 2023 /bin/sh -> dash +``` +then you should remove this symlink and create a new one pointing to the correct bash interpreter + +```bash +sudo rm /bin/sh +sudo ln -s /bin/bash /bin/sh +``` +Now the migration creation script should work properly + +## Write tests + +Add pgTap files ending on .sql to one of these folders: + +```bash +test/ +├── integration/ # test collaboration of multiple triggers/functions +├── performance/ # test performance e.g. with perform_ok() or perform_within() +├── units/ + ├── functions/ # test a single function + ├── triggers/ # test a single trigger +``` + +## Testing + +### Prepare env + +First Copy `.env.example` to `.env` and adjust the `POSTGRES_PORT_TEST` in case you have already a process listinging on this port. + +### Run tests + +On Linux / Mac + +```bash +# To run unit tests: +bash ./test.sh -u +# To run integration tests: +bash ./test.sh -i +# To run performance tests: +bash ./test.sh -p +# To run any combination of tests, combine the flags. For example, to run both unit and integration tests: +bash ./test.sh -u -i +# To run all tests: +bash ./test.sh -u -i -p +``` + +On Windows + +```powershell +# To run unit tests: +call ./test.bat -u +# To run integration tests: +call ./test.bat -i +# To run performance tests: +call ./test.bat -p +# To run any combination of tests, combine the flags. For example, to run both unit and integration tests: +call ./test.bat -u -i +# To run all tests: +call ./test.bat -u -i -p +``` + +## Setup CI + +To setup CI, just run this command: + +```bash +bash ./test.sh -u -i -p +``` diff --git a/database/dev.sh b/database/dev.sh new file mode 100644 index 000000000..a41341686 --- /dev/null +++ b/database/dev.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Load environment variables from .env file +if [ -f .env ]; then + export $(grep -v '^#' .env | xargs) +fi + +# set the name of the docker compose project +export COMPOSE_PROJECT_NAME=dev + +# Set the heavy Dockerfile (containing a filled database) +if [ "$DOCKER_PLATFORM" = "ARM" ]; then + export DOCKER_FILE=heavy.arm.Dockerfile +else + export DOCKER_FILE=dev.Dockerfile +fi + +# Set the postgres port +export POSTGRES_PORT=$POSTGRES_PORT_DEV + +# Shut down dev container +docker compose down -v + +# Create dev container +docker compose up -d --wait --build + +# Ensure filled_db is ready +docker exec $COMPOSE_PROJECT_NAME-postgres-1 sh -c 'until psql -U postgres -d filled_db -c "SELECT 1"; do echo "Waiting for PostgreSQL..."; sleep 0.5; done' + +# Migrate databases based on test types +docker exec $COMPOSE_PROJECT_NAME-postgres-1 sh -c "scripts/migrate_up_filled_db.sh" diff --git a/database/docker-compose.yaml b/database/docker-compose.yaml new file mode 100644 index 000000000..b2de173a2 --- /dev/null +++ b/database/docker-compose.yaml @@ -0,0 +1,54 @@ +# See https://docs.redpanda.com/current/get-started/quick-start/ + +volumes: + postgis-logs: + driver: local + driver_opts: + type: none + device: ./logs/postgres + o: bind + # postgis-data: null + test: + driver: local + driver_opts: + type: none + device: ./test + o: bind + migrations: + driver: local + driver_opts: + type: none + device: ./migrations + o: bind + +services: + # Postgres Database Server with + # access postgres from host machine: postgres://postgres:local_pw@{DOCKER_IP}:${DOCKER_PG_HOST_PORT} + postgres: + build: + context: ./postgres + dockerfile: ${DOCKER_FILE} + shm_size: 1g + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: pw + POSTGRES_SCHEMA_ONLY_DB: schema_only_db + POSTGRES_FILLED_DB: filled_db + POSTGRES_CRON_DB: postgres + command: 'postgres -c wal_level=logical -c logging_collector=on -c log_destination=stderr -c log_directory=/logs' + ports: + - ${POSTGRES_PORT}:5432 + restart: always + volumes: + # We do not use a volume for the postgres data + # since we do not want to persist it across container restarts + # - 'postgis-data:/var/lib/postgresql/data' + - 'postgis-logs:/logs' + - 'test:/test' + - 'migrations:/migrations' + healthcheck: + test: ['CMD-SHELL', 'pg_isready', '-q'] + interval: 0.5s + timeout: 0.5s + retries: 20 + start_period: 80s diff --git a/database/logs/postgres/README.md b/database/logs/postgres/README.md new file mode 100644 index 000000000..64ccad144 --- /dev/null +++ b/database/logs/postgres/README.md @@ -0,0 +1 @@ +This folder has to exist as a container for postgres logs, as they are produced by the docker compose setup. \ No newline at end of file diff --git a/server/db-migrate/migrations/20240109102503-pro-t-visibility-settings.js b/database/migrations/20240109102503-pro-t-visibility-settings.js similarity index 100% rename from server/db-migrate/migrations/20240109102503-pro-t-visibility-settings.js rename to database/migrations/20240109102503-pro-t-visibility-settings.js diff --git a/server/db-migrate/migrations/20190723160435-dfh-v-class.js b/database/migrations/20240529120605-pgwar-entity.js similarity index 86% rename from server/db-migrate/migrations/20190723160435-dfh-v-class.js rename to database/migrations/20240529120605-pgwar-entity.js index ce4348605..f59f3ef47 100644 --- a/server/db-migrate/migrations/20190723160435-dfh-v-class.js +++ b/database/migrations/20240529120605-pgwar-entity.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190723160435-dfh-v-class-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240529120605-pgwar-entity-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190723160435-dfh-v-class-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240529120605-pgwar-entity-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20240530193851-pgwar-statements.js b/database/migrations/20240530193851-pgwar-statements.js new file mode 100644 index 000000000..d97c932e8 --- /dev/null +++ b/database/migrations/20240530193851-pgwar-statements.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240530193851-pgwar-statements-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240530193851-pgwar-statements-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20190516065758-pro-t-argument-refactor.js b/database/migrations/20240606082339-pgwar-project-statements.js similarity index 84% rename from server/db-migrate/migrations/20190516065758-pro-t-argument-refactor.js rename to database/migrations/20240606082339-pgwar-project-statements.js index f0072816a..aad7d1176 100644 --- a/server/db-migrate/migrations/20190516065758-pro-t-argument-refactor.js +++ b/database/migrations/20240606082339-pgwar-project-statements.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516065758-pro-t-argument-refactor-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240606082339-pgwar-project-statements-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516065758-pro-t-argument-refactor-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240606082339-pgwar-project-statements-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/server/db-migrate/migrations/20190515143720-dfh-t-property-of-property.js b/database/migrations/20240606151841-pgwar-community-statements.js similarity index 84% rename from server/db-migrate/migrations/20190515143720-dfh-t-property-of-property.js rename to database/migrations/20240606151841-pgwar-community-statements.js index d5856cf38..94da39c61 100644 --- a/server/db-migrate/migrations/20190515143720-dfh-t-property-of-property.js +++ b/database/migrations/20240606151841-pgwar-community-statements.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515143720-dfh-t-property-of-property-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240606151841-pgwar-community-statements-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515143720-dfh-t-property-of-property-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240606151841-pgwar-community-statements-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/server/db-migrate/migrations/20190617094318-war-bugfix.js b/database/migrations/20240612071824-pgwar-fulltext.js similarity index 85% rename from server/db-migrate/migrations/20190617094318-war-bugfix.js rename to database/migrations/20240612071824-pgwar-fulltext.js index 1788796b6..fd11e1803 100644 --- a/server/db-migrate/migrations/20190617094318-war-bugfix.js +++ b/database/migrations/20240612071824-pgwar-fulltext.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190617094318-war-bugfix-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240612071824-pgwar-fulltext-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190617094318-war-bugfix-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240612071824-pgwar-fulltext-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20240612071825-pgwar-project-entity-labels.js b/database/migrations/20240612071825-pgwar-project-entity-labels.js new file mode 100644 index 000000000..dbc9bb93f --- /dev/null +++ b/database/migrations/20240612071825-pgwar-project-entity-labels.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240612071825-pgwar-project-entity-labels-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240612071825-pgwar-project-entity-labels-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js b/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js new file mode 100644 index 000000000..e3b9106be --- /dev/null +++ b/database/migrations/20240613180752-inf-t-resource-add-fk-class-not-null.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613180752-inf-t-resource-add-fk-class-not-null-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240613180752-inf-t-resource-add-fk-class-not-null-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20190604161529-war-debugging.js b/database/migrations/20240618112815-pgwar-indexes.js similarity index 86% rename from server/db-migrate/migrations/20190604161529-war-debugging.js rename to database/migrations/20240618112815-pgwar-indexes.js index f7ce675b7..fb305a7da 100644 --- a/server/db-migrate/migrations/20190604161529-war-debugging.js +++ b/database/migrations/20240618112815-pgwar-indexes.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190604161529-war-debugging-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-indexes-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190604161529-war-debugging-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240618112815-pgwar-indexes-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/server/db-migrate/migrations/20190516073414-inf-t-dimension.js b/database/migrations/20240625144815-war-drop-schema.js similarity index 85% rename from server/db-migrate/migrations/20190516073414-inf-t-dimension.js rename to database/migrations/20240625144815-war-drop-schema.js index 5eec12fcc..ad5dd0530 100644 --- a/server/db-migrate/migrations/20190516073414-inf-t-dimension.js +++ b/database/migrations/20240625144815-war-drop-schema.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516073414-inf-t-dimension-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240625144815-war-drop-schema-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516073414-inf-t-dimension-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240625144815-war-drop-schema-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20240626082849-pgwar-property-and-class-views.js b/database/migrations/20240626082849-pgwar-property-and-class-views.js new file mode 100644 index 000000000..197dad353 --- /dev/null +++ b/database/migrations/20240626082849-pgwar-property-and-class-views.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240626082849-pgwar-property-and-class-views-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240626082849-pgwar-property-and-class-views-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20190527083437-pro-add-namespace.js b/database/migrations/20240627084826-pgwar-field-change.js similarity index 85% rename from server/db-migrate/migrations/20190527083437-pro-add-namespace.js rename to database/migrations/20240627084826-pgwar-field-change.js index 0bd7e1c9e..2e90a3867 100644 --- a/server/db-migrate/migrations/20190527083437-pro-add-namespace.js +++ b/database/migrations/20240627084826-pgwar-field-change.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190527083437-pro-add-namespace-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627084826-pgwar-field-change-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190527083437-pro-add-namespace-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627084826-pgwar-field-change-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/server/db-migrate/migrations/20190515131648-initialize-beta-schema.js b/database/migrations/20240627125256-pgwar-add-notifications.js similarity index 84% rename from server/db-migrate/migrations/20190515131648-initialize-beta-schema.js rename to database/migrations/20240627125256-pgwar-add-notifications.js index fca4197d6..dde1e1bcb 100644 --- a/server/db-migrate/migrations/20190515131648-initialize-beta-schema.js +++ b/database/migrations/20240627125256-pgwar-add-notifications.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515131648-initialize-beta-schema-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627125256-pgwar-add-notifications-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515131648-initialize-beta-schema-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627125256-pgwar-add-notifications-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/server/db-migrate/migrations/20190515144536-dat-refactoring.js b/database/migrations/20240627141623-pgwar-ts-vector.js similarity index 85% rename from server/db-migrate/migrations/20190515144536-dat-refactoring.js rename to database/migrations/20240627141623-pgwar-ts-vector.js index 2df20cfad..d89ef7626 100644 --- a/server/db-migrate/migrations/20190515144536-dat-refactoring.js +++ b/database/migrations/20240627141623-pgwar-ts-vector.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515144536-dat-refactoring-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627141623-pgwar-ts-vector-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190515144536-dat-refactoring-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240627141623-pgwar-ts-vector-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20240627193836-pgwar-entity-class.js b/database/migrations/20240627193836-pgwar-entity-class.js new file mode 100644 index 000000000..a538976ba --- /dev/null +++ b/database/migrations/20240627193836-pgwar-entity-class.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240627193836-pgwar-entity-class-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240627193836-pgwar-entity-class-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20190613082017-dat-update.js b/database/migrations/20240628121705-pgwar-fk-type.js similarity index 86% rename from server/db-migrate/migrations/20190613082017-dat-update.js rename to database/migrations/20240628121705-pgwar-fk-type.js index 4328bb8fe..ac09c9337 100644 --- a/server/db-migrate/migrations/20190613082017-dat-update.js +++ b/database/migrations/20240628121705-pgwar-fk-type.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613082017-dat-update-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240628121705-pgwar-fk-type-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613082017-dat-update-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240628121705-pgwar-fk-type-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20240628133110-pgwar-type-label.js b/database/migrations/20240628133110-pgwar-type-label.js new file mode 100644 index 000000000..d52a59db3 --- /dev/null +++ b/database/migrations/20240628133110-pgwar-type-label.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240628133110-pgwar-type-label-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240628133110-pgwar-type-label-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20240709164334-inf-add-indexes.js b/database/migrations/20240709164334-inf-add-indexes.js similarity index 100% rename from server/db-migrate/migrations/20240709164334-inf-add-indexes.js rename to database/migrations/20240709164334-inf-add-indexes.js diff --git a/database/migrations/20240711081550-com-f-get-field-pages.js b/database/migrations/20240711081550-com-f-get-field-pages.js new file mode 100644 index 000000000..8a8ea88d6 --- /dev/null +++ b/database/migrations/20240711081550-com-f-get-field-pages.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240711081550-com-f-get-field-pages-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20240711081550-com-f-get-field-pages-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/server/db-migrate/migrations/20190529115142-dat-v-chunk.js b/database/migrations/20240725085620-pgwar-time-span.js similarity index 85% rename from server/db-migrate/migrations/20190529115142-dat-v-chunk.js rename to database/migrations/20240725085620-pgwar-time-span.js index 23f581635..84c724928 100644 --- a/server/db-migrate/migrations/20190529115142-dat-v-chunk.js +++ b/database/migrations/20240725085620-pgwar-time-span.js @@ -19,7 +19,7 @@ exports.setup = function(options, seedLink) { }; exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190529115142-dat-v-chunk-up.sql'); + var filePath = path.join(__dirname, 'sqls', '20240725085620-pgwar-time-span-up.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); @@ -34,7 +34,7 @@ exports.up = function(db) { }; exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190529115142-dat-v-chunk-down.sql'); + var filePath = path.join(__dirname, 'sqls', '20240725085620-pgwar-time-span-down.sql'); return new Promise( function( resolve, reject ) { fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ if (err) return reject(err); diff --git a/database/migrations/20241017094816-pgwar-entity-label-async-update.js b/database/migrations/20241017094816-pgwar-entity-label-async-update.js new file mode 100644 index 000000000..7f3eaeea7 --- /dev/null +++ b/database/migrations/20241017094816-pgwar-entity-label-async-update.js @@ -0,0 +1,53 @@ +'use strict'; + +var dbm; +var type; +var seed; +var fs = require('fs'); +var path = require('path'); +var Promise; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function(options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; + Promise = options.Promise; +}; + +exports.up = function(db) { + var filePath = path.join(__dirname, 'sqls', '20241017094816-pgwar-entity-label-async-update-up.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports.down = function(db) { + var filePath = path.join(__dirname, 'sqls', '20241017094816-pgwar-entity-label-async-update-down.sql'); + return new Promise( function( resolve, reject ) { + fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ + if (err) return reject(err); + console.log('received data: ' + data); + + resolve(data); + }); + }) + .then(function(data) { + return db.runSql(data); + }); +}; + +exports._meta = { + "version": 1 +}; diff --git a/database/migrations/sqls/20240109102503-pro-t-visibility-settings-down.sql b/database/migrations/sqls/20240109102503-pro-t-visibility-settings-down.sql new file mode 100644 index 000000000..e69de29bb diff --git a/database/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql b/database/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql new file mode 100644 index 000000000..8f2649bb6 --- /dev/null +++ b/database/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql @@ -0,0 +1,17285 @@ +-- +-- PostgreSQL database dump +-- +-- Dumped from database version 14.5 (Debian 14.5-1.pgdg110+1) +-- Dumped by pg_dump version 16.0 +-- Started on 2024-05-29 13:48:57 CEST +SET statement_timeout = 0; + +SET lock_timeout = 0; + +SET idle_in_transaction_session_timeout = 0; + +SET client_encoding = 'UTF8'; + +SET standard_conforming_strings = ON; + +SELECT + pg_catalog.set_config('search_path', '', FALSE); + +SET check_function_bodies = FALSE; + +SET xmloption = content; + +SET client_min_messages = warning; + +SET row_security = OFF; + +-- +-- TOC entry 8 (class 2615 OID 19618) +-- Name: commons; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA commons; + +-- +-- TOC entry 9 (class 2615 OID 19619) +-- Name: data; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA data; + +-- +-- TOC entry 10 (class 2615 OID 19620) +-- Name: data_for_history; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA data_for_history; + +-- +-- TOC entry 11 (class 2615 OID 19621) +-- Name: information; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA information; + +-- +-- TOC entry 12 (class 2615 OID 19622) +-- Name: projects; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA projects; + +-- +-- TOC entry 6 (class 2615 OID 2200) +-- Name: public; Type: SCHEMA; Schema: -; Owner: - +-- +-- *not* creating schema, since initdb creates it +-- +-- TOC entry 13 (class 2615 OID 19623) +-- Name: system; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA SYSTEM; + +-- +-- TOC entry 15 (class 2615 OID 23770) +-- Name: tables; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA tables; + +-- +-- TOC entry 14 (class 2615 OID 19624) +-- Name: topology; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA topology; + +-- +-- TOC entry 6471 (class 0 OID 0) +-- Dependencies: 14 +-- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: - +-- +COMMENT ON SCHEMA topology IS 'PostGIS Topology schema'; + +-- +-- TOC entry 18 (class 2615 OID 24158) +-- Name: war; Type: SCHEMA; Schema: -; Owner: - +-- +CREATE SCHEMA war; + +-- +-- TOC entry 2 (class 3079 OID 19626) +-- Name: postgis; Type: EXTENSION; Schema: -; Owner: - +-- +CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; + +-- +-- TOC entry 6472 (class 0 OID 0) +-- Dependencies: 2 +-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: - +-- +COMMENT ON EXTENSION postgis IS 'PostGIS geometry and geography spatial types and functions'; + +-- +-- TOC entry 3 (class 3079 OID 20657) +-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: - +-- +CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology; + +-- +-- TOC entry 6473 (class 0 OID 0) +-- Dependencies: 3 +-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: - +-- +COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; + +-- +-- TOC entry 1996 (class 1247 OID 20818) +-- Name: calendar_granularities; Type: TYPE; Schema: public; Owner: - +-- +CREATE TYPE public.calendar_granularities AS ENUM( + '1 year', + '1 month', + '1 day', + '1 hour', + '1 minute', + '1 second' +); + +-- +-- TOC entry 1999 (class 1247 OID 20832) +-- Name: calendar_type; Type: TYPE; Schema: public; Owner: - +-- +CREATE TYPE public.calendar_type AS ENUM( + 'gregorian', + 'julian' +); + +-- +-- TOC entry 2395 (class 1247 OID 23945) +-- Name: month_and_day_of_month; Type: TYPE; Schema: public; Owner: - +-- +CREATE TYPE public.month_and_day_of_month AS ( + month integer, + day_of_month integer +); + +-- +-- TOC entry 2392 (class 1247 OID 23942) +-- Name: year_and_day_of_year; Type: TYPE; Schema: public; Owner: - +-- +CREATE TYPE public.year_and_day_of_year AS ( + year integer, + day_of_year integer +); + +-- +-- TOC entry 2398 (class 1247 OID 23949) +-- Name: year_month_day; Type: TYPE; Schema: public; Owner: - +-- +CREATE TYPE public.year_month_day AS ( + year integer, + month integer, + day integer +); + +-- +-- TOC entry 2443 (class 1247 OID 24160) +-- Name: edge_target_type; Type: TYPE; Schema: war; Owner: - +-- +CREATE TYPE war.edge_target_type AS ENUM( + 'text', + 'type' +); + +-- +-- TOC entry 2446 (class 1247 OID 24167) +-- Name: node_id; Type: TYPE; Schema: war; Owner: - +-- +CREATE TYPE war.node_id AS ( + pk_entity integer, + fk_project integer +); + +-- +-- TOC entry 1250 (class 1255 OID 20837) +-- Name: _validate_json_schema_type(text, jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons._validate_json_schema_type(type text, data jsonb) + RETURNS boolean + LANGUAGE plpgsql + IMMUTABLE + AS $$ +BEGIN + IF type = 'integer' THEN + IF jsonb_typeof(data) != 'number' THEN + RETURN FALSE; + END IF; + IF trunc(data::text::numeric) != data::text::numeric THEN + RETURN FALSE; + END IF; + ELSE + IF type != jsonb_typeof(data) THEN + RETURN FALSE; + END IF; + END IF; + RETURN TRUE; +END; +$$; + +-- +-- TOC entry 1311 (class 1255 OID 24013) +-- Name: analysis__create_temporal_distribution(integer[], integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.analysis__create_temporal_distribution(param_pk_entities integer[], param_project integer) + RETURNS jsonb + LANGUAGE plpgsql + AS $$ +DECLARE + res jsonb; +BEGIN + WITH tw0 AS ( + SELECT + first_second, + last_second, + pk_entity + FROM + war.entity_preview + WHERE + pk_entity = ANY (param_pk_entities) + AND project_id = param_project + AND first_second IS NOT NULL + AND last_second IS NOT NULL +), +tw1 AS ( + SELECT + first_second julian_second, + pk_entity + FROM + tw0 + UNION + SELECT + last_second julian_second, + pk_entity + FROM + tw0 + ORDER BY + 1 +), +tw2 AS ( + SELECT DISTINCT ON (julian_second) + julian_second + FROM + tw1 +), +tw3 AS ( + SELECT + julian_second, + row_number() OVER () pk, +(row_number() OVER () + 1) fk_next +FROM tw2 +), +tw4 AS ( + SELECT + t1.julian_second x1, + t2.julian_second x2 + FROM + tw3 t1, + tw3 t2 + WHERE + t1.fk_next = t2.pk +), +tw5 AS ( + SELECT + t1.x1, + t1.x2, + -- for czml we need to remove a very little ms here to that the x vals stay unique + json_strip_nulls(json_agg(t2.pk_entity)) AS data, + count(t2.pk_entity) + FROM + tw4 t1 + LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 + AND t2.last_second > t1.x1 + GROUP BY + t1.x1, + t1.x2 + ORDER BY + t1.x1 +), +tw6 AS ( + -- select the very first point + SELECT + x1 x, + 0 y, + '[]'::json AS data, + x1, + x2 + FROM + tw5 + ORDER BY + x1 + LIMIT 1 +), +tw7 AS ( + -- select the very last point + SELECT + x2 x, + 0 y, + '[]'::json AS data, + x1, + x2 + FROM + tw5 + ORDER BY + x1 DESC + LIMIT 1 +), +tw8 AS ( + -- first point + SELECT + 0, + x, + y, + data, + x1, + x2 + FROM + tw6 + UNION ALL + -- all other points + SELECT + 2, + x1 x, + count y, + data, + x1, + x2 + FROM + tw5 + UNION ALL + SELECT + 1, + x2 x, + count y, + data, + x1, + x2 + FROM + tw5 + UNION ALL + -- last point + SELECT + 3, + x, + y, + data, + x1, + x2 + FROM + tw7 + ORDER BY + x, + 1 +) +SELECT + jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) INTO res +FROM + tw8; + RETURN coalesce(res, '[]'::jsonb); +END; +$$; + +-- +-- TOC entry 1336 (class 1255 OID 24026) +-- Name: analysis__time_chart_cont__czml_time_values(integer[], integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.analysis__time_chart_cont__czml_time_values(param_pk_entities integer[], param_project integer) + RETURNS jsonb + LANGUAGE plpgsql + AS $$ +DECLARE + res jsonb; +BEGIN + WITH tw0 AS ( + -- temporal entities + SELECT + first_second, + last_second, + pk_entity + FROM + war.entity_preview + WHERE + pk_entity = ANY (param_pk_entities) + AND project_id = param_project + AND first_second IS NOT NULL + AND last_second IS NOT NULL +), +tw1 AS ( + SELECT + first_second julian_second, + pk_entity + FROM + tw0 + UNION + SELECT + last_second julian_second, + pk_entity + FROM + tw0 + ORDER BY + 1 +), +tw2 AS ( + SELECT DISTINCT ON (julian_second) + julian_second + FROM + tw1 +), +tw3 AS ( + SELECT + julian_second, + row_number() OVER () pk, +(row_number() OVER () + 1) fk_next +FROM tw2 +), +tw4 AS ( + SELECT + t1.julian_second x1, + t2.julian_second x2 + FROM + tw3 t1, + tw3 t2 + WHERE + t1.fk_next = t2.pk +), +tw5 AS ( + SELECT + t1.x1, + t1.x2, + -- for czml we need to remove a very little ms here to that the x vals stay unique + commons.julian_second__to_iso_8601(t1.x1 + 1) iso_x1, + commons.julian_second__to_iso_8601(t1.x2) iso_x2, + coalesce(json_agg(t2.pk_entity) FILTER (WHERE t2.pk_entity IS NOT NULL), '[]') AS data, +count(t2.pk_entity) +FROM + tw4 t1 + LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 + AND t2.last_second > t1.x1 +GROUP BY + t1.x1, + t1.x2 +ORDER BY + t1.x1 +), +tw6 AS ( + -- select the very first point + SELECT + x1 x, + commons.julian_second__to_iso_8601(x1 - 1) iso_x, + 0 y, + '[]'::json AS data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw5 + ORDER BY + x1 + LIMIT 1 +), +tw7 AS ( + -- select the very last point + SELECT + x2 x, + commons.julian_second__to_iso_8601(x2 + 1) iso_x, + 0 y, + '[]'::json AS data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw5 + ORDER BY + x1 DESC + LIMIT 1 +), +tw8 AS ( + -- first point + SELECT + 0, + x, + iso_x, + y, + data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw6 + UNION ALL + -- all other points + SELECT + 2, + x1 x, + iso_x1 iso_x, + count y, + data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw5 + UNION ALL + SELECT + 1, + x2 x, + iso_x2 iso_x, + count y, + data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw5 + UNION ALL + -- last point + SELECT + 3, + x, + iso_x, + y, + data, + x1, + x2, + iso_x1, + iso_x2 + FROM + tw7 + ORDER BY + x, + 1 +), +tw9 AS ( + SELECT + row_number() OVER () data_id, + x, + iso_x, + y, + data, + x1, + x2, + iso_x1, + iso_x2 + FROM tw8 +) +SELECT + json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) INTO res +FROM + tw9; + RETURN res; +END; +$$; + +-- +-- TOC entry 1251 (class 1255 OID 20838) +-- Name: appellation_label_to_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.appellation_label_to_quill_doc(orig jsonb) + RETURNS jsonb + LANGUAGE plpgsql + IMMUTABLE + AS $$ +BEGIN + RETURN commons.text_to_quill_doc(information.appellation_label_to_string(orig)); +END; +$$; + +-- +-- TOC entry 1252 (class 1255 OID 20839) +-- Name: change_fk_reference_of_versioned_table(character varying, character varying, character varying, character varying, character varying, character varying, boolean); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.change_fk_reference_of_versioned_table(schema_name character varying, table_name character varying, fk_column character varying, referenced_schema_and_table_name character varying, old_referenced_column character varying, new_referenced_column character varying, fk_col_not_null boolean DEFAULT TRUE) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format( ' + + DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; + DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; + DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; + DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; + DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; + DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; + + + -- table + ALTER TABLE %1$s.%2$s RENAME COLUMN %3$s TO _deprecated_%3$s; + ALTER TABLE %1$s.%2$s ADD COLUMN %3$s integer; + UPDATE %1$s.%2$s + SET %3$s = subq.%6$s + FROM ( + SELECT %6$s, %5$s + FROM %4$s + ) as subq + WHERE _deprecated_%3$s = subq.%5$s; + + ALTER TABLE %1$s.%2$s + DROP CONSTRAINT IF EXISTS %2$s_%3$s_fkey; + + ALTER TABLE %1$s.%2$s ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); + + -- table_vt + ALTER TABLE %1$s.%2$s_vt RENAME COLUMN %3$s TO _deprecated_%3$s; + ALTER TABLE %1$s.%2$s_vt ADD COLUMN %3$s integer; + UPDATE %1$s.%2$s_vt + SET %3$s = subq.%6$s + FROM ( + SELECT %6$s, %5$s + FROM %4$s + ) as subq + WHERE _deprecated_%3$s = subq.%5$s; + + ALTER TABLE %1$s.%2$s_vt + DROP CONSTRAINT IF EXISTS %2$s_vt_%3$s_fkey; + + ALTER TABLE %1$s.%2$s_vt ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); + + SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); + + -- Trigger: creation_tmsp + CREATE TRIGGER creation_tmsp + BEFORE INSERT + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_creation(); + + -- Trigger: insert_schema_table_name + CREATE TRIGGER insert_schema_table_name + BEFORE INSERT + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.insert_schema_table_name(); + + -- Trigger: last_modification_tmsp + CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_last_modification(); + + + + ' +, schema_name, table_name, fk_column, referenced_schema_and_table_name, old_referenced_column, new_referenced_column); + IF(fk_col_not_null = TRUE) THEN + EXECUTE format(' + ALTER TABLE %1$s.%2$s ALTER COLUMN %3$s SET NOT NULL; + ', schema_name, table_name, fk_column); + END IF; +END +$_$; + +-- +-- TOC entry 1253 (class 1255 OID 20840) +-- Name: change_parent_entity_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.change_parent_entity_table(child_schema_and_table_name character varying, old_parent_schema_and_table_name character varying, new_parent_schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + -- Do the Magic: + EXECUTE format(' + ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; + ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; + UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; + ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; + + ALTER TABLE %1$s NO INHERIT %2$s; + ALTER TABLE %1$s INHERIT %3$s; + SELECT setval(''%3$s_pk_entity_seq'', (SELECT MAX(pk_entity) FROM %1$s)); + ', child_schema_and_table_name, old_parent_schema_and_table_name, new_parent_schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1328 (class 1255 OID 24786) +-- Name: clone_project(integer, text, text); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.clone_project(pk_project integer, project_label text, project_description text) + RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + fk_project_default_language int; + fk_system_type__project_label int; + fk_system_type__project_description int; + pk_new_project int; + pk_new_default_namespace int; +BEGIN + -- system type for project label + fk_system_type__project_label = 639; + -- system type for project description + fk_system_type__project_description = 638; + SELECT + fk_language INTO fk_project_default_language + FROM + projects.project + WHERE + pk_entity = pk_project; + + /* + * create the project + */ + INSERT INTO projects.project(fk_language, fk_cloned_from_project) + VALUES (fk_project_default_language, pk_project) + ON CONFLICT + DO NOTHING + RETURNING + pk_entity INTO pk_new_project; + + /* + * add label of project + */ + INSERT INTO projects.text_property(fk_project, fk_pro_project, string, fk_system_type, fk_language) + VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); + + /* + * add description of project + */ + INSERT INTO projects.text_property(fk_project, fk_pro_project, string, fk_system_type, fk_language) + VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); + + /* + * add dfh profiles to project + */ + INSERT INTO projects.dfh_profile_proj_rel(fk_project, fk_profile, enabled) + SELECT + pk_new_project AS fk_project, + fk_profile, + enabled + FROM + projects.dfh_profile_proj_rel + WHERE + fk_project = pk_project; + + /* + * add dfh classes to project + */ + INSERT INTO projects.dfh_class_proj_rel(fk_project, fk_class, enabled_in_entities) + SELECT + pk_new_project AS fk_project, + fk_class, + enabled_in_entities + FROM + projects.dfh_class_proj_rel + WHERE + fk_project = pk_project; + + /* + * add default namespace to project + */ + INSERT INTO data.namespace(fk_project, standard_label) + VALUES (pk_new_project, 'Default Namespace') + RETURNING + pk_entity INTO pk_new_default_namespace; + + /* + * add all information to project except for statements referencing to data + */ + WITH tw1 AS ( + /* + * select all info_proj_rel of sandbox except those that are + * referencing an statement associating entities in data schema + */ + SELECT + t1.pk_entity + FROM + projects.info_proj_rel t1 + WHERE + fk_project = pk_project + EXCEPT + SELECT + t1.pk_entity + FROM + projects.info_proj_rel t1, + information.statement t2 + WHERE + fk_project = pk_project + AND t1.fk_entity = t2.pk_entity + AND (t2.fk_subject_tables_cell != 0 + OR t2.fk_object_tables_cell != 0 + OR t2.fk_subject_tables_row != 0 + OR t2.fk_object_tables_row != 0 + OR t2.fk_subject_data != 0 + OR t2.fk_object_data != 0)) + INSERT INTO projects.info_proj_rel(fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) + SELECT + pk_new_project AS fk_project, + t1.fk_entity, + t1.fk_entity_version, + t1.fk_entity_version_concat, + t1.is_in_project, + t1.is_standard_in_project, + t1.ord_num_of_domain, + t1.ord_num_of_range, + t1.ord_num_of_text_property, + t1.entity_version + FROM + projects.info_proj_rel t1, + tw1 t2 + WHERE + t1.pk_entity = t2.pk_entity; + + /* + * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) + */ + INSERT INTO data.digital(fk_namespace, fk_system_type, quill_doc, metadata) + -- Select all digitals of sandbox project + SELECT + pk_new_default_namespace AS fk_namespace, + t2.fk_system_type, + t2.quill_doc, + jsonb_build_object('fk_cloned_from', t2.pk_entity) + FROM + data.namespace t1, + data.digital t2 + WHERE + t1.fk_project = pk_project + AND t1.pk_entity = t2.fk_namespace; + + /* + * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from + * and add them to the project + */ + INSERT INTO information.statement(fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) + -- select statements pointing to the new digital's fk_cloned_from + SELECT + coalesce(t2.fk_subject_info, 0), + t3.pk_entity AS fk_subject_data, -- pk of new digital + coalesce(t2.fk_subject_tables_cell, 0), + coalesce(t2.fk_subject_tables_row, 0), + coalesce(t2.fk_property, 0), + coalesce(t2.fk_property_of_property, 0), + coalesce(t2.fk_object_info, 0), + coalesce(t2.fk_object_data, 0), + coalesce(t2.fk_object_tables_cell, 0), + coalesce(t2.fk_object_tables_row, 0), + jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion + FROM + projects.info_proj_rel t1, + information.statement t2, + data.digital t3 + WHERE + fk_project = pk_project + AND t1.is_in_project = TRUE + AND t1.fk_entity = t2.pk_entity + AND t2.fk_subject_data =(t3.metadata ->> 'fk_cloned_from')::int + AND t3.fk_namespace = pk_new_default_namespace; + + /* + * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) + */ + INSERT INTO data.chunk(fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) + -- Select all chunks of sandbox project + SELECT + pk_new_default_namespace AS fk_namespace, + t2.quill_doc, + t4.pk_text, + 1 AS fk_entity_version, + jsonb_build_object('fk_cloned_from', t2.pk_entity) + FROM + data.namespace t1, + data.chunk t2, + data.digital t3, + data.digital t4 + WHERE + t1.fk_project = pk_project + AND t1.pk_entity = t2.fk_namespace + AND t3.pk_text = t2.fk_text + AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; + + /* + * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from + * and add them to the project + */ + INSERT INTO information.statement(fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) + -- select statements pointing to the new chunk's fk_cloned_from + SELECT + coalesce(t2.fk_subject_info, 0), + t3.pk_entity AS fk_subject_data, -- pk of new chunk + coalesce(t2.fk_subject_tables_cell, 0), + coalesce(t2.fk_subject_tables_row, 0), + coalesce(t2.fk_property, 0), + coalesce(t2.fk_property_of_property, 0), + coalesce(t2.fk_object_info, 0), + coalesce(t2.fk_object_data, 0), + coalesce(t2.fk_object_tables_cell, 0), + coalesce(t2.fk_object_tables_row, 0), + jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion + FROM + projects.info_proj_rel t1, + information.statement t2, + data.chunk t3 + WHERE + t1.fk_project = pk_project + AND t1.is_in_project = TRUE + AND t1.fk_entity = t2.pk_entity + AND t2.fk_subject_data =(t3.metadata ->> 'fk_cloned_from')::int + AND t3.fk_namespace = pk_new_default_namespace; + -- make sure this is a chunk of this new project's namespace + /* + * Add the statements pointing to data to the new project + */ + INSERT INTO projects.info_proj_rel(fk_entity, fk_project, is_in_project) + SELECT + t1.pk_entity AS fk_entity, + pk_new_project AS fk_project, + TRUE AS is_in_project + FROM + information.statement t1, + data.entity t2 + WHERE + t1.fk_subject_data = t2.pk_entity + AND t2.fk_namespace = pk_new_default_namespace; + + /* + * Clone all entity_previews from sandbox project + * so that warehouse for this project is ready instantly + */ + INSERT INTO war.entity_preview(pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, first_second, last_second, tmsp_last_modification) + SELECT + pk_entity, + pk_new_project AS fk_project, + pk_new_project AS project, + fk_class, + entity_type, + class_label, + entity_label, + time_span, + fk_type, + type_label, + full_text, + first_second, + last_second, + tmsp_last_modification + FROM + war.entity_preview + WHERE + fk_project = pk_project + ON CONFLICT ON CONSTRAINT war_entity_preview_unique + DO NOTHING; + + /* + * Clone analysis + */ + INSERT INTO projects.analysis(fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) + SELECT + fk_last_modifier, + pk_new_project AS fk_project, + fk_analysis_type, + name, + description, + analysis_definition + FROM + projects.analysis + WHERE + fk_project = pk_project; + RETURN pk_new_project; +END; +$$; + +-- +-- TOC entry 1304 (class 1255 OID 23934) +-- Name: clone_sandbox_project(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.clone_sandbox_project(account_id integer) + RETURNS void + LANGUAGE plpgsql + AS $$ +DECLARE + pk_sandbox_project int; + fk_project_default_language int; + fk_system_type__project_label int; + fk_system_type__project_description int; + project_label varchar; + project_description varchar; + pk_new_project int; + pk_new_default_namespace int; +BEGIN + -- pk_entity of the sandbox project + pk_sandbox_project = 375232; + -- default language = english + fk_project_default_language = 18889; + -- system type for project label + fk_system_type__project_label = 639; + -- system type for project description + fk_system_type__project_description = 638; + -- the label of the new project + project_label = 'Sandbox Project'; + -- the description of the new project + project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; + + /* + * create the project + */ + INSERT INTO projects.project(fk_language, fk_cloned_from_project) + VALUES (fk_project_default_language, pk_sandbox_project) + ON CONFLICT + DO NOTHING + RETURNING + pk_entity INTO pk_new_project; + + /* + * add label of project + */ + INSERT INTO projects.text_property(fk_project, fk_pro_project, string, fk_system_type, fk_language) + VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); + + /* + * add description of project + */ + INSERT INTO projects.text_property(fk_project, fk_pro_project, string, fk_system_type, fk_language) + VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); + + /* + * add dfh profiles to project + */ + INSERT INTO projects.dfh_profile_proj_rel(fk_project, fk_profile, enabled) + SELECT + pk_new_project AS fk_project, + fk_profile, + enabled + FROM + projects.dfh_profile_proj_rel + WHERE + fk_project = pk_sandbox_project; + + /* + * add dfh classes to project + */ + INSERT INTO projects.dfh_class_proj_rel(fk_project, fk_class, enabled_in_entities) + SELECT + pk_new_project AS fk_project, + fk_class, + enabled_in_entities + FROM + projects.dfh_class_proj_rel + WHERE + fk_project = pk_sandbox_project; + + /* + * add default namespace to project + */ + INSERT INTO data.namespace(fk_project, standard_label) + VALUES (pk_new_project, 'Default Namespace') + RETURNING + pk_entity INTO pk_new_default_namespace; + + /* + * add account to project + */ + INSERT INTO public.account_project_rel(fk_project, account_id, ROLE) + VALUES (pk_new_project, account_id, 'owner'); + + /* + * add all information to project except for statements referencing to data + */ + WITH tw1 AS ( + /* + * select all info_proj_rel of sandbox except those that are + * referencing an statement associating entities in data schema + */ + SELECT + t1.pk_entity + FROM + projects.info_proj_rel t1 + WHERE + fk_project = pk_sandbox_project + EXCEPT + SELECT + t1.pk_entity + FROM + projects.info_proj_rel t1, + information.statement t2 + WHERE + fk_project = pk_sandbox_project + AND t1.fk_entity = t2.pk_entity + AND (t2.fk_subject_tables_cell != 0 + OR t2.fk_object_tables_cell != 0 + OR t2.fk_subject_tables_row != 0 + OR t2.fk_object_tables_row != 0 + OR t2.fk_subject_data != 0 + OR t2.fk_object_data != 0)) + INSERT INTO projects.info_proj_rel(fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) + SELECT + pk_new_project AS fk_project, + t1.fk_entity, + t1.fk_entity_version, + t1.fk_entity_version_concat, + t1.is_in_project, + t1.is_standard_in_project, + t1.ord_num_of_domain, + t1.ord_num_of_range, + t1.ord_num_of_text_property, + t1.entity_version + FROM + projects.info_proj_rel t1, + tw1 t2 + WHERE + t1.pk_entity = t2.pk_entity; + + /* + * Clone all entity_previews from sandbox project + * so that warehouse for this project is ready instantly + */ + INSERT INTO war.entity_preview(pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification, entity_id, parent_classes, ancestor_classes, project_id, type_id) + SELECT + pk_entity, + pk_new_project AS fk_project, + pk_new_project AS project, + fk_class, + entity_type, + class_label, + entity_label, + time_span, + fk_type, + type_label, + full_text, + ts_vector, + first_second, + last_second, + tmsp_last_modification, + entity_id, + parent_classes, + ancestor_classes, + project_id, + type_id + FROM + war.entity_preview + WHERE + fk_project = pk_sandbox_project + ON CONFLICT (entity_id, + project_id) + DO NOTHING; + + /* + * Clone analysis + */ + INSERT INTO projects.analysis(fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) + SELECT + account_id AS fk_last_modifier, + pk_new_project AS fk_project, + fk_analysis_type, + name, + description, + analysis_definition + FROM + projects.analysis + WHERE + fk_project = pk_sandbox_project; +END; +$$; + +-- +-- TOC entry 1254 (class 1255 OID 20841) +-- Name: create_entity_version_key(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.create_entity_version_key() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.entity_version = 1; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1255 (class 1255 OID 20842) +-- Name: evpr_fk_entity_fk_entity_version(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.evpr_fk_entity_fk_entity_version() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + result text; +BEGIN + -- Added if condition: + -- only if there is a fk_entity_version_concat, generate fk_entity and fk_entity_version + IF (NEW.fk_entity_version_concat IS NOT NULL) THEN + NEW.fk_entity = split_part(NEW.fk_entity_version_concat, '_', 1)::integer; + NEW.fk_entity_version = split_part(NEW.fk_entity_version_concat, '_', 2)::integer; + END IF; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1298 (class 1255 OID 23909) +-- Name: get_entity_appellation(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.get_entity_appellation(pk_entity integer) + RETURNS character varying + LANGUAGE sql + AS $_$ + SELECT + t3.string + FROM + information.statement t1, + information.statement t2, + information.appellation t3 + WHERE + t1.fk_object_info = $1 + AND t2.fk_subject_info = t1.fk_subject_info + AND t2.fk_property = 1113 + AND t2.fk_object_info = t3.pk_entity; +$_$; + +-- +-- TOC entry 1337 (class 1255 OID 24967) +-- Name: get_entity_preview_table_name(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.get_entity_preview_table_name() + RETURNS text + LANGUAGE plpgsql + AS $$ +DECLARE + table_name text; +BEGIN + SELECT + substring(view_definition FROM 'FROM[[:space:]]+([[:alnum:]_\.]+)') + FROM + information_schema.views t1 + WHERE + t1.table_schema = 'war' + AND t1.table_name = 'entity_preview' INTO table_name; + RETURN table_name; +END; +$$; + +-- +-- TOC entry 1317 (class 1255 OID 20843) +-- Name: init_entity_child_table(character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.init_entity_child_table(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +DECLARE + unique_constraint_name varchar; +BEGIN + -- Create the name of the unique constraint that will be applied to the new table's pk_entity + SELECT + INTO unique_constraint_name replace(schema_and_table_name, '.', '_') _pk_entity_unique; + -- Do the Magic: + EXECUTE format( ' + + -- Add unique constraint to pk_entity of the new table, so that it can be referenced by foreign keys + + ALTER TABLE %1$s ADD CONSTRAINT %2$s_pk_entity_unique UNIQUE (pk_entity); + + -- Trigger: creation_tmsp + + CREATE TRIGGER creation_tmsp + BEFORE INSERT + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_creation(); + + -- Trigger: insert_schema_table_name + + CREATE TRIGGER insert_schema_table_name + BEFORE INSERT + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.insert_schema_table_name(); + + -- Trigger: last_modification_tmsp + + CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_last_modification(); + + -- Table: _vt + + CREATE TABLE %1$s_vt (LIKE %1$s); + + -- Trigger: versioning_trigger + + CREATE TRIGGER versioning_trigger + BEFORE INSERT OR UPDATE OR DELETE ON %1$s + FOR EACH ROW EXECUTE PROCEDURE versioning( + "sys_period", ''%1$s_vt'', true + );' +, schema_and_table_name, unique_constraint_name); +END +$_$; + +-- +-- TOC entry 1256 (class 1255 OID 20844) +-- Name: init_version_table(character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.init_version_table(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + -- Do the Magic: + EXECUTE format( ' + + ALTER TABLE %1$s ADD COLUMN IF NOT EXISTS + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone); + + -- Table: _vt + + CREATE TABLE %1$s_vt (LIKE %1$s); + + -- Trigger: versioning_trigger + + CREATE TRIGGER versioning_trigger + BEFORE INSERT OR UPDATE OR DELETE ON %1$s + FOR EACH ROW EXECUTE PROCEDURE versioning( + "sys_period", ''%1$s_vt'', true + ); + + -- Trigger: create_entity_version_key + + CREATE TRIGGER create_entity_version_key + BEFORE INSERT + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.create_entity_version_key(); + + -- Trigger: update_entity_version_key + + CREATE TRIGGER update_entity_version_key + BEFORE UPDATE + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.update_entity_version_key();' +, schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1257 (class 1255 OID 20845) +-- Name: insert_schema_table_name(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.insert_schema_table_name() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ + -- source https://www.postgresql.org/docs/current/static/plpgsql-trigger.html +BEGIN + NEW.schema_name = TG_TABLE_SCHEMA; + NEW.table_name = TG_TABLE_NAME; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1296 (class 1255 OID 23908) +-- Name: isnumeric(text); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.isnumeric(text) + RETURNS boolean + LANGUAGE plpgsql + IMMUTABLE STRICT + AS $_$ +DECLARE + x numeric; +BEGIN + x = $1::numeric; + RETURN TRUE; +EXCEPTION + WHEN OTHERS THEN + RETURN FALSE; +END; + +$_$; + +-- +-- TOC entry 1294 (class 1255 OID 23950) +-- Name: julian_cal__add_1_month(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__add_1_month(julian_day integer) + RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + x year_month_day; + is_leap boolean; + days_in_month int[]; +BEGIN + SELECT + * + FROM + commons.julian_cal__year_month_day(julian_day) INTO x; + is_leap = commons.julian_cal__is_leap_year(x.year); + IF (is_leap = FALSE) THEN + days_in_month = ARRAY[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + ELSE + days_in_month = ARRAY[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + END IF; + RETURN julian_day + days_in_month[x.month]; +END; +$$; + +-- +-- TOC entry 1301 (class 1255 OID 23938) +-- Name: julian_cal__add_1_year(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__add_1_year(julian_day integer) + RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + _year integer; +BEGIN + SELECT + year INTO _year + FROM + commons.julian_cal__year_and_day_of_year(julian_day); + IF (_year % 4) = 0 THEN + RETURN julian_day + 366; + ELSE + RETURN julian_day + 365; + END IF; +END; +$$; + +-- +-- TOC entry 1299 (class 1255 OID 23936) +-- Name: julian_cal__is_leap_year(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__is_leap_year(year integer) + RETURNS boolean + LANGUAGE plpgsql + AS $$ +BEGIN + -- year is the year BC: no year 0. + IF(year > 0) THEN + -- if devisable by 4 without remainder + RETURN((year % 4) = 0); + ELSE + -- if devisable by 4 without remainder = -1 + RETURN((year % 4) = - 1); + END IF; +END; +$$; + +-- +-- TOC entry 1302 (class 1255 OID 23939) +-- Name: julian_cal__month_and_day_of_month(integer, integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__month_and_day_of_month(year integer, day_of_year integer) + RETURNS TABLE( + month integer, + day_of_month integer) + LANGUAGE plpgsql + AS $$ +DECLARE + -- true, if year is a leap year according to julian calendar + is_leap boolean; + -- month corrections (note that january has index 0) + month_correnctions int[]; + -- month correction + mc int; + -- leap year correction + lc int; + -- resulting month, one-based (begins with 1) + month int; + -- resulting day of month, one-based (begins with 1) + day_of_month int; +BEGIN + -- leap year + is_leap = commons.julian_cal__is_leap_year(year); + -- month corrections (note that january has index 0) + month_correnctions = ARRAY[-1, 0, -2, -1, -1, 0, 0, 1, +2, +2, +3, +3]; + -- resulting month + month = floor((day_of_year + 1) / 30::numeric) + 1; + -- month correction + mc = month_correnctions[month]; + -- leap year correction + IF (is_leap = TRUE AND month > 2) THEN + lc = 1; + ELSE + lc = 0; + END IF; + -- resulting day + day_of_month = day_of_year - 30 *(month - 1) -(lc + mc); + -- check if month and day still valid + IF (month > 12 OR day_of_month < 1) THEN + month = month - 1; + IF (month < 1) THEN + is_leap = NOT is_leap; + END IF; + -- leap year correction + IF (is_leap = TRUE AND month > 2) THEN + lc = 1; + ELSE + lc = 0; + END IF; + -- month correction + mc = month_correnctions[month]; + -- resulting day + day_of_month = day_of_year - 30 *(month - 1) -(lc + mc); + END IF; + RETURN QUERY + SELECT + month, + day_of_month; +END; +$$; + +-- +-- TOC entry 1300 (class 1255 OID 23937) +-- Name: julian_cal__year_and_day_of_year(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__year_and_day_of_year(julian_day integer) + RETURNS TABLE( + year integer, + day_of_year integer) + LANGUAGE plpgsql + AS $$ +DECLARE + -- number of full 4 year cycles + n4 integer; + -- number of days of the last uncomplete 4 years cycle + r4 integer; + -- number of full years of the last uncomplete 4 years cycle + n1 integer; + -- number of days in the last year, zero-based (begins with 0) + day_of_year integer; + -- number of years (counted from julian year 0 (=4713 BC)) + julian_year integer; + -- year in christian counting + year integer; +BEGIN + /* + * Inspired by + * https://de.wikipedia.org/wiki/Umrechnung_zwischen_julianischem_Datum_und_julianischem_Kalender + */ + -- number of full 4 year cycles + n4 = floor((julian_day +(3 * 365)) / 1461::numeric)::integer; + -- number of days of the last uncomplete 4 years cycle + r4 =(julian_day +(3 * 365)) % 1461; + -- number of full years of the last uncomplete 4 years cycle + n1 = floor(r4 / 365::numeric); + -- number of days in the last year + day_of_year = r4 % 365; + IF (n1 = 4) THEN + n1 = 3; + day_of_year = 365; + END IF; + -- number of years (counted from julian year 0 (=4713 BC)) + julian_year = 4 * n4 + n1; + -- if BC + IF (julian_year <= 4715) THEN + -- resulting year + year = julian_year - 4716; + -- if AD + ELSE + year = julian_year - 4715; + END IF; + RETURN QUERY( + SELECT + year, day_of_year); +END; +$$; + +-- +-- TOC entry 1303 (class 1255 OID 23946) +-- Name: julian_cal__year_month_day(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_cal__year_month_day(julian_day integer) + RETURNS TABLE( + year integer, + month integer, + day integer) + LANGUAGE plpgsql + AS $$ +DECLARE + -- year and day_of_year according to julian calendar + y year_and_day_of_year; + -- month and day_of_month according to julian calendar + m month_and_day_of_month; +BEGIN + SELECT + * + FROM + commons.julian_cal__year_and_day_of_year(julian_day) INTO y; + SELECT + * + FROM + commons.julian_cal__month_and_day_of_month(y.year, y.day_of_year) INTO m; + RETURN QUERY + SELECT + y.year, + m.month, + m.day_of_month; +END; +$$; + +-- +-- TOC entry 1307 (class 1255 OID 24025) +-- Name: julian_second__to_iso_8601(bigint); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.julian_second__to_iso_8601(julian_second bigint) + RETURNS text + LANGUAGE sql + AS $$ + SELECT + to_char((('J' ||(julian_second / 86400)::text)::timestamp +(julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') +$$; + +-- +-- TOC entry 1258 (class 1255 OID 20846) +-- Name: make_table_child_of_text(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.make_table_child_of_text(schema_and_table_name character varying, parent_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + -- Do the Magic: + EXECUTE format( ' + ------ PREPARE THE TABLE + + UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; + + ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; + + -- SET schema_name NOT NULL + ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; + + -- SET table_name NOT NULL + ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; + + -- Add the column for the pk_text and fill the new pk_text column + ALTER TABLE %1$s + ADD COLUMN pk_text integer NOT NULL DEFAULT nextval(''commons.text_pk_text_seq''); + + -- Add the column for quill_doc and fill it with empty QuillDoc + ALTER TABLE %1$s ADD COLUMN quill_doc jsonb; + UPDATE %1$s SET quill_doc = jsonb_build_object(''latestId'', 0, ''ops'', ARRAY[]::integer[]) WHERE quill_doc IS NULL; + ALTER TABLE %1$s ALTER COLUMN quill_doc SET NOT NULL; + + -- Add the schema validation check + ALTER TABLE %1$s + ADD CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)); + + -- Add the column for string and fill with empty string + ALTER TABLE %1$s ADD COLUMN string text DEFAULT ''''; + UPDATE %1$s SET string = '''' WHERE string IS NULL; + ALTER TABLE %1$s ALTER COLUMN string SET NOT NULL; + + ---- SET THE INHERITANCE + ALTER TABLE %1$s + INHERIT commons.%2$s; + + ' +, schema_and_table_name, parent_table_name); +END +$_$; + +-- +-- TOC entry 1259 (class 1255 OID 20847) +-- Name: make_versioned_table_child_of_text(character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.make_versioned_table_child_of_text(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + PERFORM + commons.make_table_child_of_text(schema_and_table_name, 'text'); + PERFORM + commons.make_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); + EXECUTE format( ' + -- Create trigger for syncing quill_doc and string + CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); + ' +, schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1260 (class 1255 OID 20848) +-- Name: modernize_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.modernize_quill_doc(orig jsonb) + RETURNS jsonb + LANGUAGE plpgsql + IMMUTABLE + AS $$ +DECLARE + newJ jsonb; + latestId int; + newOps jsonb; + oldOp jsonb; + char text; +BEGIN + newOps = jsonb_build_array(); + latestId = 0; + -- LOOP over ops + FOR oldOp IN + SELECT + * + FROM + jsonb_array_elements((orig -> 'contents' ->> 'ops')::jsonb) + LOOP + RAISE NOTICE 'Parsing Item % % %', oldOp ->> 'insert', oldOp ->> 'attributes',( + SELECT + char_length(oldOp ->> 'insert') > 1); + -- LOOP over insert characters + FOREACH char IN ARRAY ( + SELECT + chars + FROM ( + SELECT + regexp_split_to_array(oldOp ->> 'insert', '')) AS x(chars)) + LOOP + latestId = latestId + 1; + IF char = E'\n' THEN + newOps = newOps || jsonb_build_object('insert', char, 'attributes', jsonb_set(COALESCE(oldOp -> 'attributes', '{}'::jsonb), '{blockid}'::text[], to_json(latestId::text)::jsonb)); + ELSE + newOps = newOps || jsonb_build_object('insert', char, 'attributes', jsonb_set(COALESCE(oldOp -> 'attributes', '{}'::jsonb) - 'node', '{charid}'::text[], to_json(latestId::text)::jsonb)); + END IF; + END LOOP; + END LOOP; + RAISE NOTICE 'New Ops: %', newOps; + newJ = jsonb_build_object('latestId', latestId, 'ops', newOps); + RETURN newJ; +END; +$$; + +-- +-- TOC entry 1261 (class 1255 OID 20849) +-- Name: move_entity_child_with_vt_to_schema(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.move_entity_child_with_vt_to_schema(table_name character varying, old_schema character varying, new_schema character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + -- Do the Magic: + EXECUTE format( ' + -- MOVE TABLES + ALTER TABLE %2$s.%1$s SET SCHEMA %3$s; + ALTER TABLE %2$s.%1$s_vt SET SCHEMA %3$s; + + -- REINIT VERSIONING TRIGGERS + SELECT commons.reinit_versioning_triggers(''%3$s.%1$s''); + + -- CHANGE PARENT ENTITY TABLE + SELECT commons.change_parent_entity_table(''%3$s.%1$s'', ''%2$s.entity'', ''%3$s.entity'') + ' +, table_name, old_schema, new_schema); +END +$_$; + +-- +-- TOC entry 1319 (class 1255 OID 24512) +-- Name: notify_modification_trigger(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.notify_modification_trigger() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + -- Notify the channel, e.g.: "modified_projects_text_property" + PERFORM + pg_notify('modified_' || TG_TABLE_SCHEMA || '_' || TG_TABLE_NAME, now()::text); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1262 (class 1255 OID 20850) +-- Name: quill_doc_to_string(jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.quill_doc_to_string(text_property_quill_doc jsonb, OUT string text) + RETURNS text + LANGUAGE sql + AS $$ + SELECT + TRIM(TRAILING E' +' FROM STRING_AGG(l.ops->>'insert', '')) +FROM( + SELECT + jsonb_array_elements(text_property_quill_doc -> 'ops') AS ops) AS l +$$; + +-- +-- TOC entry 1263 (class 1255 OID 20851) +-- Name: reinit_versioning_triggers(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.reinit_versioning_triggers(schema_and_table_name character varying, schema_and_table_vt_name character varying DEFAULT NULL::character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + IF schema_and_table_vt_name IS NULL THEN + schema_and_table_vt_name = schema_and_table_name || '_vt'; + END IF; + -- Do the Magic: + EXECUTE format( ' + + -- Trigger: versioning_trigger + + DROP TRIGGER IF EXISTS versioning_trigger ON %1$s; + CREATE TRIGGER versioning_trigger + BEFORE INSERT OR UPDATE OR DELETE ON %1$s + FOR EACH ROW EXECUTE PROCEDURE versioning( + "sys_period", ''%2$s'', true + ); + + -- Trigger: create_entity_version_key + + DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s; + CREATE TRIGGER create_entity_version_key + BEFORE INSERT + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.create_entity_version_key(); + + -- Trigger: update_entity_version_key + + DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s; + CREATE TRIGGER update_entity_version_key + BEFORE UPDATE + ON %1$s + FOR EACH ROW + EXECUTE PROCEDURE commons.update_entity_version_key();' +, schema_and_table_name, schema_and_table_vt_name); +END +$_$; + +-- +-- TOC entry 1264 (class 1255 OID 20852) +-- Name: rename_versioned_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.rename_versioned_table(schema character varying, old_table_name character varying, new_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + -- Do the Magic: + EXECUTE format(' + ALTER TABLE %1$s.%2$s RENAME TO %3$s; + ALTER TABLE %1$s.%2$s_vt RENAME TO %3$s_vt; + SELECT commons.reinit_versioning_triggers(''%1$s.%3$s''); + ', schema, old_table_name, new_table_name); +END +$_$; + +-- +-- TOC entry 1284 (class 1255 OID 20853) +-- Name: string_to_quill_doc(text); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.string_to_quill_doc(text text) + RETURNS jsonb + LANGUAGE plpgsql + IMMUTABLE + AS $$ +DECLARE + latestId int; + ops jsonb; + char text; +BEGIN + ops = jsonb_build_array(); + latestId = 1; + -- LOOP over text characters + FOREACH char IN ARRAY ( + SELECT + CASE WHEN chars = ARRAY[''] THEN + ARRAY[]::text[] + ELSE + chars + END + FROM ( + SELECT + regexp_split_to_array(text, '')) AS x(chars)) + LOOP + IF char = E'\n' THEN + ops = ops || jsonb_build_object('insert', char, 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb)); + ELSE + ops = ops || jsonb_build_object('insert', char, 'attributes', jsonb_build_object('charid', to_json(latestId::text)::jsonb)); + END IF; + latestId = latestId + 1; + END LOOP; + ops = ops || jsonb_build_object('insert', E'\n', 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb)); + RETURN jsonb_build_object('latestId', latestId, 'ops', ops); +END; +$$; + +-- +-- TOC entry 1268 (class 1255 OID 20854) +-- Name: text__sync_quill_doc_and_string(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.text__sync_quill_doc_and_string() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + string_is_new boolean; + quill_doc_is_new boolean; +BEGIN + IF TG_OP = 'UPDATE' THEN + string_is_new =(NEW.string IS NOT NULL + AND NEW.string != OLD.string); + quill_doc_is_new =(NEW.quill_doc IS NOT NULL + AND NEW.quill_doc != OLD.quill_doc); + ELSE + string_is_new =(NEW.string IS NOT NULL); + quill_doc_is_new =(NEW.quill_doc IS NOT NULL); + END IF; + -- If both string and quill_doc are NOT NULL, raise exception + IF (string_is_new = TRUE AND quill_doc_is_new = TRUE) THEN + RAISE EXCEPTION 'You can not provide a string and a quill_doc at the same time when upserting a text.'; + -- If only string is NOT NULL create quill_doc + ELSIF string_is_new = TRUE THEN + NEW.quill_doc = commons.string_to_quill_doc(NEW.string); + -- If only quill_doc is NOT NULL create string + ELSIF quill_doc_is_new = TRUE THEN + NEW.string = commons.quill_doc_to_string(NEW.quill_doc); + -- If both string and quill_doc are NULL, do nothing + END IF; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1295 (class 1255 OID 23951) +-- Name: time_primitive__get_first_second(integer); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.time_primitive__get_first_second(julian_day integer) + RETURNS bigint + LANGUAGE sql + AS $$ + SELECT +(julian_day::bigint * 86400::bigint); + -- 86400 = 60 * 60 * 24 = number of seconds per day +$$; + +-- +-- TOC entry 1305 (class 1255 OID 23952) +-- Name: time_primitive__get_last_second(integer, public.calendar_granularities, public.calendar_type); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.time_primitive__get_last_second(julian_day integer, duration public.calendar_granularities, calendar public.calendar_type) + RETURNS bigint + LANGUAGE plpgsql + AS $$ +DECLARE + day_after_added_duration int; +BEGIN + IF (calendar IS NULL) THEN + RAISE WARNING 'No calendar provided'; + IF (julian_day < 2299161) THEN + calendar = 'julian'; + ELSE + calendar = 'gregorian'; + END IF; + END IF; + IF (calendar = 'gregorian') THEN + IF (duration = '1 day') THEN + SELECT + julian_day + 1 INTO day_after_added_duration; + ELSIF (duration = '1 month') THEN + SELECT + to_char((('J' || julian_day::text)::date + INTERVAL '1 month'), 'J') INTO day_after_added_duration; + ELSIF (duration = '1 year') THEN + SELECT + to_char((('J' || julian_day::text)::date + INTERVAL '1 year'), 'J') INTO day_after_added_duration; + ELSE + RAISE EXCEPTION 'duration not supported --> %', duration + USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; + END IF; + ELSIF (calendar = 'julian') THEN + IF (duration = '1 day') THEN + SELECT + julian_day + 1 INTO day_after_added_duration; + ELSIF (duration = '1 month') THEN + SELECT + commons.julian_cal__add_1_month(julian_day) INTO day_after_added_duration; + ELSIF (duration = '1 year') THEN + SELECT + commons.julian_cal__add_1_year(julian_day) INTO day_after_added_duration; + ELSE + RAISE EXCEPTION 'duration not supported --> %', duration + USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; + END IF; + ELSE + RAISE EXCEPTION 'calendar not supported --> %', calendar + USING HINT = 'Supported calendars: "gregorian", "julian"'; + END IF; + -- calculate the first second of the day after the added duration and subtract one second + -- so that we get the last second of the duration + RETURN commons.time_primitive__get_first_second(day_after_added_duration) - 1; +END; +$$; + +-- +-- TOC entry 1321 (class 1255 OID 24580) +-- Name: time_primitive__get_to_day(integer, public.calendar_granularities, public.calendar_type); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.time_primitive__get_to_day(julian_day integer, duration public.calendar_granularities, calendar public.calendar_type) + RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + day_after_added_duration int; +BEGIN + IF (calendar IS NULL) THEN + RAISE WARNING 'No calendar provided'; + IF (julian_day < 2299161) THEN + calendar = 'julian'; + ELSE + calendar = 'gregorian'; + END IF; + END IF; + IF (calendar = 'gregorian') THEN + IF (duration = '1 day') THEN + SELECT + julian_day + 1 INTO day_after_added_duration; + ELSIF (duration = '1 month') THEN + SELECT + to_char((('J' || julian_day::text)::date + INTERVAL '1 month'), 'J') INTO day_after_added_duration; + ELSIF (duration = '1 year') THEN + SELECT + to_char((('J' || julian_day::text)::date + INTERVAL '1 year'), 'J') INTO day_after_added_duration; + ELSE + RAISE EXCEPTION 'duration not supported --> %', duration + USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; + END IF; + ELSIF (calendar = 'julian') THEN + IF (duration = '1 day') THEN + SELECT + julian_day + 1 INTO day_after_added_duration; + ELSIF (duration = '1 month') THEN + SELECT + commons.julian_cal__add_1_month(julian_day) INTO day_after_added_duration; + ELSIF (duration = '1 year') THEN + SELECT + commons.julian_cal__add_1_year(julian_day) INTO day_after_added_duration; + ELSE + RAISE EXCEPTION 'duration not supported --> %', duration + USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; + END IF; + ELSE + RAISE EXCEPTION 'calendar not supported --> %', calendar + USING HINT = 'Supported calendars: "gregorian", "julian"'; + END IF; + RETURN day_after_added_duration; +END; +$$; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- TOC entry 233 (class 1259 OID 20867) +-- Name: entity; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.entity( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb +); + +-- +-- TOC entry 302 (class 1259 OID 21439) +-- Name: time_primitive; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.time_primitive( + duration public.calendar_granularities, + fk_class integer, + julian_day integer, + calendar public.calendar_type NOT NULL +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 1316 (class 1255 OID 24695) +-- Name: time_primitive__pretty_json(information.time_primitive); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.time_primitive__pretty_json(time_primitive information.time_primitive) + RETURNS jsonb + LANGUAGE plpgsql + AS $$ +DECLARE + from_day int; + from_second bigint; + from_julian_cal varchar; + from_gregorian_cal varchar; + from_gregorian_cal_iso8601 varchar; + to_day int; + to_second bigint; + to_julian_cal varchar; + to_gregorian_cal varchar; + to_gregorian_cal_iso8601 varchar; + label varchar; +BEGIN + from_day = time_primitive.julian_day; + SELECT + commons.time_primitive__get_first_second(from_day) INTO from_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO from_julian_cal + FROM + commons.julian_cal__year_month_day(from_day) t; + SELECT + to_char((('J' || from_day)::timestamp), 'YYYY-MM-DD') INTO from_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(from_second) INTO from_gregorian_cal_iso8601; + SELECT + commons.time_primitive__get_to_day(from_day, time_primitive.duration, time_primitive.calendar) INTO to_day; + SELECT + commons.time_primitive__get_first_second(to_day) INTO to_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO to_julian_cal + FROM + commons.julian_cal__year_month_day(to_day) t; + SELECT + to_char((('J' || to_day)::timestamp), 'YYYY-MM-DD') INTO to_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(to_second) INTO to_gregorian_cal_iso8601; + SELECT + CASE WHEN time_primitive.calendar = 'gregorian' THEN + concat(from_gregorian_cal, ' (', time_primitive.duration, ')') + ELSE + concat(from_julian_cal, ' (', time_primitive.duration, ')') + END INTO label; + RETURN jsonb_build_object('pkEntity', time_primitive.pk_entity, 'fkClass', time_primitive.fk_class, 'julianDay', time_primitive.julian_day, 'duration', time_primitive.duration, 'calendar', time_primitive.calendar::text, 'label', label, 'from', jsonb_build_object('julianDay', from_day, 'julianSecond', from_second, 'calGregorian', from_gregorian_cal, 'calGregorianIso8601', from_gregorian_cal_iso8601, 'calJulian', from_julian_cal), 'to', jsonb_build_object('julianDay', to_day, 'julianSecond', to_second, 'calGregorian', to_gregorian_cal, 'calGregorianIso8601', to_gregorian_cal_iso8601, 'calJulian', to_julian_cal)); +END; +$$; + +-- +-- TOC entry 1322 (class 1255 OID 24581) +-- Name: time_primitive__pretty_json(information.time_primitive, public.calendar_type); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.time_primitive__pretty_json(time_primitive information.time_primitive, calendar public.calendar_type) + RETURNS jsonb + LANGUAGE plpgsql + AS $$ +DECLARE + from_day int; + from_second bigint; + from_julian_cal varchar; + from_gregorian_cal varchar; + from_gregorian_cal_iso8601 varchar; + to_day int; + to_second bigint; + to_julian_cal varchar; + to_gregorian_cal varchar; + to_gregorian_cal_iso8601 varchar; + label varchar; +BEGIN + from_day = time_primitive.julian_day; + SELECT + commons.time_primitive__get_first_second(from_day) INTO from_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO from_julian_cal + FROM + commons.julian_cal__year_month_day(from_day) t; + SELECT + to_char((('J' || from_day)::timestamp), 'YYYY-MM-DD') INTO from_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(from_second) INTO from_gregorian_cal_iso8601; + SELECT + commons.time_primitive__get_to_day(from_day, time_primitive.duration, calendar) INTO to_day; + SELECT + commons.time_primitive__get_first_second(to_day) INTO to_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO to_julian_cal + FROM + commons.julian_cal__year_month_day(to_day) t; + SELECT + to_char((('J' || to_day)::timestamp), 'YYYY-MM-DD') INTO to_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(to_second) INTO to_gregorian_cal_iso8601; + SELECT + CASE WHEN calendar = 'gregorian' THEN + concat(from_gregorian_cal, ' (', time_primitive.duration, ')') + ELSE + concat(from_julian_cal, ' (', time_primitive.duration, ')') + END INTO label; + RETURN jsonb_build_object('pkEntity', time_primitive.pk_entity, 'fkClass', time_primitive.fk_class, 'julianDay', time_primitive.julian_day, 'duration', time_primitive.duration, 'calendar', calendar::text, 'label', label, 'from', jsonb_build_object('julianDay', from_day, 'julianSecond', from_second, 'calGregorian', from_gregorian_cal, 'calGregorianIso8601', from_gregorian_cal_iso8601, 'calJulian', from_julian_cal), 'to', jsonb_build_object('julianDay', to_day, 'julianSecond', to_second, 'calGregorian', to_gregorian_cal, 'calGregorianIso8601', to_gregorian_cal_iso8601, 'calJulian', to_julian_cal)); +END; +$$; + +-- +-- TOC entry 1265 (class 1255 OID 20855) +-- Name: tmsp_creation(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.tmsp_creation() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.tmsp_creation = NOW(); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1266 (class 1255 OID 20856) +-- Name: tmsp_last_modification(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.tmsp_last_modification() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.tmsp_last_modification = NOW(); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1269 (class 1255 OID 20857) +-- Name: unmake_change_fk_reference_of_versioned_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.unmake_change_fk_reference_of_versioned_table(schema_name character varying, table_name character varying, fk_column character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format( ' + + DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; + DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; + DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; + + DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; + DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; + DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; + + -- table_vt + ALTER TABLE %1$s.%2$s_vt DROP CONSTRAINT %2$s_vt_%3$s_fkey; + UPDATE %1$s.%2$s_vt + SET %3$s = _deprecated_%3$s; + ALTER TABLE %1$s.%2$s_vt DROP COLUMN %3$s; + ALTER TABLE %1$s.%2$s_vt RENAME COLUMN _deprecated_%3$s TO %3$s; + + -- table + ALTER TABLE %1$s.%2$s DROP CONSTRAINT %2$s_%3$s_fkey; + UPDATE %1$s.%2$s + SET %3$s = _deprecated_%3$s; + ALTER TABLE %1$s.%2$s DROP COLUMN %3$s; + ALTER TABLE %1$s.%2$s RENAME COLUMN _deprecated_%3$s TO %3$s; + + + SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); + + -- Trigger: creation_tmsp + CREATE TRIGGER creation_tmsp + BEFORE INSERT + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_creation(); + + -- Trigger: insert_schema_table_name + CREATE TRIGGER insert_schema_table_name + BEFORE INSERT + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.insert_schema_table_name(); + + -- Trigger: last_modification_tmsp + CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON %1$s.%2$s + FOR EACH ROW + EXECUTE PROCEDURE commons.tmsp_last_modification(); + ' +, schema_name, table_name, fk_column); +END +$_$; + +-- +-- TOC entry 1270 (class 1255 OID 20858) +-- Name: unmake_table_child_of_text(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.unmake_table_child_of_text(schema_and_table_name character varying, parent_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format(' + ALTER TABLE %1$s NO INHERIT commons.%2$s; + + ALTER TABLE %1$s DROP COLUMN string; + + ALTER TABLE %1$s DROP CONSTRAINT text_quill_doc_check; + + ALTER TABLE %1$s DROP COLUMN quill_doc; + + ALTER TABLE %1$s DROP COLUMN pk_text; + + ', schema_and_table_name, parent_table_name); +END +$_$; + +-- +-- TOC entry 1271 (class 1255 OID 20859) +-- Name: unmake_versioned_table_child_of_text(character varying); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.unmake_versioned_table_child_of_text(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + PERFORM + commons.unmake_table_child_of_text(schema_and_table_name, 'text'); + PERFORM + commons.unmake_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); + EXECUTE format(' + DROP TRIGGER sync_quill_doc_and_string ON %1$s; + ', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1272 (class 1255 OID 20860) +-- Name: update_entity_version_key(); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.update_entity_version_key() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.entity_version := NEW.entity_version + 1; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1273 (class 1255 OID 20861) +-- Name: validate_json_schema(jsonb, jsonb, jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.validate_json_schema(schema jsonb, data jsonb, root_schema jsonb DEFAULT NULL::jsonb) + RETURNS boolean + LANGUAGE plpgsql + IMMUTABLE + AS $_$ +DECLARE + prop text; + item jsonb; + path text[]; + types text[]; + pattern text; + props text[]; +BEGIN + IF root_schema IS NULL THEN + root_schema = SCHEMA; + END IF; + IF SCHEMA ? 'type' THEN + IF jsonb_typeof(schema -> 'type') = 'array' THEN + types = ARRAY ( + SELECT + jsonb_array_elements_text(schema -> 'type')); + ELSE + types = ARRAY[SCHEMA ->> 'type']; + END IF; + IF ( + SELECT + NOT bool_or(commons._validate_json_schema_type(type, data)) + FROM + unnest(types) + type) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'properties' THEN + FOR prop IN + SELECT + jsonb_object_keys(schema -> 'properties') + LOOP + IF data ? prop AND NOT commons.validate_json_schema(schema -> 'properties' -> prop, data -> prop, root_schema) THEN + RETURN FALSE; + END IF; + END LOOP; + END IF; + IF SCHEMA ? 'required' AND jsonb_typeof(data) = 'object' THEN + IF NOT ARRAY ( + SELECT + jsonb_object_keys(data)) @> ARRAY ( + SELECT + jsonb_array_elements_text(schema -> 'required')) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'items' AND jsonb_typeof(data) = 'array' THEN + IF jsonb_typeof(schema -> 'items') = 'object' THEN + FOR item IN + SELECT + jsonb_array_elements(data) + LOOP + IF NOT commons.validate_json_schema(schema -> 'items', item, root_schema) THEN + RETURN FALSE; + END IF; + END LOOP; + ELSE + IF NOT ( + SELECT + bool_and(i > jsonb_array_length(schema -> 'items') OR commons.validate_json_schema(schema -> 'items' ->(i::int - 1), elem, root_schema)) + FROM + jsonb_array_elements(data) + WITH ORDINALITY AS t(elem, i)) THEN + RETURN FALSE; + END IF; + END IF; + END IF; + IF jsonb_typeof(schema -> 'additionalItems') = 'boolean' AND NOT (schema -> 'additionalItems')::text::boolean AND jsonb_typeof(schema -> 'items') = 'array' THEN + IF jsonb_array_length(data) > jsonb_array_length(schema -> 'items') THEN + RETURN FALSE; + END IF; + END IF; + IF jsonb_typeof(schema -> 'additionalItems') = 'object' THEN + IF NOT ( + SELECT + bool_and(validate_json_schema(schema -> 'additionalItems', elem, root_schema)) + FROM + jsonb_array_elements(data) + WITH ORDINALITY AS t(elem, i) + WHERE + i > jsonb_array_length(schema -> 'items')) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'minimum' AND jsonb_typeof(data) = 'number' THEN + IF data::text::numeric <(schema ->> 'minimum')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'maximum' AND jsonb_typeof(data) = 'number' THEN + IF data::text::numeric >(schema ->> 'maximum')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF COALESCE((schema -> 'exclusiveMinimum')::text::bool, FALSE) THEN + IF data::text::numeric =(schema ->> 'minimum')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF COALESCE((schema -> 'exclusiveMaximum')::text::bool, FALSE) THEN + IF data::text::numeric =(schema ->> 'maximum')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'anyOf' THEN + IF NOT ( + SELECT + bool_or(validate_json_schema(sub_schema, data, root_schema)) + FROM + jsonb_array_elements(schema -> 'anyOf') sub_schema) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'allOf' THEN + IF NOT ( + SELECT + bool_and(validate_json_schema(sub_schema, data, root_schema)) + FROM + jsonb_array_elements(schema -> 'allOf') sub_schema) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'oneOf' THEN + IF 1 !=( + SELECT + COUNT(*) + FROM jsonb_array_elements(schema -> 'oneOf') sub_schema + WHERE + commons.validate_json_schema(sub_schema, data, root_schema)) THEN + RETURN FALSE; + END IF; + END IF; + IF COALESCE((schema -> 'uniqueItems')::text::boolean, FALSE) THEN + IF ( + SELECT + COUNT(*) + FROM + jsonb_array_elements(data)) !=( + SELECT + count(DISTINCT val) + FROM + jsonb_array_elements(data) val) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'additionalProperties' AND jsonb_typeof(data) = 'object' THEN + props := ARRAY ( + SELECT + key + FROM + jsonb_object_keys(data) + key + WHERE + key NOT IN ( + SELECT + jsonb_object_keys(schema -> 'properties')) + AND NOT EXISTS ( + SELECT + * + FROM + jsonb_object_keys(schema -> 'patternProperties') pat + WHERE + key ~ pat)); + IF jsonb_typeof(schema -> 'additionalProperties') = 'boolean' THEN + IF NOT (schema -> 'additionalProperties')::text::boolean AND jsonb_typeof(data) = 'object' AND NOT props <@ ARRAY ( + SELECT + jsonb_object_keys(schema -> 'properties')) THEN + RETURN FALSE; + END IF; + ELSEIF NOT ( + SELECT + bool_and(validate_json_schema(schema -> 'additionalProperties', data -> key, root_schema)) + FROM + unnest(props) + key) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? '$ref' THEN + path := ARRAY ( + SELECT + regexp_replace(regexp_replace(path_part, '~1', '/'), '~0', '~') + FROM + UNNEST(regexp_split_to_array(schema ->> '$ref', '/')) path_part); + -- ASSERT path[1] = '#', 'only refs anchored at the root are supported'; + IF NOT commons.validate_json_schema(root_schema #> path[2:array_length(path, 1)], data, root_schema) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'enum' THEN + IF NOT EXISTS ( + SELECT + * + FROM + jsonb_array_elements(schema -> 'enum') val + WHERE + val = data) THEN + RETURN FALSE; + END IF; +END IF; + IF SCHEMA ? 'minLength' AND jsonb_typeof(data) = 'string' THEN + IF char_length(data #>> '{}') <(schema ->> 'minLength')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'maxLength' AND jsonb_typeof(data) = 'string' THEN + IF char_length(data #>> '{}') >(schema ->> 'maxLength')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'not' THEN + IF commons.validate_json_schema(schema -> 'not', data, root_schema) THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'maxProperties' AND jsonb_typeof(data) = 'object' THEN + IF ( + SELECT + count(*) + FROM + jsonb_object_keys(data)) >(schema ->> 'maxProperties')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'minProperties' AND jsonb_typeof(data) = 'object' THEN + IF ( + SELECT + count(*) + FROM + jsonb_object_keys(data)) <(schema ->> 'minProperties')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'maxItems' AND jsonb_typeof(data) = 'array' THEN + IF ( + SELECT + count(*) + FROM + jsonb_array_elements(data)) >(schema ->> 'maxItems')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'minItems' AND jsonb_typeof(data) = 'array' THEN + IF ( + SELECT + count(*) + FROM + jsonb_array_elements(data)) <(schema ->> 'minItems')::numeric THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'dependencies' THEN + FOR prop IN + SELECT + jsonb_object_keys(schema -> 'dependencies') + LOOP + IF data ? prop THEN + IF jsonb_typeof(schema -> 'dependencies' -> prop) = 'array' THEN + IF NOT ( + SELECT + bool_and(data ? dep) + FROM + jsonb_array_elements_text(schema -> 'dependencies' -> prop) dep) THEN + RETURN FALSE; + END IF; + ELSE + IF NOT commons.validate_json_schema(schema -> 'dependencies' -> prop, data, root_schema) THEN + RETURN FALSE; + END IF; + END IF; + END IF; + END LOOP; + END IF; + IF SCHEMA ? 'pattern' AND jsonb_typeof(data) = 'string' THEN + IF (data #>> '{}') !~(schema ->> 'pattern') THEN + RETURN FALSE; + END IF; + END IF; + IF SCHEMA ? 'patternProperties' AND jsonb_typeof(data) = 'object' THEN + FOR prop IN + SELECT + jsonb_object_keys(data) + LOOP + FOR pattern IN + SELECT + jsonb_object_keys(schema -> 'patternProperties') + LOOP + RAISE NOTICE 'prop %s, pattern %, schema %', prop, pattern, schema -> 'patternProperties' -> pattern; + IF prop ~ pattern AND NOT commons.validate_json_schema(schema -> 'patternProperties' -> pattern, data -> prop, root_schema) THEN + RETURN FALSE; + END IF; + END LOOP; + END LOOP; + END IF; + IF SCHEMA ? 'multipleOf' AND jsonb_typeof(data) = 'number' THEN + IF data::text::numeric %(schema ->> 'multipleOf')::numeric != 0 THEN + RETURN FALSE; + END IF; + END IF; + RETURN TRUE; +END; +$_$; + +-- +-- TOC entry 1274 (class 1255 OID 20863) +-- Name: validate_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - +-- +CREATE FUNCTION commons.validate_quill_doc(quilldoc jsonb) + RETURNS boolean + LANGUAGE plpgsql + IMMUTABLE + AS $_$ +DECLARE + isValid boolean; +BEGIN + SELECT + INTO isValid commons.validate_json_schema('{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "QuillDoc": { + "type": "object", + "properties": { + "latestId": { + "type": "number" + }, + "ops": { + "type": "array", + "items": { + "$ref": "#/definitions/Op" + } + } + }, + "required": [ + "latestId" + ], + "additionalProperties": false + }, + "Op": { + "type": "object", + "properties": { + "insert": { + "type": "string", + "minLength": 1, + "maxLength": 1 + }, + "attributes": { + "type": "object", + "properties": { + "charid": { + "type": "string" + }, + "blockid": { + "type": "string" + } + } + } + }, + "required": [ + "insert" + ], + "additionalProperties": false + } + }, + "$ref": "#/definitions/QuillDoc" + }'::jsonb, quillDoc); + RETURN isValid; +END; +$_$; + +-- +-- TOC entry 1286 (class 1255 OID 23556) +-- Name: rebuild_digital_table(integer, integer[]); Type: FUNCTION; Schema: data; Owner: - +-- +CREATE FUNCTION data.rebuild_digital_table(id_digital integer, column_list integer[]) + RETURNS text + LANGUAGE plpgsql + AS $$ +DECLARE + query_start text; + query_from text; + query text; + field text; + field_label text; + field_metadata json; + n integer = 1; + a integer; + output_query text; +BEGIN + query_start = 'DROP VIEW IF EXISTS tv_' || id_digital || '; + CREATE OR REPLACE TEMPORARY VIEW tv_' || id_digital || ' AS + SELECT dr.pk_entity'; + query_from = ' FROM data.row dr'; + IF array_length(column_list, 1) > 0 THEN + FOR a IN + SELECT + UNNEST(column_list) + LOOP + SELECT + row_to_json(pk_entity, id_for_import_txt, fk_data_type) INTO field_metadata + FROM + data.column + WHERE + pk_entity = a; + field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); + IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN + field = 't' || n || '.numeric_value'; + ELSE + field = 't' || n || '.id_for_import_txt'; + -- .string .id_for_import_txt + END IF; + query_start = query_start || ', ' || field || ' AS ' || field_label; + query_from = query_from || ' JOIN data.cell t' || n || ' ON dr.pk_entity = t' || n || '.fk_row AND t' || n || '.fk_column = ' ||(field_metadata -> 'f1')::text; + n = n + 1; + -- RAISE NOTICE '%', query_start ; -- return current row of SELECT + END LOOP; + ELSE + FOR field_metadata IN + SELECT + row_to_json(pk_entity, id_for_import_txt, fk_data_type) + FROM + data.column + WHERE + fk_digital = id_digital + ORDER BY + pk_entity LOOP + field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); + IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN + field = 't' || n || '.numeric_value'; + ELSE + field = 't' || n || '.id_for_import_txt'; + -- .string .id_for_import_txt + END IF; + query_start = query_start || ', ' || field || ' AS ' || field_label; + query_from = query_from || ' JOIN data.cell t' || n || ' ON dr.pk_entity = t' || n || '.fk_row AND t' || n || '.fk_column = ' ||(field_metadata -> 'f1')::text; + n = n + 1; + -- RAISE NOTICE '%', query_start ; -- return current row of SELECT + END LOOP; + END IF; + query := query_start || query_from || 'WHERE dr.fk_digital = ' || id_digital || ';'; + RAISE NOTICE '%', query; + EXECUTE query; + output_query := 'SELECT * FROM tv_' || id_digital || ' LIMIT 10'; + RETURN output_query; +END; +$$; + +-- +-- TOC entry 1285 (class 1255 OID 23228) +-- Name: v_chunk_find_or_create(); Type: FUNCTION; Schema: data; Owner: - +-- +CREATE FUNCTION data.v_chunk_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + same_chunk data.chunk; + same_chunk_version boolean; + resulting_row data.v_chunk; + resulting_pk int; +BEGIN + ------ Search if such a chunk exists ----- + SELECT + * + FROM + INTO same_chunk data.chunk + WHERE + quill_doc::jsonb = NEW.quill_doc::jsonb + AND fk_text = NEW.fk_text; + -- if not existing + IF same_chunk.pk_entity IS NULL THEN + -- insert a new chunk + WITH _insert AS ( +INSERT INTO data.chunk(quill_doc, fk_text, fk_entity_version, metadata, fk_namespace, fk_license, fk_publication_status) + VALUES (NEW.quill_doc::jsonb, NEW.fk_text, NEW.fk_entity_version, NEW.metadata, NEW.fk_namespace, NEW.fk_license, NEW.fk_publication_status) + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- if existing + ELSIF same_chunk.pk_entity IS NOT NULL THEN + -- if the fk_entity_version of the found chunk differs from the new + IF NEW.fk_entity_version != same_chunk.fk_entity_version THEN + -- update the chunk so that we keep track of when which version was annotated + UPDATE + data.chunk + SET + fk_entity_version = NEW.fk_entity_version + WHERE + pk_entity = same_chunk.pk_entity; + END IF; + -- set the resulting pk + resulting_pk = same_chunk.pk_entity; + END IF; + -- select and return the latest chunk version from the view + SELECT + * + FROM + INTO resulting_row data.v_chunk + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1308 (class 1255 OID 24129) +-- Name: update_api_classes_profile_table(integer, character varying, timestamp with time zone, json); Type: FUNCTION; Schema: data_for_history; Owner: - +-- +CREATE FUNCTION data_for_history.update_api_classes_profile_table(param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_classes_profile_data json DEFAULT '[]' ::json) + RETURNS json + LANGUAGE plpgsql + AS $$ +DECLARE + removed json; + updated json; + inserted json; +BEGIN + /* + * create a table with same type as from json + */ + DROP TABLE IF EXISTS classes_profile_from_api; + CREATE TEMP TABLE classes_profile_from_api AS + SELECT + param_requested_language AS requested_language, + "classID" AS dfh_pk_class, + "classIdentifierInNamespace" AS dfh_class_identifier_in_namespace, + "classLabelLanguage" AS dfh_class_label_language, + "classLabel" AS dfh_class_label, + "classScopeNoteLanguage" AS dfh_class_scope_note_language, + "classScopeNote" AS dfh_class_scope_note, + "entityBasicType" AS dfh_basic_type, + "entityBasicTypeLabel" AS dfh_basic_type_label, + "namespaceID" AS dfh_fk_namespace, + "namespaceLabelLanguage" AS dfh_namespace_label_language, + "namespaceLabel" AS dfh_namespace_label, + "namespaceURI" AS dfh_namespace_uri, + "profileAssociationType" AS dfh_profile_association_type, + "profileID" AS dfh_fk_profile, + "profileLabelLanguage" AS dfh_profile_label_language, + "profileLabel" AS dfh_profile_label, + "parentClasses" AS dfh_parent_classes, + "ancestorClasses" AS dfh_ancestor_classes + FROM + json_to_recordset(param_classes_profile_data) AS x("classID" int, + "classIdentifierInNamespace" varchar, + "classLabel" text, + "classLabelLanguage" varchar, + "classScopeNote" text, + "classScopeNoteLanguage" varchar, + "entityBasicType" int, + "entityBasicTypeLabel" text, + "namespaceID" int, + "namespaceLabel" text, + "namespaceLabelLanguage" varchar, + "namespaceURI" text, + "profileAssociationType" text, + "profileID" int, + "profileLabel" text, + "profileLabelLanguage" varchar, + "parentClasses" int[], + "ancestorClasses" int[]); + + /* + * Update tmsp_last_dfh_update for all records of given + * profile_id + */ + UPDATE + data_for_history.api_class + SET + tmsp_last_dfh_update = param_tmsp_last_dfh_update + WHERE + dfh_fk_profile = param_profile_id; + + /* + * Mark all records missing in the json data + * as removed from api. + * (this is independent from the requested language) + */ + WITH tw1 AS ( + SELECT + dfh_pk_class, + dfh_fk_profile + FROM + data_for_history.api_class + WHERE + dfh_fk_profile = param_profile_id + EXCEPT + SELECT + dfh_pk_class, + dfh_fk_profile + FROM + classes_profile_from_api + WHERE + dfh_fk_profile = param_profile_id +), +tw2 AS ( + UPDATE + data_for_history.api_class t1 + SET + removed_from_api = TRUE + FROM + tw1 t2 + WHERE + t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class + RETURNING + t1.* +) +SELECT + jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) INTO removed +FROM + tw2; + + /* + * Update class_label + */ + UPDATE + data_for_history.api_class t1 + SET + dfh_class_label = t2.dfh_class_label + FROM + classes_profile_from_api t2 + WHERE + t1.dfh_class_label_language = t2.dfh_class_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class; + + /* + * Update class_scope_note + */ + UPDATE + data_for_history.api_class t1 + SET + dfh_class_scope_note = t2.dfh_class_scope_note + FROM + classes_profile_from_api t2 + WHERE + t1.dfh_class_scope_note_language = t2.dfh_class_scope_note_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class; + + /* + * Update namespace_label + */ + UPDATE + data_for_history.api_class t1 + SET + dfh_namespace_label = t2.dfh_namespace_label + FROM + classes_profile_from_api t2 + WHERE + t1.dfh_namespace_label_language = t2.dfh_namespace_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class; + + /* + * Update profile_label + */ + UPDATE + data_for_history.api_class t1 + SET + dfh_profile_label = t2.dfh_profile_label + FROM + classes_profile_from_api t2 + WHERE + t1.dfh_profile_label_language = t2.dfh_profile_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class; + + /* + * Update language independent fields of existing records + * This affects also records of other languages than the requested + */ + WITH tw1 AS ( + UPDATE + data_for_history.api_class t1 + SET + removed_from_api = FALSE, + dfh_class_identifier_in_namespace = t2.dfh_class_identifier_in_namespace, + dfh_basic_type = t2.dfh_basic_type, + dfh_basic_type_label = t2.dfh_basic_type_label, + dfh_fk_namespace = t2.dfh_fk_namespace, + dfh_namespace_uri = t2.dfh_namespace_uri, + dfh_profile_association_type = t2.dfh_profile_association_type, + dfh_parent_classes = t2.dfh_parent_classes, + dfh_ancestor_classes = t2.dfh_ancestor_classes + FROM + classes_profile_from_api t2 + WHERE + t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_class = t2.dfh_pk_class + RETURNING + t1.* +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label, 'dfh_parent_classes', dfh_parent_classes, 'dfh_ancestor_classes', dfh_ancestor_classes)) INTO updated + FROM + tw1; + + /* + * Insert all new records + */ + WITH tw1 AS ( +INSERT INTO data_for_history.api_class(tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_class, dfh_class_identifier_in_namespace, dfh_class_label_language, dfh_class_label, dfh_class_scope_note_language, dfh_class_scope_note, dfh_basic_type, dfh_basic_type_label, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_namespace_uri, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label, dfh_parent_classes, dfh_ancestor_classes) + SELECT DISTINCT ON (t1.requested_language, + t1.dfh_pk_class, + t1.dfh_fk_profile) + param_tmsp_last_dfh_update, + FALSE, + t1.requested_language, + t1.dfh_pk_class, + t1.dfh_class_identifier_in_namespace, + t1.dfh_class_label_language, + t1.dfh_class_label, + t1.dfh_class_scope_note_language, + t1.dfh_class_scope_note, + t1.dfh_basic_type, + t1.dfh_basic_type_label, + t1.dfh_fk_namespace, + t1.dfh_namespace_label_language, + t1.dfh_namespace_label, + t1.dfh_namespace_uri, + t1.dfh_profile_association_type, + t1.dfh_fk_profile, + t1.dfh_profile_label_language, + t1.dfh_profile_label, + t1.dfh_parent_classes, + t1.dfh_ancestor_classes + FROM + classes_profile_from_api t1 + WHERE + t1.requested_language = param_requested_language + AND t1.dfh_fk_profile = param_profile_id + ON CONFLICT (requested_language, + dfh_pk_class, + dfh_fk_profile) + DO UPDATE SET + tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, + removed_from_api = EXCLUDED.removed_from_api, + --requested_language = EXCLUDED.requested_language, + --dfh_pk_class = EXCLUDED.dfh_pk_class, + dfh_class_identifier_in_namespace = EXCLUDED.dfh_class_identifier_in_namespace, + dfh_class_label_language = EXCLUDED.dfh_class_label_language, + dfh_class_label = EXCLUDED.dfh_class_label, + dfh_class_scope_note_language = EXCLUDED.dfh_class_scope_note_language, + dfh_class_scope_note = EXCLUDED.dfh_class_scope_note, + dfh_basic_type = EXCLUDED.dfh_basic_type, + dfh_basic_type_label = EXCLUDED.dfh_basic_type_label, + dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, + dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, + dfh_namespace_label = EXCLUDED.dfh_namespace_label, + dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, + dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, + -- dfh_fk_profile = EXCLUDED.dfh_fk_profile, + dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, + dfh_profile_label = EXCLUDED.dfh_profile_label, + dfh_parent_classes = EXCLUDED.dfh_parent_classes, + dfh_ancestor_classes = EXCLUDED.dfh_ancestor_classes + RETURNING + * +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label, 'dfh_parent_classes', dfh_parent_classes, 'dfh_ancestor_classes', dfh_ancestor_classes)) INTO inserted + FROM + tw1; + + /* + * Return kind of a protocol + */ + RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); +END; +$$; + +-- +-- TOC entry 1327 (class 1255 OID 24128) +-- Name: update_api_profiles_table(integer, character varying, timestamp with time zone, json); Type: FUNCTION; Schema: data_for_history; Owner: - +-- +CREATE FUNCTION data_for_history.update_api_profiles_table(param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_profile_data json DEFAULT NULL::json) + RETURNS json + LANGUAGE plpgsql + AS $$ +DECLARE + removed json; + updated json; + inserted json; +BEGIN + /* + * Update tmsp_last_dfh_update for all records of given + * profile_id + */ + UPDATE + data_for_history.api_profile + SET + tmsp_last_dfh_update = param_tmsp_last_dfh_update + WHERE + dfh_pk_profile = param_profile_id; + + /* + * Q: Is profile still present in API ? + */ + IF (param_profile_data IS NULL) THEN + /* + * A: No. Profile is removed from API + */ + WITH tw1 AS ( + UPDATE + data_for_history.api_profile + SET + removed_from_api = TRUE + WHERE + dfh_pk_profile = param_profile_id + AND removed_from_api = FALSE + RETURNING + * +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_profile_label', dfh_profile_label)) INTO removed + FROM + tw1; + ELSE + /* + * A: Yes. Profile is still present in API + */ + /* + * Update profile_label + */ + UPDATE + data_for_history.api_profile + SET + dfh_profile_label = param_profile_data ->> 'profileLabel' + WHERE + dfh_pk_profile = param_profile_id + AND dfh_profile_label_language = param_profile_data ->> 'profileLabelLanguage'; + + /* + * Update profile_definition + */ + UPDATE + data_for_history.api_profile + SET + dfh_profile_definition = param_profile_data ->> 'profileDefinition' + WHERE + dfh_pk_profile = param_profile_id + AND dfh_profile_definition_language = param_profile_data ->> 'profileDefinitionLanguage'; + + /* + * Update project_label + */ + UPDATE + data_for_history.api_profile + SET + dfh_project_label = param_profile_data ->> 'ownedByProjectLabel' + WHERE + dfh_pk_profile = param_profile_id + AND dfh_project_label_language = param_profile_data ->> 'ownedByProjectLabelLanguage'; + + /* + * Update language independent fields of existing records + * of the queried profile + */ + WITH tw1 AS ( + UPDATE + data_for_history.api_profile + SET + removed_from_api = FALSE, + dfh_owned_by_project =(param_profile_data ->> 'ownedByProjectID')::int, + dfh_is_ongoing_forced_publication =(param_profile_data ->> 'isOngoingForcedPublication')::bool, + dfh_date_profile_published =(param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE, + dfh_date_profile_deprecated =(param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE + WHERE + dfh_pk_profile = param_profile_id + RETURNING + * +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO updated + FROM + tw1; + + /* + * Insert or update all fields + * of the queried profile and the requested language + */ + WITH tw1 AS ( +INSERT INTO data_for_history.api_profile(tmsp_last_dfh_update, requested_language, dfh_pk_profile, dfh_profile_label_language, dfh_profile_label, dfh_profile_definition_language, dfh_profile_definition, dfh_owned_by_project, dfh_project_label_language, dfh_project_label, dfh_is_ongoing_forced_publication, dfh_date_profile_published, dfh_date_profile_deprecated, dfh_is_root_profile, dfh_fk_root_profile) + VALUES (param_tmsp_last_dfh_update, param_requested_language,(param_profile_data ->> 'profileID')::int, param_profile_data ->> 'profileLabelLanguage', param_profile_data ->> 'profileLabel', param_profile_data ->> 'profileDefinitionLanguage', param_profile_data ->> 'profileDefinition',(param_profile_data ->> 'ownedByProjectID')::int, param_profile_data ->> 'ownedByProjectLabelLanguage', param_profile_data ->> 'ownedByProjectLabel',(param_profile_data ->> 'isOngoingForcedPublication')::bool,(param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE,(param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE,(param_profile_data ->> 'isRootProfile')::bool,(param_profile_data ->> 'fkRootProfile')::int) + ON CONFLICT (dfh_pk_profile, requested_language) + DO UPDATE SET + tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, requested_language = EXCLUDED.requested_language, dfh_pk_profile = EXCLUDED.dfh_pk_profile, dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, dfh_profile_label = EXCLUDED.dfh_profile_label, dfh_profile_definition_language = EXCLUDED.dfh_profile_definition_language, dfh_profile_definition = EXCLUDED.dfh_profile_definition, dfh_owned_by_project = EXCLUDED.dfh_owned_by_project, dfh_project_label_language = EXCLUDED.dfh_project_label_language, dfh_project_label = EXCLUDED.dfh_project_label, dfh_is_ongoing_forced_publication = EXCLUDED.dfh_is_ongoing_forced_publication, dfh_date_profile_published = EXCLUDED.dfh_date_profile_published, dfh_date_profile_deprecated = EXCLUDED.dfh_date_profile_deprecated, dfh_is_root_profile = EXCLUDED.dfh_is_root_profile, dfh_fk_root_profile = EXCLUDED.dfh_fk_root_profile + RETURNING + *) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO inserted + FROM + tw1; + END IF; + RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); +END; +$$; + +-- +-- TOC entry 1310 (class 1255 OID 24131) +-- Name: update_api_properties_profile_table(integer, character varying, timestamp with time zone, json); Type: FUNCTION; Schema: data_for_history; Owner: - +-- +CREATE FUNCTION data_for_history.update_api_properties_profile_table(param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_properties_profile_data json DEFAULT '[]' ::json) + RETURNS json + LANGUAGE plpgsql + AS $$ +DECLARE + removed json; + updated json; + inserted json; +BEGIN + /* + * create a table with same type as from json + */ + DROP TABLE IF EXISTS properties_profile_from_api; + CREATE TABLE properties_profile_from_api AS + SELECT + param_requested_language AS requested_language, + "propertyID" AS dfh_pk_property, + "propertyLabelLanguage" AS dfh_property_label_language, + "propertyLabel" AS dfh_property_label, + "propertyInverseLabel" AS dfh_property_inverse_label, + "propertyScopeNoteLanguage" AS dfh_property_scope_note_language, + "propertyScopeNote" AS dfh_property_scope_note, + "isInherited" AS dfh_is_inherited, + "propertyDomain" AS dfh_property_domain, + "domainInstancesMinQuantifier" AS dfh_domain_instances_min_quantifier, + "domainInstancesMaxQuantifier" AS dfh_domain_instances_max_quantifier, + "propertyRange" AS dfh_property_range, + "rangeInstancesMinQuantifier" AS dfh_range_instances_min_quantifier, + "rangeInstancesMaxQuantifier" AS dfh_range_instances_max_quantifier, + "identityDefining" AS dfh_identity_defining, + "isHasTypeSubproperty" AS dfh_is_has_type_subproperty, + "propertyIdentifierInNamespace" AS dfh_property_identifier_in_namespace, + "namespaceURI" AS dfh_namespace_uri, + "namespaceID" AS dfh_fk_namespace, + "namespaceLabelLanguage" AS dfh_namespace_label_language, + "namespaceLabel" AS dfh_namespace_label, + "profileAssociationType" AS dfh_profile_association_type, + "profileID" AS dfh_fk_profile, + "profileLabelLanguage" AS dfh_profile_label_language, + "profileLabel" AS dfh_profile_label, + "parentProperties" AS dfh_parent_properties, + coalesce("ancestorProperties", '{}'::int[]) AS dfh_ancestor_properties + FROM + json_to_recordset(param_properties_profile_data) AS x("propertyID" INT, + "propertyLabelLanguage" VARCHAR, + "propertyLabel" TEXT, + "propertyInverseLabel" TEXT, + "propertyScopeNoteLanguage" VARCHAR, + "propertyScopeNote" TEXT, + "isInherited" BOOLEAN, + "propertyDomain" INTEGER, + "domainInstancesMinQuantifier" INTEGER, + "domainInstancesMaxQuantifier" INTEGER, + "propertyRange" INTEGER, + "rangeInstancesMinQuantifier" INTEGER, + "rangeInstancesMaxQuantifier" INTEGER, + "identityDefining" BOOLEAN, + "isHasTypeSubproperty" BOOLEAN, + "propertyIdentifierInNamespace" VARCHAR, + "namespaceURI" TEXT, + "namespaceID" INTEGER, + "namespaceLabelLanguage" VARCHAR, + "namespaceLabel" TEXT, + "profileAssociationType" TEXT, + "profileID" INTEGER, + "profileLabelLanguage" VARCHAR, + "profileLabel" TEXT, + "parentProperties" int[], + "ancestorProperties" int[]); + + /* + * Update tmsp_last_dfh_update for all records of given + * profile_id + */ + UPDATE + data_for_history.api_property + SET + tmsp_last_dfh_update = param_tmsp_last_dfh_update + WHERE + dfh_fk_profile = param_profile_id; + + /* + * Mark all records missing in the json data + * as removed from api. + * (this is independent from the requested language) + */ + WITH tw1 AS ( + SELECT + dfh_pk_property, + dfh_property_domain, + dfh_property_range, + dfh_fk_profile + FROM + data_for_history.api_property + WHERE + dfh_fk_profile = param_profile_id + EXCEPT + SELECT + dfh_pk_property, + dfh_property_domain, + dfh_property_range, + dfh_fk_profile + FROM + properties_profile_from_api + WHERE + dfh_fk_profile = param_profile_id +), +tw2 AS ( + UPDATE + data_for_history.api_property t1 + SET + removed_from_api = TRUE + FROM + tw1 t2 + WHERE + t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property + AND t1.dfh_property_domain = t2.dfh_property_domain + AND t1.dfh_property_range = t2.dfh_property_range + RETURNING + t1.* +) +SELECT + jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO removed +FROM + tw2; + + /* + * Update language dependent fields of existing records + */ + /* + * Update property_labels + */ + UPDATE + data_for_history.api_property t1 + SET + dfh_property_label = t2.dfh_property_label + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_property_label_language = t2.dfh_property_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property; + + /* + * Update property_inverse_labels + */ + UPDATE + data_for_history.api_property t1 + SET + dfh_property_inverse_label = t2.dfh_property_inverse_label + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_property_label_language = t2.dfh_property_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property; + + /* + * Update scope_notes + */ + UPDATE + data_for_history.api_property t1 + SET + dfh_property_scope_note = t2.dfh_property_scope_note + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property; + + /* + * Update dfh_namespace_label + */ + UPDATE + data_for_history.api_property t1 + SET + dfh_namespace_label = t2.dfh_namespace_label + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_namespace_label_language = t2.dfh_namespace_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property; + + /* + * Update dfh_profile_label + */ + UPDATE + data_for_history.api_property t1 + SET + dfh_profile_label = t2.dfh_profile_label + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_profile_label_language = t2.dfh_profile_label_language + AND t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property; + + /* + * Update language independent fields of existing records + * This affects also records of other languages than the requested + */ + WITH tw1 AS ( + UPDATE + data_for_history.api_property t1 + SET + removed_from_api = FALSE, + dfh_pk_property = t2.dfh_pk_property, + dfh_is_inherited = t2.dfh_is_inherited, + dfh_property_domain = t2.dfh_property_domain, + dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, + dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, + dfh_property_range = t2.dfh_property_range, + dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, + dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, + dfh_identity_defining = t2.dfh_identity_defining, + dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, + dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, + dfh_namespace_uri = t2.dfh_namespace_uri, + dfh_fk_namespace = t2.dfh_fk_namespace, + dfh_profile_association_type = t2.dfh_profile_association_type, + dfh_fk_profile = t2.dfh_fk_profile, + dfh_parent_properties = t2.dfh_parent_properties, + dfh_ancestor_properties = t2.dfh_ancestor_properties + FROM + properties_profile_from_api t2 + WHERE + t1.dfh_fk_profile = t2.dfh_fk_profile + AND t1.dfh_pk_property = t2.dfh_pk_property + AND t1.dfh_property_domain = t2.dfh_property_domain + AND t1.dfh_property_range = t2.dfh_property_range + RETURNING + t1.* +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO updated + FROM + tw1; + + /* + * Insert or update all new records + */ + WITH tw1 AS ( +INSERT INTO data_for_history.api_property(tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_property, dfh_property_label_language, dfh_property_label, dfh_property_inverse_label, dfh_property_scope_note_language, dfh_property_scope_note, dfh_is_inherited, dfh_property_domain, dfh_domain_instances_min_quantifier, dfh_domain_instances_max_quantifier, dfh_property_range, dfh_range_instances_min_quantifier, dfh_range_instances_max_quantifier, dfh_identity_defining, dfh_is_has_type_subproperty, dfh_property_identifier_in_namespace, dfh_namespace_uri, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label, dfh_parent_properties, dfh_ancestor_properties) + SELECT DISTINCT ON (t1.requested_language, + t1.dfh_pk_property, + t1.dfh_property_domain, + t1.dfh_property_range, + t1.dfh_fk_profile) + param_tmsp_last_dfh_update, + FALSE, + t1.requested_language, + t1.dfh_pk_property, + t1.dfh_property_label_language, + t1.dfh_property_label, + t1.dfh_property_inverse_label, + t1.dfh_property_scope_note_language, + t1.dfh_property_scope_note, + t1.dfh_is_inherited, + t1.dfh_property_domain, + t1.dfh_domain_instances_min_quantifier, + t1.dfh_domain_instances_max_quantifier, + t1.dfh_property_range, + t1.dfh_range_instances_min_quantifier, + t1.dfh_range_instances_max_quantifier, + t1.dfh_identity_defining, + t1.dfh_is_has_type_subproperty, + t1.dfh_property_identifier_in_namespace, + t1.dfh_namespace_uri, + t1.dfh_fk_namespace, + t1.dfh_namespace_label_language, + t1.dfh_namespace_label, + t1.dfh_profile_association_type, + t1.dfh_fk_profile, + t1.dfh_profile_label_language, + t1.dfh_profile_label, + t1.dfh_parent_properties, + t1.dfh_ancestor_properties + FROM + properties_profile_from_api t1 + WHERE + t1.requested_language = param_requested_language + AND t1.dfh_fk_profile = param_profile_id + ON CONFLICT (requested_language, + dfh_pk_property, + dfh_property_domain, + dfh_property_range, + dfh_fk_profile) + DO UPDATE SET + tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, + removed_from_api = EXCLUDED.removed_from_api, + requested_language = EXCLUDED.requested_language, + dfh_pk_property = EXCLUDED.dfh_pk_property, + dfh_property_label_language = EXCLUDED.dfh_property_label_language, + dfh_property_label = EXCLUDED.dfh_property_label, + dfh_property_inverse_label = EXCLUDED.dfh_property_inverse_label, + dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, + dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, + dfh_is_inherited = EXCLUDED.dfh_is_inherited, + dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, + dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, + dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, + dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, + dfh_identity_defining = EXCLUDED.dfh_identity_defining, + dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, + dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, + dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, + dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, + dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, + dfh_namespace_label = EXCLUDED.dfh_namespace_label, + dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, + dfh_fk_profile = EXCLUDED.dfh_fk_profile, + dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, + dfh_profile_label = EXCLUDED.dfh_profile_label, + dfh_parent_properties = EXCLUDED.dfh_parent_properties, + dfh_ancestor_properties = EXCLUDED.dfh_ancestor_properties + RETURNING + * +) + SELECT + jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO inserted + FROM + tw1; + + /* + * Return kind of a protocol + */ + RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); +END; +$$; + +-- +-- TOC entry 1306 (class 1255 OID 24133) +-- Name: update_api_tables(integer, character varying, timestamp with time zone, json, json, json); Type: FUNCTION; Schema: data_for_history; Owner: - +-- +CREATE FUNCTION data_for_history.update_api_tables(param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_profile_data json DEFAULT NULL::json, param_classes_profile_data json DEFAULT NULL::json, param_properties_profile_data json DEFAULT NULL::json) + RETURNS json + LANGUAGE plpgsql + AS $$ +DECLARE + api_profile json; + api_class json; + api_property json; +BEGIN + /************************************************************** + * Profiles + ***************************************************************/ + SELECT + data_for_history.update_api_profiles_table(param_profile_id, param_requested_language, param_tmsp_last_dfh_update, param_profile_data) INTO api_profile; + + /************************************************************** + * Classes-Profile + ***************************************************************/ + SELECT + data_for_history.update_api_classes_profile_table(param_profile_id, param_requested_language, param_tmsp_last_dfh_update, param_classes_profile_data) INTO api_class; + + /************************************************************** + * Properties-Profile + ***************************************************************/ + SELECT + data_for_history.update_api_properties_profile_table(param_profile_id, param_requested_language, param_tmsp_last_dfh_update, param_properties_profile_data) INTO api_property; + RETURN json_build_object('api_profile', api_profile, 'api_class', api_class, 'api_property', api_property); +END; +$$; + +-- +-- TOC entry 1291 (class 1255 OID 23700) +-- Name: add_te_en_to_project(integer, integer, integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.add_te_en_to_project(param_pk_entity integer, param_pk_project integer, param_account_id integer) + RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + -- Find all roles related to temporal entity + WITH te_ent_roles AS( + SELECT + * + FROM + information.get_outgoing_roles_to_add(param_pk_entity) + UNION ALL + SELECT + * + FROM + information.get_ingoing_roles_to_add(param_pk_entity) +), +-- Find all entity_associations of temporal entities +te_ent_entity_associations AS( + SELECT + * + FROM + information.get_outgoing_entity_associations_to_add(param_pk_entity) + UNION ALL + SELECT + * + FROM + information.get_ingoing_entity_associations_to_add(param_pk_entity) +), +-- get a list of all pk_entities of repo version +pk_entities_of_repo AS( + SELECT + param_pk_entity AS pk_entity, + NULL::calendar_type AS calendar + UNION + SELECT + pk_entity, + calendar + FROM + te_ent_roles + UNION + SELECT + pk_entity, + NULL::calendar_type AS calendar + FROM + te_ent_entity_associations) + INSERT INTO projects.v_info_proj_rel(fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) + SELECT + param_pk_project, + TRUE, + pk_entity, + calendar, + param_account_id + FROM + pk_entities_of_repo; +END +$$; + +-- +-- TOC entry 1275 (class 1255 OID 20865) +-- Name: appe_tokens_for_comparision(jsonb); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.appe_tokens_for_comparision(appe_label jsonb, OUT tokens_for_comparision jsonb) + RETURNS jsonb + LANGUAGE sql + AS $$ + SELECT + array_to_json(array_agg(json_build_object('string', tokens_without_ids.string, 'typeId', tokens_without_ids.typeId)))::jsonb AS tokens_for_comparision + FROM( + SELECT + appe.tokens ->> 'string' AS string, + appe.tokens ->> 'typeId' AS typeId + FROM( + SELECT + jsonb_array_elements(appe_label -> 'tokens') AS tokens) AS appe) AS tokens_without_ids +$$; + +-- +-- TOC entry 1276 (class 1255 OID 20866) +-- Name: appellation_label_to_string(jsonb); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.appellation_label_to_string(appellation_label jsonb, OUT string text) + RETURNS text + LANGUAGE sql + AS $$ + SELECT + STRING_AGG(l.tokens ->> 'string', '') + FROM( + SELECT + jsonb_array_elements(appellation_label -> 'tokens') AS tokens) AS l +$$; + +-- +-- TOC entry 1297 (class 1255 OID 23910) +-- Name: get_accociated_text_properties(integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_accociated_text_properties(param_pk_entity integer) + RETURNS TABLE( + pk_entity integer, + fk_class_field integer) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY + SELECT + t1.pk_entity, + t1.fk_class_field + FROM + information.text_property t1 + WHERE + fk_concerned_entity = param_pk_entity; +END; +$$; + +-- +-- TOC entry 1290 (class 1255 OID 23698) +-- Name: get_ingoing_entity_associations_to_add(integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_ingoing_entity_associations_to_add(param_pk_entity integer) + RETURNS TABLE( + pk_entity integer, + fk_class integer, + fk_info_domain integer, + fk_property integer, + fk_info_range integer, + max_quantifier smallint) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY WITH tw1 AS( + SELECT + t1.pk_entity, + t1.fk_class, + 'persistent_item' table_name + FROM + information.persistent_item t1 + WHERE + t1.pk_entity = param_pk_entity + UNION ALL + SELECT + t2.pk_entity, + t2.fk_class, + 'temporal_entity' table_name + FROM + information.temporal_entity t2 + WHERE + t2.pk_entity = param_pk_entity +) + SELECT DISTINCT + ts2.pk_entity, + ts1.fk_class, + ts2.fk_info_domain, + ts2.fk_property, + ts2.fk_info_range, + ts1.max_quantifier + FROM( + SELECT + t1.dfh_pk_property, + t1.fk_class, + t1.max_quantifier + FROM + system.v_auto_add_properties t1, + tw1 + WHERE + t1.fk_class = tw1.fk_class) AS ts1 + CROSS JOIN LATERAL( + SELECT + t1.pk_entity, + t1.fk_info_domain, + t1.fk_property, + t1.fk_info_range + FROM + information.v_entity_association t1, + tw1 + WHERE + t1.fk_info_range = tw1.pk_entity + AND t1.fk_property = ts1.dfh_pk_property + AND t1.is_in_project_count IS NOT NULL + ORDER BY + t1.is_in_project_count DESC, + t1.tmsp_creation DESC + LIMIT( + SELECT + CASE WHEN ts1.max_quantifier = - 1 THEN + NULL + ELSE + ts1.max_quantifier + END)) AS ts2; +END; +$$; + +-- +-- TOC entry 1288 (class 1255 OID 23695) +-- Name: get_ingoing_roles_to_add(integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_ingoing_roles_to_add(param_pk_entity integer) + RETURNS TABLE( + pk_entity integer, + fk_class integer, + fk_temporal_entity integer, + fk_property integer, + fk_entity integer, + max_quantifier smallint, + calendar public.calendar_type) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY WITH tw1 AS( + SELECT + t1.pk_entity, + t1.fk_class, + 'persistent_item' table_name + FROM + information.persistent_item t1 + WHERE + t1.pk_entity = param_pk_entity + UNION ALL + SELECT + t2.pk_entity, + t2.fk_class, + 'temporal_entity' table_name + FROM + information.temporal_entity t2 + WHERE + t2.pk_entity = param_pk_entity +) + SELECT DISTINCT + ts2.pk_entity, + ts1.fk_class, + ts2.fk_temporal_entity, + ts2.fk_property, + ts2.fk_entity, + ts1.max_quantifier, + ts2.calendar + FROM( + SELECT + t1.dfh_pk_property, + t1.fk_class, + t1.max_quantifier + FROM + system.v_auto_add_properties t1, + tw1 + WHERE + t1.fk_class = tw1.fk_class) AS ts1 + CROSS JOIN LATERAL( + SELECT + t1.pk_entity, + t1.fk_temporal_entity, + t1.fk_property, + t1.fk_entity, + t1.community_favorite_calendar AS calendar + FROM + information.v_role t1, + tw1 + WHERE + t1.fk_entity = tw1.pk_entity + AND t1.fk_property = ts1.dfh_pk_property + AND t1.is_in_project_count IS NOT NULL + ORDER BY + t1.is_in_project_count DESC, + t1.tmsp_creation DESC + LIMIT( + SELECT + CASE WHEN ts1.max_quantifier = - 1 THEN + NULL + ELSE + ts1.max_quantifier + END)) AS ts2; +END; +$$; + +-- +-- TOC entry 1315 (class 1255 OID 24285) +-- Name: get_ingoing_roles_to_add(integer, integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_ingoing_roles_to_add(entity_id integer, project_id integer) + RETURNS TABLE( + pk_entity integer, + fk_entity integer, + fk_temporal_entity integer, + calendar public.calendar_type) + LANGUAGE sql + AS $$ + WITH tw1 AS( + -- select profiles the project + SELECT + fk_profile + FROM + projects.dfh_profile_proj_rel + WHERE + fk_project = project_id + UNION + SELECT + 5 AS fk_profile -- GEOVISTORY BASICS +), +tw2 AS( + -- select properties of the project + SELECT DISTINCT ON(pk_property, + has_domain, + has_range) + pk_property, + has_domain, + has_range, + domain_instances_max_quantifier + FROM + tw1 t1, + data_for_history.api_property t2, + data_for_history.v_property t3 + WHERE + t1.fk_profile = t2.dfh_fk_profile + AND t3.pk_property = t2.dfh_pk_property +), +tw3 AS( + -- select all ingoing roles, joined with range and domain class + SELECT + t1.pk_entity, + t1.fk_entity, + t1.fk_temporal_entity, + t3.fk_class range_class, + t1.fk_property, + CASE WHEN t4.domain_instances_max_quantifier = - 1 THEN + FLOAT8 '+infinity' + WHEN t4.domain_instances_max_quantifier IS NULL THEN + FLOAT8 '+infinity' + ELSE + t4.domain_instances_max_quantifier + END target_max_quantifier, + t1.is_in_project_count, + -- counts the items of same range and property + row_number() OVER(PARTITION BY t3.fk_class, + t1.fk_property ORDER BY is_in_project_count DESC) AS rank, + t1.community_favorite_calendar calendar + FROM + information.v_role t1, + information.v_entity_class_map t2, + information.v_entity_class_map t3, + tw2 t4 + WHERE + fk_entity = entity_id + AND t1.fk_temporal_entity = t2.pk_entity + AND t1.fk_entity = t3.pk_entity + AND t1.fk_property = t4.pk_property + AND t2.fk_class = t4.has_domain + AND t3.fk_class = t4.has_range +) +SELECT + pk_entity, + fk_entity, + fk_temporal_entity, + calendar +FROM + tw3 +WHERE + target_max_quantifier >= rank; +$$; + +-- +-- TOC entry 1289 (class 1255 OID 23697) +-- Name: get_outgoing_entity_associations_to_add(integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_outgoing_entity_associations_to_add(param_pk_entity integer) + RETURNS TABLE( + pk_entity integer, + fk_class integer, + fk_info_domain integer, + fk_property integer, + fk_info_range integer, + max_quantifier smallint) + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY WITH tw1 AS( + SELECT + t1.pk_entity, + t1.fk_class, + 'persistent_item' table_name + FROM + information.persistent_item t1 + WHERE + t1.pk_entity = param_pk_entity + UNION ALL + SELECT + t2.pk_entity, + t2.fk_class, + 'temporal_entity' table_name + FROM + information.temporal_entity t2 + WHERE + t2.pk_entity = param_pk_entity +) + SELECT DISTINCT + ts2.pk_entity, + ts1.fk_class, + ts2.fk_info_domain, + ts2.fk_property, + ts2.fk_info_range, + ts1.max_quantifier + FROM( + SELECT + t1.dfh_pk_property, + t1.fk_class, + t1.max_quantifier + FROM + system.v_auto_add_properties t1, + tw1 + WHERE + t1.fk_class = tw1.fk_class) AS ts1 + CROSS JOIN LATERAL( + SELECT + t1.pk_entity, + t1.fk_info_domain, + t1.fk_property, + t1.fk_info_range + FROM + information.v_entity_association t1, + tw1 + WHERE + t1.fk_info_domain = tw1.pk_entity + AND t1.fk_property = ts1.dfh_pk_property + AND t1.is_in_project_count IS NOT NULL + ORDER BY + t1.is_in_project_count DESC, + t1.tmsp_creation DESC + LIMIT( + SELECT + CASE WHEN ts1.max_quantifier = - 1 THEN + NULL + ELSE + ts1.max_quantifier + END)) AS ts2; +END; +$$; + +-- +-- TOC entry 1326 (class 1255 OID 24702) +-- Name: get_outgoing_statements_to_add(integer, integer); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.get_outgoing_statements_to_add(entity_id integer, project_id integer) + RETURNS TABLE( + pk_entity integer, + fk_object_info integer, + fk_subject_info integer) + LANGUAGE sql + AS $$ + WITH tw1 AS( + -- select profiles the project + SELECT + fk_profile + FROM + projects.dfh_profile_proj_rel + WHERE + fk_project = project_id + UNION + SELECT + 5 AS fk_profile -- GEOVISTORY BASICS +), +tw2 AS( + -- select properties of the project + SELECT DISTINCT ON(pk_property, + has_domain, + has_range) + pk_property, + has_domain, + has_range, + range_instances_max_quantifier + FROM + tw1 t1, + data_for_history.api_property t2, + data_for_history.v_property t3 + WHERE + t1.fk_profile = t2.dfh_fk_profile + AND t3.pk_property = t2.dfh_pk_property +), +tw3 AS( + -- select all outgoing statements, joined with range and domain class + SELECT + t1.pk_entity, + t1.fk_object_info, + t1.fk_subject_info, + t3.fk_class range_class, + t1.fk_property, + CASE WHEN t4.range_instances_max_quantifier = - 1 THEN + FLOAT8 '+infinity' + WHEN t4.range_instances_max_quantifier IS NULL THEN + FLOAT8 '+infinity' + ELSE + t4.range_instances_max_quantifier + END target_max_quantifier, + t1.is_in_project_count, + -- counts the items of same domain and property + row_number() OVER(PARTITION BY t3.fk_class, + t1.fk_property ORDER BY is_in_project_count DESC) AS rank + FROM + information.v_statement t1, + information.v_entity_class_map t2, + information.v_entity_class_map t3, + tw2 t4 + WHERE + fk_subject_info = entity_id + AND t1.fk_subject_info = t2.pk_entity + AND t1.fk_object_info = t3.pk_entity + AND t1.fk_property = t4.pk_property + AND t1.is_in_project_count > 0 + AND t4.has_domain IN(t2.fk_class, 50 -- make every class to a timespan class +) + AND t3.fk_class = t4.has_range +) +SELECT + pk_entity, + fk_object_info, + fk_subject_info +FROM + tw3 +WHERE + target_max_quantifier >= rank; +$$; + +-- +-- TOC entry 1277 (class 1255 OID 20882) +-- Name: text_property_to_string(jsonb); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.text_property_to_string(text_property_quill_doc jsonb, OUT string text) + RETURNS text + LANGUAGE sql + AS $$ + SELECT + STRING_AGG(l.ops ->> 'insert', '') + FROM( + SELECT + jsonb_array_elements(text_property_quill_doc -> 'contents' -> 'ops') AS ops) AS l +$$; + +-- +-- TOC entry 1281 (class 1255 OID 23180) +-- Name: v_dimension_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_dimension_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_dimension; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + pk_entity + FROM + INTO resulting_pk information.dimension + WHERE + fk_class = NEW.fk_class + AND fk_measurement_unit = NEW.fk_measurement_unit + AND numeric_value = NEW.numeric_value; + -- RAISE INFO 'result of select: %', resulting_row; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.dimension(fk_class, fk_measurement_unit, numeric_value) + VALUES (NEW.fk_class, NEW.fk_measurement_unit, NEW.numeric_value) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row information.v_dimension + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1318 (class 1255 OID 24425) +-- Name: v_lang_string_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_lang_string_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_lang_string; +BEGIN + ------ if existing, store in result ----- + SELECT + pk_entity + FROM + INTO resulting_pk information.lang_string + WHERE + fk_class IS NOT DISTINCT FROM NEW.fk_class + AND fk_language IS NOT DISTINCT FROM NEW.fk_language + AND string = coalesce(NEW.string, commons.quill_doc_to_string(NEW.quill_doc)); + -- RAISE INFO 'resulting_pk: %', resulting_pk; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + --RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.lang_string(fk_class, fk_language, string, quill_doc) + VALUES (NEW.fk_class, NEW.fk_language, NEW.string, NEW.quill_doc) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row information.v_lang_string + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1278 (class 1255 OID 20885) +-- Name: v_language_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_language_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_language; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + * + FROM + INTO resulting_row information.v_language + WHERE + fk_class = NEW.fk_class + AND lang_type = NEW.lang_type + AND scope = NEW.scope + AND iso6392b = NEW.iso6392b + AND iso6392t = NEW.iso6392t + AND iso6391 = NEW.iso6391 + AND pk_language = NEW.pk_language; + -- RAISE INFO 'result of select: %', resulting_row; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.language(fk_class, lang_type, scope, iso6392b, iso6392t, iso6391, pk_language) + VALUES (NEW.fk_class, NEW.lang_type, NEW.scope, NEW.iso6392b, NEW.iso6392t, NEW.iso6391, NEW.pk_language) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row information.v_language + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1283 (class 1255 OID 20887) +-- Name: v_place_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_place_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_place; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + * + FROM + INTO resulting_row information.v_place + WHERE + geo_point = ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography + AND fk_class = NEW.fk_class; + -- RAISE INFO 'result of select: %', resulting_row; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.place(geo_point, fk_class) + VALUES (ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, NEW.fk_class) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + SELECT + * + FROM + INTO resulting_row information.v_place + WHERE + pk_entity = resulting_pk; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1279 (class 1255 OID 20889) +-- Name: v_statement_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_statement_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_statement; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + pk_entity + FROM + INTO resulting_pk information.statement + WHERE + fk_property = NEW.fk_property + AND fk_property_of_property = NEW.fk_property_of_property + AND fk_subject_info = NEW.fk_subject_info + AND fk_subject_data = NEW.fk_subject_data + AND fk_subject_tables_row = NEW.fk_subject_tables_row + AND fk_subject_tables_cell = NEW.fk_subject_tables_cell + AND fk_object_info = NEW.fk_object_info + AND fk_object_data = NEW.fk_object_data + AND fk_object_tables_row = NEW.fk_object_tables_row + AND fk_object_tables_cell = NEW.fk_object_tables_cell; + -- RAISE INFO 'result of select: %', resulting_row; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.statement(fk_property, fk_property_of_property, fk_subject_info, fk_subject_data, fk_subject_tables_row, fk_subject_tables_cell, fk_object_info, fk_object_data, fk_object_tables_row, fk_object_tables_cell) + VALUES (NEW.fk_property, NEW.fk_property_of_property, NEW.fk_subject_info, NEW.fk_subject_data, NEW.fk_subject_tables_row, NEW.fk_subject_tables_cell, NEW.fk_object_info, NEW.fk_object_data, NEW.fk_object_tables_row, NEW.fk_object_tables_cell) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row information.v_statement + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1282 (class 1255 OID 20891) +-- Name: v_text_property_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_text_property_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_text_property; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + * + FROM + INTO resulting_row information.v_text_property + WHERE + string = COALESCE(NEW.string, commons.quill_doc_to_string(NEW.quill_doc)) + AND fk_class_field = NEW.fk_class_field + AND fk_concerned_entity = NEW.fk_concerned_entity + AND fk_language = NEW.fk_language; + -- RAISE INFO 'result of select: %', resulting_pk; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.text_property(string, quill_doc, fk_class_field, fk_concerned_entity, fk_language) + VALUES (NEW.string, NEW.quill_doc::jsonb, NEW.fk_class_field, NEW.fk_concerned_entity, NEW.fk_language) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + SELECT + * + FROM + INTO resulting_row information.v_text_property + WHERE + pk_entity = resulting_pk; + -- RAISE INFO 'result of insert: %', resulting_pk; + END IF; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1280 (class 1255 OID 20892) +-- Name: v_time_primitive_find_or_create(); Type: FUNCTION; Schema: information; Owner: - +-- +CREATE FUNCTION information.v_time_primitive_find_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row information.v_time_primitive; +BEGIN + -- RAISE INFO 'input values: %', NEW; + ------ if existing, store in result ----- + SELECT + pk_entity + FROM + INTO resulting_pk information.time_primitive + WHERE + julian_day = NEW.julian_day + AND duration = NEW.duration + AND calendar = NEW.calendar + AND fk_class = NEW.fk_class; + -- RAISE INFO 'result of select: %', resulting_row; + ------- if not existing, insert and store in result ----- + IF NOT FOUND THEN + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO information.time_primitive(julian_day, duration, calendar, fk_class) + VALUES (NEW.julian_day, NEW.duration, NEW.calendar, NEW.fk_class) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row information.v_time_primitive + WHERE + pk_entity = resulting_pk; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1334 (class 1255 OID 24968) +-- Name: add_entity_preview_partition(); Type: FUNCTION; Schema: projects; Owner: - +-- +CREATE FUNCTION projects.add_entity_preview_partition() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $_$ +DECLARE + entity_preview_table text; +BEGIN + -- get the table name of the current + SELECT + commons.get_entity_preview_table_name() INTO entity_preview_table; + -- create the partition + EXECUTE format('CREATE TABLE %1$s_%2$s PARTITION OF %1$s FOR VALUES IN (%2$s);', entity_preview_table, NEW.pk_entity); + RETURN NEW; +END; +$_$; + +-- +-- TOC entry 1314 (class 1255 OID 24279) +-- Name: deactivate_ontome_profile_for_geovistory_project(integer, integer); Type: FUNCTION; Schema: projects; Owner: - +-- +CREATE FUNCTION projects.deactivate_ontome_profile_for_geovistory_project(profileid integer, projectid integer) + RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + /** + * Deactivate Profile + */ + UPDATE + projects.dfh_profile_proj_rel + SET + enabled = FALSE + WHERE + fk_profile = profileId + AND fk_project = projectId; + + /** + * Deactivate Classes + * (only classes that are not part of another ontome profile + * activated by the geovistroy project) + */ + -- select class profile relations + WITH ctw1 AS( + SELECT DISTINCT + t1.dfh_pk_class fk_class, + t1.dfh_fk_profile fk_profile + FROM + data_for_history.api_class t1 +), +-- select the classes of deactivation-profile +ctw2 AS( + SELECT + pk_class, + identifier_in_namespace + FROM + data_for_history.v_class t1, + ctw1 t2 + WHERE + t1.pk_class = t2.fk_class + AND t2.fk_profile = profileId +), +-- select the profiles the project has without deactivation-profile +ctw3 AS( + SELECT DISTINCT + fk_profile + FROM + projects.dfh_profile_proj_rel + WHERE + fk_project = projectId + AND fk_profile != profileId + AND enabled = TRUE + UNION + SELECT + 5 AS fk_profile -- GEOVISTORY BASICS +), +-- select the classes of the profiles of the project except the deactivation-profile +ctw4 AS( + SELECT DISTINCT + pk_class, + identifier_in_namespace + FROM + data_for_history.v_class t1, + ctw1 t2, + ctw3 t3 + WHERE + t1.pk_class = t2.fk_class + AND t2.fk_profile = t3.fk_profile +), +-- select the classes to be deactivated +ctw5 AS( + SELECT + pk_class + FROM + ctw2 + EXCEPT + SELECT + pk_class + FROM + ctw4) +UPDATE + projects.dfh_class_proj_rel t1 +SET + enabled_in_entities = FALSE +FROM + ctw5 t2 +WHERE + t1.fk_class = t2.pk_class + AND t1.fk_project = projectId; +END; +$$; + +-- +-- TOC entry 1287 (class 1255 OID 23638) +-- Name: v_info_proj_rel_update_or_create(); Type: FUNCTION; Schema: projects; Owner: - +-- +CREATE FUNCTION projects.v_info_proj_rel_update_or_create() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + resulting_pk integer; + resulting_row projects.v_info_proj_rel; +BEGIN + RAISE INFO 'input values: %', NEW; + ------ if existing, store in resulting_pk ... ----- + SELECT + * + FROM + INTO resulting_row projects.v_info_proj_rel + WHERE + fk_entity = NEW.fk_entity + AND fk_project = NEW.fk_project; + ------ ... and update the found row ----- + IF FOUND THEN + -- RAISE INFO 'result of select: %', resulting_row; + -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); + UPDATE + projects.info_proj_rel + SET + fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), + fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), + is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), + is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), + ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), + ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), + ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), + fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), + fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier), + project_visibility = COALESCE(NEW.project_visibility, resulting_row.project_visibility) + WHERE + pk_entity = resulting_row.pk_entity; + ------- if not existing, insert and store in result ----- + ELSE + -- RAISE INFO 'Not found, creating new...'; + WITH _insert AS ( +INSERT INTO projects.info_proj_rel(fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version, fk_creator, fk_last_modifier, project_visibility) + VALUES (NEW.fk_project, NEW.fk_entity, NEW.fk_entity_version, NEW.fk_entity_version_concat, NEW.is_in_project, NEW.is_standard_in_project, NEW.ord_num_of_domain, NEW.ord_num_of_range, NEW.ord_num_of_text_property, 1, NEW.fk_creator, NEW.fk_last_modifier, NEW.project_visibility) + -- return all fields of the new row + RETURNING + *) + SELECT + pk_entity + FROM + INTO resulting_pk _insert; + -- RAISE INFO 'result of insert: %', resulting_row; + END IF; + SELECT + * + FROM + INTO resulting_row projects.v_info_proj_rel + WHERE + pk_entity = resulting_pk + OR pk_entity = resulting_row.pk_entity; + RETURN resulting_row; +END; +$$; + +-- +-- TOC entry 1267 (class 1255 OID 20894) +-- Name: versioning(); Type: FUNCTION; Schema: public; Owner: - +-- +CREATE FUNCTION public.versioning() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $_$ +DECLARE + sys_period text; + history_table text; + manipulate jsonb; + commonColumns text[]; + time_stamp_to_use timestamptz := CURRENT_TIMESTAMP; + range_lower timestamptz; + transaction_info txid_snapshot; + existing_range tstzrange; + holder record; + holder2 record; + pg_version integer; +BEGIN + -- version 0.2.0 + IF TG_WHEN != 'BEFORE' OR TG_LEVEL != 'ROW' THEN + RAISE TRIGGER_PROTOCOL_VIOLATED + USING MESSAGE = 'function "versioning" must be fired BEFORE ROW'; + END IF; + IF TG_OP != 'INSERT' AND TG_OP != 'UPDATE' AND TG_OP != 'DELETE' THEN + RAISE TRIGGER_PROTOCOL_VIOLATED + USING MESSAGE = 'function "versioning" must be fired for INSERT or UPDATE or DELETE'; + END IF; + IF TG_NARGS != 3 THEN + RAISE INVALID_PARAMETER_VALUE + USING MESSAGE = 'wrong number of parameters for function "versioning"', HINT = 'expected 3 parameters but got ' || TG_NARGS; + END IF; + sys_period := TG_ARGV[0]; + history_table := TG_ARGV[1]; + -- check if sys_period exists on original table + SELECT + atttypid, + attndims INTO holder + FROM + pg_attribute + WHERE + attrelid = TG_RELID + AND attname = sys_period + AND NOT attisdropped; + IF NOT FOUND THEN + RAISE 'column "%" of relation "%" does not exist', sys_period, TG_TABLE_NAME + USING ERRCODE = 'undefined_column'; + END IF; + IF holder.atttypid != to_regtype('tstzrange') THEN + IF holder.attndims > 0 THEN + RAISE 'system period column "%" of relation "%" is not a range but an array', sys_period, TG_TABLE_NAME + USING ERRCODE = 'datatype_mismatch'; + END IF; + SELECT + rngsubtype INTO holder2 + FROM + pg_range + WHERE + rngtypid = holder.atttypid; + IF FOUND THEN + RAISE 'system period column "%" of relation "%" is not a range of timestamp with timezone but of type %', sys_period, TG_TABLE_NAME, format_type(holder2.rngsubtype, NULL) + USING ERRCODE = 'datatype_mismatch'; + END IF; + RAISE 'system period column "%" of relation "%" is not a range but type %', sys_period, TG_TABLE_NAME, format_type(holder.atttypid, NULL) + USING ERRCODE = 'datatype_mismatch'; + END IF; + IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN + -- Ignore rows already modified in this transaction + transaction_info := txid_current_snapshot(); + IF OLD.xmin::text >=(txid_snapshot_xmin(transaction_info) %(2 ^ 32)::bigint)::text AND OLD.xmin::text <=(txid_snapshot_xmax(transaction_info) %(2 ^ 32)::bigint)::text THEN + IF TG_OP = 'DELETE' THEN + RETURN OLD; + END IF; + RETURN NEW; + END IF; + SELECT + current_setting('server_version_num')::integer INTO pg_version; + -- to support postgres < 9.6 + IF pg_version < 90600 THEN + -- check if history table exits + IF to_regclass(history_table::cstring) IS NULL THEN + RAISE 'relation "%" does not exist', history_table; + END IF; + ELSE + IF to_regclass(history_table) IS NULL THEN + RAISE 'relation "%" does not exist', history_table; + END IF; + END IF; + -- check if history table has sys_period + IF NOT EXISTS ( + SELECT + * + FROM + pg_attribute + WHERE + attrelid = history_table::regclass + AND attname = sys_period + AND NOT attisdropped) THEN + RAISE 'history relation "%" does not contain system period column "%"', history_table, sys_period + USING HINT = 'history relation must contain system period column with the same name and data type as the versioned one'; + END IF; + EXECUTE format('SELECT $1.%I', sys_period) + USING OLD INTO existing_range; + IF existing_range IS NULL THEN + RAISE 'system period column "%" of relation "%" must not be null', sys_period, TG_TABLE_NAME + USING ERRCODE = 'null_value_not_allowed'; + END IF; + IF isempty(existing_range) OR NOT upper_inf(existing_range) THEN + RAISE 'system period column "%" of relation "%" contains invalid value', sys_period, TG_TABLE_NAME + USING ERRCODE = 'data_exception', DETAIL = 'valid ranges must be non-empty and unbounded on the high side'; + END IF; + IF TG_ARGV[2] = 'true' THEN + -- mitigate update conflicts + range_lower := lower(existing_range); + IF range_lower >= time_stamp_to_use THEN + time_stamp_to_use := range_lower + interval '1 microseconds'; + END IF; + END IF; + WITH history AS ( + SELECT + attname, + atttypid + FROM + pg_attribute + WHERE + attrelid = history_table::regclass + AND attnum > 0 + AND NOT attisdropped +), +main AS ( + SELECT + attname, + atttypid + FROM + pg_attribute + WHERE + attrelid = TG_RELID + AND attnum > 0 + AND NOT attisdropped +) +SELECT + history.attname AS history_name, + main.attname AS main_name, + history.atttypid AS history_type, + main.atttypid AS main_type INTO holder +FROM + history + INNER JOIN main ON history.attname = main.attname +WHERE + history.atttypid != main.atttypid; + IF FOUND THEN + RAISE 'column "%" of relation "%" is of type % but column "%" of history relation "%" is of type %', holder.main_name, TG_TABLE_NAME, format_type(holder.main_type, NULL), holder.history_name, history_table, format_type(holder.history_type, NULL) + USING ERRCODE = 'datatype_mismatch'; + END IF; + WITH history AS ( + SELECT + attname + FROM + pg_attribute + WHERE + attrelid = history_table::regclass + AND attnum > 0 + AND NOT attisdropped +), +main AS ( + SELECT + attname + FROM + pg_attribute + WHERE + attrelid = TG_RELID + AND attnum > 0 + AND NOT attisdropped +) +SELECT + array_agg(quote_ident(history.attname)) INTO commonColumns +FROM + history + INNER JOIN main ON history.attname = main.attname + AND history.attname != sys_period; + EXECUTE ('INSERT INTO ' || CASE split_part(history_table, '.', 2) + WHEN '' THEN + quote_ident(history_table) + ELSE + quote_ident(split_part(history_table, '.', 1)) || '.' || quote_ident(split_part(history_table, '.', 2)) + END || '(' || array_to_string(commonColumns, ',') || ',' || quote_ident(sys_period) || ') VALUES ($1.' || array_to_string(commonColumns, ',$1.') || ',tstzrange($2, $3, ''[)''))') + USING OLD, range_lower, time_stamp_to_use; +END IF; + IF TG_OP = 'UPDATE' OR TG_OP = 'INSERT' THEN + manipulate := jsonb_set('{}'::jsonb,('{' || sys_period || '}')::text[], to_jsonb(tstzrange(time_stamp_to_use, NULL, '[)'))); + RETURN jsonb_populate_record(NEW, manipulate); + END IF; + RETURN OLD; +END; +$_$; + +-- +-- TOC entry 1293 (class 1255 OID 23812) +-- Name: create_cell_table_for_digital(integer); Type: FUNCTION; Schema: tables; Owner: - +-- +CREATE FUNCTION tables.create_cell_table_for_digital(pk_digital integer) + RETURNS text + LANGUAGE plpgsql + AS $$ +DECLARE + test_query_result boolean; + create_query text; + result_text text; +BEGIN + EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' + AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result; + IF test_query_result THEN + result_text := 'tables.cell_' || pk_digital::text || ' already exists'; + ELSE + create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' + ( + CHECK (fk_digital = ' || pk_digital::text || '), + CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), + CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) + REFERENCES data."column" (pk_entity) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION, + CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) + REFERENCES data.digital (pk_entity) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION, + CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) + REFERENCES tables."row_' || pk_digital::text || '" (pk_row) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + ) + INHERITS (tables.cell); + + CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx + ON tables.cell_' || pk_digital::text || ' USING btree + (fk_digital); + + CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); + + CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); + + CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx + ON tables.cell_' || pk_digital::text || ' USING btree + (fk_column); + + CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx + ON tables.cell_' || pk_digital::text || ' USING btree + (fk_row); + + CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx + ON tables.cell_' || pk_digital::text || ' USING hash(id_for_import_txt); + + CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx + ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); + + CREATE INDEX cell_' || pk_digital::text || '_string_value_idx + ON tables.cell_' || pk_digital::text || ' USING hash(string_value); + + CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); + + CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); + + CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); + + CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE + ON tables.cell_' || pk_digital::text || ' + FOR EACH ROW + EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); '; + RAISE NOTICE '%', create_query; + EXECUTE create_query; + result_text := 'tables.cell_' || pk_digital::text; + END IF; + RETURN result_text; +END; +$$; + +-- +-- TOC entry 1323 (class 1255 OID 24641) +-- Name: create_row_table_for_digital(integer); Type: FUNCTION; Schema: tables; Owner: - +-- +CREATE FUNCTION tables.create_row_table_for_digital(pk_digital integer) + RETURNS text + LANGUAGE plpgsql + AS $$ +DECLARE + test_query_result boolean; + create_query text; + result_text text; +BEGIN + EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' + AND table_name = ''row_' || pk_digital::text || ''';' INTO test_query_result; + IF test_query_result THEN + result_text := 'tables.row_' || pk_digital::text || ' already exists'; + ELSE + create_query := 'CREATE TABLE IF NOT EXISTS tables.row_' || pk_digital::text || ' + ( + CHECK (fk_digital = ' || pk_digital::text || '), + CONSTRAINT data_row_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_row), + CONSTRAINT row_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) + REFERENCES data.digital (pk_entity) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + ) + INHERITS (tables.row); + + CREATE INDEX row_' || pk_digital::text || '_fk_digital_idx + ON tables.row_' || pk_digital::text || ' USING btree + (fk_digital); + + CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.row_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); + + CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.row_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); + + CREATE INDEX row_' || pk_digital::text || '_id_for_import_txt_idx + ON tables.row_' || pk_digital::text || ' USING hash(id_for_import_txt); + + CREATE INDEX row_' || pk_digital::text || '_pk_row_idx + ON tables.row_' || pk_digital::text || ' USING btree(pk_row); + + CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.row_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); + + CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.row_' || pk_digital::text || ' + FOR + EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); + + CREATE TABLE IF NOT EXISTS tables.row_' || pk_digital::text || '_vt ( ) INHERITS (tables.row_vt); + + CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE + ON tables.row_' || pk_digital::text || ' + FOR EACH ROW + EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.row_' || pk_digital::text || '_vt'', ''true''); '; + RAISE NOTICE '%', create_query; + EXECUTE create_query; + result_text := 'tables.row_' || pk_digital::text; + END IF; + RETURN result_text; +END; +$$; + +-- +-- TOC entry 1292 (class 1255 OID 23865) +-- Name: rebuild_partitioned_table(integer, text, integer[]); Type: FUNCTION; Schema: tables; Owner: - +-- +CREATE FUNCTION tables.rebuild_partitioned_table(id_digital integer, view_name text, column_list integer[]) + RETURNS text + LANGUAGE plpgsql + AS $$ +DECLARE + new_view_name text; + query_start text; + query_from text; + query text; + field text; + field_label text; + field_metadata json; + n integer = 1; + a integer; + output_query text; +BEGIN + IF view_name IS NOT NULL THEN + new_view_name = view_name; + ELSE + new_view_name = 'tv_' || id_digital; + END IF; + query_start = 'DROP VIEW IF EXISTS ' || new_view_name || '; + CREATE OR REPLACE TEMPORARY VIEW ' || new_view_name || ' AS + SELECT dr.pk_row'; + query_from = ' FROM tables.row dr'; + IF array_length(column_list, 1) > 0 THEN + FOR a IN + SELECT + UNNEST(column_list) + LOOP + SELECT + row_to_json(pk_entity, pk_entity::text, fk_data_type) INTO field_metadata --id_for_import_txt + FROM + data.column + WHERE + pk_entity = a; + field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); + IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN + field = 't' || n || '.numeric_value'; + ELSE + field = 't' || n || '.string_value'; + -- .string .id_for_import_txt + END IF; + query_start = query_start || ', ' || field || ' AS ' || field_label; + query_from = query_from || ' LEFT JOIN tables.cell_' || id_digital || ' t' || n || ' ON dr.pk_row = t' || n || '.fk_row AND t' || n || '.fk_column = ' ||(field_metadata -> 'f1')::text; + n = n + 1; + -- RAISE NOTICE '%', query_start ; -- return current row of SELECT + END LOOP; + ELSE + FOR field_metadata IN + SELECT + row_to_json(pk_entity, pk_entity::text, fk_data_type) --id_for_import_txt + FROM + data.column + WHERE + fk_digital = id_digital + ORDER BY + pk_entity LOOP + field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); + IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN + field = 't' || n || '.numeric_value'; + ELSE + field = 't' || n || '.string_value'; + -- .string .id_for_import_txt + END IF; + query_start = query_start || ', ' || field || ' AS ' || field_label; + query_from = query_from || ' LEFT JOIN tables.cell_' || id_digital || ' t' || n || ' ON dr.pk_row = t' || n || '.fk_row AND t' || n || '.fk_column = ' ||(field_metadata -> 'f1')::text; + n = n + 1; + -- RAISE NOTICE '%', query_start ; -- return current row of SELECT + END LOOP; + END IF; + query := query_start || query_from || ' WHERE dr.fk_digital = ' || id_digital || ';'; + RAISE NOTICE '%', query; + EXECUTE query; + output_query := 'SELECT * FROM ' || new_view_name || ' LIMIT 10'; + RETURN output_query; +END; +$$; + +-- +-- TOC entry 1309 (class 1255 OID 24207) +-- Name: after_info_proj_rel_upsert(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.after_info_proj_rel_upsert() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + PERFORM + pg_notify('project_updated', 'true'); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1333 (class 1255 OID 24920) +-- Name: create_sink_table_entity_preview(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.create_sink_table_entity_preview(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +DECLARE + project_id int; +BEGIN + -- Create table and triggers + EXECUTE format(' + CREATE TABLE %1$s (LIKE war.entity_preview_template INCLUDING ALL) + PARTITION BY LIST (project_id); + + CREATE TRIGGER generate_key + BEFORE INSERT OR UPDATE + ON %1$s + FOR EACH ROW + EXECUTE FUNCTION war.entity_preview_generate_key(); + + CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON %1$s + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + + CREATE TRIGGER ts_vector + BEFORE INSERT OR UPDATE + ON %1$s + FOR EACH ROW + EXECUTE FUNCTION war.entity_preview_ts_vector(); + ', schema_and_table_name); + -- Create partitions for each project + FOR project_id IN + SELECT + pk_entity + FROM + projects.project LOOP + -- Construct and execute the dynamic SQL statement + -- e.g CREATE TABLE war.entity_preview_xyz_33 PARTITION OF war.entity_preview_xyz FOR VALUES IN (33); + EXECUTE format('CREATE TABLE %1$s_%2$s PARTITION OF %1$s FOR VALUES IN (%2$s);', schema_and_table_name, project_id); + END LOOP; + -- Create partition for community data + EXECUTE format('CREATE TABLE %1$s_0 PARTITION OF %1$s FOR VALUES IN (0);', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1329 (class 1255 OID 24927) +-- Name: create_sink_table_field_change(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.create_sink_table_field_change(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format('CREATE TABLE %1$s (LIKE war.field_change_template INCLUDING ALL);', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1331 (class 1255 OID 24943) +-- Name: create_sink_table_statement(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.create_sink_table_statement(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format('CREATE TABLE %1$s (LIKE war.statement_template INCLUDING ALL);', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1325 (class 1255 OID 24690) +-- Name: entity_preview_generate_key(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.entity_preview_generate_key() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.key = concat(NEW.project, '_', NEW.pk_entity); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1320 (class 1255 OID 24555) +-- Name: entity_preview_ts_vector(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.entity_preview_ts_vector() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + NEW.ts_vector =( + SELECT + setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(NEW.type_label, '')), 'B') || setweight(to_tsvector(coalesce(NEW.class_label, '')), 'B') || setweight(to_tsvector(coalesce(NEW.full_text, '')), 'C')); + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1312 (class 1255 OID 24227) +-- Name: entity_previews__notify_upsert(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.entity_previews__notify_upsert() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + notification text; +BEGIN + SELECT DISTINCT + tmsp_last_modification::text INTO notification + FROM + new_table + WHERE + tmsp_last_modification IS NOT NULL + LIMIT 1; + IF notification IS NOT NULL THEN + PERFORM + pg_notify('entity_previews_updated'::text, notification); + END IF; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1324 (class 1255 OID 24686) +-- Name: field_change__notify_upsert(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.field_change__notify_upsert() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE + item json; +BEGIN + FOR item IN + SELECT + row_to_json(new_table) + FROM + new_table LOOP + PERFORM + pg_notify('field_change'::text, item::text); + END LOOP; + RETURN NEW; +END; +$$; + +-- +-- TOC entry 1313 (class 1255 OID 24235) +-- Name: notify__need_to_check_class_labels(); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.notify__need_to_check_class_labels() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + PERFORM + pg_notify('need_to_check_class_labels', 'check for updates'); + RETURN NULL; +END; +$$; + +-- +-- TOC entry 1335 (class 1255 OID 24970) +-- Name: switch_entity_preview_table(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.switch_entity_preview_table(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format(' + CREATE OR REPLACE VIEW war.entity_preview AS + SELECT + pk_entity, + entity_type, + fk_class, + class_label, + entity_label, + full_text, + ts_vector, + type_label, + fk_type, + time_span, + first_second, + last_second, + tmsp_last_modification, + key, + entity_id, + parent_classes, + ancestor_classes, + project_id, + type_id + FROM %1$s; + + DROP TRIGGER IF EXISTS after_insert_on_entity_preview ON %1$s; + + CREATE TRIGGER after_insert_on_entity_preview + AFTER INSERT + ON %1$s + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT + EXECUTE FUNCTION war.entity_previews__notify_upsert(); + + DROP TRIGGER IF EXISTS after_update_on_entity_preview ON %1$s; + + CREATE TRIGGER after_update_on_entity_preview + AFTER UPDATE + ON %1$s + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT + EXECUTE FUNCTION war.entity_previews__notify_upsert(); + + ', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1330 (class 1255 OID 24928) +-- Name: switch_field_change_table(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.switch_field_change_table(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format(' + CREATE OR REPLACE VIEW war.field_change AS + SELECT * FROM %1$s; + + DROP TRIGGER IF EXISTS after_insert_field_change ON %1$s; + + CREATE TRIGGER after_insert_field_change + AFTER INSERT + ON %1$s + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT + EXECUTE FUNCTION war.field_change__notify_upsert(); + + DROP TRIGGER IF EXISTS after_update_field_change ON %1$s; + + CREATE TRIGGER after_update_field_change + AFTER UPDATE + ON %1$s + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT + EXECUTE FUNCTION war.field_change__notify_upsert();', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 1332 (class 1255 OID 24944) +-- Name: switch_statement_table(character varying); Type: FUNCTION; Schema: war; Owner: - +-- +CREATE FUNCTION war.switch_statement_table(schema_and_table_name character varying) + RETURNS void + LANGUAGE plpgsql + AS $_$ +BEGIN + EXECUTE format(' + CREATE OR REPLACE VIEW war.statement AS + SELECT * FROM %1$s; + ', schema_and_table_name); +END +$_$; + +-- +-- TOC entry 235 (class 1259 OID 20921) +-- Name: text; Type: TABLE; Schema: commons; Owner: - +-- +CREATE TABLE commons.text ( + pk_text integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + quill_doc jsonb, + string text +); + +-- +-- TOC entry 236 (class 1259 OID 20927) +-- Name: text_pk_text_seq; Type: SEQUENCE; Schema: commons; Owner: - +-- +CREATE SEQUENCE commons.text_pk_text_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6474 (class 0 OID 0) +-- Dependencies: 236 +-- Name: text_pk_text_seq; Type: SEQUENCE OWNED BY; Schema: commons; Owner: - +-- +ALTER SEQUENCE commons.text_pk_text_seq OWNED BY commons.text.pk_text; + +-- +-- TOC entry 237 (class 1259 OID 20928) +-- Name: text_vt; Type: TABLE; Schema: commons; Owner: - +-- +CREATE TABLE commons.text_vt( + pk_text integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + quill_doc jsonb, + string text +); + +-- +-- TOC entry 238 (class 1259 OID 20933) +-- Name: v_text_version; Type: VIEW; Schema: commons; Owner: - +-- +CREATE VIEW commons.v_text_version AS +SELECT + t.pk_text, + t.schema_name, + t.table_name, + t.entity_version, + t.quill_doc, + t.string, + concat(((t.pk_text || '_'::text) || t.entity_version)) AS pk_text_version +FROM + commons.text t +UNION ALL +SELECT + t.pk_text, + t.schema_name, + t.table_name, + t.entity_version, + t.quill_doc, + t.string, + concat(((t.pk_text || '_'::text) || t.entity_version)) AS pk_text_version +FROM + commons.text_vt t; + +-- +-- TOC entry 239 (class 1259 OID 20937) +-- Name: entity; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.entity( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 240 (class 1259 OID 20944) +-- Name: avatar; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.avatar( + fk_class integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 241 (class 1259 OID 20951) +-- Name: avatar_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.avatar_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_class integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 242 (class 1259 OID 20974) +-- Name: chunk; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.chunk( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + quill_doc jsonb NOT NULL, + string text NOT NULL, + fk_text integer, + fk_entity_version integer, + CONSTRAINT text_quill_doc_check CHECK (((quill_doc IS NULL) OR commons.validate_quill_doc(quill_doc))) +) +INHERITS ( + data.entity, + commons.text +); + +-- +-- TOC entry 243 (class 1259 OID 20984) +-- Name: chunk_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.chunk_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_text integer, + fk_entity_version integer, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 244 (class 1259 OID 20992) +-- Name: class_column_mapping; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.class_column_mapping( + fk_class integer NOT NULL, + fk_column integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 245 (class 1259 OID 20999) +-- Name: class_column_mapping_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.class_column_mapping_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_class integer NOT NULL, + fk_column integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 246 (class 1259 OID 21004) +-- Name: column; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data."column"( + fk_digital integer NOT NULL, + fk_data_type integer NOT NULL, + fk_column_content_type integer NOT NULL, + fk_original_column integer, + is_imported boolean DEFAULT FALSE NOT NULL, + fk_column_relationship_type integer DEFAULT 3367 NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 247 (class 1259 OID 21011) +-- Name: column_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.column_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_digital integer NOT NULL, + fk_data_type integer NOT NULL, + fk_column_content_type integer NOT NULL, + fk_original_column integer, + is_imported boolean NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer, + fk_column_relationship_type integer +); + +-- +-- TOC entry 248 (class 1259 OID 21016) +-- Name: data_association; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.data_association( + fk_property integer NOT NULL, + fk_data_domain integer, + fk_data_range integer, + fk_info_value_range integer, + fk_info_domain bigint, + fk_info_range bigint, + fk_cell_domain bigint, + fk_cell_range bigint +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 266 (class 1259 OID 21146) +-- Name: data_association_mapping; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.data_association_mapping( + fk_property integer NOT NULL, + fk_domain_column integer NOT NULL, + fk_range_column integer NOT NULL, + fk_factoid_mapping integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 267 (class 1259 OID 21153) +-- Name: data_association_mapping_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.data_association_mapping_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property integer NOT NULL, + fk_domain_column integer NOT NULL, + fk_range_column integer NOT NULL, + fk_factoid_mapping integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 249 (class 1259 OID 21023) +-- Name: data_association_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.data_association_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property integer NOT NULL, + fk_data_domain integer, + fk_data_range integer, + fk_info_value_range integer, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 253 (class 1259 OID 21050) +-- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: data; Owner: - +-- +CREATE SEQUENCE data.entity_pk_entity_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6475 (class 0 OID 0) +-- Dependencies: 253 +-- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: data; Owner: - +-- +ALTER SEQUENCE data.entity_pk_entity_seq OWNED BY data.entity.pk_entity; + +-- +-- TOC entry 251 (class 1259 OID 21029) +-- Name: digital; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.digital( + pk_entity integer DEFAULT nextval('data.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer DEFAULT 1, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + quill_doc jsonb NOT NULL, + string text NOT NULL, + fk_system_type integer, + CONSTRAINT text_quill_doc_check CHECK (((quill_doc IS NULL) OR commons.validate_quill_doc(quill_doc))) +) +INHERITS ( + data.entity, + commons.text +); + +-- +-- TOC entry 252 (class 1259 OID 21042) +-- Name: digital_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.digital_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_namespace integer, + metadata jsonb, + fk_system_type integer, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 254 (class 1259 OID 21051) +-- Name: factoid; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid( + fk_class integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 255 (class 1259 OID 21058) +-- Name: factoid_mapping; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_mapping( + fk_digital integer NOT NULL, + fk_class integer NOT NULL, + title text, + comment text +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 256 (class 1259 OID 21065) +-- Name: factoid_mapping_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_mapping_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_digital integer NOT NULL, + fk_class integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 257 (class 1259 OID 21070) +-- Name: factoid_property_mapping; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_property_mapping( + fk_property integer NOT NULL, + fk_column integer NOT NULL, + fk_factoid_mapping integer NOT NULL, + is_outgoing boolean DEFAULT TRUE NOT NULL, + comment text, + fk_default integer +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 258 (class 1259 OID 21077) +-- Name: factoid_property_mapping_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_property_mapping_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property integer NOT NULL, + fk_column integer NOT NULL, + fk_factoid_mapping integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 259 (class 1259 OID 21082) +-- Name: factoid_role; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_role( + fk_property integer NOT NULL, + fk_domain_factoid integer NOT NULL, + fk_data_range integer, + fk_info_value_range integer +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 260 (class 1259 OID 21089) +-- Name: factoid_role_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_role_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property integer NOT NULL, + fk_domain_factoid integer NOT NULL, + fk_data_range integer, + fk_info_value_range integer, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 261 (class 1259 OID 21094) +-- Name: factoid_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.factoid_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_class integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 262 (class 1259 OID 21099) +-- Name: namespace; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.namespace( + fk_root_namespace integer, + fk_project integer, + standard_label text +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 263 (class 1259 OID 21106) +-- Name: namespace_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.namespace_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_root_namespace integer, + fk_project integer, + standard_label text, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 358 (class 1259 OID 23099) +-- Name: property_of_property; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.property_of_property( + fk_property_of_property integer NOT NULL, + fk_domain_factoid_property integer, + fk_domain_data_association integer, + fk_data_range integer NOT NULL, + fk_info_value_range integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 356 (class 1259 OID 23037) +-- Name: property_of_property_mapping; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.property_of_property_mapping( + fk_property_of_property integer NOT NULL, + fk_domain_factoid_property_mapping integer, + fk_domain_data_association_mapping integer, + fk_range_column integer NOT NULL +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 357 (class 1259 OID 23070) +-- Name: property_of_property_mapping_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.property_of_property_mapping_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property_of_property integer NOT NULL, + fk_domain_factoid_property_mapping_vt integer, + fk_domain_data_association_mapping integer, + fk_range_column integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 359 (class 1259 OID 23127) +-- Name: property_of_property_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.property_of_property_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property_of_property integer NOT NULL, + fk_domain_factoid_property_vt integer, + fk_domain_data_association integer, + fk_data_range integer NOT NULL, + fk_info_value_range integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 264 (class 1259 OID 21123) +-- Name: text_property; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.text_property( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + quill_doc jsonb NOT NULL, + string text NOT NULL, + fk_system_type integer NOT NULL, + fk_language integer NOT NULL, + fk_entity integer, + CONSTRAINT text_quill_doc_check CHECK (((quill_doc IS NULL) OR commons.validate_quill_doc(quill_doc))) +) +INHERITS ( + data.entity, + commons.text +); + +-- +-- TOC entry 265 (class 1259 OID 21133) +-- Name: text_property_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.text_property_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_system_type integer NOT NULL, + fk_language integer NOT NULL, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer, + fk_entity integer +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 364 (class 1259 OID 23224) +-- Name: v_chunk; Type: VIEW; Schema: data; Owner: - +-- +CREATE VIEW data.v_chunk AS +SELECT + chunk.pk_entity, + chunk.schema_name, + chunk.table_name, + chunk.entity_version, + chunk.notes, + chunk.fk_namespace, + chunk.fk_creator, + chunk.fk_last_modifier, + chunk.tmsp_creation, + chunk.tmsp_last_modification, + chunk.sys_period, + chunk.metadata, + chunk.pk_text, + chunk.quill_doc, + chunk.string, + chunk.fk_text, + chunk.fk_entity_version, + chunk.id_for_import, + chunk.id_for_import_txt, + chunk.fk_publication_status, + chunk.fk_license +FROM + data.chunk; + +-- +-- TOC entry 268 (class 1259 OID 21158) +-- Name: values_association; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.values_association( + fk_property integer NOT NULL, + fk_domain_cell integer, + fk_range_cell integer, + fk_domain_chunk integer, + fk_range_chunk integer +) +INHERITS ( + data.entity +); + +-- +-- TOC entry 269 (class 1259 OID 21165) +-- Name: values_association_vt; Type: TABLE; Schema: data; Owner: - +-- +CREATE TABLE data.values_association_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_property integer NOT NULL, + fk_domain_cell integer, + fk_range_cell integer, + fk_domain_chunk integer, + fk_range_chunk integer, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer +); + +-- +-- TOC entry 270 (class 1259 OID 21170) +-- Name: entity; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.entity( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean DEFAULT FALSE +); + +-- +-- TOC entry 386 (class 1259 OID 24080) +-- Name: api_class; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_class( + requested_language character varying, + dfh_pk_class integer, + dfh_class_identifier_in_namespace character varying, + dfh_class_label_language character varying, + dfh_class_label text, + dfh_class_scope_note_language character varying, + dfh_class_scope_note text, + dfh_basic_type integer, + dfh_basic_type_label text, + dfh_fk_namespace integer, + dfh_namespace_label_language character varying, + dfh_namespace_label text, + dfh_namespace_uri text, + dfh_profile_association_type text, + dfh_fk_profile integer, + dfh_profile_label_language character varying, + dfh_profile_label text, + dfh_parent_classes integer[] DEFAULT '{}' ::integer[] NOT NULL, + dfh_ancestor_classes integer[] DEFAULT '{}' ::integer[] NOT NULL +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 387 (class 1259 OID 24094) +-- Name: api_class_vt; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_class_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean, + requested_language character varying, + dfh_pk_class integer, + dfh_class_identifier_in_namespace character varying, + dfh_class_label_language character varying, + dfh_class_label text, + dfh_class_scope_note_language character varying, + dfh_class_scope_note text, + dfh_basic_type integer, + dfh_basic_type_label text, + dfh_fk_namespace integer, + dfh_namespace_label_language character varying, + dfh_namespace_label text, + dfh_namespace_uri text, + dfh_profile_association_type text, + dfh_fk_profile integer, + dfh_profile_label_language character varying, + dfh_profile_label text, + dfh_parent_classes integer[] DEFAULT '{}' ::integer[] NOT NULL, + dfh_ancestor_classes integer[] DEFAULT '{}' ::integer[] NOT NULL +); + +-- +-- TOC entry 278 (class 1259 OID 21230) +-- Name: api_profile; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_profile( + dfh_pk_profile integer, + requested_language character varying(4), + dfh_profile_label_language character varying(4), + dfh_profile_label text, + dfh_profile_definition_language character varying(4), + dfh_profile_definition text, + dfh_owned_by_project integer, + dfh_project_label_language character varying(4), + dfh_project_label text, + dfh_is_ongoing_forced_publication boolean, + dfh_date_profile_published date, + dfh_date_profile_deprecated date, + dfh_is_root_profile boolean DEFAULT FALSE, + dfh_fk_root_profile integer +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 279 (class 1259 OID 21238) +-- Name: api_profile_vt; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_profile_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_profile integer, + requested_language character varying(4), + dfh_profile_label_language character varying(4), + dfh_profile_label text, + dfh_profile_definition_language character varying(4), + dfh_profile_definition text, + dfh_owned_by_project integer, + dfh_project_label_language character varying(4), + dfh_project_label text, + dfh_is_ongoing_forced_publication boolean, + dfh_date_profile_published date, + dfh_date_profile_deprecated date, + dfh_is_root_profile boolean DEFAULT FALSE, + dfh_fk_root_profile integer +); + +-- +-- TOC entry 388 (class 1259 OID 24104) +-- Name: api_property; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_property( + requested_language character varying, + dfh_pk_property integer, + dfh_property_label_language character varying, + dfh_property_label text, + dfh_property_scope_note_language character varying, + dfh_property_scope_note text, + dfh_is_inherited boolean, + dfh_property_domain integer, + dfh_domain_instances_min_quantifier integer, + dfh_domain_instances_max_quantifier integer, + dfh_property_range integer, + dfh_range_instances_min_quantifier integer, + dfh_range_instances_max_quantifier integer, + dfh_identity_defining boolean, + dfh_is_has_type_subproperty boolean, + dfh_property_identifier_in_namespace character varying, + dfh_namespace_uri text, + dfh_fk_namespace integer, + dfh_namespace_label_language character varying, + dfh_namespace_label text, + dfh_profile_association_type character varying, + dfh_fk_profile integer, + dfh_profile_label_language character varying, + dfh_profile_label text, + dfh_property_inverse_label text, + dfh_parent_properties integer[] DEFAULT '{}' ::integer[] NOT NULL, + dfh_ancestor_properties integer[] DEFAULT '{}' ::integer[] NOT NULL +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 389 (class 1259 OID 24118) +-- Name: api_property_vt; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.api_property_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean, + requested_language character varying, + dfh_pk_property integer, + dfh_property_label_language character varying, + dfh_property_label text, + dfh_property_scope_note_language character varying, + dfh_property_scope_note text, + dfh_is_inherited boolean, + dfh_property_domain integer, + dfh_domain_instances_min_quantifier integer, + dfh_domain_instances_max_quantifier integer, + dfh_property_range integer, + dfh_range_instances_min_quantifier integer, + dfh_range_instances_max_quantifier integer, + dfh_identity_defining boolean, + dfh_is_has_type_subproperty boolean, + dfh_property_identifier_in_namespace character varying, + dfh_namespace_uri text, + dfh_fk_namespace integer, + dfh_namespace_label_language character varying, + dfh_namespace_label text, + dfh_profile_association_type character varying, + dfh_fk_profile integer, + dfh_profile_label_language character varying, + dfh_profile_label text, + dfh_property_inverse_label text, + dfh_parent_properties integer[] DEFAULT '{}' ::integer[] NOT NULL, + dfh_ancestor_properties integer[] DEFAULT '{}' ::integer[] NOT NULL +); + +-- +-- TOC entry 271 (class 1259 OID 21178) +-- Name: associates_system_type_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.associates_system_type_deprecated( + is_enabled_in_profile boolean, + removed_from_api boolean DEFAULT FALSE, + dfh_pk_associates_system_type integer, + dfh_fk_system_type integer, + dfh_fk_class integer, + dfh_fk_class_type integer, + dfh_fk_property integer, + dfh_fk_property_type integer, + dfh_fk_namespace integer, + dfh_fk_label integer, + dfh_fk_text_property integer, + dfh_fk_project integer, + dfh_fk_profile integer, + dfh_fk_entity_association integer +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 272 (class 1259 OID 21186) +-- Name: associates_system_type_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.associates_system_type_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_associates_system_type integer, + dfh_fk_system_type integer, + dfh_fk_class integer, + dfh_fk_class_type integer, + dfh_fk_property integer, + dfh_fk_property_type integer, + dfh_fk_namespace integer, + dfh_fk_label integer, + dfh_fk_text_property integer, + dfh_fk_project integer, + dfh_fk_profile integer, + dfh_fk_entity_association integer, + is_inabled_in_profile boolean, + removed_from_api boolean +); + +-- +-- TOC entry 273 (class 1259 OID 21199) +-- Name: class_profile_view_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.class_profile_view_deprecated( + tmsp_last_dfh_update timestamp with time zone, + removed_from_api boolean DEFAULT NULL, + dfh_fk_class integer, + dfh_identifier_in_namespace text, + dfh_class_standard_label character varying, + dfh_fk_system_type integer, + dfh_type_label character varying, + dfh_root_namespace text, + dfh_profile_association_type character varying, + dfh_fk_profile integer, + dfh_profile_label character varying +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 274 (class 1259 OID 21206) +-- Name: class_profile_view_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.class_profile_view_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + dfh_fk_class integer, + dfh_identifier_in_namespace text, + dfh_class_standard_label character varying, + dfh_fk_system_type integer, + dfh_type_label character varying, + dfh_root_namespace text, + dfh_profile_association_type character varying, + dfh_fk_profile integer, + dfh_profile_label character varying, + is_enabled_in_profile boolean, + tmsp_last_dfh_update timestamp with time zone, + removed_from_api boolean +); + +-- +-- TOC entry 275 (class 1259 OID 21216) +-- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: data_for_history; Owner: - +-- +CREATE SEQUENCE data_for_history.entity_pk_entity_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6476 (class 0 OID 0) +-- Dependencies: 275 +-- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: data_for_history; Owner: - +-- +ALTER SEQUENCE data_for_history.entity_pk_entity_seq OWNED BY data_for_history.entity.pk_entity; + +-- +-- TOC entry 276 (class 1259 OID 21217) +-- Name: label_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.label_deprecated( + dfh_pk_label integer, + dfh_label text, + dfh_language_iso_code character varying, + dfh_is_standard_label_for_language boolean, + dfh_fk_property integer, + dfh_fk_namespace integer, + dfh_fk_class integer, + dfh_fk_project integer, + dfh_fk_class_type integer, + dfh_fk_property_type integer, + dfh_fk_profile integer, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone, + dfh_fk_system_type integer, + com_fk_system_type integer, + inf_fk_language integer +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 277 (class 1259 OID 21225) +-- Name: label_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.label_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_label integer, + dfh_label text, + dfh_language_iso_code character varying, + dfh_is_standard_label_for_language boolean, + dfh_fk_property integer, + dfh_fk_namespace integer, + dfh_fk_class integer, + dfh_fk_project integer, + dfh_fk_class_type integer, + dfh_fk_property_type integer, + dfh_fk_profile integer, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone +); + +-- +-- TOC entry 280 (class 1259 OID 21243) +-- Name: property; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property( + dfh_pk_property integer, + dfh_identifier_in_namespace text, + dfh_has_domain integer, + dfh_has_range integer, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone, + dfh_standard_label character varying(500), + dfh_domain_instances_min_quantifier smallint, + dfh_domain_instances_max_quantifier smallint, + dfh_range_instances_min_quantifier smallint, + dfh_range_instances_max_quantifier smallint, + dfh_fk_property_of_origin integer, + identity_defining boolean DEFAULT FALSE +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 6477 (class 0 OID 0) +-- Dependencies: 280 +-- Name: COLUMN property.identity_defining; Type: COMMENT; Schema: data_for_history; Owner: - +-- +COMMENT ON COLUMN data_for_history.property.identity_defining IS 'If the value is set to true, this means that this property is relevant for the TeEn identity.'; + +-- +-- TOC entry 401 (class 1259 OID 24427) +-- Name: property_of_property; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property_of_property( + pk_property_of_property integer NOT NULL, + label text, + label_language character varying, + scope_note text, + scope_note_language character varying, + is_inherited boolean, + has_domain integer, + dfh_domain_instances_min_quantifier integer, + dfh_domain_instances_max_quantifier integer, + has_range integer, + dfh_range_instances_min_quantifier integer, + dfh_range_instances_max_quantifier integer, + identifier_in_namespace character varying, + fk_profile integer +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 402 (class 1259 OID 24445) +-- Name: property_of_property_vt; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property_of_property_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean, + pk_property_of_property integer NOT NULL, + label text, + label_language character varying, + scope_note text, + scope_note_language character varying, + is_inherited boolean, + has_domain integer, + dfh_domain_instances_min_quantifier integer, + dfh_domain_instances_max_quantifier integer, + has_range integer, + dfh_range_instances_min_quantifier integer, + dfh_range_instances_max_quantifier integer, + identifier_in_namespace character varying, + fk_profile integer +); + +-- +-- TOC entry 281 (class 1259 OID 21252) +-- Name: property_profile_view_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property_profile_view_deprecated( + is_enabled_in_profile boolean, + removed_from_api boolean DEFAULT NULL, + dfh_pk_property integer, + dfh_identifier_in_namespace text, + dfh_has_domain integer, + dfh_has_range integer, + dfh_fk_property_of_origin integer, + dfh_standard_label character varying, + dfh_root_namespace text, + dfh_pk_profile integer, + dfh_profile_label character varying +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 282 (class 1259 OID 21259) +-- Name: property_profile_view_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property_profile_view_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_property integer, + dfh_identifier_in_namespace text, + dfh_has_domain integer, + dfh_has_range integer, + dfh_fk_property_of_origin integer, + dfh_standard_label character varying, + dfh_root_namespace text, + dfh_pk_profile integer, + dfh_profile_label character varying, + is_inabled_in_profile boolean, + removed_from_api boolean +); + +-- +-- TOC entry 283 (class 1259 OID 21264) +-- Name: property_vt; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.property_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_property integer, + dfh_identifier_in_namespace text, + dfh_has_domain integer, + dfh_has_range integer, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone, + dfh_domain_instances_cardinality smallint, + dfh_range_instances_cardinality smallint, + dfh_standard_label character varying(500), + dfh_fk_property_of_origin integer, + identity_defining boolean +); + +-- +-- TOC entry 284 (class 1259 OID 21269) +-- Name: system_type_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.system_type_deprecated( + dfh_pk_system_type integer, + dfh_used_in_table character varying(250), + dfh_standard_label character varying(500), + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 285 (class 1259 OID 21277) +-- Name: system_type_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.system_type_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + is_inabled_in_profile boolean, + removed_from_api boolean, + dfh_pk_system_type integer, + dfh_used_in_table character varying(250), + dfh_standard_label character varying(500), + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone +); + +-- +-- TOC entry 286 (class 1259 OID 21282) +-- Name: text_property_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.text_property_deprecated( + dfh_pk_text_property integer, + dfh_text_property text, + dfh_language_iso_code character varying, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone, + dfh_fk_property integer, + dfh_fk_namespace integer, + dfh_fk_class integer, + dfh_fk_project integer, + dfh_fk_class_type integer, + dfh_fk_property_type integer, + dfh_fk_system_type integer, + dfh_fk_entity_association integer, + dfh_fk_profile integer, + dfh_fk_is_subclass_of integer +) +INHERITS ( + data_for_history.entity +); + +-- +-- TOC entry 287 (class 1259 OID 21290) +-- Name: text_property_vt_deprecated; Type: TABLE; Schema: data_for_history; Owner: - +-- +CREATE TABLE data_for_history.text_property_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + dfh_pk_text_property integer, + dfh_text_property text, + dfh_language_iso_code character varying, + dfh_creation_time timestamp without time zone, + dfh_modification_time timestamp without time zone, + dfh_fk_property integer, + dfh_fk_namespace integer, + dfh_fk_class integer, + dfh_fk_project integer, + dfh_fk_class_type integer, + dfh_fk_property_type integer, + dfh_fk_system_type integer, + dfh_fk_entity_association integer, + dfh_fk_profile integer, + dfh_fk_is_subclass_of integer +); + +-- +-- TOC entry 392 (class 1259 OID 24143) +-- Name: v_class; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_class AS +WITH tw1 AS ( + SELECT + t1_1.dfh_pk_class, + jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles + FROM + data_for_history.api_class t1_1 + GROUP BY + t1_1.dfh_pk_class +) +SELECT DISTINCT ON (t1.dfh_pk_class) + t1.dfh_pk_class AS pk_class, + t1.dfh_class_identifier_in_namespace AS identifier_in_namespace, + t1.dfh_basic_type AS basic_type, + t1.dfh_basic_type_label AS basic_type_label, + tw1.profiles, + t1.dfh_parent_classes AS parent_classes, + t1.dfh_ancestor_classes AS ancestor_classes +FROM + tw1, + data_for_history.api_class t1 +WHERE (tw1.dfh_pk_class = t1.dfh_pk_class); + +-- +-- TOC entry 391 (class 1259 OID 24138) +-- Name: v_label; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_label AS SELECT DISTINCT ON (t1.dfh_pk_profile, t1.dfh_profile_label, t1.dfh_profile_label_language) + 'label'::text AS type, + t1.dfh_profile_label AS label, + t1.dfh_profile_label_language AS + LANGUAGE, + t1.dfh_pk_profile AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_profile t1 +UNION +SELECT DISTINCT ON (t1.dfh_pk_profile, t1.dfh_profile_definition, t1.dfh_profile_definition_language) + 'definition'::text AS type, + t1.dfh_profile_definition AS label, + t1.dfh_profile_definition_language AS + LANGUAGE, + t1.dfh_pk_profile AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_profile t1 +UNION +SELECT DISTINCT ON (t1.dfh_owned_by_project, t1.dfh_project_label, t1.dfh_project_label_language) + 'label'::text AS type, + t1.dfh_project_label AS label, + t1.dfh_project_label_language AS + LANGUAGE, + NULL::integer AS fk_profile, + t1.dfh_owned_by_project AS fk_project, + NULL::integer AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_profile t1 +UNION +SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_label, t1.dfh_property_label_language) + 'label'::text AS type, + t1.dfh_property_label AS label, + t1.dfh_property_label_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + t1.dfh_pk_property AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_property t1 +UNION +SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_inverse_label, t1.dfh_property_label_language) + 'inverse_label'::text AS type, + t1.dfh_property_inverse_label AS label, + t1.dfh_property_label_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + t1.dfh_pk_property AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_property t1 +WHERE (t1.dfh_property_inverse_label IS NOT NULL) +UNION +SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) + 'scope_note'::text AS type, + t1.dfh_property_scope_note AS label, + t1.dfh_property_scope_note_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + t1.dfh_pk_property AS fk_property, + NULL::integer AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_property t1 +UNION +SELECT DISTINCT ON (t1.dfh_pk_class, t1.dfh_class_label, t1.dfh_class_label_language) + 'label'::text AS type, + t1.dfh_class_label AS label, + t1.dfh_class_label_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + t1.dfh_pk_class AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_class t1 +UNION +SELECT DISTINCT ON (t1.dfh_pk_class, t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) + 'scope_note'::text AS type, + t1.dfh_class_scope_note AS label, + t1.dfh_class_scope_note_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + t1.dfh_pk_class AS fk_class, + NULL::integer AS fk_property_of_property +FROM + data_for_history.api_class t1 +UNION +SELECT DISTINCT ON (t1.pk_property_of_property, t1.label, t1.label_language) + 'label'::text AS type, + t1.label, + t1.label_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + NULL::integer AS fk_class, + t1.pk_property_of_property AS fk_property_of_property +FROM + data_for_history.property_of_property t1 +UNION +SELECT DISTINCT ON (t1.pk_property_of_property, t1.scope_note, t1.scope_note_language) + 'scope_note'::text AS type, + t1.scope_note AS label, + t1.scope_note_language AS + LANGUAGE, + NULL::integer AS fk_profile, + NULL::integer AS fk_project, + NULL::integer AS fk_property, + NULL::integer AS fk_class, + t1.pk_property_of_property AS fk_property_of_property +FROM + data_for_history.property_of_property t1; + +-- +-- TOC entry 390 (class 1259 OID 24134) +-- Name: v_profile; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_profile AS SELECT DISTINCT + t1.dfh_pk_profile AS pk_profile, + t1.dfh_owned_by_project AS owned_by_project, + t1.dfh_is_ongoing_forced_publication AS is_ongoing_forced_publication, + t1.dfh_date_profile_published AS date_profile_published, + t1.dfh_date_profile_deprecated AS date_profile_deprecated, + t1.tmsp_last_dfh_update +FROM + data_for_history.api_profile t1; + +-- +-- TOC entry 420 (class 1259 OID 24731) +-- Name: v_property; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_property AS +WITH tw0 AS ( + SELECT + t1_1.dfh_pk_property, + t1_1.dfh_is_inherited, + t1_1.dfh_property_domain, + t1_1.dfh_domain_instances_min_quantifier, + t1_1.dfh_domain_instances_max_quantifier, + t1_1.dfh_property_range, + t1_1.dfh_range_instances_min_quantifier, + t1_1.dfh_range_instances_max_quantifier, + t1_1.dfh_property_identifier_in_namespace, + t1_1.dfh_fk_profile, + t1_1.removed_from_api, + t1_1.dfh_parent_properties, + t1_1.dfh_ancestor_properties + FROM + data_for_history.api_property t1_1 +), +tw1 AS ( + SELECT + t1_1.dfh_pk_property, + t1_1.dfh_property_domain, + t1_1.dfh_property_range, + jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles +FROM + tw0 t1_1 +GROUP BY + t1_1.dfh_pk_property, + t1_1.dfh_property_domain, + t1_1.dfh_property_range +) +SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range) + t1.dfh_pk_property AS pk_property, + t1.dfh_property_domain AS has_domain, + t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, + t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, + t1.dfh_property_range AS has_range, + t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, + t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, + t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, + t1.dfh_parent_properties AS parent_properties, + t1.dfh_ancestor_properties AS ancestor_properties, + t2.profiles +FROM + tw0 t1, + tw1 t2 +WHERE ((t1.dfh_pk_property = t2.dfh_pk_property) + AND (t1.dfh_property_domain = t2.dfh_property_domain) + AND (t1.dfh_property_range = t2.dfh_property_range)) +ORDER BY + t1.dfh_pk_property, + t1.dfh_property_domain, + t1.dfh_property_range, + t1.removed_from_api; + +-- +-- TOC entry 367 (class 1259 OID 23707) +-- Name: v_property_deprecated; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_property_deprecated AS SELECT DISTINCT + t1.pk_entity, + CASE WHEN (t1.dfh_fk_property_of_origin IS NOT NULL) THEN + TRUE + ELSE + FALSE + END AS is_inherited, + t1.dfh_has_domain, + COALESCE(t1.dfh_fk_property_of_origin, t1.dfh_pk_property) AS fk_property, + t1.dfh_has_range, + t1.dfh_pk_property, + t1.dfh_identifier_in_namespace, + t1.dfh_standard_label, + t1.is_enabled_in_profile, + t1.removed_from_api, + t1.dfh_fk_property_of_origin, + t1.dfh_domain_instances_min_quantifier, + t1.dfh_domain_instances_max_quantifier, + t1.dfh_range_instances_min_quantifier, + t1.dfh_range_instances_max_quantifier, + t1.identity_defining +FROM + data_for_history.property t1 +ORDER BY + t1.dfh_has_domain, + COALESCE(t1.dfh_fk_property_of_origin, t1.dfh_pk_property), + CASE WHEN (t1.dfh_fk_property_of_origin IS NOT NULL) THEN + TRUE + ELSE + FALSE + END, + t1.dfh_pk_property; + +-- +-- TOC entry 366 (class 1259 OID 23702) +-- Name: v_property_profile_view_deprecated; Type: VIEW; Schema: data_for_history; Owner: - +-- +CREATE VIEW data_for_history.v_property_profile_view_deprecated AS SELECT DISTINCT + t1.pk_entity, + CASE WHEN (t1.dfh_fk_property_of_origin IS NOT NULL) THEN + TRUE + ELSE + FALSE + END AS is_inherited, + t1.dfh_has_domain, + COALESCE(t1.dfh_fk_property_of_origin, t1.dfh_pk_property) AS fk_property, + t1.dfh_has_range, + t1.dfh_pk_property, + t1.dfh_identifier_in_namespace, + t1.dfh_standard_label, + t1.dfh_pk_profile, + t1.dfh_profile_label, + t1.is_enabled_in_profile, + t1.removed_from_api, + t1.dfh_fk_property_of_origin, + t2.dfh_domain_instances_min_quantifier, + t2.dfh_domain_instances_max_quantifier, + t2.dfh_range_instances_min_quantifier, + t2.dfh_range_instances_max_quantifier, + t2.identity_defining +FROM + data_for_history.property_profile_view_deprecated t1, + data_for_history.property t2 +WHERE (t1.dfh_pk_property = t2.dfh_pk_property) +ORDER BY + CASE WHEN (t1.dfh_fk_property_of_origin IS NOT NULL) THEN + TRUE + ELSE + FALSE + END, + COALESCE(t1.dfh_fk_property_of_origin, t1.dfh_pk_property), + t1.dfh_pk_property; + +-- +-- TOC entry 290 (class 1259 OID 21340) +-- Name: _backup_entity_association; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information._backup_entity_association( + fk_info_domain integer, + fk_info_range integer, + fk_property integer, + fk_data_domain integer, + fk_data_range integer, + fk_cell_domain bigint, + fk_cell_range bigint +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 288 (class 1259 OID 21321) +-- Name: appellation; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.appellation( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + entity_version integer, + quill_doc jsonb NOT NULL, + string text NOT NULL, + fk_class integer NOT NULL +) +INHERITS ( + commons.text, + information.entity +); + +-- +-- TOC entry 289 (class 1259 OID 21332) +-- Name: appellation_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.appellation_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class integer NOT NULL +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 360 (class 1259 OID 23145) +-- Name: dimension; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.dimension( + fk_class integer NOT NULL, + fk_measurement_unit integer NOT NULL, + numeric_value numeric NOT NULL +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 361 (class 1259 OID 23168) +-- Name: dimension_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.dimension_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_class integer NOT NULL, + fk_measurement_unit integer NOT NULL, + numeric_value numeric NOT NULL +); + +-- +-- TOC entry 250 (class 1259 OID 21028) +-- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: information; Owner: - +-- +CREATE SEQUENCE information.entity_pk_entity_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6478 (class 0 OID 0) +-- Dependencies: 250 +-- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - +-- +ALTER SEQUENCE information.entity_pk_entity_seq OWNED BY information.entity.pk_entity; + +-- +-- TOC entry 398 (class 1259 OID 24388) +-- Name: lang_string; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.lang_string( + entity_version integer DEFAULT 1, + fk_language integer NOT NULL, + fk_class integer NOT NULL +) +INHERITS ( + information.entity, + commons.text +); + +-- +-- TOC entry 399 (class 1259 OID 24415) +-- Name: lang_string_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.lang_string_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + pk_text integer, + entity_version integer, + quill_doc jsonb, + string text, + fk_language integer NOT NULL, + fk_class integer NOT NULL +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 291 (class 1259 OID 21353) +-- Name: language; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.language( + pk_language character(3) NOT NULL, + fk_class integer, + lang_type character varying, + scope character varying, + iso6392b character(3), + iso6392t character(3), + iso6391 character(3) +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 292 (class 1259 OID 21360) +-- Name: language_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.language_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + pk_language character(3) NOT NULL, + fk_class integer, + lang_type character varying, + scope character varying, + iso6392b character(3), + iso6392t character(3), + iso6391 character(3) +); + +-- +-- TOC entry 293 (class 1259 OID 21365) +-- Name: persistent_item_backup; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.persistent_item_backup( + pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass) NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + fk_class integer +); + +-- +-- TOC entry 294 (class 1259 OID 21373) +-- Name: persistent_item_vt_backup; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.persistent_item_vt_backup( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class integer +); + +-- +-- TOC entry 295 (class 1259 OID 21378) +-- Name: place; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.place( + geo_point public.geography(point, 4326), + fk_class integer +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 296 (class 1259 OID 21385) +-- Name: place_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.place_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + geo_point public.geography(point, 4326), + fk_class integer +); + +-- +-- TOC entry 416 (class 1259 OID 24647) +-- Name: resource; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.resource( + pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT NULL, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT NULL, + metadata jsonb, + fk_class integer, + community_visibility jsonb +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 417 (class 1259 OID 24658) +-- Name: resource_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.resource_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + fk_class integer, + community_visibility jsonb +); + +-- +-- TOC entry 297 (class 1259 OID 21402) +-- Name: statement; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.statement( + fk_object_info integer DEFAULT 0 NOT NULL, + fk_subject_info integer DEFAULT 0 NOT NULL, + fk_property integer DEFAULT 0 NOT NULL, + fk_property_of_property integer DEFAULT 0 NOT NULL, + fk_subject_data integer DEFAULT 0 NOT NULL, + fk_subject_tables_row bigint DEFAULT 0 NOT NULL, + fk_subject_tables_cell bigint DEFAULT 0 NOT NULL, + fk_object_data integer DEFAULT 0 NOT NULL, + fk_object_tables_row bigint DEFAULT 0 NOT NULL, + fk_object_tables_cell bigint DEFAULT 0 NOT NULL +) +INHERITS ( + information.entity +); + +-- +-- TOC entry 298 (class 1259 OID 21410) +-- Name: statement_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.statement_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_object_info integer, + fk_subject_info integer, + fk_property integer, + fk_property_of_property integer DEFAULT 0 NOT NULL, + fk_subject_data integer DEFAULT 0 NOT NULL, + fk_subject_tables_row bigint DEFAULT 0 NOT NULL, + fk_subject_tables_cell bigint DEFAULT 0 NOT NULL, + fk_object_data integer DEFAULT 0 NOT NULL, + fk_object_tables_row bigint DEFAULT 0 NOT NULL, + fk_object_tables_cell bigint DEFAULT 0 NOT NULL +); + +-- +-- TOC entry 234 (class 1259 OID 20874) +-- Name: temporal_entity_backup; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.temporal_entity_backup( + pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass) NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + fk_class integer +); + +-- +-- TOC entry 299 (class 1259 OID 21416) +-- Name: temporal_entity_vt_backup; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.temporal_entity_vt_backup( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class integer +); + +-- +-- TOC entry 300 (class 1259 OID 21421) +-- Name: text_property; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.text_property( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + entity_version integer, + quill_doc jsonb NOT NULL, + string text NOT NULL, + _deprecated_text_property text, + fk_concerned_entity integer NOT NULL, + _deprecated_text_property_quill_doc jsonb, + fk_language integer NOT NULL, + fk_class_field integer, + CONSTRAINT text_quill_doc_check CHECK (((quill_doc IS NULL) OR commons.validate_quill_doc(quill_doc))) +) +INHERITS ( + commons.text, + information.entity +); + +-- +-- TOC entry 301 (class 1259 OID 21431) +-- Name: text_property_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.text_property_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + _deprecated_text_property text, + fk_concerned_entity integer, + _deprecated_text_property_quill_doc jsonb, + fk_language integer, + fk_class_field integer +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 303 (class 1259 OID 21447) +-- Name: time_primitive_vt; Type: TABLE; Schema: information; Owner: - +-- +CREATE TABLE information.time_primitive_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + duration public.calendar_granularities, + fk_class integer, + julian_day integer, + calendar public.calendar_type +); + +-- +-- TOC entry 362 (class 1259 OID 23176) +-- Name: v_dimension; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_dimension AS +SELECT + dimension.pk_entity, + dimension.schema_name, + dimension.table_name, + dimension.notes, + dimension.fk_creator, + dimension.fk_last_modifier, + dimension.tmsp_creation, + dimension.tmsp_last_modification, + dimension.sys_period, + dimension.metadata, + dimension.fk_class, + dimension.fk_measurement_unit, + dimension.numeric_value +FROM + information.dimension; + +-- +-- TOC entry 397 (class 1259 OID 24280) +-- Name: v_entity_class_map; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_entity_class_map AS +SELECT + appellation.pk_entity, + appellation.fk_class, + 'appellation'::text AS table_name +FROM + information.appellation +UNION ALL +SELECT + language.pk_entity, + language.fk_class, + 'language'::text AS table_name +FROM + information.language +UNION ALL +SELECT + resource.pk_entity, + resource.fk_class, + 'resource'::text AS table_name +FROM + information.resource +UNION ALL +SELECT + place.pk_entity, + place.fk_class, + 'place'::text AS table_name +FROM + information.place +UNION ALL +SELECT + dimension.pk_entity, + dimension.fk_class, + 'dimension'::text AS table_name +FROM + information.dimension +UNION ALL +SELECT + lang_string.pk_entity, + lang_string.fk_class, + 'lang_string'::text AS table_name +FROM + information.lang_string +UNION ALL +SELECT + time_primitive.pk_entity, + time_primitive.fk_class, + 'time_primitive'::text AS table_name +FROM + information.time_primitive; + +-- +-- TOC entry 400 (class 1259 OID 24421) +-- Name: v_lang_string; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_lang_string AS +SELECT + lang_string.pk_entity, + lang_string.schema_name, + lang_string.table_name, + lang_string.notes, + lang_string.fk_creator, + lang_string.fk_last_modifier, + lang_string.tmsp_creation, + lang_string.tmsp_last_modification, + lang_string.sys_period, + lang_string.metadata, + lang_string.pk_text, + lang_string.entity_version, + lang_string.quill_doc, + lang_string.string, + lang_string.fk_language, + lang_string.fk_class +FROM + information.lang_string; + +-- +-- TOC entry 306 (class 1259 OID 21481) +-- Name: v_language; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_language AS +SELECT + language.pk_entity, + language.schema_name, + language.table_name, + language.notes, + language.fk_creator, + language.fk_last_modifier, + language.tmsp_creation, + language.tmsp_last_modification, + language.sys_period, + language.pk_language, + language.fk_class, + language.lang_type, + language.scope, + language.iso6392b, + language.iso6392t, + language.iso6391 +FROM + information.language; + +-- +-- TOC entry 304 (class 1259 OID 21461) +-- Name: entity; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.entity( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) +); + +-- +-- TOC entry 307 (class 1259 OID 21485) +-- Name: class_field_config; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.class_field_config( + fk_app_context integer, + _deprecated_fk_project integer, + fk_property integer, + property_is_outgoing boolean, + fk_class_field integer, + fk_class_for_class_field integer, + ord_num integer, + fk_project integer NOT NULL, + fk_domain_class integer, + fk_range_class integer, + fk_property_deprecated integer +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 309 (class 1259 OID 21493) +-- Name: entity; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.entity( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) +); + +-- +-- TOC entry 349 (class 1259 OID 21755) +-- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: system; Owner: - +-- +CREATE SEQUENCE system.entity_pk_entity_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6479 (class 0 OID 0) +-- Dependencies: 349 +-- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: system; Owner: - +-- +ALTER SEQUENCE system.entity_pk_entity_seq OWNED BY system.entity.pk_entity; + +-- +-- TOC entry 310 (class 1259 OID 21500) +-- Name: class_field; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_field( + pk_entity integer DEFAULT nextval('system.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + label character varying NOT NULL, + description text, + used_table text, + fk_system_type_ng_component integer +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 311 (class 1259 OID 21508) +-- Name: v_ordered_fields_per_class; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_ordered_fields_per_class AS +SELECT + c.pk_entity, + c.ord_num AS field_order, + CASE WHEN (c.property_is_outgoing = TRUE) THEN + p.dfh_has_domain + WHEN (c.property_is_outgoing = FALSE) THEN + p.dfh_has_range + ELSE + c.fk_class_for_class_field + END AS fk_class, + c.fk_property, + c.property_is_outgoing, + c.fk_class_field, + f.used_table +FROM ((projects.class_field_config c + LEFT JOIN data_for_history.property p ON (p.dfh_pk_property = c.fk_property)) + LEFT JOIN system.class_field f ON (f.pk_entity = c.fk_class_field)) +WHERE (c.fk_app_context = 45) +ORDER BY + CASE WHEN (c.property_is_outgoing = TRUE) THEN + p.dfh_has_domain + WHEN (c.property_is_outgoing = FALSE) THEN + p.dfh_has_range + ELSE + c.fk_class_for_class_field + END, + c.ord_num; + +-- +-- TOC entry 312 (class 1259 OID 21517) +-- Name: v_place; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_place AS +SELECT + place.pk_entity, + place.schema_name, + place.table_name, + place.notes, + place.fk_creator, + place.fk_last_modifier, + place.tmsp_creation, + place.tmsp_last_modification, + place.sys_period, + place.geo_point, + place.fk_class, + public.st_x((place.geo_point)::public.geometry) AS long, + public.st_y((place.geo_point)::public.geometry) AS lat +FROM + information.place; + +-- +-- TOC entry 308 (class 1259 OID 21492) +-- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: projects; Owner: - +-- +CREATE SEQUENCE projects.entity_pk_entity_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6480 (class 0 OID 0) +-- Dependencies: 308 +-- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - +-- +ALTER SEQUENCE projects.entity_pk_entity_seq OWNED BY projects.entity.pk_entity; + +-- +-- TOC entry 305 (class 1259 OID 21468) +-- Name: info_proj_rel; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.info_proj_rel( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_entity integer NOT NULL, + fk_entity_version integer, + fk_entity_version_concat text, + is_in_project boolean, + is_standard_in_project boolean, + calendar_backup public.calendar_type, + ord_num_of_domain integer, + fk_project integer NOT NULL, + ord_num_of_range integer, + ord_num_of_text_property integer, + project_visibility jsonb +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 418 (class 1259 OID 24696) +-- Name: v_statement; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_statement AS +SELECT + t1.pk_entity, + t1.fk_property, + t1.fk_property_of_property, + t1.fk_object_info, + t1.fk_subject_info, + t1.fk_subject_data, + t1.fk_subject_tables_row, + t1.fk_subject_tables_cell, + t1.fk_object_data, + t1.fk_object_tables_row, + t1.fk_object_tables_cell, + t2.is_in_project_count, + t2.is_standard_in_project_count, + t1.notes, + t1.tmsp_creation, + t1.tmsp_last_modification, + t1.sys_period +FROM (information.statement t1 + LEFT JOIN LATERAL ( + SELECT + (count(info_proj_rel.pk_entity))::integer AS is_in_project_count, +(COALESCE(count(*) FILTER (WHERE (info_proj_rel.ord_num_of_domain = 0)),(0)::bigint))::integer AS is_standard_in_project_count + FROM + projects.info_proj_rel + WHERE ((info_proj_rel.fk_entity = t1.pk_entity) + AND (info_proj_rel.is_in_project = TRUE)) + GROUP BY + info_proj_rel.fk_entity) t2 ON (TRUE)); + +-- +-- TOC entry 313 (class 1259 OID 21534) +-- Name: v_text_property; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_text_property AS +SELECT + text_property.pk_entity, + text_property.schema_name, + text_property.table_name, + text_property.notes, + text_property.fk_creator, + text_property.fk_last_modifier, + text_property.tmsp_creation, + text_property.tmsp_last_modification, + text_property.sys_period, + text_property.fk_concerned_entity, + text_property.fk_language, + text_property.fk_class_field, + text_property.quill_doc, + text_property.string, + count(epr.fk_project) AS is_in_project_count +FROM (information.text_property + LEFT JOIN projects.info_proj_rel epr ON (((epr.fk_entity = text_property.pk_entity) + AND (epr.is_in_project = TRUE)))) +GROUP BY + text_property.pk_entity, + text_property.schema_name, + text_property.table_name, + text_property.notes, + text_property.fk_creator, + text_property.fk_last_modifier, + text_property.tmsp_creation, + text_property.tmsp_last_modification, + text_property.sys_period, + text_property._deprecated_text_property, + text_property.fk_concerned_entity, + text_property.quill_doc, + text_property.fk_language, + text_property.fk_class_field, + text_property.string; + +-- +-- TOC entry 363 (class 1259 OID 23192) +-- Name: v_time_primitive; Type: VIEW; Schema: information; Owner: - +-- +CREATE VIEW information.v_time_primitive AS +SELECT + time_primitive.pk_entity, + time_primitive.schema_name, + time_primitive.table_name, + time_primitive.notes, + time_primitive.fk_creator, + time_primitive.fk_last_modifier, + time_primitive.tmsp_creation, + time_primitive.tmsp_last_modification, + time_primitive.sys_period, + time_primitive.metadata, + time_primitive.duration, + time_primitive.fk_class, + time_primitive.julian_day, + time_primitive.calendar +FROM + information.time_primitive; + +-- +-- TOC entry 383 (class 1259 OID 24028) +-- Name: _backup_class_field_config; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects._backup_class_field_config( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_app_context integer, + _deprecated_fk_project integer, + fk_property integer, + property_is_outgoing boolean, + fk_class_field integer, + fk_class_for_class_field integer, + ord_num integer, + fk_project integer, + fk_domain_class integer, + fk_range_class integer, + fk_property_deprecated integer +); + +-- +-- TOC entry 381 (class 1259 OID 23977) +-- Name: analysis; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.analysis( + fk_project integer NOT NULL, + fk_analysis_type integer NOT NULL, + name text, + description text, + analysis_definition jsonb +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 382 (class 1259 OID 24000) +-- Name: analysis_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.analysis_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_project integer NOT NULL, + fk_analysis_type integer NOT NULL, + name text, + description text, + analysis_definition jsonb +); + +-- +-- TOC entry 314 (class 1259 OID 21556) +-- Name: argument; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.argument( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_argument_method_type integer NOT NULL, + is_based_on_reliability integer, + value integer, + fk_is_about_info_entity integer, + fk_is_based_on_info_entity integer, + fk_is_based_on_data_entity integer, + fk_project integer NOT NULL +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 315 (class 1259 OID 21564) +-- Name: argument_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.argument_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_argument_method_type integer NOT NULL, + is_based_on_reliability integer, + value integer, + fk_is_about_info_entity integer, + fk_is_based_on_info_entity integer, + fk_is_based_on_data_entity integer, + fk_project integer NOT NULL +); + +-- +-- TOC entry 316 (class 1259 OID 21569) +-- Name: class_field_config_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.class_field_config_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_app_context integer, + _deprecated_fk_project integer, + fk_property integer, + property_is_outgoing boolean, + fk_class_field integer, + fk_class_for_class_field integer, + ord_num integer, + fk_project integer, + fk_domain_class integer, + fk_range_class integer, + fk_property_deprecated integer +); + +-- +-- TOC entry 317 (class 1259 OID 21574) +-- Name: dfh_class_proj_rel; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.dfh_class_proj_rel( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean DEFAULT FALSE, + _deprecated_fk_project integer, + fk_entity_deprecated integer, + enabled_in_entities boolean, + fk_project integer NOT NULL, + fk_class integer +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 6481 (class 0 OID 0) +-- Dependencies: 317 +-- Name: TABLE dfh_class_proj_rel; Type: COMMENT; Schema: projects; Owner: - +-- +COMMENT ON TABLE projects.dfh_class_proj_rel IS 'This table relates any child table of the data_for_history.entity to a project.'; + +-- +-- TOC entry 6482 (class 0 OID 0) +-- Dependencies: 317 +-- Name: COLUMN dfh_class_proj_rel.enabled_in_entities; Type: COMMENT; Schema: projects; Owner: - +-- +COMMENT ON COLUMN projects.dfh_class_proj_rel.enabled_in_entities IS 'If true, the entity is (added / activated / visible) in the project, if false it is not in the project'; + +-- +-- TOC entry 318 (class 1259 OID 21583) +-- Name: dfh_class_proj_rel_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.dfh_class_proj_rel_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + tmsp_last_dfh_update timestamp with time zone, + is_enabled_in_profile boolean, + removed_from_api boolean, + _deprecated_fk_project integer, + fk_entity integer, + enabled_in_entities boolean, + fk_project integer, + fk_class integer +); + +-- +-- TOC entry 384 (class 1259 OID 24052) +-- Name: dfh_profile_proj_rel; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.dfh_profile_proj_rel( + fk_project integer NOT NULL, + fk_profile integer NOT NULL, + enabled boolean NOT NULL +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 385 (class 1259 OID 24070) +-- Name: dfh_profile_proj_rel_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.dfh_profile_proj_rel_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_project integer NOT NULL, + fk_profile integer NOT NULL, + enabled boolean NOT NULL +); + +-- +-- TOC entry 409 (class 1259 OID 24532) +-- Name: entity_label_config; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.entity_label_config( + entity_version integer DEFAULT 1, + fk_project integer, + fk_class integer, + config jsonb +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 410 (class 1259 OID 24546) +-- Name: entity_label_config_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.entity_label_config_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_project integer, + fk_class integer, + config jsonb +); + +-- +-- TOC entry 319 (class 1259 OID 21589) +-- Name: info_proj_rel_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.info_proj_rel_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_entity integer, + fk_entity_version integer, + fk_entity_version_concat text, + is_in_project boolean, + is_standard_in_project boolean, + calendar_backup public.calendar_type, + ord_num_of_domain integer, + fk_project integer, + ord_num_of_range integer, + ord_num_of_text_property integer, + project_visibility jsonb +); + +-- +-- TOC entry 320 (class 1259 OID 21595) +-- Name: language; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.language( + pk_language character(3) NOT NULL, + lang_type character varying, + scope character varying, + iso6392b character(3), + iso6392t character(3), + iso6391 character(3), + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) +); + +-- +-- TOC entry 321 (class 1259 OID 21602) +-- Name: language_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.language_vt( + pk_language character(3) NOT NULL, + lang_type character varying, + scope character varying, + iso6392b character(3), + iso6392t character(3), + iso6391 character(3), + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange +); + +-- +-- TOC entry 322 (class 1259 OID 21607) +-- Name: project; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.project( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_language integer, + fk_cloned_from_project integer +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 323 (class 1259 OID 21616) +-- Name: project_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.project_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + notes text, + sys_period tstzrange +); + +-- +-- TOC entry 368 (class 1259 OID 23724) +-- Name: property_label_deprecated; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.property_label_deprecated( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + label text, + fk_project integer, + fk_language integer, + fk_system_type integer, + fk_property integer, + fk_domain_class integer, + fk_range_class integer +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 369 (class 1259 OID 23762) +-- Name: property_label_deprecated_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.property_label_deprecated_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + label text, + fk_project integer, + fk_language integer, + fk_system_type integer, + fk_property integer, + fk_domain_class integer, + fk_range_class integer +); + +-- +-- TOC entry 324 (class 1259 OID 21621) +-- Name: query; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.query( + name character varying, + description character varying, + query jsonb, + _deprecated_fk_project integer, + fk_project integer NOT NULL, + fk_cloned_from_query integer +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 325 (class 1259 OID 21628) +-- Name: query_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.query_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + name character varying, + description character varying, + query jsonb, + _deprecated_fk_project integer, + fk_project integer, + fk_cloned_from_query integer +); + +-- +-- TOC entry 412 (class 1259 OID 24584) +-- Name: table_config; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.table_config( + fk_project integer NOT NULL, + account_id integer, + fk_digital integer NOT NULL, + config jsonb +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 413 (class 1259 OID 24612) +-- Name: table_config_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.table_config_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_project integer NOT NULL, + account_id integer, + fk_digital integer NOT NULL, + config jsonb +); + +-- +-- TOC entry 326 (class 1259 OID 21633) +-- Name: text_property; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.text_property( + pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + quill_doc jsonb NOT NULL, + string text NOT NULL, + fk_system_type integer, + fk_pro_project integer, + fk_language integer, + fk_project integer, + fk_dfh_property integer, + fk_dfh_property_domain integer, + fk_dfh_property_range integer, + fk_dfh_class integer, + CONSTRAINT text_quill_doc_check CHECK (((quill_doc IS NULL) OR commons.validate_quill_doc(quill_doc))) +) +INHERITS ( + projects.entity, + commons.text +); + +-- +-- TOC entry 327 (class 1259 OID 21645) +-- Name: text_property_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.text_property_vt( + pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + quill_doc jsonb NOT NULL, + string text DEFAULT ''::text NOT NULL, + pk_entity integer NOT NULL, + fk_system_type integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_language integer, + fk_dfh_property integer, + fk_dfh_property_domain integer, + fk_dfh_property_range integer, + fk_dfh_class integer, + fk_project integer, + fk_pro_project integer +) +INHERITS ( + commons.text_vt +); + +-- +-- TOC entry 419 (class 1259 OID 24703) +-- Name: v_info_proj_rel; Type: VIEW; Schema: projects; Owner: - +-- +CREATE VIEW projects.v_info_proj_rel AS +SELECT + info_proj_rel.pk_entity, + info_proj_rel.schema_name, + info_proj_rel.table_name, + info_proj_rel.entity_version, + info_proj_rel.notes, + info_proj_rel.fk_creator, + info_proj_rel.fk_last_modifier, + info_proj_rel.tmsp_creation, + info_proj_rel.tmsp_last_modification, + info_proj_rel.sys_period, + info_proj_rel.fk_entity, + info_proj_rel.fk_entity_version, + info_proj_rel.fk_entity_version_concat, + info_proj_rel.is_in_project, + info_proj_rel.is_standard_in_project, + info_proj_rel.calendar_backup, + info_proj_rel.ord_num_of_domain, + info_proj_rel.fk_project, + info_proj_rel.ord_num_of_range, + info_proj_rel.ord_num_of_text_property, + info_proj_rel.project_visibility +FROM + projects.info_proj_rel; + +-- +-- TOC entry 424 (class 1259 OID 24971) +-- Name: visibility_settings; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.visibility_settings( + fk_project integer NOT NULL, + settings jsonb NOT NULL +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 425 (class 1259 OID 24991) +-- Name: visibility_settings_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.visibility_settings_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_project integer NOT NULL, + settings jsonb NOT NULL +); + +-- +-- TOC entry 328 (class 1259 OID 21657) +-- Name: visual; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.visual( + name character varying, + description character varying, + visual jsonb, + _deprecated_fk_project integer, + fk_project integer NOT NULL +) +INHERITS ( + projects.entity +); + +-- +-- TOC entry 329 (class 1259 OID 21664) +-- Name: visual_vt; Type: TABLE; Schema: projects; Owner: - +-- +CREATE TABLE projects.visual_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + name character varying, + description character varying, + visual jsonb, + _deprecated_fk_project integer, + fk_project integer +); + +-- +-- TOC entry 330 (class 1259 OID 21669) +-- Name: accesstoken; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.accesstoken( + id text NOT NULL, + ttl integer DEFAULT 1209600, + scopes text, + created timestamp with time zone, + userid integer +); + +-- +-- TOC entry 331 (class 1259 OID 21675) +-- Name: account; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.account( + realm text, + username text, + email text NOT NULL, + emailverified boolean, + verificationtoken text, + id integer NOT NULL +); + +-- +-- TOC entry 332 (class 1259 OID 21680) +-- Name: account_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.account_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6483 (class 0 OID 0) +-- Dependencies: 332 +-- Name: account_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.account_id_seq OWNED BY public.account.id; + +-- +-- TOC entry 333 (class 1259 OID 21681) +-- Name: account_project_rel; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.account_project_rel( + account_id integer NOT NULL, + _deprecated_fk_project integer, + role text NOT NULL, + id integer NOT NULL, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_project integer NOT NULL, + entity_version integer +); + +-- +-- TOC entry 334 (class 1259 OID 21687) +-- Name: account_project_rel_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.account_project_rel_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6484 (class 0 OID 0) +-- Dependencies: 334 +-- Name: account_project_rel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.account_project_rel_id_seq OWNED BY public.account_project_rel.id; + +-- +-- TOC entry 335 (class 1259 OID 21688) +-- Name: account_project_rel_vt; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.account_project_rel_vt( + account_id integer NOT NULL, + _deprecated_fk_project integer, + role text NOT NULL, + id integer NOT NULL, + sys_period tstzrange, + fk_project integer, + entity_version integer +); + +-- +-- TOC entry 336 (class 1259 OID 21693) +-- Name: acl; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.acl( + model text, + property text, + accesstype text, + permission text, + principaltype text, + principalid text, + id integer NOT NULL +); + +-- +-- TOC entry 337 (class 1259 OID 21698) +-- Name: acl_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.acl_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6485 (class 0 OID 0) +-- Dependencies: 337 +-- Name: acl_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.acl_id_seq OWNED BY public.acl.id; + +-- +-- TOC entry 405 (class 1259 OID 24477) +-- Name: credential; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.credential( + id integer NOT NULL, + accountid integer NOT NULL, + password text NOT NULL +); + +-- +-- TOC entry 404 (class 1259 OID 24476) +-- Name: credential_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.credential_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6486 (class 0 OID 0) +-- Dependencies: 404 +-- Name: credential_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.credential_id_seq OWNED BY public.credential.id; + +-- +-- TOC entry 338 (class 1259 OID 21699) +-- Name: role; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.role( + id integer NOT NULL, + name text NOT NULL, + description text, + created timestamp with time zone, + modified timestamp with time zone +); + +-- +-- TOC entry 339 (class 1259 OID 21704) +-- Name: role_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.role_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6487 (class 0 OID 0) +-- Dependencies: 339 +-- Name: role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.role_id_seq OWNED BY public.role.id; + +-- +-- TOC entry 340 (class 1259 OID 21705) +-- Name: rolemapping; Type: TABLE; Schema: public; Owner: - +-- +CREATE TABLE public.rolemapping( + id integer NOT NULL, + principaltype text, + principalid text, + roleid integer +); + +-- +-- TOC entry 341 (class 1259 OID 21710) +-- Name: rolemapping_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- +CREATE SEQUENCE public.rolemapping_id_seq + AS integer START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 6488 (class 0 OID 0) +-- Dependencies: 341 +-- Name: rolemapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- +ALTER SEQUENCE public.rolemapping_id_seq OWNED BY public.rolemapping.id; + +-- +-- TOC entry 379 (class 1259 OID 23956) +-- Name: analysis_type_deprecated; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.analysis_type_deprecated( + standard_label text, + rows_limit integer +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 380 (class 1259 OID 23969) +-- Name: analysis_type_vt_deprecated; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.analysis_type_vt_deprecated( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + standard_label text, + rows_limit integer +); + +-- +-- TOC entry 342 (class 1259 OID 21711) +-- Name: app_context; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.app_context( + pk_entity integer DEFAULT nextval('system.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + label character varying NOT NULL, + description text +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 343 (class 1259 OID 21719) +-- Name: app_context_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.app_context_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + label character varying NOT NULL, + description text +); + +-- +-- TOC entry 344 (class 1259 OID 21724) +-- Name: class_field_property_rel; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_field_property_rel( + pk_entity integer DEFAULT nextval('system.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_class_field integer, + fk_property integer, + property_is_outgoing boolean, + ord_num integer +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 6489 (class 0 OID 0) +-- Dependencies: 344 +-- Name: TABLE class_field_property_rel; Type: COMMENT; Schema: system; Owner: - +-- +COMMENT ON TABLE system.class_field_property_rel IS 'This table stores, what properties are bundled in the property set'; + +-- +-- TOC entry 6490 (class 0 OID 0) +-- Dependencies: 344 +-- Name: COLUMN class_field_property_rel.fk_class_field; Type: COMMENT; Schema: system; Owner: - +-- +COMMENT ON COLUMN system.class_field_property_rel.fk_class_field IS 'The property set'; + +-- +-- TOC entry 6491 (class 0 OID 0) +-- Dependencies: 344 +-- Name: COLUMN class_field_property_rel.fk_property; Type: COMMENT; Schema: system; Owner: - +-- +COMMENT ON COLUMN system.class_field_property_rel.fk_property IS 'The property belonging to the property set'; + +-- +-- TOC entry 6492 (class 0 OID 0) +-- Dependencies: 344 +-- Name: COLUMN class_field_property_rel.property_is_outgoing; Type: COMMENT; Schema: system; Owner: - +-- +COMMENT ON COLUMN system.class_field_property_rel.property_is_outgoing IS 'Wether the property is outgoing, seen from the class that will use it'; + +-- +-- TOC entry 6493 (class 0 OID 0) +-- Dependencies: 344 +-- Name: COLUMN class_field_property_rel.ord_num; Type: COMMENT; Schema: system; Owner: - +-- +COMMENT ON COLUMN system.class_field_property_rel.ord_num IS 'The order number of the property within the property set.'; + +-- +-- TOC entry 345 (class 1259 OID 21732) +-- Name: class_field_property_rel_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_field_property_rel_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class_field integer, + fk_property integer, + property_is_outgoing boolean, + ord_num integer +); + +-- +-- TOC entry 346 (class 1259 OID 21737) +-- Name: class_field_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_field_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + label character varying NOT NULL, + description text, + used_table text, + fk_system_type_ng_component integer +); + +-- +-- TOC entry 347 (class 1259 OID 21742) +-- Name: class_has_type_property; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_has_type_property( + pk_entity integer DEFAULT nextval('system.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + fk_class integer, + fk_property integer +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 348 (class 1259 OID 21750) +-- Name: class_has_type_property_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.class_has_type_property_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class integer, + fk_property integer +); + +-- +-- TOC entry 406 (class 1259 OID 24491) +-- Name: config; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.config( + entity_version integer DEFAULT 1, + key character varying, + config jsonb +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 407 (class 1259 OID 24505) +-- Name: config_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.config_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + key character varying, + config jsonb +); + +-- +-- TOC entry 350 (class 1259 OID 21756) +-- Name: system_relevant_class; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_relevant_class( + fk_class integer NOT NULL, + required_by_entities boolean, + required_by_sources boolean, + required_by_basics boolean, + excluded_from_entities boolean +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 351 (class 1259 OID 21763) +-- Name: system_relevant_class_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_relevant_class_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_class integer NOT NULL, + required_by_entities boolean, + required_by_sources boolean, + required_by_basics boolean, + excluded_from_entities boolean +); + +-- +-- TOC entry 352 (class 1259 OID 21768) +-- Name: system_relevant_type; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_relevant_type( + fk_type integer NOT NULL +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 353 (class 1259 OID 21775) +-- Name: system_relevant_type_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_relevant_type_vt( + pk_entity integer NOT NULL, + schema_name character varying NOT NULL, + table_name character varying NOT NULL, + entity_version integer NOT NULL, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + fk_type integer NOT NULL +); + +-- +-- TOC entry 354 (class 1259 OID 21780) +-- Name: system_type; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_type( + pk_entity integer DEFAULT nextval('system.entity_pk_entity_seq'::regclass), + schema_name character varying, + table_name character varying, + entity_version integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + st_schema_name character varying, + st_table_name character varying, + definition text, + st_column_name text, + st_group text +) +INHERITS ( + system.entity +); + +-- +-- TOC entry 355 (class 1259 OID 21788) +-- Name: system_type_vt; Type: TABLE; Schema: system; Owner: - +-- +CREATE TABLE system.system_type_vt( + pk_entity integer NOT NULL, + schema_name character varying, + table_name character varying, + st_schema_name character varying, + st_table_name character varying, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + definition text, + st_column_name text, + st_group text, + entity_version integer +); + +-- +-- TOC entry 365 (class 1259 OID 23690) +-- Name: v_auto_add_properties; Type: VIEW; Schema: system; Owner: - +-- +CREATE VIEW system.v_auto_add_properties AS +SELECT + p.dfh_has_domain AS fk_class, + p.fk_property AS dfh_pk_property, + p.dfh_range_instances_max_quantifier AS max_quantifier +FROM (data_for_history.v_property_deprecated p + JOIN projects.class_field_config ctxt ON (p.fk_property = ctxt.fk_property)) +WHERE ((ctxt.fk_app_context = 45) + AND (ctxt.ord_num IS NOT NULL) + AND (ctxt.property_is_outgoing = TRUE)) +UNION +SELECT + p.dfh_has_range AS fk_class, + p.fk_property AS dfh_pk_property, + p.dfh_domain_instances_max_quantifier AS max_quantifier +FROM (data_for_history.v_property_deprecated p + JOIN projects.class_field_config ctxt ON (p.fk_property = ctxt.fk_property)) +WHERE ((ctxt.fk_app_context = 45) + AND (ctxt.ord_num IS NOT NULL) + AND (ctxt.property_is_outgoing = FALSE)) +UNION +SELECT + ctxt.fk_class_for_class_field AS fk_class, + psprel.fk_property AS dfh_pk_property, + p.dfh_domain_instances_max_quantifier AS max_quantifier +FROM ((data_for_history.v_property_deprecated p + JOIN system.class_field_property_rel psprel ON (psprel.fk_property = p.fk_property)) + JOIN projects.class_field_config ctxt ON (psprel.fk_class_field = ctxt.fk_class_field)) +WHERE ((ctxt.fk_app_context = 45) + AND (ctxt.ord_num IS NOT NULL) + AND (psprel.property_is_outgoing = FALSE)) +UNION +SELECT + ctxt.fk_class_for_class_field AS fk_class, + psprel.fk_property AS dfh_pk_property, + p.dfh_range_instances_max_quantifier AS max_quantifier +FROM ((data_for_history.v_property_deprecated p + JOIN system.class_field_property_rel psprel ON (psprel.fk_property = p.fk_property)) + JOIN projects.class_field_config ctxt ON (psprel.fk_class_field = ctxt.fk_class_field)) +WHERE ((ctxt.fk_app_context = 45) + AND (ctxt.ord_num IS NOT NULL) + AND (psprel.property_is_outgoing = TRUE)); + +-- +-- TOC entry 373 (class 1259 OID 23813) +-- Name: cell_pk_cell_seq; Type: SEQUENCE; Schema: tables; Owner: - +-- +CREATE SEQUENCE tables.cell_pk_cell_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 371 (class 1259 OID 23798) +-- Name: cell; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables.cell( + pk_cell bigint DEFAULT nextval('tables.cell_pk_cell_seq'::regclass) NOT NULL, + fk_column integer NOT NULL, + fk_row bigint NOT NULL, + fk_digital integer NOT NULL, + numeric_value numeric, + string_value text, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer, + fk_class integer DEFAULT 521 NOT NULL +); + +-- +-- TOC entry 372 (class 1259 OID 23807) +-- Name: cell_vt; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables.cell_vt( + pk_cell bigint NOT NULL, + fk_column integer NOT NULL, + fk_row bigint NOT NULL, + fk_digital integer NOT NULL, + numeric_value numeric, + string_value text, + entity_version integer NOT NULL, + notes text, + fk_namespace integer, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + id_for_import integer, + id_for_import_txt text, + fk_publication_status integer, + fk_license integer, + fk_class integer +); + +-- +-- TOC entry 374 (class 1259 OID 23815) +-- Name: quill_doc_cell; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables.quill_doc_cell() +INHERITS ( + tables.cell, + commons.text +); + +-- +-- TOC entry 375 (class 1259 OID 23842) +-- Name: quill_doc_cell_vt; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables.quill_doc_cell_vt() +INHERITS ( + tables.cell_vt, + commons.text_vt +); + +-- +-- TOC entry 370 (class 1259 OID 23790) +-- Name: row_pk_row_seq; Type: SEQUENCE; Schema: tables; Owner: - +-- +CREATE SEQUENCE tables.row_pk_row_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +-- +-- TOC entry 414 (class 1259 OID 24621) +-- Name: row; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables."row"( + pk_row bigint DEFAULT nextval('tables.row_pk_row_seq'::regclass) NOT NULL, + fk_digital integer NOT NULL, + "position" numeric NOT NULL, + entity_version integer NOT NULL, + fk_publication_status integer, + fk_license integer, + fk_namespace integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone DEFAULT now(), + tmsp_last_modification timestamp with time zone, + sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), + metadata jsonb, + id_for_import integer, + id_for_import_txt text +); + +-- +-- TOC entry 415 (class 1259 OID 24636) +-- Name: row_vt; Type: TABLE; Schema: tables; Owner: - +-- +CREATE TABLE tables.row_vt( + pk_row bigint NOT NULL, + fk_digital integer NOT NULL, + "position" numeric NOT NULL, + entity_version integer NOT NULL, + fk_publication_status integer, + fk_license integer, + fk_namespace integer, + notes text, + fk_creator integer, + fk_last_modifier integer, + tmsp_creation timestamp with time zone, + tmsp_last_modification timestamp with time zone, + sys_period tstzrange, + metadata jsonb, + id_for_import integer, + id_for_import_txt text +); + +-- +-- TOC entry 408 (class 1259 OID 24523) +-- Name: class_preview; Type: TABLE; Schema: war; Owner: - +-- +CREATE TABLE war.class_preview( + fk_class integer NOT NULL, + fk_project integer NOT NULL, + label text, + tmsp_last_modification timestamp with time zone +); + +-- +-- TOC entry 423 (class 1259 OID 24953) +-- Name: entity_preview_template; Type: TABLE; Schema: war; Owner: - +-- +CREATE TABLE war.entity_preview_template( + pk_entity integer NOT NULL, + fk_project integer, + project integer DEFAULT 0 NOT NULL, + entity_type text, + fk_class integer, + class_label character varying, + entity_label text, + full_text text, + ts_vector tsvector, + type_label text, + fk_type integer, + time_span jsonb, + first_second bigint, + last_second bigint, + tmsp_last_modification timestamp with time zone, + key character varying NOT NULL, + entity_id character varying NOT NULL, + parent_classes jsonb NOT NULL, + ancestor_classes jsonb NOT NULL, + project_id integer NOT NULL, + type_id character varying +) +PARTITION BY LIST (project_id); + +-- +-- TOC entry 421 (class 1259 OID 24922) +-- Name: field_change_template; Type: TABLE; Schema: war; Owner: - +-- +CREATE TABLE war.field_change_template( + fk_project integer NOT NULL, + fk_source_info integer NOT NULL, + fk_source_tables_cell bigint NOT NULL, + fk_property integer NOT NULL, + fk_property_of_property integer NOT NULL, + is_outgoing boolean NOT NULL, + tmsp_last_modification timestamp with time zone NOT NULL +); + +-- +-- TOC entry 411 (class 1259 OID 24563) +-- Name: statement_backup; Type: TABLE; Schema: war; Owner: - +-- +CREATE TABLE war.statement_backup( + pk_entity integer NOT NULL, + fk_project integer, + project integer DEFAULT 0 NOT NULL, + fk_property integer, + fk_object_info integer, + fk_subject_info integer, + ord_num_of_domain integer, + ord_num_of_range integer, + is_in_project_count integer, + object_info_value jsonb +); + +-- +-- TOC entry 422 (class 1259 OID 24929) +-- Name: statement_template; Type: TABLE; Schema: war; Owner: - +-- +CREATE TABLE war.statement_template( + pk_entity integer NOT NULL, + project integer DEFAULT 0 NOT NULL, + fk_project integer, + fk_property integer, + fk_object_info integer, + fk_subject_info integer, + ord_num_of_domain integer, + ord_num_of_range integer, + is_in_project_count integer, + object_info_value jsonb +); + +-- +-- TOC entry 395 (class 1259 OID 24191) +-- Name: v_class_preview; Type: VIEW; Schema: war; Owner: - +-- +CREATE VIEW war.v_class_preview AS +WITH tw0 AS ( + SELECT + project.pk_entity, + project.fk_language + FROM + projects.project + UNION ALL + SELECT + NULL::integer AS int4, + 18889 +), +tw1 AS ( + SELECT + t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 1 AS rank, + 'project label'::text AS text + FROM + tw0 t1, + projects.text_property t2 + WHERE ((t1.pk_entity = t2.fk_project) + AND (t2.fk_dfh_class IS NOT NULL) + AND (t2.fk_language = t1.fk_language)) +UNION ALL +SELECT + t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 2 AS rank, + 'default project label in default lang'::text AS text +FROM + tw0 t1, + projects.text_property t2 + WHERE ((375669 = t2.fk_project) + AND (t2.fk_dfh_class IS NOT NULL) + AND (t2.fk_language = t1.fk_language)) +UNION ALL +SELECT + t3.fk_class, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in default lang'::text AS text +FROM + tw0 t1, + information.language t2, + data_for_history.v_label t3 + WHERE ((t3.fk_class IS NOT NULL) + AND (t1.fk_language = t2.pk_entity) + AND ((t3.language)::bpchar = t2.iso6391) + AND (t3.type = 'label'::text)) +UNION ALL +SELECT + t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 4 AS rank, + 'default project label in en'::text AS text +FROM + tw0 t1, + projects.text_property t2 + WHERE ((375669 = t2.fk_project) + AND (t2.fk_dfh_class IS NOT NULL) + AND (t2.fk_language = 18889)) +UNION ALL +SELECT + t3.fk_class, + t1.pk_entity AS fk_project, + t3.label, + 5 AS rank, + 'ontome label in en'::text AS text +FROM + tw0 t1, + data_for_history.v_label t3 + WHERE ((t3.fk_class IS NOT NULL) + AND ((t3.language)::text = 'en'::text) + AND (t3.type = 'label'::text))) +SELECT DISTINCT ON (tw1.fk_project, tw1.fk_class) + tw1.fk_class, + tw1.fk_project, + tw1.label +FROM + tw1 +ORDER BY + tw1.fk_project, + tw1.fk_class, + tw1.rank; + +-- +-- TOC entry 396 (class 1259 OID 24274) +-- Name: v_property_preview; Type: VIEW; Schema: war; Owner: - +-- +CREATE VIEW war.v_property_preview AS +WITH tw0 AS ( + SELECT + project.pk_entity, + project.fk_language + FROM + projects.project + UNION ALL + SELECT + NULL::integer AS int4, + 18889 +), +tw1 AS ( + SELECT + t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 1 AS rank, + 'project label'::text AS text + FROM + tw0 t1, + projects.text_property t2 + WHERE ((t1.pk_entity = t2.fk_project) + AND (t2.fk_dfh_property IS NOT NULL) + AND (t2.fk_language = t1.fk_language)) +UNION ALL +SELECT + t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 2 AS rank, + 'default project label in default lang'::text AS text +FROM + tw0 t1, + projects.text_property t2 + WHERE ((375669 = t2.fk_project) + AND (t2.fk_dfh_property IS NOT NULL) + AND (t2.fk_language = t1.fk_language)) +UNION ALL +SELECT + t3.fk_property, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in default lang'::text AS text +FROM + tw0 t1, + information.language t2, + data_for_history.v_label t3 + WHERE ((t3.fk_property IS NOT NULL) + AND ((t3.language)::bpchar = t2.iso6391) + AND (t3.type = 'label'::text)) +UNION ALL +SELECT + t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 4 AS rank, + 'default project label in en'::text AS text +FROM + tw0 t1, + projects.text_property t2 + WHERE ((375669 = t2.fk_project) + AND (t2.fk_dfh_property IS NOT NULL) + AND (t2.fk_language = 18889)) +UNION ALL +SELECT + t3.fk_property, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in en'::text AS text +FROM + tw0 t1, + data_for_history.v_label t3 + WHERE ((t3.fk_property IS NOT NULL) + AND ((t3.language)::text = 'en'::text) + AND (t3.type = 'label'::text))) +SELECT DISTINCT ON (tw1.fk_project, tw1.fk_property) + tw1.fk_property, + tw1.fk_project, + tw1.label +FROM + tw1 +ORDER BY + tw1.fk_project, + tw1.fk_property, + tw1.rank; + +-- +-- TOC entry 403 (class 1259 OID 24465) +-- Name: vm_statement; Type: MATERIALIZED VIEW; Schema: war; Owner: - +-- +CREATE MATERIALIZED VIEW war.vm_statement AS +WITH tw1 AS ( + SELECT + t1.pk_entity, + t1.fk_property, + t1.fk_object_info, + t1.fk_subject_info, + t2.is_in_project_count, + t1.notes, + t1.tmsp_creation, + t1.tmsp_last_modification, + t1.sys_period + FROM (information.statement t1 + LEFT JOIN LATERAL ( + SELECT + (count(info_proj_rel.pk_entity))::integer AS is_in_project_count + FROM + projects.info_proj_rel + WHERE ((info_proj_rel.fk_entity = t1.pk_entity) + AND (info_proj_rel.is_in_project = TRUE)) + GROUP BY + info_proj_rel.fk_entity) t2 ON (TRUE))) +SELECT + t1.pk_entity, + t1.fk_object_info, + t1.fk_subject_info, + t1.fk_property, + t2.fk_project, + COALESCE(t2.fk_project, 0) AS project, + t2.ord_num_of_domain, + t2.ord_num_of_range, + t1.is_in_project_count +FROM + tw1 t1, + projects.info_proj_rel t2 +WHERE ((t2.fk_entity = t1.pk_entity) + AND (t2.is_in_project = TRUE)) +UNION +SELECT + t1.pk_entity, + t1.fk_object_info, + t1.fk_subject_info, + t1.fk_property, + NULL::integer AS fk_project, + 0 AS project, + NULL::integer AS ord_num_of_domain, + NULL::integer AS ord_num_of_range, + t1.is_in_project_count +FROM + tw1 t1 +WHERE (t1.is_in_project_count > 0 +) +WITH NO DATA; + +-- +-- TOC entry 5023 (class 2604 OID 21863) +-- Name: text pk_text; Type: DEFAULT; Schema: commons; Owner: - +-- +ALTER TABLE ONLY commons.text + ALTER COLUMN pk_text SET DEFAULT nextval('commons.text_pk_text_seq'::regclass); + +-- +-- TOC entry 5027 (class 2604 OID 23441) +-- Name: avatar pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5028 (class 2604 OID 21865) +-- Name: avatar tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5029 (class 2604 OID 21866) +-- Name: avatar sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5030 (class 2604 OID 23443) +-- Name: chunk pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5031 (class 2604 OID 21871) +-- Name: chunk tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5032 (class 2604 OID 21872) +-- Name: chunk sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5036 (class 2604 OID 23444) +-- Name: class_column_mapping pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5037 (class 2604 OID 21874) +-- Name: class_column_mapping tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5038 (class 2604 OID 21875) +-- Name: class_column_mapping sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5039 (class 2604 OID 23445) +-- Name: column pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5040 (class 2604 OID 21877) +-- Name: column tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5041 (class 2604 OID 21878) +-- Name: column sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5044 (class 2604 OID 23446) +-- Name: data_association pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5045 (class 2604 OID 21880) +-- Name: data_association tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5046 (class 2604 OID 21881) +-- Name: data_association sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5076 (class 2604 OID 23466) +-- Name: data_association_mapping pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5077 (class 2604 OID 21906) +-- Name: data_association_mapping tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5078 (class 2604 OID 21907) +-- Name: data_association_mapping sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5024 (class 2604 OID 23440) +-- Name: entity pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.entity + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5054 (class 2604 OID 23459) +-- Name: factoid pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5055 (class 2604 OID 21885) +-- Name: factoid tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5056 (class 2604 OID 21886) +-- Name: factoid sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5057 (class 2604 OID 23460) +-- Name: factoid_mapping pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5058 (class 2604 OID 21888) +-- Name: factoid_mapping tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5059 (class 2604 OID 21889) +-- Name: factoid_mapping sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5060 (class 2604 OID 23461) +-- Name: factoid_property_mapping pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5061 (class 2604 OID 21891) +-- Name: factoid_property_mapping tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5062 (class 2604 OID 21892) +-- Name: factoid_property_mapping sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5064 (class 2604 OID 23462) +-- Name: factoid_role pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5065 (class 2604 OID 21894) +-- Name: factoid_role tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5066 (class 2604 OID 21895) +-- Name: factoid_role sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5067 (class 2604 OID 23463) +-- Name: namespace pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5068 (class 2604 OID 21897) +-- Name: namespace tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5069 (class 2604 OID 21898) +-- Name: namespace sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5233 (class 2604 OID 23534) +-- Name: property_of_property pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5234 (class 2604 OID 23103) +-- Name: property_of_property tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5235 (class 2604 OID 23104) +-- Name: property_of_property sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5230 (class 2604 OID 23533) +-- Name: property_of_property_mapping pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5231 (class 2604 OID 23041) +-- Name: property_of_property_mapping tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5232 (class 2604 OID 23042) +-- Name: property_of_property_mapping sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5070 (class 2604 OID 23465) +-- Name: text_property pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5071 (class 2604 OID 21903) +-- Name: text_property tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5072 (class 2604 OID 21904) +-- Name: text_property sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5079 (class 2604 OID 23467) +-- Name: values_association pk_entity; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5080 (class 2604 OID 21909) +-- Name: values_association tmsp_creation; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5081 (class 2604 OID 21910) +-- Name: values_association sys_period; Type: DEFAULT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5260 (class 2604 OID 24083) +-- Name: api_class pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5261 (class 2604 OID 24084) +-- Name: api_class tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5262 (class 2604 OID 24085) +-- Name: api_class sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5263 (class 2604 OID 24086) +-- Name: api_class removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5097 (class 2604 OID 23483) +-- Name: api_profile pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5098 (class 2604 OID 21927) +-- Name: api_profile tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5099 (class 2604 OID 21928) +-- Name: api_profile sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5100 (class 2604 OID 21929) +-- Name: api_profile removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5268 (class 2604 OID 24107) +-- Name: api_property pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5269 (class 2604 OID 24108) +-- Name: api_property tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5270 (class 2604 OID 24109) +-- Name: api_property sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5271 (class 2604 OID 24110) +-- Name: api_property removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5086 (class 2604 OID 23472) +-- Name: associates_system_type_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.associates_system_type_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5087 (class 2604 OID 21912) +-- Name: associates_system_type_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.associates_system_type_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5088 (class 2604 OID 21913) +-- Name: associates_system_type_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.associates_system_type_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5090 (class 2604 OID 23474) +-- Name: class_profile_view_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.class_profile_view_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5091 (class 2604 OID 21919) +-- Name: class_profile_view_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.class_profile_view_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5092 (class 2604 OID 21920) +-- Name: class_profile_view_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.class_profile_view_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5082 (class 2604 OID 23471) +-- Name: entity pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.entity + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5093 (class 2604 OID 23482) +-- Name: label_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5094 (class 2604 OID 21923) +-- Name: label_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5095 (class 2604 OID 21924) +-- Name: label_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5096 (class 2604 OID 21925) +-- Name: label_deprecated removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5103 (class 2604 OID 23484) +-- Name: property pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5104 (class 2604 OID 21931) +-- Name: property tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5105 (class 2604 OID 21932) +-- Name: property sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5106 (class 2604 OID 21933) +-- Name: property removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5282 (class 2604 OID 24430) +-- Name: property_of_property pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5283 (class 2604 OID 24431) +-- Name: property_of_property tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5284 (class 2604 OID 24432) +-- Name: property_of_property sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5285 (class 2604 OID 24433) +-- Name: property_of_property removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5108 (class 2604 OID 23485) +-- Name: property_profile_view_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_profile_view_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5109 (class 2604 OID 21935) +-- Name: property_profile_view_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_profile_view_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5110 (class 2604 OID 21936) +-- Name: property_profile_view_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_profile_view_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5111 (class 2604 OID 23486) +-- Name: system_type_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5112 (class 2604 OID 21938) +-- Name: system_type_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5113 (class 2604 OID 21939) +-- Name: system_type_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5114 (class 2604 OID 21940) +-- Name: system_type_deprecated removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5115 (class 2604 OID 23487) +-- Name: text_property_deprecated pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5116 (class 2604 OID 21942) +-- Name: text_property_deprecated tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5117 (class 2604 OID 21943) +-- Name: text_property_deprecated sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5118 (class 2604 OID 21944) +-- Name: text_property_deprecated removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ALTER COLUMN removed_from_api SET DEFAULT FALSE; + +-- +-- TOC entry 5125 (class 2604 OID 23501) +-- Name: _backup_entity_association pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information._backup_entity_association + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5126 (class 2604 OID 21955) +-- Name: _backup_entity_association tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information._backup_entity_association + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5127 (class 2604 OID 21956) +-- Name: _backup_entity_association sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information._backup_entity_association + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5120 (class 2604 OID 23491) +-- Name: appellation pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.appellation + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5121 (class 2604 OID 21950) +-- Name: appellation tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.appellation + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5122 (class 2604 OID 21951) +-- Name: appellation sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.appellation + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5236 (class 2604 OID 23535) +-- Name: dimension pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5237 (class 2604 OID 23149) +-- Name: dimension tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5238 (class 2604 OID 23150) +-- Name: dimension sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5017 (class 2604 OID 23489) +-- Name: entity pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.entity + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5277 (class 2604 OID 24391) +-- Name: lang_string pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5278 (class 2604 OID 24392) +-- Name: lang_string tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5279 (class 2604 OID 24393) +-- Name: lang_string sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5280 (class 2604 OID 24394) +-- Name: lang_string pk_text; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ALTER COLUMN pk_text SET DEFAULT nextval('commons.text_pk_text_seq'::regclass); + +-- +-- TOC entry 5128 (class 2604 OID 23502) +-- Name: language pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.language + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5129 (class 2604 OID 21959) +-- Name: language tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.language + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5130 (class 2604 OID 21960) +-- Name: language sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.language + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5134 (class 2604 OID 23504) +-- Name: place pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.place + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5135 (class 2604 OID 21966) +-- Name: place tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.place + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5136 (class 2604 OID 21967) +-- Name: place sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.place + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5137 (class 2604 OID 23506) +-- Name: statement pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.statement + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5138 (class 2604 OID 21972) +-- Name: statement tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.statement + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5139 (class 2604 OID 21973) +-- Name: statement sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.statement + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5158 (class 2604 OID 23508) +-- Name: text_property pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5159 (class 2604 OID 21980) +-- Name: text_property tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5160 (class 2604 OID 21981) +-- Name: text_property sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5163 (class 2604 OID 23509) +-- Name: time_primitive pk_entity; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5164 (class 2604 OID 21983) +-- Name: time_primitive tmsp_creation; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5165 (class 2604 OID 21984) +-- Name: time_primitive sys_period; Type: DEFAULT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5254 (class 2604 OID 23980) +-- Name: analysis pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5255 (class 2604 OID 23981) +-- Name: analysis tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5256 (class 2604 OID 23982) +-- Name: analysis sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5172 (class 2604 OID 23513) +-- Name: class_field_config pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5173 (class 2604 OID 21988) +-- Name: class_field_config tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5174 (class 2604 OID 21989) +-- Name: class_field_config sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5257 (class 2604 OID 24055) +-- Name: dfh_profile_proj_rel pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5258 (class 2604 OID 24056) +-- Name: dfh_profile_proj_rel tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5259 (class 2604 OID 24057) +-- Name: dfh_profile_proj_rel sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5166 (class 2604 OID 23511) +-- Name: entity pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5291 (class 2604 OID 24535) +-- Name: entity_label_config pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity_label_config + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5293 (class 2604 OID 24536) +-- Name: entity_label_config tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity_label_config + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5294 (class 2604 OID 24537) +-- Name: entity_label_config sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity_label_config + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5240 (class 2604 OID 23727) +-- Name: property_label_deprecated tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5241 (class 2604 OID 23728) +-- Name: property_label_deprecated sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5193 (class 2604 OID 23520) +-- Name: query pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5194 (class 2604 OID 21994) +-- Name: query tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5195 (class 2604 OID 21995) +-- Name: query sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5296 (class 2604 OID 24587) +-- Name: table_config pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5297 (class 2604 OID 24588) +-- Name: table_config tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5298 (class 2604 OID 24589) +-- Name: table_config sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5305 (class 2604 OID 24974) +-- Name: visibility_settings pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5306 (class 2604 OID 24975) +-- Name: visibility_settings tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5307 (class 2604 OID 24976) +-- Name: visibility_settings sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5202 (class 2604 OID 23521) +-- Name: visual pk_entity; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5203 (class 2604 OID 21998) +-- Name: visual tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5204 (class 2604 OID 21999) +-- Name: visual sys_period; Type: DEFAULT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5206 (class 2604 OID 22000) +-- Name: account id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account + ALTER COLUMN id SET DEFAULT nextval('public.account_id_seq'::regclass); + +-- +-- TOC entry 5207 (class 2604 OID 22001) +-- Name: account_project_rel id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account_project_rel + ALTER COLUMN id SET DEFAULT nextval('public.account_project_rel_id_seq'::regclass); + +-- +-- TOC entry 5209 (class 2604 OID 22002) +-- Name: acl id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.acl + ALTER COLUMN id SET DEFAULT nextval('public.acl_id_seq'::regclass); + +-- +-- TOC entry 5286 (class 2604 OID 24480) +-- Name: credential id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.credential + ALTER COLUMN id SET DEFAULT nextval('public.credential_id_seq'::regclass); + +-- +-- TOC entry 5210 (class 2604 OID 22003) +-- Name: role id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.role + ALTER COLUMN id SET DEFAULT nextval('public.role_id_seq'::regclass); + +-- +-- TOC entry 5211 (class 2604 OID 22004) +-- Name: rolemapping id; Type: DEFAULT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.rolemapping + ALTER COLUMN id SET DEFAULT nextval('public.rolemapping_id_seq'::regclass); + +-- +-- TOC entry 5251 (class 2604 OID 23959) +-- Name: analysis_type_deprecated pk_entity; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.analysis_type_deprecated + ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5252 (class 2604 OID 23960) +-- Name: analysis_type_deprecated tmsp_creation; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.analysis_type_deprecated + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5253 (class 2604 OID 23961) +-- Name: analysis_type_deprecated sys_period; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.analysis_type_deprecated + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5287 (class 2604 OID 24494) +-- Name: config pk_entity; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.config + ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5289 (class 2604 OID 24495) +-- Name: config tmsp_creation; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.config + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5290 (class 2604 OID 24496) +-- Name: config sys_period; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.config + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5175 (class 2604 OID 23522) +-- Name: entity pk_entity; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.entity + ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5221 (class 2604 OID 23530) +-- Name: system_relevant_class pk_entity; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_class + ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5222 (class 2604 OID 22007) +-- Name: system_relevant_class tmsp_creation; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_class + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5223 (class 2604 OID 22008) +-- Name: system_relevant_class sys_period; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_class + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5224 (class 2604 OID 23531) +-- Name: system_relevant_type pk_entity; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); + +-- +-- TOC entry 5225 (class 2604 OID 22010) +-- Name: system_relevant_type tmsp_creation; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5226 (class 2604 OID 22011) +-- Name: system_relevant_type sys_period; Type: DEFAULT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5246 (class 2604 OID 23818) +-- Name: quill_doc_cell pk_cell; Type: DEFAULT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ALTER COLUMN pk_cell SET DEFAULT nextval('tables.cell_pk_cell_seq'::regclass); + +-- +-- TOC entry 5247 (class 2604 OID 23819) +-- Name: quill_doc_cell tmsp_creation; Type: DEFAULT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ALTER COLUMN tmsp_creation SET DEFAULT now(); + +-- +-- TOC entry 5248 (class 2604 OID 23820) +-- Name: quill_doc_cell sys_period; Type: DEFAULT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); + +-- +-- TOC entry 5249 (class 2604 OID 23821) +-- Name: quill_doc_cell pk_text; Type: DEFAULT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ALTER COLUMN pk_text SET DEFAULT nextval('commons.text_pk_text_seq'::regclass); + +-- +-- TOC entry 5250 (class 2604 OID 24709) +-- Name: quill_doc_cell fk_class; Type: DEFAULT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ALTER COLUMN fk_class SET DEFAULT 521; + +-- +-- TOC entry 5334 (class 2606 OID 22013) +-- Name: text text_pkey; Type: CONSTRAINT; Schema: commons; Owner: - +-- +ALTER TABLE ONLY commons.text + ADD CONSTRAINT text_pkey PRIMARY KEY (pk_text); + +-- +-- TOC entry 5337 (class 2606 OID 22015) +-- Name: text text_version_unique; Type: CONSTRAINT; Schema: commons; Owner: - +-- +ALTER TABLE ONLY commons.text + ADD CONSTRAINT text_version_unique UNIQUE (pk_text, entity_version); + +-- +-- TOC entry 5343 (class 2606 OID 24789) +-- Name: avatar avatar_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar + ADD CONSTRAINT avatar_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5348 (class 2606 OID 24791) +-- Name: chunk chunk_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk + ADD CONSTRAINT chunk_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5355 (class 2606 OID 24793) +-- Name: class_column_mapping class_column_mapping_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ADD CONSTRAINT class_column_mapping_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5360 (class 2606 OID 24795) +-- Name: column column_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT column_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5413 (class 2606 OID 24799) +-- Name: data_association_mapping data_association_mapping_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT data_association_mapping_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5369 (class 2606 OID 24797) +-- Name: data_association data_association_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ADD CONSTRAINT data_association_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5345 (class 2606 OID 22017) +-- Name: avatar data_avatar_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar + ADD CONSTRAINT data_avatar_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5351 (class 2606 OID 22021) +-- Name: chunk data_chunk_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk + ADD CONSTRAINT data_chunk_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5357 (class 2606 OID 22023) +-- Name: class_column_mapping data_class_column_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ADD CONSTRAINT data_class_column_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5362 (class 2606 OID 22025) +-- Name: column data_column_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT data_column_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5371 (class 2606 OID 22027) +-- Name: data_association data_data_association_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ADD CONSTRAINT data_data_association_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5385 (class 2606 OID 22029) +-- Name: factoid_mapping data_factoid_class_digital_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ADD CONSTRAINT data_factoid_class_digital_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5380 (class 2606 OID 22031) +-- Name: factoid data_factoid_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid + ADD CONSTRAINT data_factoid_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5390 (class 2606 OID 22033) +-- Name: factoid_property_mapping data_factoid_property_column_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ADD CONSTRAINT data_factoid_property_column_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5395 (class 2606 OID 22035) +-- Name: factoid_role data_factoid_role_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ADD CONSTRAINT data_factoid_role_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5400 (class 2606 OID 22037) +-- Name: namespace data_namespace_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ADD CONSTRAINT data_namespace_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5638 (class 2606 OID 23066) +-- Name: property_of_property_mapping data_property_of_property_mapping_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ADD CONSTRAINT data_property_of_property_mapping_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5643 (class 2606 OID 23123) +-- Name: property_of_property data_property_of_property_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ADD CONSTRAINT data_property_of_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5405 (class 2606 OID 22041) +-- Name: text_property data_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ADD CONSTRAINT data_text_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5415 (class 2606 OID 22043) +-- Name: data_association_mapping data_value_association_columns_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT data_value_association_columns_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5417 (class 2606 OID 22045) +-- Name: values_association data_values_association_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ADD CONSTRAINT data_values_association_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5374 (class 2606 OID 24801) +-- Name: digital digital_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.digital + ADD CONSTRAINT digital_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5340 (class 2606 OID 22049) +-- Name: entity entity_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.entity + ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5388 (class 2606 OID 24805) +-- Name: factoid_mapping factoid_mapping_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ADD CONSTRAINT factoid_mapping_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5383 (class 2606 OID 24803) +-- Name: factoid factoid_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid + ADD CONSTRAINT factoid_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5392 (class 2606 OID 24807) +-- Name: factoid_property_mapping factoid_property_mapping_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ADD CONSTRAINT factoid_property_mapping_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5398 (class 2606 OID 24809) +-- Name: factoid_role factoid_role_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ADD CONSTRAINT factoid_role_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5377 (class 2606 OID 22051) +-- Name: digital information_digital_object_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.digital + ADD CONSTRAINT information_digital_object_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5403 (class 2606 OID 24811) +-- Name: namespace namespace_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ADD CONSTRAINT namespace_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5641 (class 2606 OID 24815) +-- Name: property_of_property_mapping property_of_property_mapping_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ADD CONSTRAINT property_of_property_mapping_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5646 (class 2606 OID 24813) +-- Name: property_of_property property_of_property_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ADD CONSTRAINT property_of_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5408 (class 2606 OID 24817) +-- Name: text_property text_property_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ADD CONSTRAINT text_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5419 (class 2606 OID 24819) +-- Name: values_association values_association_pkey; Type: CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ADD CONSTRAINT values_association_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5687 (class 2606 OID 24821) +-- Name: api_class api_class_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ADD CONSTRAINT api_class_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5438 (class 2606 OID 24823) +-- Name: api_profile api_profile_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ADD CONSTRAINT api_profile_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5693 (class 2606 OID 24825) +-- Name: api_property api_property_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ADD CONSTRAINT api_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5423 (class 2606 OID 24827) +-- Name: associates_system_type_deprecated associates_system_type_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.associates_system_type_deprecated + ADD CONSTRAINT associates_system_type_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5428 (class 2606 OID 24829) +-- Name: class_profile_view_deprecated class_profile_view_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.class_profile_view_deprecated + ADD CONSTRAINT class_profile_view_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5689 (class 2606 OID 24090) +-- Name: api_class data_for_history_api_class_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ADD CONSTRAINT data_for_history_api_class_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5695 (class 2606 OID 24114) +-- Name: api_property data_for_history_api_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ADD CONSTRAINT data_for_history_api_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5426 (class 2606 OID 22053) +-- Name: associates_system_type_deprecated data_for_history_associates_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.associates_system_type_deprecated + ADD CONSTRAINT data_for_history_associates_system_type_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5431 (class 2606 OID 22057) +-- Name: class_profile_view_deprecated data_for_history_class_profile_view_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.class_profile_view_deprecated + ADD CONSTRAINT data_for_history_class_profile_view_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5433 (class 2606 OID 22059) +-- Name: label_deprecated data_for_history_label_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ADD CONSTRAINT data_for_history_label_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5440 (class 2606 OID 22061) +-- Name: api_profile data_for_history_profile_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ADD CONSTRAINT data_for_history_profile_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5713 (class 2606 OID 24441) +-- Name: property_of_property data_for_history_property_of_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ADD CONSTRAINT data_for_history_property_of_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5445 (class 2606 OID 22063) +-- Name: property data_for_history_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ADD CONSTRAINT data_for_history_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5450 (class 2606 OID 22065) +-- Name: property_profile_view_deprecated data_for_history_property_profile_view_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_profile_view_deprecated + ADD CONSTRAINT data_for_history_property_profile_view_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5455 (class 2606 OID 22067) +-- Name: system_type_deprecated data_for_history_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ADD CONSTRAINT data_for_history_system_type_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5460 (class 2606 OID 22069) +-- Name: text_property_deprecated data_for_history_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ADD CONSTRAINT data_for_history_text_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5421 (class 2606 OID 22071) +-- Name: entity entity_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.entity + ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5435 (class 2606 OID 24831) +-- Name: label_deprecated label_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ADD CONSTRAINT label_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5715 (class 2606 OID 24439) +-- Name: property_of_property property_of_property_has_domain_pk_property_of_property_has_key; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ADD CONSTRAINT property_of_property_has_domain_pk_property_of_property_has_key UNIQUE (has_domain, pk_property_of_property, has_range); + +-- +-- TOC entry 5717 (class 2606 OID 24437) +-- Name: property_of_property property_of_property_pk_entity_key; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ADD CONSTRAINT property_of_property_pk_entity_key UNIQUE (pk_entity); + +-- +-- TOC entry 5719 (class 2606 OID 24833) +-- Name: property_of_property property_of_property_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_of_property + ADD CONSTRAINT property_of_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5452 (class 2606 OID 24835) +-- Name: property_profile_view_deprecated property_profile_view_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property_profile_view_deprecated + ADD CONSTRAINT property_profile_view_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5457 (class 2606 OID 24837) +-- Name: system_type_deprecated system_type_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.system_type_deprecated + ADD CONSTRAINT system_type_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5462 (class 2606 OID 24839) +-- Name: text_property_deprecated text_property_deprecated_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.text_property_deprecated + ADD CONSTRAINT text_property_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5443 (class 2606 OID 24051) +-- Name: api_profile unique_dfh_pk_profile_requested_language; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_profile + ADD CONSTRAINT unique_dfh_pk_profile_requested_language UNIQUE (dfh_pk_profile, requested_language); + +-- +-- TOC entry 5448 (class 2606 OID 22077) +-- Name: property unique_dfh_pk_property; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.property + ADD CONSTRAINT unique_dfh_pk_property UNIQUE (dfh_pk_property); + +-- +-- TOC entry 5691 (class 2606 OID 24103) +-- Name: api_class unique_requested_language_dfh_pk_class_dfh_fk_profile; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_class + ADD CONSTRAINT unique_requested_language_dfh_pk_class_dfh_fk_profile UNIQUE (requested_language, dfh_pk_class, dfh_fk_profile); + +-- +-- TOC entry 5697 (class 2606 OID 24127) +-- Name: api_property unique_requested_language_dfh_pk_property_dfh_fk_profile; Type: CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.api_property + ADD CONSTRAINT unique_requested_language_dfh_pk_property_dfh_fk_profile UNIQUE (requested_language, dfh_pk_property, dfh_property_domain, dfh_property_range, dfh_fk_profile); + +-- +-- TOC entry 5470 (class 2606 OID 24841) +-- Name: _backup_entity_association _backup_entity_association_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information._backup_entity_association + ADD CONSTRAINT _backup_entity_association_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5466 (class 2606 OID 24843) +-- Name: appellation appellation_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.appellation + ADD CONSTRAINT appellation_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5649 (class 2606 OID 24845) +-- Name: dimension dimension_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ADD CONSTRAINT dimension_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5329 (class 2606 OID 22083) +-- Name: entity entity_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.entity + ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5468 (class 2606 OID 22085) +-- Name: appellation information_appellation_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.appellation + ADD CONSTRAINT information_appellation_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5651 (class 2606 OID 23164) +-- Name: dimension information_dimension_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ADD CONSTRAINT information_dimension_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5477 (class 2606 OID 22087) +-- Name: _backup_entity_association information_entity_association_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information._backup_entity_association + ADD CONSTRAINT information_entity_association_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5705 (class 2606 OID 24411) +-- Name: lang_string information_lang_string_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ADD CONSTRAINT information_lang_string_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5479 (class 2606 OID 22089) +-- Name: language information_language_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.language + ADD CONSTRAINT information_language_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5484 (class 2606 OID 22093) +-- Name: persistent_item_backup information_persistent_item_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.persistent_item_backup + ADD CONSTRAINT information_persistent_item_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5487 (class 2606 OID 22095) +-- Name: place information_place_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.place + ADD CONSTRAINT information_place_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5757 (class 2606 OID 24654) +-- Name: resource information_resource_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.resource + ADD CONSTRAINT information_resource_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5492 (class 2606 OID 22099) +-- Name: statement information_statement_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.statement + ADD CONSTRAINT information_statement_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5331 (class 2606 OID 22101) +-- Name: temporal_entity_backup information_temporal_entity_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.temporal_entity_backup + ADD CONSTRAINT information_temporal_entity_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5502 (class 2606 OID 22103) +-- Name: text_property information_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ADD CONSTRAINT information_text_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5512 (class 2606 OID 22105) +-- Name: time_primitive information_time_primitive_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ADD CONSTRAINT information_time_primitive_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5709 (class 2606 OID 24847) +-- Name: lang_string lang_string_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ADD CONSTRAINT lang_string_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5482 (class 2606 OID 22109) +-- Name: language language_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.language + ADD CONSTRAINT language_pkey PRIMARY KEY (pk_language); + +-- +-- TOC entry 5490 (class 2606 OID 24849) +-- Name: place place_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.place + ADD CONSTRAINT place_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5761 (class 2606 OID 24851) +-- Name: resource resource_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.resource + ADD CONSTRAINT resource_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5500 (class 2606 OID 24853) +-- Name: statement statement_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.statement + ADD CONSTRAINT statement_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5505 (class 2606 OID 22117) +-- Name: text_property text_property_identity_unique; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ADD CONSTRAINT text_property_identity_unique UNIQUE (fk_class_field, fk_language, fk_concerned_entity, _deprecated_text_property_quill_doc); + +-- +-- TOC entry 5508 (class 2606 OID 24855) +-- Name: text_property text_property_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ADD CONSTRAINT text_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5515 (class 2606 OID 24857) +-- Name: time_primitive time_primitive_pkey; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ADD CONSTRAINT time_primitive_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5517 (class 2606 OID 24694) +-- Name: time_primitive time_primitive_unique_constraint; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.time_primitive + ADD CONSTRAINT time_primitive_unique_constraint UNIQUE (julian_day, duration, calendar, fk_class); + +-- +-- TOC entry 5711 (class 2606 OID 24409) +-- Name: lang_string unique__fk_language__fk_class__string; Type: CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ADD CONSTRAINT unique__fk_language__fk_class__string UNIQUE (fk_language, fk_class, string); + +-- +-- TOC entry 5679 (class 2606 OID 24859) +-- Name: _backup_class_field_config _backup_class_field_config_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects._backup_class_field_config + ADD CONSTRAINT _backup_class_field_config_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5675 (class 2606 OID 24861) +-- Name: analysis analysis_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ADD CONSTRAINT analysis_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5548 (class 2606 OID 24863) +-- Name: argument argument_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.argument + ADD CONSTRAINT argument_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5536 (class 2606 OID 24865) +-- Name: class_field_config class_field_config_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ADD CONSTRAINT class_field_config_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5550 (class 2606 OID 22123) +-- Name: argument commons_assertion_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.argument + ADD CONSTRAINT commons_assertion_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5559 (class 2606 OID 22127) +-- Name: project commons_project_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT commons_project_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5564 (class 2606 OID 22129) +-- Name: query commons_query_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ADD CONSTRAINT commons_query_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5571 (class 2606 OID 22131) +-- Name: text_property commons_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT commons_text_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5538 (class 2606 OID 22133) +-- Name: class_field_config commons_ui_context_config_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ADD CONSTRAINT commons_ui_context_config_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5582 (class 2606 OID 22135) +-- Name: visual commons_visual_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ADD CONSTRAINT commons_visual_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5552 (class 2606 OID 22137) +-- Name: dfh_class_proj_rel data_for_history_proj_rel_pk_entity; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_class_proj_rel + ADD CONSTRAINT data_for_history_proj_rel_pk_entity PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5555 (class 2606 OID 24154) +-- Name: dfh_class_proj_rel dfh_class_project_rel__class_and_project_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_class_proj_rel + ADD CONSTRAINT dfh_class_project_rel__class_and_project_unique UNIQUE (fk_class, fk_project); + +-- +-- TOC entry 5681 (class 2606 OID 24867) +-- Name: dfh_profile_proj_rel dfh_profile_proj_rel_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ADD CONSTRAINT dfh_profile_proj_rel_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5737 (class 2606 OID 24869) +-- Name: entity_label_config entity_label_config_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity_label_config + ADD CONSTRAINT entity_label_config_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5519 (class 2606 OID 22141) +-- Name: entity entity_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity + ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5521 (class 2606 OID 22143) +-- Name: info_proj_rel entity_version_project_rel_fk_entity_fk_project_key; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.info_proj_rel + ADD CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key UNIQUE (fk_entity, fk_project); + +-- +-- TOC entry 5523 (class 2606 OID 22145) +-- Name: info_proj_rel entity_version_project_rel_fk_entity_version_concat_fk_proj_key; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.info_proj_rel + ADD CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key UNIQUE (fk_entity_version_concat, fk_project); + +-- +-- TOC entry 5529 (class 2606 OID 24871) +-- Name: info_proj_rel info_proj_rel_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.info_proj_rel + ADD CONSTRAINT info_proj_rel_pkey PRIMARY KEY (fk_entity, fk_project); + +-- +-- TOC entry 5532 (class 2606 OID 22149) +-- Name: info_proj_rel information_entity_version_project_rel_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.info_proj_rel + ADD CONSTRAINT information_entity_version_project_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5557 (class 2606 OID 22153) +-- Name: language language_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.language + ADD CONSTRAINT language_pkey PRIMARY KEY (pk_language); + +-- +-- TOC entry 5562 (class 2606 OID 24873) +-- Name: project project_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT project_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5677 (class 2606 OID 23996) +-- Name: analysis projects_analysis_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ADD CONSTRAINT projects_analysis_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5683 (class 2606 OID 24066) +-- Name: dfh_profile_proj_rel projects_dfh_profile_proj_rel_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ADD CONSTRAINT projects_dfh_profile_proj_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5739 (class 2606 OID 24542) +-- Name: entity_label_config projects_entity_label_config_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.entity_label_config + ADD CONSTRAINT projects_entity_label_config_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5653 (class 2606 OID 23758) +-- Name: property_label_deprecated projects_property_label_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ADD CONSTRAINT projects_property_label_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5751 (class 2606 OID 24608) +-- Name: table_config projects_table_config_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ADD CONSTRAINT projects_table_config_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5783 (class 2606 OID 24987) +-- Name: visibility_settings projects_visibility_settings_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ADD CONSTRAINT projects_visibility_settings_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5655 (class 2606 OID 24875) +-- Name: property_label_deprecated property_label_deprecated_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ADD CONSTRAINT property_label_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5566 (class 2606 OID 22157) +-- Name: query query__unique_name_per_project; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ADD CONSTRAINT query__unique_name_per_project UNIQUE (name, fk_project); + +-- +-- TOC entry 5569 (class 2606 OID 24877) +-- Name: query query_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ADD CONSTRAINT query_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5753 (class 2606 OID 24879) +-- Name: table_config table_config_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ADD CONSTRAINT table_config_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5574 (class 2606 OID 24881) +-- Name: text_property text_property_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT text_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5577 (class 2606 OID 24560) +-- Name: text_property uniq_incoming_property_label; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT uniq_incoming_property_label UNIQUE (fk_project, fk_dfh_property, fk_dfh_property_range, fk_language); + +-- +-- TOC entry 5579 (class 2606 OID 24558) +-- Name: text_property uniq_outgoing_property_label; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT uniq_outgoing_property_label UNIQUE (fk_project, fk_dfh_property, fk_dfh_property_domain, fk_language); + +-- +-- TOC entry 5685 (class 2606 OID 24079) +-- Name: dfh_profile_proj_rel unique_fk_project_fk_profile; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ADD CONSTRAINT unique_fk_project_fk_profile UNIQUE (fk_project, fk_profile); + +-- +-- TOC entry 5785 (class 2606 OID 24980) +-- Name: visibility_settings visibility_settings_fk_project_key; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ADD CONSTRAINT visibility_settings_fk_project_key UNIQUE (fk_project); + +-- +-- TOC entry 5584 (class 2606 OID 22161) +-- Name: visual visual__unique_name_per_project; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ADD CONSTRAINT visual__unique_name_per_project UNIQUE (name, fk_project); + +-- +-- TOC entry 5586 (class 2606 OID 24883) +-- Name: visual visual_pkey; Type: CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ADD CONSTRAINT visual_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5588 (class 2606 OID 22163) +-- Name: accesstoken accesstoken_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.accesstoken + ADD CONSTRAINT accesstoken_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5590 (class 2606 OID 22165) +-- Name: account account_email_key; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account + ADD CONSTRAINT account_email_key UNIQUE (email); + +-- +-- TOC entry 5592 (class 2606 OID 22167) +-- Name: account account_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account + ADD CONSTRAINT account_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5596 (class 2606 OID 22169) +-- Name: account_project_rel account_project_rel_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account_project_rel + ADD CONSTRAINT account_project_rel_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5594 (class 2606 OID 22171) +-- Name: account account_username_key; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account + ADD CONSTRAINT account_username_key UNIQUE (username); + +-- +-- TOC entry 5598 (class 2606 OID 22173) +-- Name: acl acl_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.acl + ADD CONSTRAINT acl_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5727 (class 2606 OID 24484) +-- Name: credential credential_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.credential + ADD CONSTRAINT credential_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5600 (class 2606 OID 22175) +-- Name: role role_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.role + ADD CONSTRAINT role_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5602 (class 2606 OID 22177) +-- Name: rolemapping rolemapping_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.rolemapping + ADD CONSTRAINT rolemapping_pkey PRIMARY KEY (id); + +-- +-- TOC entry 5671 (class 2606 OID 24885) +-- Name: analysis_type_deprecated analysis_type_deprecated_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.analysis_type_deprecated + ADD CONSTRAINT analysis_type_deprecated_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5605 (class 2606 OID 24887) +-- Name: app_context app_context_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.app_context + ADD CONSTRAINT app_context_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5543 (class 2606 OID 24889) +-- Name: class_field class_field_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field + ADD CONSTRAINT class_field_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5610 (class 2606 OID 24891) +-- Name: class_field_property_rel class_field_property_rel_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field_property_rel + ADD CONSTRAINT class_field_property_rel_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5614 (class 2606 OID 22179) +-- Name: class_has_type_property class_has_type_property_fk_class_key; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_has_type_property + ADD CONSTRAINT class_has_type_property_fk_class_key UNIQUE (fk_class); + +-- +-- TOC entry 5617 (class 2606 OID 24893) +-- Name: class_has_type_property class_has_type_property_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_has_type_property + ADD CONSTRAINT class_has_type_property_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5619 (class 2606 OID 22181) +-- Name: class_has_type_property commons_class_has_type_property_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_has_type_property + ADD CONSTRAINT commons_class_has_type_property_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5545 (class 2606 OID 22183) +-- Name: class_field commons_property_set_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field + ADD CONSTRAINT commons_property_set_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5612 (class 2606 OID 22185) +-- Name: class_field_property_rel commons_property_set_property_rel_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field_property_rel + ADD CONSTRAINT commons_property_set_property_rel_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5631 (class 2606 OID 22187) +-- Name: system_type commons_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_type + ADD CONSTRAINT commons_system_type_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5607 (class 2606 OID 22189) +-- Name: app_context commons_ui_context_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.app_context + ADD CONSTRAINT commons_ui_context_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5729 (class 2606 OID 24895) +-- Name: config config_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.config + ADD CONSTRAINT config_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5540 (class 2606 OID 22191) +-- Name: entity entity_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.entity + ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5673 (class 2606 OID 23965) +-- Name: analysis_type_deprecated system_analysis_type_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.analysis_type_deprecated + ADD CONSTRAINT system_analysis_type_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5731 (class 2606 OID 24501) +-- Name: config system_config_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.config + ADD CONSTRAINT system_config_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5622 (class 2606 OID 24897) +-- Name: system_relevant_class system_relevant_class_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_class + ADD CONSTRAINT system_relevant_class_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5627 (class 2606 OID 24899) +-- Name: system_relevant_type system_relevant_type_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ADD CONSTRAINT system_relevant_type_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5624 (class 2606 OID 22193) +-- Name: system_relevant_class system_system_relevant_class_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_class + ADD CONSTRAINT system_system_relevant_class_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5629 (class 2606 OID 22195) +-- Name: system_relevant_type system_system_relevant_type_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ADD CONSTRAINT system_system_relevant_type_pk_entity_unique UNIQUE (pk_entity); + +-- +-- TOC entry 5634 (class 2606 OID 24901) +-- Name: system_type system_type_pkey; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_type + ADD CONSTRAINT system_type_pkey PRIMARY KEY (pk_entity); + +-- +-- TOC entry 5636 (class 2606 OID 22197) +-- Name: system_type unique_note; Type: CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_type + ADD CONSTRAINT unique_note UNIQUE (notes); + +-- +-- TOC entry 5660 (class 2606 OID 23806) +-- Name: cell cell_pk_cell_primary_key; Type: CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.cell + ADD CONSTRAINT cell_pk_cell_primary_key PRIMARY KEY (pk_cell); + +-- +-- TOC entry 5667 (class 2606 OID 23826) +-- Name: quill_doc_cell quill_doc_cell_pk_cell_primary_key; Type: CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ADD CONSTRAINT quill_doc_cell_pk_cell_primary_key PRIMARY KEY (pk_cell); + +-- +-- TOC entry 5755 (class 2606 OID 24630) +-- Name: row row_pkey; Type: CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables."row" + ADD CONSTRAINT row_pkey PRIMARY KEY (pk_row); + +-- +-- TOC entry 5733 (class 2606 OID 24903) +-- Name: class_preview class_preview_pkey; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.class_preview + ADD CONSTRAINT class_preview_pkey PRIMARY KEY (fk_class, fk_project); + +-- +-- TOC entry 5773 (class 2606 OID 24958) +-- Name: entity_preview_template entity_preview_template_pkey; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.entity_preview_template + ADD CONSTRAINT entity_preview_template_pkey PRIMARY KEY (entity_id, project_id); + +-- +-- TOC entry 5763 (class 2606 OID 24926) +-- Name: field_change_template field_change_pkey; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.field_change_template + ADD CONSTRAINT field_change_pkey PRIMARY KEY (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing); + +-- +-- TOC entry 5747 (class 2606 OID 24579) +-- Name: statement_backup statement_pk_entity_project_key; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.statement_backup + ADD CONSTRAINT statement_pk_entity_project_key UNIQUE (pk_entity, project); + +-- +-- TOC entry 5749 (class 2606 OID 24907) +-- Name: statement_backup statement_pkey; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.statement_backup + ADD CONSTRAINT statement_pkey PRIMARY KEY (pk_entity, project); + +-- +-- TOC entry 5771 (class 2606 OID 24936) +-- Name: statement_template statement_template_pkey; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.statement_template + ADD CONSTRAINT statement_template_pkey PRIMARY KEY (pk_entity, project); + +-- +-- TOC entry 5735 (class 2606 OID 24529) +-- Name: class_preview war_class_preview_unique; Type: CONSTRAINT; Schema: war; Owner: - +-- +ALTER TABLE ONLY war.class_preview + ADD CONSTRAINT war_class_preview_unique UNIQUE (fk_class, fk_project); + +-- +-- TOC entry 5335 (class 1259 OID 23542) +-- Name: text_string_idx; Type: INDEX; Schema: commons; Owner: - +-- +CREATE INDEX text_string_idx ON commons.text USING btree(string); + +-- +-- TOC entry 5338 (class 1259 OID 23543) +-- Name: text_vt_string_idx; Type: INDEX; Schema: commons; Owner: - +-- +CREATE INDEX text_vt_string_idx ON commons.text_vt USING btree(string); + +-- +-- TOC entry 5341 (class 1259 OID 23572) +-- Name: avatar_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX avatar_pk_entity_idx ON data.avatar USING btree(pk_entity); + +-- +-- TOC entry 5346 (class 1259 OID 23573) +-- Name: chunk_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX chunk_pk_entity_idx ON data.chunk USING btree(pk_entity); + +-- +-- TOC entry 5349 (class 1259 OID 23554) +-- Name: chunk_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX chunk_string_idx ON data.chunk USING btree(string); + +-- +-- TOC entry 5352 (class 1259 OID 23555) +-- Name: chunk_vt_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX chunk_vt_string_idx ON data.chunk_vt USING btree(string); + +-- +-- TOC entry 5353 (class 1259 OID 23558) +-- Name: class_column_mapping_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX class_column_mapping_pk_entity_idx ON data.class_column_mapping USING btree(pk_entity); + +-- +-- TOC entry 5358 (class 1259 OID 23559) +-- Name: column_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX column_pk_entity_idx ON data."column" USING btree(pk_entity); + +-- +-- TOC entry 5363 (class 1259 OID 23870) +-- Name: data_association_fk_cell_domain_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_fk_cell_domain_idx ON data.data_association USING btree(fk_cell_domain); + +-- +-- TOC entry 5364 (class 1259 OID 23871) +-- Name: data_association_fk_cell_range_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_fk_cell_range_idx ON data.data_association USING btree(fk_cell_range); + +-- +-- TOC entry 5365 (class 1259 OID 23868) +-- Name: data_association_fk_info_domain_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_fk_info_domain_idx ON data.data_association USING btree(fk_info_domain); + +-- +-- TOC entry 5366 (class 1259 OID 23869) +-- Name: data_association_fk_info_range_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_fk_info_range_idx ON data.data_association USING btree(fk_info_range); + +-- +-- TOC entry 5411 (class 1259 OID 23571) +-- Name: data_association_mapping_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_mapping_pk_entity_idx ON data.data_association_mapping USING btree(pk_entity); + +-- +-- TOC entry 5367 (class 1259 OID 23560) +-- Name: data_association_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX data_association_pk_entity_idx ON data.data_association USING btree(pk_entity); + +-- +-- TOC entry 5372 (class 1259 OID 23561) +-- Name: digital_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX digital_pk_entity_idx ON data.digital USING btree(pk_entity); + +-- +-- TOC entry 5375 (class 1259 OID 23864) +-- Name: digital_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX digital_string_idx ON data.digital USING HASH (string); + +-- +-- TOC entry 5378 (class 1259 OID 23872) +-- Name: digital_vt_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX digital_vt_string_idx ON data.digital_vt USING HASH (string); + +-- +-- TOC entry 5386 (class 1259 OID 23564) +-- Name: factoid_mapping_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX factoid_mapping_pk_entity_idx ON data.factoid_mapping USING btree(pk_entity); + +-- +-- TOC entry 5381 (class 1259 OID 23563) +-- Name: factoid_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX factoid_pk_entity_idx ON data.factoid USING btree(pk_entity); + +-- +-- TOC entry 5393 (class 1259 OID 23566) +-- Name: factoid_role_mapping_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX factoid_role_mapping_pk_entity_idx ON data.factoid_property_mapping USING btree(pk_entity); + +-- +-- TOC entry 5396 (class 1259 OID 23567) +-- Name: factoid_role_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX factoid_role_pk_entity_idx ON data.factoid_role USING btree(pk_entity); + +-- +-- TOC entry 5401 (class 1259 OID 23568) +-- Name: namespace_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX namespace_pk_entity_idx ON data.namespace USING btree(pk_entity); + +-- +-- TOC entry 5639 (class 1259 OID 23565) +-- Name: property_of_property_mapping_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX property_of_property_mapping_pk_entity_idx ON data.property_of_property_mapping USING btree(pk_entity); + +-- +-- TOC entry 5644 (class 1259 OID 23562) +-- Name: property_of_property_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX property_of_property_pk_entity_idx ON data.property_of_property USING btree(pk_entity); + +-- +-- TOC entry 5406 (class 1259 OID 23570) +-- Name: text_property_pk_entity_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX text_property_pk_entity_idx ON data.text_property USING btree(pk_entity); + +-- +-- TOC entry 5409 (class 1259 OID 23550) +-- Name: text_property_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX text_property_string_idx ON data.text_property USING btree(string); + +-- +-- TOC entry 5410 (class 1259 OID 23551) +-- Name: text_property_vt_string_idx; Type: INDEX; Schema: data; Owner: - +-- +CREATE INDEX text_property_vt_string_idx ON data.text_property_vt USING btree(string); + +-- +-- TOC entry 5424 (class 1259 OID 23583) +-- Name: associates_system_type_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX associates_system_type_pk_entity_idx ON data_for_history.associates_system_type_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5429 (class 1259 OID 23575) +-- Name: class_profile_view_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX class_profile_view_pk_entity_idx ON data_for_history.class_profile_view_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5436 (class 1259 OID 23577) +-- Name: label_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX label_pk_entity_idx ON data_for_history.label_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5441 (class 1259 OID 23578) +-- Name: profile_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX profile_pk_entity_idx ON data_for_history.api_profile USING btree(pk_entity); + +-- +-- TOC entry 5446 (class 1259 OID 23579) +-- Name: property_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX property_pk_entity_idx ON data_for_history.property USING btree(pk_entity); + +-- +-- TOC entry 5453 (class 1259 OID 23580) +-- Name: property_profile_view_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX property_profile_view_pk_entity_idx ON data_for_history.property_profile_view_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5458 (class 1259 OID 23581) +-- Name: system_type_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX system_type_pk_entity_idx ON data_for_history.system_type_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5463 (class 1259 OID 23582) +-- Name: text_property_pk_entity_idx; Type: INDEX; Schema: data_for_history; Owner: - +-- +CREATE INDEX text_property_pk_entity_idx ON data_for_history.text_property_deprecated USING btree(pk_entity); + +-- +-- TOC entry 5464 (class 1259 OID 23585) +-- Name: appellation_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX appellation_pk_entity_idx ON information.appellation USING btree(pk_entity); + +-- +-- TOC entry 5647 (class 1259 OID 23594) +-- Name: dimension_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX dimension_pk_entity_idx ON information.dimension USING btree(pk_entity); + +-- +-- TOC entry 5471 (class 1259 OID 23866) +-- Name: entity_association_fk_cell_domain_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX entity_association_fk_cell_domain_idx ON information._backup_entity_association USING btree(fk_cell_domain); + +-- +-- TOC entry 5472 (class 1259 OID 23867) +-- Name: entity_association_fk_cell_range_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX entity_association_fk_cell_range_idx ON information._backup_entity_association USING btree(fk_cell_range); + +-- +-- TOC entry 5473 (class 1259 OID 23617) +-- Name: entity_association_fk_info_domain_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX entity_association_fk_info_domain_idx ON information._backup_entity_association USING btree(fk_info_domain); + +-- +-- TOC entry 5474 (class 1259 OID 23618) +-- Name: entity_association_fk_info_range_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX entity_association_fk_info_range_idx ON information._backup_entity_association USING btree(fk_info_range); + +-- +-- TOC entry 5475 (class 1259 OID 23586) +-- Name: entity_association_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX entity_association_pk_entity_idx ON information._backup_entity_association USING btree(pk_entity); + +-- +-- TOC entry 5706 (class 1259 OID 24405) +-- Name: lang_string_fk_language_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX lang_string_fk_language_idx ON information.lang_string USING btree(fk_language); + +-- +-- TOC entry 5707 (class 1259 OID 24404) +-- Name: lang_string_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX lang_string_pk_entity_idx ON information.lang_string USING btree(pk_entity); + +-- +-- TOC entry 5480 (class 1259 OID 23587) +-- Name: language_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX language_pk_entity_idx ON information.language USING btree(pk_entity); + +-- +-- TOC entry 5485 (class 1259 OID 23588) +-- Name: persistent_item_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX persistent_item_pk_entity_idx ON information.persistent_item_backup USING btree(pk_entity); + +-- +-- TOC entry 5488 (class 1259 OID 23589) +-- Name: place_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX place_pk_entity_idx ON information.place USING btree(pk_entity); + +-- +-- TOC entry 5758 (class 1259 OID 24950) +-- Name: resource_fk_class_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX resource_fk_class_idx ON information.resource USING btree(fk_class); + +-- +-- TOC entry 5759 (class 1259 OID 24949) +-- Name: resource_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX resource_pk_entity_idx ON information.resource USING btree(pk_entity); + +-- +-- TOC entry 5493 (class 1259 OID 23615) +-- Name: statement_fk_object_info_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_fk_object_info_idx ON information.statement USING btree(fk_object_info); + +-- +-- TOC entry 5494 (class 1259 OID 24785) +-- Name: statement_fk_object_tables_cell_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_fk_object_tables_cell_idx ON information.statement USING btree(fk_object_tables_cell); + +-- +-- TOC entry 5495 (class 1259 OID 24740) +-- Name: statement_fk_property_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_fk_property_idx ON information.statement USING btree(fk_property); + +-- +-- TOC entry 5496 (class 1259 OID 23616) +-- Name: statement_fk_subject_info_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_fk_subject_info_idx ON information.statement USING btree(fk_subject_info); + +-- +-- TOC entry 5497 (class 1259 OID 24741) +-- Name: statement_fk_subject_tables_cell_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_fk_subject_tables_cell_idx ON information.statement USING btree(fk_subject_tables_cell); + +-- +-- TOC entry 5498 (class 1259 OID 23591) +-- Name: statement_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX statement_pk_entity_idx ON information.statement USING btree(pk_entity); + +-- +-- TOC entry 5332 (class 1259 OID 23584) +-- Name: temporal_entity_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX temporal_entity_pk_entity_idx ON information.temporal_entity_backup USING btree(pk_entity); + +-- +-- TOC entry 5503 (class 1259 OID 23619) +-- Name: text_property_fk_concerned_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX text_property_fk_concerned_entity_idx ON information.text_property USING btree(fk_concerned_entity); + +-- +-- TOC entry 5506 (class 1259 OID 23592) +-- Name: text_property_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX text_property_pk_entity_idx ON information.text_property USING btree(pk_entity); + +-- +-- TOC entry 5509 (class 1259 OID 23546) +-- Name: text_property_string_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX text_property_string_idx ON information.text_property USING btree(string); + +-- +-- TOC entry 5510 (class 1259 OID 23547) +-- Name: text_property_vt_string_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX text_property_vt_string_idx ON information.text_property_vt USING btree(string); + +-- +-- TOC entry 5513 (class 1259 OID 23593) +-- Name: time_primitive_pk_entity_idx; Type: INDEX; Schema: information; Owner: - +-- +CREATE INDEX time_primitive_pk_entity_idx ON information.time_primitive USING btree(pk_entity); + +-- +-- TOC entry 5546 (class 1259 OID 23601) +-- Name: argument_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX argument_pk_entity_idx ON projects.argument USING btree(pk_entity); + +-- +-- TOC entry 5533 (class 1259 OID 24027) +-- Name: class_field_config_fk_app_context_fk_project_fk_property_fk_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE UNIQUE INDEX class_field_config_fk_app_context_fk_project_fk_property_fk_idx ON projects.class_field_config USING btree(fk_app_context, fk_project, fk_property, fk_domain_class, fk_range_class); + +-- +-- TOC entry 5534 (class 1259 OID 23599) +-- Name: class_field_config_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX class_field_config_pk_entity_idx ON projects.class_field_config USING btree(pk_entity); + +-- +-- TOC entry 5553 (class 1259 OID 23595) +-- Name: dfh_class_proj_rel_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX dfh_class_proj_rel_pk_entity_idx ON projects.dfh_class_proj_rel USING btree(pk_entity); + +-- +-- TOC entry 5524 (class 1259 OID 23613) +-- Name: info_proj_rel_fk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX info_proj_rel_fk_entity_idx ON projects.info_proj_rel USING btree(fk_entity); + +-- +-- TOC entry 5525 (class 1259 OID 23614) +-- Name: info_proj_rel_fk_project_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX info_proj_rel_fk_project_idx ON projects.info_proj_rel USING btree(fk_project); + +-- +-- TOC entry 5526 (class 1259 OID 24304) +-- Name: info_proj_rel_is_in_project_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX info_proj_rel_is_in_project_idx ON projects.info_proj_rel USING btree(is_in_project); + +-- +-- TOC entry 5527 (class 1259 OID 23600) +-- Name: info_proj_rel_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX info_proj_rel_pk_entity_idx ON projects.info_proj_rel USING btree(pk_entity); + +-- +-- TOC entry 5530 (class 1259 OID 24305) +-- Name: info_proj_rel_tmsp_last_modification_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX info_proj_rel_tmsp_last_modification_idx ON projects.info_proj_rel USING btree(tmsp_last_modification); + +-- +-- TOC entry 5560 (class 1259 OID 23596) +-- Name: project_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX project_pk_entity_idx ON projects.project USING btree(pk_entity); + +-- +-- TOC entry 5567 (class 1259 OID 23598) +-- Name: query_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX query_pk_entity_idx ON projects.query USING btree(pk_entity); + +-- +-- TOC entry 5572 (class 1259 OID 23597) +-- Name: text_property_pk_entity_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX text_property_pk_entity_idx ON projects.text_property USING btree(pk_entity); + +-- +-- TOC entry 5575 (class 1259 OID 23548) +-- Name: text_property_string_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX text_property_string_idx ON projects.text_property USING btree(string); + +-- +-- TOC entry 5580 (class 1259 OID 23549) +-- Name: text_property_vt_string_idx; Type: INDEX; Schema: projects; Owner: - +-- +CREATE INDEX text_property_vt_string_idx ON projects.text_property_vt USING btree(string); + +-- +-- TOC entry 5603 (class 1259 OID 23608) +-- Name: app_context_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX app_context_pk_entity_idx ON system.app_context USING btree(pk_entity); + +-- +-- TOC entry 5541 (class 1259 OID 23607) +-- Name: class_field_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX class_field_pk_entity_idx ON system.class_field USING btree(pk_entity); + +-- +-- TOC entry 5608 (class 1259 OID 23606) +-- Name: class_field_property_rel_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX class_field_property_rel_pk_entity_idx ON system.class_field_property_rel USING btree(pk_entity); + +-- +-- TOC entry 5615 (class 1259 OID 23602) +-- Name: class_has_type_property_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX class_has_type_property_pk_entity_idx ON system.class_has_type_property USING btree(pk_entity); + +-- +-- TOC entry 5620 (class 1259 OID 23604) +-- Name: system_relevant_class_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX system_relevant_class_pk_entity_idx ON system.system_relevant_class USING btree(pk_entity); + +-- +-- TOC entry 5625 (class 1259 OID 23605) +-- Name: system_relevant_type_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX system_relevant_type_pk_entity_idx ON system.system_relevant_type USING btree(pk_entity); + +-- +-- TOC entry 5632 (class 1259 OID 23603) +-- Name: system_type_pk_entity_idx; Type: INDEX; Schema: system; Owner: - +-- +CREATE INDEX system_type_pk_entity_idx ON system.system_type USING btree(pk_entity); + +-- +-- TOC entry 5656 (class 1259 OID 24737) +-- Name: cell_fk_column_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX cell_fk_column_idx ON tables.cell USING btree(fk_column); + +-- +-- TOC entry 5657 (class 1259 OID 24738) +-- Name: cell_fk_row_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX cell_fk_row_idx ON tables.cell USING btree(fk_row); + +-- +-- TOC entry 5658 (class 1259 OID 24739) +-- Name: cell_pk_cell_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX cell_pk_cell_idx ON tables.cell USING btree(pk_cell); + +-- +-- TOC entry 5661 (class 1259 OID 23848) +-- Name: quill_doc_cell_fk_column_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_fk_column_idx ON tables.quill_doc_cell USING btree(fk_column); + +-- +-- TOC entry 5662 (class 1259 OID 23849) +-- Name: quill_doc_cell_fk_digital_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_fk_digital_idx ON tables.quill_doc_cell USING btree(fk_digital); + +-- +-- TOC entry 5663 (class 1259 OID 23850) +-- Name: quill_doc_cell_fk_row_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_fk_row_idx ON tables.quill_doc_cell USING btree(fk_row); + +-- +-- TOC entry 5664 (class 1259 OID 23851) +-- Name: quill_doc_cell_id_for_import_txt_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_id_for_import_txt_idx ON tables.quill_doc_cell USING btree(id_for_import_txt); + +-- +-- TOC entry 5665 (class 1259 OID 23852) +-- Name: quill_doc_cell_pk_cell_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_pk_cell_idx ON tables.quill_doc_cell USING btree(pk_cell); + +-- +-- TOC entry 5668 (class 1259 OID 23853) +-- Name: quill_doc_cell_string_value_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX quill_doc_cell_string_value_idx ON tables.quill_doc_cell USING btree(string_value); + +-- +-- TOC entry 5669 (class 1259 OID 23859) +-- Name: text_string_idx; Type: INDEX; Schema: tables; Owner: - +-- +CREATE INDEX text_string_idx ON tables.quill_doc_cell USING btree(string); + +-- +-- TOC entry 5774 (class 1259 OID 24963) +-- Name: ep__entity_label_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__entity_label_idx ON ONLY war.entity_preview_template USING btree(entity_label); + +-- +-- TOC entry 5775 (class 1259 OID 24959) +-- Name: ep__entity_type_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__entity_type_idx ON ONLY war.entity_preview_template USING btree(entity_type); + +-- +-- TOC entry 5776 (class 1259 OID 24960) +-- Name: ep__fk_class_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__fk_class_idx ON ONLY war.entity_preview_template USING btree(fk_class); + +-- +-- TOC entry 5777 (class 1259 OID 24961) +-- Name: ep__fk_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__fk_project_idx ON ONLY war.entity_preview_template USING btree(fk_project); + +-- +-- TOC entry 5778 (class 1259 OID 24964) +-- Name: ep__key_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__key_idx ON ONLY war.entity_preview_template USING btree(key); + +-- +-- TOC entry 5779 (class 1259 OID 24965) +-- Name: ep__pk_entity_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__pk_entity_idx ON ONLY war.entity_preview_template USING btree(pk_entity); + +-- +-- TOC entry 5780 (class 1259 OID 24962) +-- Name: ep__project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__project_idx ON ONLY war.entity_preview_template USING btree(project); + +-- +-- TOC entry 5781 (class 1259 OID 24966) +-- Name: ep__ts_vector_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX ep__ts_vector_idx ON ONLY war.entity_preview_template USING gin(ts_vector); + +-- +-- TOC entry 5740 (class 1259 OID 24567) +-- Name: statement_fk_object_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_fk_object_info_idx ON war.statement_backup USING btree(fk_object_info); + +-- +-- TOC entry 5741 (class 1259 OID 24568) +-- Name: statement_fk_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_fk_project_idx ON war.statement_backup USING btree(fk_project); + +-- +-- TOC entry 5742 (class 1259 OID 24569) +-- Name: statement_fk_property_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_fk_property_idx ON war.statement_backup USING btree(fk_property); + +-- +-- TOC entry 5743 (class 1259 OID 24570) +-- Name: statement_fk_subject_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_fk_subject_info_idx ON war.statement_backup USING btree(fk_subject_info); + +-- +-- TOC entry 5744 (class 1259 OID 24571) +-- Name: statement_pk_entity_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_pk_entity_idx ON war.statement_backup USING btree(pk_entity); + +-- +-- TOC entry 5745 (class 1259 OID 24572) +-- Name: statement_pk_entity_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE UNIQUE INDEX statement_pk_entity_project_idx ON war.statement_backup USING btree(pk_entity, project); + +-- +-- TOC entry 5764 (class 1259 OID 24937) +-- Name: statement_template_fk_object_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_template_fk_object_info_idx ON war.statement_template USING btree(fk_object_info); + +-- +-- TOC entry 5765 (class 1259 OID 24938) +-- Name: statement_template_fk_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_template_fk_project_idx ON war.statement_template USING btree(fk_project); + +-- +-- TOC entry 5766 (class 1259 OID 24939) +-- Name: statement_template_fk_property_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_template_fk_property_idx ON war.statement_template USING btree(fk_property); + +-- +-- TOC entry 5767 (class 1259 OID 24940) +-- Name: statement_template_fk_subject_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_template_fk_subject_info_idx ON war.statement_template USING btree(fk_subject_info); + +-- +-- TOC entry 5768 (class 1259 OID 24941) +-- Name: statement_template_pk_entity_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX statement_template_pk_entity_idx ON war.statement_template USING btree(pk_entity); + +-- +-- TOC entry 5769 (class 1259 OID 24942) +-- Name: statement_template_pk_entity_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE UNIQUE INDEX statement_template_pk_entity_project_idx ON war.statement_template USING btree(pk_entity, project); + +-- +-- TOC entry 5720 (class 1259 OID 24470) +-- Name: vm_statement_fk_object_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX vm_statement_fk_object_info_idx ON war.vm_statement USING btree(fk_object_info); + +-- +-- TOC entry 5721 (class 1259 OID 24471) +-- Name: vm_statement_fk_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX vm_statement_fk_project_idx ON war.vm_statement USING btree(fk_project); + +-- +-- TOC entry 5722 (class 1259 OID 24472) +-- Name: vm_statement_fk_property_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX vm_statement_fk_property_idx ON war.vm_statement USING btree(fk_property); + +-- +-- TOC entry 5723 (class 1259 OID 24473) +-- Name: vm_statement_fk_subject_info_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX vm_statement_fk_subject_info_idx ON war.vm_statement USING btree(fk_subject_info); + +-- +-- TOC entry 5724 (class 1259 OID 24474) +-- Name: vm_statement_pk_entity_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE INDEX vm_statement_pk_entity_idx ON war.vm_statement USING btree(pk_entity); + +-- +-- TOC entry 5725 (class 1259 OID 24475) +-- Name: vm_statement_pk_entity_project_idx; Type: INDEX; Schema: war; Owner: - +-- +CREATE UNIQUE INDEX vm_statement_pk_entity_project_idx ON war.vm_statement USING btree(pk_entity, project); + +-- +-- TOC entry 5905 (class 2620 OID 22206) +-- Name: text sync_quill_doc_and_string; Type: TRIGGER; Schema: commons; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON commons.text + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 5906 (class 2620 OID 22220) +-- Name: avatar create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5912 (class 2620 OID 22208) +-- Name: chunk create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5919 (class 2620 OID 23035) +-- Name: class_column_mapping create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5925 (class 2620 OID 22210) +-- Name: column create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data."column" + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5931 (class 2620 OID 22219) +-- Name: data_association create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5981 (class 2620 OID 23032) +-- Name: data_association_mapping create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5937 (class 2620 OID 22207) +-- Name: digital create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5944 (class 2620 OID 22216) +-- Name: factoid create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5950 (class 2620 OID 23026) +-- Name: factoid_mapping create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5956 (class 2620 OID 23029) +-- Name: factoid_property_mapping create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5962 (class 2620 OID 22217) +-- Name: factoid_role create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5968 (class 2620 OID 22222) +-- Name: namespace create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6196 (class 2620 OID 23133) +-- Name: property_of_property create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6190 (class 2620 OID 23076) +-- Name: property_of_property_mapping create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5974 (class 2620 OID 22221) +-- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5987 (class 2620 OID 22218) +-- Name: values_association create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5907 (class 2620 OID 22236) +-- Name: avatar creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5913 (class 2620 OID 22224) +-- Name: chunk creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5920 (class 2620 OID 22230) +-- Name: class_column_mapping creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5926 (class 2620 OID 22226) +-- Name: column creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data."column" + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5932 (class 2620 OID 22235) +-- Name: data_association creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5982 (class 2620 OID 22229) +-- Name: data_association_mapping creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5938 (class 2620 OID 22223) +-- Name: digital creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5945 (class 2620 OID 22232) +-- Name: factoid creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5951 (class 2620 OID 22228) +-- Name: factoid_mapping creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5957 (class 2620 OID 22231) +-- Name: factoid_property_mapping creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5963 (class 2620 OID 22233) +-- Name: factoid_role creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5969 (class 2620 OID 22238) +-- Name: namespace creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6197 (class 2620 OID 23124) +-- Name: property_of_property creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6191 (class 2620 OID 23067) +-- Name: property_of_property_mapping creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5975 (class 2620 OID 22237) +-- Name: text_property creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5988 (class 2620 OID 22234) +-- Name: values_association creation_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5908 (class 2620 OID 22252) +-- Name: avatar insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5914 (class 2620 OID 22240) +-- Name: chunk insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5921 (class 2620 OID 22246) +-- Name: class_column_mapping insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5927 (class 2620 OID 22242) +-- Name: column insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data."column" + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5933 (class 2620 OID 22251) +-- Name: data_association insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5983 (class 2620 OID 22245) +-- Name: data_association_mapping insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5939 (class 2620 OID 22239) +-- Name: digital insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5946 (class 2620 OID 22248) +-- Name: factoid insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5952 (class 2620 OID 22244) +-- Name: factoid_mapping insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5958 (class 2620 OID 22247) +-- Name: factoid_property_mapping insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5964 (class 2620 OID 22249) +-- Name: factoid_role insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5970 (class 2620 OID 22254) +-- Name: namespace insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6198 (class 2620 OID 23125) +-- Name: property_of_property insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6192 (class 2620 OID 23068) +-- Name: property_of_property_mapping insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5976 (class 2620 OID 22253) +-- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5989 (class 2620 OID 22250) +-- Name: values_association insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5909 (class 2620 OID 22268) +-- Name: avatar last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5915 (class 2620 OID 22256) +-- Name: chunk last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5922 (class 2620 OID 22262) +-- Name: class_column_mapping last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5928 (class 2620 OID 22258) +-- Name: column last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data."column" + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5934 (class 2620 OID 22267) +-- Name: data_association last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5984 (class 2620 OID 22261) +-- Name: data_association_mapping last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5940 (class 2620 OID 22255) +-- Name: digital last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5947 (class 2620 OID 22264) +-- Name: factoid last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5953 (class 2620 OID 22260) +-- Name: factoid_mapping last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5959 (class 2620 OID 22263) +-- Name: factoid_property_mapping last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5965 (class 2620 OID 22265) +-- Name: factoid_role last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5971 (class 2620 OID 22270) +-- Name: namespace last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6199 (class 2620 OID 23126) +-- Name: property_of_property last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6193 (class 2620 OID 23069) +-- Name: property_of_property_mapping last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5977 (class 2620 OID 22269) +-- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5990 (class 2620 OID 22266) +-- Name: values_association last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6208 (class 2620 OID 23229) +-- Name: v_chunk on_insert; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON data.v_chunk + FOR EACH ROW + EXECUTE FUNCTION data.v_chunk_find_or_create(); + +-- +-- TOC entry 5916 (class 2620 OID 22273) +-- Name: chunk sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 5941 (class 2620 OID 22272) +-- Name: digital sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 5978 (class 2620 OID 22275) +-- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 5910 (class 2620 OID 22289) +-- Name: avatar update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5917 (class 2620 OID 22277) +-- Name: chunk update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5923 (class 2620 OID 23036) +-- Name: class_column_mapping update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5929 (class 2620 OID 22279) +-- Name: column update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data."column" + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5935 (class 2620 OID 22288) +-- Name: data_association update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5985 (class 2620 OID 23033) +-- Name: data_association_mapping update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5942 (class 2620 OID 22276) +-- Name: digital update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.digital + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5948 (class 2620 OID 22285) +-- Name: factoid update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5954 (class 2620 OID 23027) +-- Name: factoid_mapping update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5960 (class 2620 OID 23030) +-- Name: factoid_property_mapping update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5966 (class 2620 OID 22286) +-- Name: factoid_role update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5972 (class 2620 OID 22291) +-- Name: namespace update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6200 (class 2620 OID 23134) +-- Name: property_of_property update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6194 (class 2620 OID 23077) +-- Name: property_of_property_mapping update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5979 (class 2620 OID 22290) +-- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5991 (class 2620 OID 22287) +-- Name: values_association update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5911 (class 2620 OID 22305) +-- Name: avatar versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.avatar + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.avatar_vt', 'true'); + +-- +-- TOC entry 5918 (class 2620 OID 22293) +-- Name: chunk versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.chunk + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.chunk_vt', 'true'); + +-- +-- TOC entry 5924 (class 2620 OID 23034) +-- Name: class_column_mapping versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.class_column_mapping + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.class_column_mapping_vt', 'true'); + +-- +-- TOC entry 5930 (class 2620 OID 22295) +-- Name: column versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data."column" + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.column_vt', 'true'); + +-- +-- TOC entry 5936 (class 2620 OID 22304) +-- Name: data_association versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.data_association + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.data_association_vt', 'true'); + +-- +-- TOC entry 5986 (class 2620 OID 23031) +-- Name: data_association_mapping versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.data_association_mapping + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.data_association_mapping_vt', 'true'); + +-- +-- TOC entry 5943 (class 2620 OID 22292) +-- Name: digital versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.digital + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.digital_vt', 'true'); + +-- +-- TOC entry 5949 (class 2620 OID 22301) +-- Name: factoid versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.factoid + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.factoid_vt', 'true'); + +-- +-- TOC entry 5955 (class 2620 OID 23025) +-- Name: factoid_mapping versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_mapping + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.factoid_mapping_vt', 'true'); + +-- +-- TOC entry 5961 (class 2620 OID 24562) +-- Name: factoid_property_mapping versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_property_mapping + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.factoid_property_mapping_vt', 'true'); + +-- +-- TOC entry 5967 (class 2620 OID 22302) +-- Name: factoid_role versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_role + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.factoid_role_vt', 'true'); + +-- +-- TOC entry 5973 (class 2620 OID 22307) +-- Name: namespace versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.namespace + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.namespace_vt', 'true'); + +-- +-- TOC entry 6201 (class 2620 OID 23132) +-- Name: property_of_property versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.property_of_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.property_of_property_vt', 'true'); + +-- +-- TOC entry 6195 (class 2620 OID 23075) +-- Name: property_of_property_mapping versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.property_of_property_mapping + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.property_of_property_mapping_vt', 'true'); + +-- +-- TOC entry 5980 (class 2620 OID 22306) +-- Name: text_property versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.text_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.text_property_vt', 'true'); + +-- +-- TOC entry 5992 (class 2620 OID 22303) +-- Name: values_association versioning_trigger; Type: TRIGGER; Schema: data; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data.values_association + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data.values_association_vt', 'true'); + +-- +-- TOC entry 6241 (class 2620 OID 24267) +-- Name: api_class after_api_class_upsert; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER after_api_class_upsert + AFTER INSERT OR UPDATE ON data_for_history.api_class + FOR EACH STATEMENT + EXECUTE FUNCTION war.notify__need_to_check_class_labels(); + +-- +-- TOC entry 6242 (class 2620 OID 24100) +-- Name: api_class create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6011 (class 2620 OID 24048) +-- Name: api_profile create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6249 (class 2620 OID 24124) +-- Name: api_property create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5993 (class 2620 OID 22318) +-- Name: associates_system_type_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 5999 (class 2620 OID 22312) +-- Name: class_profile_view_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6005 (class 2620 OID 22313) +-- Name: label_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6017 (class 2620 OID 22314) +-- Name: property create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6023 (class 2620 OID 22317) +-- Name: property_profile_view_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6029 (class 2620 OID 22319) +-- Name: system_type_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6034 (class 2620 OID 22315) +-- Name: text_property_deprecated create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6243 (class 2620 OID 24091) +-- Name: api_class creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6012 (class 2620 OID 22325) +-- Name: api_profile creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6250 (class 2620 OID 24115) +-- Name: api_property creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5994 (class 2620 OID 22327) +-- Name: associates_system_type_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6000 (class 2620 OID 22320) +-- Name: class_profile_view_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6006 (class 2620 OID 22322) +-- Name: label_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6018 (class 2620 OID 22324) +-- Name: property creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6268 (class 2620 OID 24442) +-- Name: property_of_property creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6024 (class 2620 OID 22326) +-- Name: property_profile_view_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6030 (class 2620 OID 22328) +-- Name: system_type_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6035 (class 2620 OID 22323) +-- Name: text_property_deprecated creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6244 (class 2620 OID 24092) +-- Name: api_class insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6013 (class 2620 OID 22334) +-- Name: api_profile insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6251 (class 2620 OID 24116) +-- Name: api_property insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5995 (class 2620 OID 22336) +-- Name: associates_system_type_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6001 (class 2620 OID 22329) +-- Name: class_profile_view_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6007 (class 2620 OID 22331) +-- Name: label_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6019 (class 2620 OID 22333) +-- Name: property insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6269 (class 2620 OID 24443) +-- Name: property_of_property insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6025 (class 2620 OID 22335) +-- Name: property_profile_view_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6031 (class 2620 OID 22337) +-- Name: system_type_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6036 (class 2620 OID 22332) +-- Name: text_property_deprecated insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6245 (class 2620 OID 24093) +-- Name: api_class last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6014 (class 2620 OID 22343) +-- Name: api_profile last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6252 (class 2620 OID 24117) +-- Name: api_property last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5996 (class 2620 OID 22345) +-- Name: associates_system_type_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6002 (class 2620 OID 22338) +-- Name: class_profile_view_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6008 (class 2620 OID 22340) +-- Name: label_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6020 (class 2620 OID 22342) +-- Name: property last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6270 (class 2620 OID 24444) +-- Name: property_of_property last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.property_of_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6026 (class 2620 OID 22344) +-- Name: property_profile_view_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6032 (class 2620 OID 22346) +-- Name: system_type_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6037 (class 2620 OID 22341) +-- Name: text_property_deprecated last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6246 (class 2620 OID 24519) +-- Name: api_class notify_modification; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON data_for_history.api_class + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6253 (class 2620 OID 24521) +-- Name: api_property notify_modification; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON data_for_history.api_property + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6247 (class 2620 OID 24101) +-- Name: api_class update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6015 (class 2620 OID 24049) +-- Name: api_profile update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6254 (class 2620 OID 24125) +-- Name: api_property update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 5997 (class 2620 OID 22354) +-- Name: associates_system_type_deprecated update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6003 (class 2620 OID 22348) +-- Name: class_profile_view_deprecated update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6009 (class 2620 OID 22349) +-- Name: label_deprecated update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6021 (class 2620 OID 22350) +-- Name: property update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6027 (class 2620 OID 22353) +-- Name: property_profile_view_deprecated update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6038 (class 2620 OID 22351) +-- Name: text_property_deprecated update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6248 (class 2620 OID 24099) +-- Name: api_class versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.api_class + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.api_class_vt', 'true'); + +-- +-- TOC entry 6016 (class 2620 OID 24047) +-- Name: api_profile versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.api_profile + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.api_profile_vt', 'true'); + +-- +-- TOC entry 6255 (class 2620 OID 24123) +-- Name: api_property versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.api_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.api_property_vt', 'true'); + +-- +-- TOC entry 5998 (class 2620 OID 22362) +-- Name: associates_system_type_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.associates_system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.associates_system_type_vt', 'true'); + +-- +-- TOC entry 6004 (class 2620 OID 22355) +-- Name: class_profile_view_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.class_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.class_profile_view_vt', 'true'); + +-- +-- TOC entry 6010 (class 2620 OID 22357) +-- Name: label_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.label_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.label_vt', 'true'); + +-- +-- TOC entry 6022 (class 2620 OID 22359) +-- Name: property versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.property_vt', 'true'); + +-- +-- TOC entry 6271 (class 2620 OID 24450) +-- Name: property_of_property versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.property_of_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.property_of_property_vt', 'true'); + +-- +-- TOC entry 6028 (class 2620 OID 22361) +-- Name: property_profile_view_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.property_profile_view_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.property_profile_view_vt', 'true'); + +-- +-- TOC entry 6033 (class 2620 OID 22363) +-- Name: system_type_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.system_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.system_type_vt', 'true'); + +-- +-- TOC entry 6039 (class 2620 OID 22358) +-- Name: text_property_deprecated versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.text_property_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'data_for_history.text_property_vt', 'true'); + +-- +-- TOC entry 6104 (class 2620 OID 22366) +-- Name: v_text_property _02_find_or_create; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER _02_find_or_create + INSTEAD OF INSERT ON information.v_text_property + FOR EACH ROW + EXECUTE FUNCTION information.v_text_property_find_or_create(); + +-- +-- TOC entry 6040 (class 2620 OID 22371) +-- Name: appellation create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6069 (class 2620 OID 22370) +-- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6047 (class 2620 OID 22374) +-- Name: _backup_entity_association creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information._backup_entity_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6041 (class 2620 OID 22373) +-- Name: appellation creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6202 (class 2620 OID 23165) +-- Name: dimension creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6261 (class 2620 OID 24412) +-- Name: lang_string creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6051 (class 2620 OID 22379) +-- Name: language creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.language + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6055 (class 2620 OID 22375) +-- Name: persistent_item_backup creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.persistent_item_backup + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6060 (class 2620 OID 22381) +-- Name: place creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.place + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6288 (class 2620 OID 24655) +-- Name: resource creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.resource + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6064 (class 2620 OID 24381) +-- Name: statement creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.statement + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 5900 (class 2620 OID 22377) +-- Name: temporal_entity_backup creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.temporal_entity_backup + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6070 (class 2620 OID 22378) +-- Name: text_property creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6076 (class 2620 OID 22380) +-- Name: time_primitive creation_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6048 (class 2620 OID 22386) +-- Name: _backup_entity_association insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information._backup_entity_association + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6042 (class 2620 OID 22385) +-- Name: appellation insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6203 (class 2620 OID 23166) +-- Name: dimension insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6262 (class 2620 OID 24413) +-- Name: lang_string insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6052 (class 2620 OID 22391) +-- Name: language insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.language + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6056 (class 2620 OID 22387) +-- Name: persistent_item_backup insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.persistent_item_backup + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6061 (class 2620 OID 22393) +-- Name: place insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.place + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6289 (class 2620 OID 24656) +-- Name: resource insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.resource + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6065 (class 2620 OID 22388) +-- Name: statement insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.statement + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 5901 (class 2620 OID 22389) +-- Name: temporal_entity_backup insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.temporal_entity_backup + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6071 (class 2620 OID 22390) +-- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6077 (class 2620 OID 22392) +-- Name: time_primitive insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6049 (class 2620 OID 22398) +-- Name: _backup_entity_association last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information._backup_entity_association + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6043 (class 2620 OID 22397) +-- Name: appellation last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6204 (class 2620 OID 23167) +-- Name: dimension last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6263 (class 2620 OID 24414) +-- Name: lang_string last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6053 (class 2620 OID 22403) +-- Name: language last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.language + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6057 (class 2620 OID 22399) +-- Name: persistent_item_backup last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.persistent_item_backup + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6062 (class 2620 OID 22405) +-- Name: place last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.place + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6290 (class 2620 OID 24657) +-- Name: resource last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.resource + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6066 (class 2620 OID 24382) +-- Name: statement last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.statement + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 5902 (class 2620 OID 22401) +-- Name: temporal_entity_backup last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.temporal_entity_backup + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6072 (class 2620 OID 22402) +-- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6078 (class 2620 OID 22404) +-- Name: time_primitive last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6058 (class 2620 OID 24516) +-- Name: persistent_item_backup notify_modification; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON information.persistent_item_backup + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6291 (class 2620 OID 24664) +-- Name: resource notify_modification; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON information.resource + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6067 (class 2620 OID 24515) +-- Name: statement notify_modification; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON information.statement + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 5903 (class 2620 OID 24517) +-- Name: temporal_entity_backup notify_modification; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON information.temporal_entity_backup + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6206 (class 2620 OID 23181) +-- Name: v_dimension on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_dimension + FOR EACH ROW + EXECUTE FUNCTION information.v_dimension_find_or_create(); + +-- +-- TOC entry 6267 (class 2620 OID 24426) +-- Name: v_lang_string on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_lang_string + FOR EACH ROW + EXECUTE FUNCTION information.v_lang_string_find_or_create(); + +-- +-- TOC entry 6089 (class 2620 OID 22411) +-- Name: v_language on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_language + FOR EACH ROW + EXECUTE FUNCTION information.v_language_find_or_create(); + +-- +-- TOC entry 6103 (class 2620 OID 22412) +-- Name: v_place on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_place + FOR EACH ROW + EXECUTE FUNCTION information.v_place_find_or_create(); + +-- +-- TOC entry 6293 (class 2620 OID 24701) +-- Name: v_statement on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_statement + FOR EACH ROW + EXECUTE FUNCTION information.v_statement_find_or_create(); + +-- +-- TOC entry 6207 (class 2620 OID 23211) +-- Name: v_time_primitive on_insert; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON information.v_time_primitive + FOR EACH ROW + EXECUTE FUNCTION information.v_time_primitive_find_or_create(); + +-- +-- TOC entry 6044 (class 2620 OID 22417) +-- Name: appellation sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 6264 (class 2620 OID 24407) +-- Name: lang_string sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 6073 (class 2620 OID 22416) +-- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 6045 (class 2620 OID 22421) +-- Name: appellation update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6265 (class 2620 OID 24406) +-- Name: lang_string update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6074 (class 2620 OID 22420) +-- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6050 (class 2620 OID 22423) +-- Name: _backup_entity_association versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information._backup_entity_association + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.entity_association_vt', 'true'); + +-- +-- TOC entry 6046 (class 2620 OID 22433) +-- Name: appellation versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.appellation_vt', 'true'); + +-- +-- TOC entry 6205 (class 2620 OID 23173) +-- Name: dimension versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.dimension_vt', 'true'); + +-- +-- TOC entry 6266 (class 2620 OID 24420) +-- Name: lang_string versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.lang_string_vt', 'true'); + +-- +-- TOC entry 6054 (class 2620 OID 22424) +-- Name: language versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.language + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.language_vt', 'true'); + +-- +-- TOC entry 6059 (class 2620 OID 22425) +-- Name: persistent_item_backup versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.persistent_item_backup + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.persistent_item_vt', 'true'); + +-- +-- TOC entry 6063 (class 2620 OID 22428) +-- Name: place versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.place + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.place_vt', 'true'); + +-- +-- TOC entry 6292 (class 2620 OID 24663) +-- Name: resource versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.resource + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.resource_vt', 'true'); + +-- +-- TOC entry 6068 (class 2620 OID 24511) +-- Name: statement versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.statement + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.statement_vt', 'true'); + +-- +-- TOC entry 5904 (class 2620 OID 22427) +-- Name: temporal_entity_backup versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.temporal_entity_backup + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.temporal_entity_vt', 'true'); + +-- +-- TOC entry 6075 (class 2620 OID 22432) +-- Name: text_property versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.text_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.text_property_vt', 'true'); + +-- +-- TOC entry 6079 (class 2620 OID 22429) +-- Name: time_primitive versioning_trigger; Type: TRIGGER; Schema: information; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'information.time_primitive_vt', 'true'); + +-- +-- TOC entry 6122 (class 2620 OID 24969) +-- Name: project add_entity_preview_partition; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER add_entity_preview_partition + BEFORE INSERT ON projects.project + FOR EACH ROW + EXECUTE FUNCTION projects.add_entity_preview_partition(); + +-- +-- TOC entry 6080 (class 2620 OID 24266) +-- Name: info_proj_rel after_epr_upsert; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER after_epr_upsert + AFTER INSERT OR UPDATE ON projects.info_proj_rel + FOR EACH STATEMENT + EXECUTE FUNCTION war.after_info_proj_rel_upsert(); + +-- +-- TOC entry 6136 (class 2620 OID 24268) +-- Name: text_property after_update_or_insert_of_class_label; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER after_update_or_insert_of_class_label + AFTER INSERT OR UPDATE ON projects.text_property + FOR EACH ROW + WHEN((new.fk_dfh_class IS NOT NULL)) + EXECUTE FUNCTION war.notify__need_to_check_class_labels(); + +-- +-- TOC entry 6228 (class 2620 OID 24006) +-- Name: analysis create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6105 (class 2620 OID 22436) +-- Name: argument create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6090 (class 2620 OID 22445) +-- Name: class_field_config create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6111 (class 2620 OID 22444) +-- Name: dfh_class_proj_rel create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6234 (class 2620 OID 24076) +-- Name: dfh_profile_proj_rel create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6081 (class 2620 OID 22443) +-- Name: info_proj_rel create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6117 (class 2620 OID 22438) +-- Name: language create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.language + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6123 (class 2620 OID 22437) +-- Name: project create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.project + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6209 (class 2620 OID 23768) +-- Name: property_label_deprecated create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6130 (class 2620 OID 22441) +-- Name: query create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.query + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6137 (class 2620 OID 22439) +-- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6145 (class 2620 OID 22442) +-- Name: visual create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6229 (class 2620 OID 23997) +-- Name: analysis creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6106 (class 2620 OID 22450) +-- Name: argument creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6091 (class 2620 OID 22455) +-- Name: class_field_config creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6112 (class 2620 OID 22454) +-- Name: dfh_class_proj_rel creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6235 (class 2620 OID 24067) +-- Name: dfh_profile_proj_rel creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6279 (class 2620 OID 24543) +-- Name: entity_label_config creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.entity_label_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6082 (class 2620 OID 22453) +-- Name: info_proj_rel creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6118 (class 2620 OID 22446) +-- Name: language creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.language + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6124 (class 2620 OID 22448) +-- Name: project creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.project + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6210 (class 2620 OID 23759) +-- Name: property_label_deprecated creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6131 (class 2620 OID 22451) +-- Name: query creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.query + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6284 (class 2620 OID 24609) +-- Name: table_config creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.table_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6138 (class 2620 OID 22449) +-- Name: text_property creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6295 (class 2620 OID 24988) +-- Name: visibility_settings creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.visibility_settings + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6146 (class 2620 OID 22452) +-- Name: visual creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6230 (class 2620 OID 23998) +-- Name: analysis insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6107 (class 2620 OID 22459) +-- Name: argument insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6092 (class 2620 OID 22464) +-- Name: class_field_config insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6113 (class 2620 OID 22463) +-- Name: dfh_class_proj_rel insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6236 (class 2620 OID 24068) +-- Name: dfh_profile_proj_rel insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6280 (class 2620 OID 24544) +-- Name: entity_label_config insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.entity_label_config + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6083 (class 2620 OID 22462) +-- Name: info_proj_rel insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6125 (class 2620 OID 22457) +-- Name: project insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.project + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6211 (class 2620 OID 23760) +-- Name: property_label_deprecated insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6132 (class 2620 OID 22460) +-- Name: query insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.query + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6285 (class 2620 OID 24610) +-- Name: table_config insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.table_config + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6139 (class 2620 OID 22458) +-- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6296 (class 2620 OID 24989) +-- Name: visibility_settings insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.visibility_settings + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6147 (class 2620 OID 22461) +-- Name: visual insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6231 (class 2620 OID 23999) +-- Name: analysis last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6108 (class 2620 OID 22469) +-- Name: argument last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6093 (class 2620 OID 22474) +-- Name: class_field_config last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6114 (class 2620 OID 22473) +-- Name: dfh_class_proj_rel last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6237 (class 2620 OID 24069) +-- Name: dfh_profile_proj_rel last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6281 (class 2620 OID 24545) +-- Name: entity_label_config last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.entity_label_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6084 (class 2620 OID 24383) +-- Name: info_proj_rel last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6119 (class 2620 OID 22465) +-- Name: language last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.language + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6126 (class 2620 OID 22467) +-- Name: project last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.project + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6212 (class 2620 OID 23761) +-- Name: property_label_deprecated last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6133 (class 2620 OID 22470) +-- Name: query last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.query + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6286 (class 2620 OID 24611) +-- Name: table_config last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.table_config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6140 (class 2620 OID 22468) +-- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6297 (class 2620 OID 24990) +-- Name: visibility_settings last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.visibility_settings + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6148 (class 2620 OID 22471) +-- Name: visual last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6094 (class 2620 OID 24522) +-- Name: class_field_config notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.class_field_config + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6238 (class 2620 OID 24520) +-- Name: dfh_profile_proj_rel notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.dfh_profile_proj_rel + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6282 (class 2620 OID 24552) +-- Name: entity_label_config notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.entity_label_config + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6085 (class 2620 OID 24518) +-- Name: info_proj_rel notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.info_proj_rel + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6127 (class 2620 OID 24513) +-- Name: project notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.project + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6141 (class 2620 OID 24514) +-- Name: text_property notify_modification; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON projects.text_property + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6294 (class 2620 OID 24742) +-- Name: v_info_proj_rel on_insert; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER on_insert + INSTEAD OF INSERT ON projects.v_info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION projects.v_info_proj_rel_update_or_create(); + +-- +-- TOC entry 6086 (class 2620 OID 24384) +-- Name: info_proj_rel on_upsert; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER on_upsert + BEFORE INSERT OR UPDATE ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.evpr_fk_entity_fk_entity_version(); + +-- +-- TOC entry 6142 (class 2620 OID 22477) +-- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 6232 (class 2620 OID 24007) +-- Name: analysis update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6109 (class 2620 OID 22478) +-- Name: argument update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6095 (class 2620 OID 22487) +-- Name: class_field_config update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6115 (class 2620 OID 22486) +-- Name: dfh_class_proj_rel update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6239 (class 2620 OID 24077) +-- Name: dfh_profile_proj_rel update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6087 (class 2620 OID 24385) +-- Name: info_proj_rel update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6120 (class 2620 OID 22480) +-- Name: language update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.language + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6128 (class 2620 OID 22479) +-- Name: project update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.project + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6213 (class 2620 OID 23769) +-- Name: property_label_deprecated update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6134 (class 2620 OID 22483) +-- Name: query update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.query + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6143 (class 2620 OID 22481) +-- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6149 (class 2620 OID 22484) +-- Name: visual update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6233 (class 2620 OID 24005) +-- Name: analysis versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.analysis + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.analysis_vt', 'true'); + +-- +-- TOC entry 6110 (class 2620 OID 22488) +-- Name: argument versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.argument + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.argument_vt', 'true'); + +-- +-- TOC entry 6096 (class 2620 OID 22497) +-- Name: class_field_config versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.class_field_config + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.class_field_config_vt', 'true'); + +-- +-- TOC entry 6116 (class 2620 OID 22496) +-- Name: dfh_class_proj_rel versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.dfh_class_proj_rel + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.dfh_class_proj_rel_vt', 'true'); + +-- +-- TOC entry 6240 (class 2620 OID 24075) +-- Name: dfh_profile_proj_rel versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.dfh_profile_proj_rel + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.dfh_profile_proj_rel_vt', 'true'); + +-- +-- TOC entry 6283 (class 2620 OID 24551) +-- Name: entity_label_config versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.entity_label_config + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.entity_label_config_vt', 'true'); + +-- +-- TOC entry 6088 (class 2620 OID 24386) +-- Name: info_proj_rel versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.info_proj_rel_vt', 'true'); + +-- +-- TOC entry 6121 (class 2620 OID 22490) +-- Name: language versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.language + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.language_vt', 'true'); + +-- +-- TOC entry 6129 (class 2620 OID 22489) +-- Name: project versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.project + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.project_vt', 'true'); + +-- +-- TOC entry 6214 (class 2620 OID 23767) +-- Name: property_label_deprecated versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.property_label_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.property_label_vt', 'true'); + +-- +-- TOC entry 6135 (class 2620 OID 22493) +-- Name: query versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.query + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.query_vt', 'true'); + +-- +-- TOC entry 6287 (class 2620 OID 24617) +-- Name: table_config versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.table_config + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.table_config_vt', 'true'); + +-- +-- TOC entry 6144 (class 2620 OID 22491) +-- Name: text_property versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.text_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.text_property_vt', 'true'); + +-- +-- TOC entry 6298 (class 2620 OID 24996) +-- Name: visibility_settings versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.visibility_settings + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.visibility_settings_vt', 'true'); + +-- +-- TOC entry 6150 (class 2620 OID 22494) +-- Name: visual versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON projects.visual + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'projects.visual_vt', 'true'); + +-- +-- TOC entry 6151 (class 2620 OID 22498) +-- Name: account_project_rel create_entity_version_key; Type: TRIGGER; Schema: public; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON public.account_project_rel + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6152 (class 2620 OID 22499) +-- Name: account_project_rel update_entity_version_key; Type: TRIGGER; Schema: public; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON public.account_project_rel + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6153 (class 2620 OID 22500) +-- Name: account_project_rel versioning_trigger; Type: TRIGGER; Schema: public; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON public.account_project_rel + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'public.account_project_rel_vt', 'true'); + +-- +-- TOC entry 6222 (class 2620 OID 23975) +-- Name: analysis_type_deprecated create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6154 (class 2620 OID 22505) +-- Name: app_context create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6097 (class 2620 OID 22502) +-- Name: class_field create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6160 (class 2620 OID 22503) +-- Name: class_field_property_rel create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6166 (class 2620 OID 22504) +-- Name: class_has_type_property create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6172 (class 2620 OID 22506) +-- Name: system_relevant_class create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6178 (class 2620 OID 22507) +-- Name: system_relevant_type create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6184 (class 2620 OID 22501) +-- Name: system_type create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6223 (class 2620 OID 23966) +-- Name: analysis_type_deprecated creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6155 (class 2620 OID 22509) +-- Name: app_context creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6098 (class 2620 OID 22510) +-- Name: class_field creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6161 (class 2620 OID 22511) +-- Name: class_field_property_rel creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6167 (class 2620 OID 22512) +-- Name: class_has_type_property creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6272 (class 2620 OID 24502) +-- Name: config creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6173 (class 2620 OID 22513) +-- Name: system_relevant_class creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6179 (class 2620 OID 22514) +-- Name: system_relevant_type creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6185 (class 2620 OID 22508) +-- Name: system_type creation_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6224 (class 2620 OID 23967) +-- Name: analysis_type_deprecated insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6156 (class 2620 OID 22516) +-- Name: app_context insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6099 (class 2620 OID 22517) +-- Name: class_field insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6162 (class 2620 OID 22518) +-- Name: class_field_property_rel insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6168 (class 2620 OID 22519) +-- Name: class_has_type_property insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6273 (class 2620 OID 24503) +-- Name: config insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.config + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6174 (class 2620 OID 22520) +-- Name: system_relevant_class insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6180 (class 2620 OID 22521) +-- Name: system_relevant_type insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6186 (class 2620 OID 22515) +-- Name: system_type insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6225 (class 2620 OID 23968) +-- Name: analysis_type_deprecated last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6157 (class 2620 OID 22523) +-- Name: app_context last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6100 (class 2620 OID 22524) +-- Name: class_field last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6163 (class 2620 OID 22525) +-- Name: class_field_property_rel last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6169 (class 2620 OID 22526) +-- Name: class_has_type_property last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6274 (class 2620 OID 24504) +-- Name: config last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.config + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6175 (class 2620 OID 22527) +-- Name: system_relevant_class last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6181 (class 2620 OID 22528) +-- Name: system_relevant_type last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6187 (class 2620 OID 22522) +-- Name: system_type last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6275 (class 2620 OID 24783) +-- Name: config notify_modification; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON system.config + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 6226 (class 2620 OID 23976) +-- Name: analysis_type_deprecated update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6158 (class 2620 OID 22533) +-- Name: app_context update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6101 (class 2620 OID 22530) +-- Name: class_field update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6164 (class 2620 OID 22531) +-- Name: class_field_property_rel update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6170 (class 2620 OID 22532) +-- Name: class_has_type_property update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6176 (class 2620 OID 22534) +-- Name: system_relevant_class update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6182 (class 2620 OID 22535) +-- Name: system_relevant_type update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6188 (class 2620 OID 22529) +-- Name: system_type update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6227 (class 2620 OID 23974) +-- Name: analysis_type_deprecated versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.analysis_type_deprecated + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.analysis_type_vt', 'true'); + +-- +-- TOC entry 6159 (class 2620 OID 22540) +-- Name: app_context versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.app_context + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.app_context_vt', 'true'); + +-- +-- TOC entry 6102 (class 2620 OID 22537) +-- Name: class_field versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.class_field + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.class_field_vt', 'true'); + +-- +-- TOC entry 6165 (class 2620 OID 22538) +-- Name: class_field_property_rel versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.class_field_property_rel + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.class_field_property_rel_vt', 'true'); + +-- +-- TOC entry 6171 (class 2620 OID 22539) +-- Name: class_has_type_property versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.class_has_type_property + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.class_has_type_property_vt', 'true'); + +-- +-- TOC entry 6276 (class 2620 OID 24510) +-- Name: config versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.config + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.config_vt', 'true'); + +-- +-- TOC entry 6177 (class 2620 OID 22541) +-- Name: system_relevant_class versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.system_relevant_class + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.system_relevant_class_vt', 'true'); + +-- +-- TOC entry 6183 (class 2620 OID 22542) +-- Name: system_relevant_type versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.system_relevant_type + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.system_relevant_type_vt', 'true'); + +-- +-- TOC entry 6189 (class 2620 OID 22536) +-- Name: system_type versioning_trigger; Type: TRIGGER; Schema: system; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON system.system_type + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'system.system_type_vt', 'true'); + +-- +-- TOC entry 6215 (class 2620 OID 23854) +-- Name: quill_doc_cell create_entity_version_key; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER create_entity_version_key + BEFORE INSERT ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.create_entity_version_key(); + +-- +-- TOC entry 6216 (class 2620 OID 23855) +-- Name: quill_doc_cell creation_tmsp; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER creation_tmsp + BEFORE INSERT ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_creation(); + +-- +-- TOC entry 6217 (class 2620 OID 23858) +-- Name: quill_doc_cell insert_schema_table_name; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER insert_schema_table_name + BEFORE INSERT ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.insert_schema_table_name(); + +-- +-- TOC entry 6218 (class 2620 OID 23856) +-- Name: quill_doc_cell last_modification_tmsp; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6219 (class 2620 OID 23860) +-- Name: quill_doc_cell sync_quill_doc_and_string; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER sync_quill_doc_and_string + BEFORE INSERT OR UPDATE ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.text__sync_quill_doc_and_string(); + +-- +-- TOC entry 6220 (class 2620 OID 23857) +-- Name: quill_doc_cell update_entity_version_key; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER update_entity_version_key + BEFORE UPDATE ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION commons.update_entity_version_key(); + +-- +-- TOC entry 6221 (class 2620 OID 23847) +-- Name: quill_doc_cell versioning_trigger; Type: TRIGGER; Schema: tables; Owner: - +-- +CREATE TRIGGER versioning_trigger + BEFORE INSERT OR DELETE OR UPDATE ON tables.quill_doc_cell + FOR EACH ROW + EXECUTE FUNCTION public.versioning('sys_period', 'tables.quill_doc_cell_vt', 'true'); + +-- +-- TOC entry 6277 (class 2620 OID 24530) +-- Name: class_preview last_modification_tmsp; Type: TRIGGER; Schema: war; Owner: - +-- +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE ON war.class_preview + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +-- +-- TOC entry 6278 (class 2620 OID 24531) +-- Name: class_preview notify_modification; Type: TRIGGER; Schema: war; Owner: - +-- +CREATE TRIGGER notify_modification + AFTER INSERT OR DELETE OR UPDATE ON war.class_preview + FOR EACH STATEMENT + EXECUTE FUNCTION commons.notify_modification_trigger(); + +-- +-- TOC entry 5789 (class 2606 OID 23333) +-- Name: avatar_vt avatar_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar_vt + ADD CONSTRAINT avatar_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5790 (class 2606 OID 23238) +-- Name: avatar_vt avatar_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.avatar_vt + ADD CONSTRAINT avatar_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5791 (class 2606 OID 23343) +-- Name: chunk_vt chunk_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk_vt + ADD CONSTRAINT chunk_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5792 (class 2606 OID 23248) +-- Name: chunk_vt chunk_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.chunk_vt + ADD CONSTRAINT chunk_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5794 (class 2606 OID 23348) +-- Name: class_column_mapping_vt class_column_mapping_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping_vt + ADD CONSTRAINT class_column_mapping_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5795 (class 2606 OID 23253) +-- Name: class_column_mapping_vt class_column_mapping_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping_vt + ADD CONSTRAINT class_column_mapping_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5793 (class 2606 OID 22571) +-- Name: class_column_mapping class_column_rel_fk_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.class_column_mapping + ADD CONSTRAINT class_column_rel_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5796 (class 2606 OID 23078) +-- Name: column column_fk_column_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT column_fk_column_type_fkey FOREIGN KEY (fk_column_content_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5797 (class 2606 OID 22576) +-- Name: column column_fk_data_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT column_fk_data_type_fkey FOREIGN KEY (fk_data_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5798 (class 2606 OID 22581) +-- Name: column column_fk_digital_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT column_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); + +-- +-- TOC entry 5799 (class 2606 OID 23088) +-- Name: column column_fk_original_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data."column" + ADD CONSTRAINT column_fk_original_column_fkey FOREIGN KEY (fk_original_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5800 (class 2606 OID 23083) +-- Name: column_vt column_vt_fk_column_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.column_vt + ADD CONSTRAINT column_vt_fk_column_type_fkey FOREIGN KEY (fk_column_content_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5801 (class 2606 OID 23353) +-- Name: column_vt column_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.column_vt + ADD CONSTRAINT column_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5802 (class 2606 OID 23093) +-- Name: column_vt column_vt_fk_original_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.column_vt + ADD CONSTRAINT column_vt_fk_original_column_fkey FOREIGN KEY (fk_original_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5803 (class 2606 OID 23258) +-- Name: column_vt column_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.column_vt + ADD CONSTRAINT column_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5804 (class 2606 OID 22591) +-- Name: data_association data_association_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association + ADD CONSTRAINT data_association_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5836 (class 2606 OID 23358) +-- Name: data_association_mapping_vt data_association_mapping_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping_vt + ADD CONSTRAINT data_association_mapping_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5837 (class 2606 OID 23263) +-- Name: data_association_mapping_vt data_association_mapping_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping_vt + ADD CONSTRAINT data_association_mapping_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5805 (class 2606 OID 23363) +-- Name: data_association_vt data_association_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_vt + ADD CONSTRAINT data_association_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5806 (class 2606 OID 23268) +-- Name: data_association_vt data_association_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_vt + ADD CONSTRAINT data_association_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5807 (class 2606 OID 22596) +-- Name: digital digital_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.digital + ADD CONSTRAINT digital_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5808 (class 2606 OID 23368) +-- Name: digital_vt digital_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.digital_vt + ADD CONSTRAINT digital_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5809 (class 2606 OID 23273) +-- Name: digital_vt digital_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.digital_vt + ADD CONSTRAINT digital_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5786 (class 2606 OID 23328) +-- Name: entity entity_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.entity + ADD CONSTRAINT entity_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5787 (class 2606 OID 22601) +-- Name: entity entity_fk_namespace_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.entity + ADD CONSTRAINT entity_fk_namespace_fkey FOREIGN KEY (fk_namespace) REFERENCES data.namespace(pk_entity); + +-- +-- TOC entry 5788 (class 2606 OID 23233) +-- Name: entity entity_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.entity + ADD CONSTRAINT entity_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5810 (class 2606 OID 22611) +-- Name: factoid_mapping factoid_class_digital_rel_fk_digital_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping + ADD CONSTRAINT factoid_class_digital_rel_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); + +-- +-- TOC entry 5811 (class 2606 OID 23373) +-- Name: factoid_mapping_vt factoid_mapping_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping_vt + ADD CONSTRAINT factoid_mapping_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5812 (class 2606 OID 23278) +-- Name: factoid_mapping_vt factoid_mapping_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_mapping_vt + ADD CONSTRAINT factoid_mapping_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5813 (class 2606 OID 22621) +-- Name: factoid_property_mapping factoid_property_column_rel_fk_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ADD CONSTRAINT factoid_property_column_rel_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5814 (class 2606 OID 22626) +-- Name: factoid_property_mapping factoid_property_column_rel_fk_factoid_class_digital_rel_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ADD CONSTRAINT factoid_property_column_rel_fk_factoid_class_digital_rel_fkey FOREIGN KEY (fk_factoid_mapping) REFERENCES data.factoid_mapping(pk_entity); + +-- +-- TOC entry 5815 (class 2606 OID 22631) +-- Name: factoid_property_mapping factoid_property_column_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping + ADD CONSTRAINT factoid_property_column_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5818 (class 2606 OID 22636) +-- Name: factoid_role factoid_role_fk_domain_factoid_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ADD CONSTRAINT factoid_role_fk_domain_factoid_fkey FOREIGN KEY (fk_domain_factoid) REFERENCES data.factoid(pk_entity); + +-- +-- TOC entry 5819 (class 2606 OID 22641) +-- Name: factoid_role factoid_role_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role + ADD CONSTRAINT factoid_role_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5816 (class 2606 OID 23378) +-- Name: factoid_property_mapping_vt factoid_role_mapping_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping_vt + ADD CONSTRAINT factoid_role_mapping_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5817 (class 2606 OID 23283) +-- Name: factoid_property_mapping_vt factoid_role_mapping_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_property_mapping_vt + ADD CONSTRAINT factoid_role_mapping_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5820 (class 2606 OID 23383) +-- Name: factoid_role_vt factoid_role_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role_vt + ADD CONSTRAINT factoid_role_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5821 (class 2606 OID 23288) +-- Name: factoid_role_vt factoid_role_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_role_vt + ADD CONSTRAINT factoid_role_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5822 (class 2606 OID 23388) +-- Name: factoid_vt factoid_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_vt + ADD CONSTRAINT factoid_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5823 (class 2606 OID 23293) +-- Name: factoid_vt factoid_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.factoid_vt + ADD CONSTRAINT factoid_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5824 (class 2606 OID 22656) +-- Name: namespace namespace_fk_project_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ADD CONSTRAINT namespace_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5825 (class 2606 OID 22661) +-- Name: namespace namespace_fk_root_namespace_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace + ADD CONSTRAINT namespace_fk_root_namespace_fkey FOREIGN KEY (fk_root_namespace) REFERENCES data.namespace(pk_entity); + +-- +-- TOC entry 5826 (class 2606 OID 23393) +-- Name: namespace_vt namespace_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace_vt + ADD CONSTRAINT namespace_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5827 (class 2606 OID 23298) +-- Name: namespace_vt namespace_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.namespace_vt + ADD CONSTRAINT namespace_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5879 (class 2606 OID 23117) +-- Name: property_of_property property_of_property_fk_domain_data_association_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ADD CONSTRAINT property_of_property_fk_domain_data_association_fkey FOREIGN KEY (fk_domain_data_association) REFERENCES data.data_association(pk_entity); + +-- +-- TOC entry 5880 (class 2606 OID 23112) +-- Name: property_of_property property_of_property_fk_domain_factoid_role_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property + ADD CONSTRAINT property_of_property_fk_domain_factoid_role_fkey FOREIGN KEY (fk_domain_factoid_property) REFERENCES data.factoid_role(pk_entity); + +-- +-- TOC entry 5874 (class 2606 OID 23055) +-- Name: property_of_property_mapping property_of_property_mapping_fk_domain_data_association_ma_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ADD CONSTRAINT property_of_property_mapping_fk_domain_data_association_ma_fkey FOREIGN KEY (fk_domain_data_association_mapping) REFERENCES data.data_association_mapping(pk_entity); + +-- +-- TOC entry 5875 (class 2606 OID 23050) +-- Name: property_of_property_mapping property_of_property_mapping_fk_domain_factoid_role_mappin_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ADD CONSTRAINT property_of_property_mapping_fk_domain_factoid_role_mappin_fkey FOREIGN KEY (fk_domain_factoid_property_mapping) REFERENCES data.factoid_property_mapping(pk_entity); + +-- +-- TOC entry 5876 (class 2606 OID 23060) +-- Name: property_of_property_mapping property_of_property_mapping_fk_range_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping + ADD CONSTRAINT property_of_property_mapping_fk_range_column_fkey FOREIGN KEY (fk_range_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5877 (class 2606 OID 23398) +-- Name: property_of_property_mapping_vt property_of_property_mapping_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping_vt + ADD CONSTRAINT property_of_property_mapping_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5878 (class 2606 OID 23303) +-- Name: property_of_property_mapping_vt property_of_property_mapping_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_mapping_vt + ADD CONSTRAINT property_of_property_mapping_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5881 (class 2606 OID 23403) +-- Name: property_of_property_vt property_of_property_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_vt + ADD CONSTRAINT property_of_property_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5882 (class 2606 OID 23308) +-- Name: property_of_property_vt property_of_property_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.property_of_property_vt + ADD CONSTRAINT property_of_property_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5828 (class 2606 OID 22676) +-- Name: text_property text_property_fk_language_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ADD CONSTRAINT text_property_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5829 (class 2606 OID 22681) +-- Name: text_property text_property_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property + ADD CONSTRAINT text_property_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5830 (class 2606 OID 23413) +-- Name: text_property_vt text_property_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property_vt + ADD CONSTRAINT text_property_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5831 (class 2606 OID 23318) +-- Name: text_property_vt text_property_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.text_property_vt + ADD CONSTRAINT text_property_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5832 (class 2606 OID 22686) +-- Name: data_association_mapping value_association_columns_rel_fk_domain_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT value_association_columns_rel_fk_domain_column_fkey FOREIGN KEY (fk_domain_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5833 (class 2606 OID 22691) +-- Name: data_association_mapping value_association_columns_rel_fk_factoid_class_digital_rel_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT value_association_columns_rel_fk_factoid_class_digital_rel_fkey FOREIGN KEY (fk_factoid_mapping) REFERENCES data.factoid_mapping(pk_entity); + +-- +-- TOC entry 5834 (class 2606 OID 22696) +-- Name: data_association_mapping value_association_columns_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT value_association_columns_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5835 (class 2606 OID 22701) +-- Name: data_association_mapping value_association_columns_rel_fk_range_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.data_association_mapping + ADD CONSTRAINT value_association_columns_rel_fk_range_column_fkey FOREIGN KEY (fk_range_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5838 (class 2606 OID 22711) +-- Name: values_association values_association_fk_domain_chunk_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ADD CONSTRAINT values_association_fk_domain_chunk_fkey FOREIGN KEY (fk_domain_chunk) REFERENCES data.chunk(pk_entity); + +-- +-- TOC entry 5839 (class 2606 OID 22716) +-- Name: values_association values_association_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ADD CONSTRAINT values_association_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5840 (class 2606 OID 22726) +-- Name: values_association values_association_fk_range_chunk_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association + ADD CONSTRAINT values_association_fk_range_chunk_fkey FOREIGN KEY (fk_range_chunk) REFERENCES data.chunk(pk_entity); + +-- +-- TOC entry 5841 (class 2606 OID 23418) +-- Name: values_association_vt values_association_vt_fk_license_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association_vt + ADD CONSTRAINT values_association_vt_fk_license_fkey FOREIGN KEY (fk_license) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5842 (class 2606 OID 23323) +-- Name: values_association_vt values_association_vt_fk_publication_status_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - +-- +ALTER TABLE ONLY data.values_association_vt + ADD CONSTRAINT values_association_vt_fk_publication_status_fkey FOREIGN KEY (fk_publication_status) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5843 (class 2606 OID 22731) +-- Name: label_deprecated label_com_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ADD CONSTRAINT label_com_fk_system_type_fkey FOREIGN KEY (com_fk_system_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5844 (class 2606 OID 22736) +-- Name: label_deprecated label_inf_fk_language_fkey; Type: FK CONSTRAINT; Schema: data_for_history; Owner: - +-- +ALTER TABLE ONLY data_for_history.label_deprecated + ADD CONSTRAINT label_inf_fk_language_fkey FOREIGN KEY (inf_fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5883 (class 2606 OID 24665) +-- Name: dimension dimension_fk_measurement_unit_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.dimension + ADD CONSTRAINT dimension_fk_measurement_unit_fkey FOREIGN KEY (fk_measurement_unit) REFERENCES information.resource(pk_entity); + +-- +-- TOC entry 5893 (class 2606 OID 24399) +-- Name: lang_string lang_string_fk_language_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.lang_string + ADD CONSTRAINT lang_string_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5845 (class 2606 OID 22791) +-- Name: text_property text_property_fk_class_field_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ADD CONSTRAINT text_property_fk_class_field_fkey FOREIGN KEY (fk_class_field) REFERENCES system.class_field(pk_entity); + +-- +-- TOC entry 5846 (class 2606 OID 22796) +-- Name: text_property text_property_fk_language_constraint; Type: FK CONSTRAINT; Schema: information; Owner: - +-- +ALTER TABLE ONLY information.text_property + ADD CONSTRAINT text_property_fk_language_constraint FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5890 (class 2606 OID 24573) +-- Name: analysis analysis_fk_analysis_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ADD CONSTRAINT analysis_fk_analysis_type_fkey FOREIGN KEY (fk_analysis_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5891 (class 2606 OID 23985) +-- Name: analysis analysis_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.analysis + ADD CONSTRAINT analysis_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5851 (class 2606 OID 23135) +-- Name: argument argument_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.argument + ADD CONSTRAINT argument_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5853 (class 2606 OID 23140) +-- Name: argument_vt argument_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.argument_vt + ADD CONSTRAINT argument_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5852 (class 2606 OID 24670) +-- Name: argument assertion_fk_assertion_method_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.argument + ADD CONSTRAINT assertion_fk_assertion_method_type_fkey FOREIGN KEY (fk_argument_method_type) REFERENCES information.resource(pk_entity); + +-- +-- TOC entry 5848 (class 2606 OID 22846) +-- Name: class_field_config class_field_config_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ADD CONSTRAINT class_field_config_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5854 (class 2606 OID 22856) +-- Name: dfh_class_proj_rel dfh_class_proj_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_class_proj_rel + ADD CONSTRAINT dfh_class_proj_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5892 (class 2606 OID 24060) +-- Name: dfh_profile_proj_rel dfh_profile_proj_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.dfh_profile_proj_rel + ADD CONSTRAINT dfh_profile_proj_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5847 (class 2606 OID 22866) +-- Name: info_proj_rel info_proj_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.info_proj_rel + ADD CONSTRAINT info_proj_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5855 (class 2606 OID 23924) +-- Name: project project_fk_cloned_from_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT project_fk_cloned_from_project_fkey FOREIGN KEY (fk_cloned_from_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5856 (class 2606 OID 22886) +-- Name: project project_fk_creator_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT project_fk_creator_fkey FOREIGN KEY (fk_creator) REFERENCES public.account(id); + +-- +-- TOC entry 5857 (class 2606 OID 22891) +-- Name: project project_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT project_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5858 (class 2606 OID 22896) +-- Name: project project_fk_last_modifier_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.project + ADD CONSTRAINT project_fk_last_modifier_fkey FOREIGN KEY (fk_last_modifier) REFERENCES public.account(id); + +-- +-- TOC entry 5884 (class 2606 OID 23752) +-- Name: property_label_deprecated property_label_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ADD CONSTRAINT property_label_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5885 (class 2606 OID 23732) +-- Name: property_label_deprecated property_label_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ADD CONSTRAINT property_label_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5886 (class 2606 OID 23747) +-- Name: property_label_deprecated property_label_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.property_label_deprecated + ADD CONSTRAINT property_label_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5859 (class 2606 OID 23929) +-- Name: query query_fk_cloned_from_query_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ADD CONSTRAINT query_fk_cloned_from_query_fkey FOREIGN KEY (fk_cloned_from_query) REFERENCES projects.query(pk_entity); + +-- +-- TOC entry 5860 (class 2606 OID 22901) +-- Name: query query_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query + ADD CONSTRAINT query_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5861 (class 2606 OID 22906) +-- Name: query_vt query_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.query_vt + ADD CONSTRAINT query_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5895 (class 2606 OID 24597) +-- Name: table_config tables_config_account_id_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ADD CONSTRAINT tables_config_account_id_fkey FOREIGN KEY (account_id) REFERENCES public.account(id); + +-- +-- TOC entry 5896 (class 2606 OID 24602) +-- Name: table_config tables_config_fk_digital_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ADD CONSTRAINT tables_config_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); + +-- +-- TOC entry 5897 (class 2606 OID 24592) +-- Name: table_config tables_config_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.table_config + ADD CONSTRAINT tables_config_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5862 (class 2606 OID 22911) +-- Name: text_property text_property_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT text_property_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); + +-- +-- TOC entry 5863 (class 2606 OID 22916) +-- Name: text_property text_property_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.text_property + ADD CONSTRAINT text_property_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5849 (class 2606 OID 22926) +-- Name: class_field_config ui_context_config_fk_ui_context_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.class_field_config + ADD CONSTRAINT ui_context_config_fk_ui_context_fkey FOREIGN KEY (fk_app_context) REFERENCES system.app_context(pk_entity); + +-- +-- TOC entry 5899 (class 2606 OID 24981) +-- Name: visibility_settings visibility_settings_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visibility_settings + ADD CONSTRAINT visibility_settings_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5864 (class 2606 OID 22931) +-- Name: visual visual_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual + ADD CONSTRAINT visual_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5865 (class 2606 OID 22936) +-- Name: visual_vt visual_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - +-- +ALTER TABLE ONLY projects.visual_vt + ADD CONSTRAINT visual_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5866 (class 2606 OID 22941) +-- Name: accesstoken accesstoken_userid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.accesstoken + ADD CONSTRAINT accesstoken_userid_fkey FOREIGN KEY (userid) REFERENCES public.account(id); + +-- +-- TOC entry 5894 (class 2606 OID 24485) +-- Name: credential account_credential_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.credential + ADD CONSTRAINT account_credential_fkey FOREIGN KEY (accountid) REFERENCES public.account(id); + +-- +-- TOC entry 5867 (class 2606 OID 22946) +-- Name: account_project_rel account_project_rel_account_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account_project_rel + ADD CONSTRAINT account_project_rel_account_id_fkey FOREIGN KEY (account_id) REFERENCES public.account(id); + +-- +-- TOC entry 5868 (class 2606 OID 22951) +-- Name: account_project_rel account_project_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.account_project_rel + ADD CONSTRAINT account_project_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); + +-- +-- TOC entry 5869 (class 2606 OID 22961) +-- Name: rolemapping rolemapping_roleid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- +ALTER TABLE ONLY public.rolemapping + ADD CONSTRAINT rolemapping_roleid_fkey FOREIGN KEY (roleid) REFERENCES public.role(id); + +-- +-- TOC entry 5872 (class 2606 OID 22971) +-- Name: class_has_type_property class_has_type_property_fk_property_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_has_type_property + ADD CONSTRAINT class_has_type_property_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5850 (class 2606 OID 22976) +-- Name: class_field fk_system_type_ng_component_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field + ADD CONSTRAINT fk_system_type_ng_component_fkey FOREIGN KEY (fk_system_type_ng_component) REFERENCES system.system_type(pk_entity); + +-- +-- TOC entry 5870 (class 2606 OID 22981) +-- Name: class_field_property_rel property_set_property_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field_property_rel + ADD CONSTRAINT property_set_property_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); + +-- +-- TOC entry 5871 (class 2606 OID 22986) +-- Name: class_field_property_rel property_set_property_rel_fk_property_set_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.class_field_property_rel + ADD CONSTRAINT property_set_property_rel_fk_property_set_fkey FOREIGN KEY (fk_class_field) REFERENCES system.class_field(pk_entity); + +-- +-- TOC entry 5873 (class 2606 OID 24675) +-- Name: system_relevant_type system_relevant_type_fk_type_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - +-- +ALTER TABLE ONLY system.system_relevant_type + ADD CONSTRAINT system_relevant_type_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES information.resource(pk_entity); + +-- +-- TOC entry 5887 (class 2606 OID 23827) +-- Name: quill_doc_cell quill_doc_cell_fk_column_fkey; Type: FK CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ADD CONSTRAINT quill_doc_cell_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); + +-- +-- TOC entry 5888 (class 2606 OID 23832) +-- Name: quill_doc_cell quill_doc_cell_fk_digital_fkey; Type: FK CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ADD CONSTRAINT quill_doc_cell_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); + +-- +-- TOC entry 5889 (class 2606 OID 24642) +-- Name: quill_doc_cell quill_doc_cell_fk_row_fkey; Type: FK CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables.quill_doc_cell + ADD CONSTRAINT quill_doc_cell_fk_row_fkey FOREIGN KEY (fk_row) REFERENCES tables."row"(pk_row); + +-- +-- TOC entry 5898 (class 2606 OID 24631) +-- Name: row row_fk_digital_fkey; Type: FK CONSTRAINT; Schema: tables; Owner: - +-- +ALTER TABLE ONLY tables."row" + ADD CONSTRAINT row_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); + +-- +-- TOC entry 6470 (class 0 OID 0) +-- Dependencies: 6 +-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: - +-- +REVOKE USAGE ON SCHEMA public FROM PUBLIC; + +GRANT ALL ON SCHEMA public TO PUBLIC; + +-- Completed on 2024-05-29 13:48:57 CEST +-- +-- PostgreSQL database dump complete +-- diff --git a/database/migrations/sqls/20240529120605-pgwar-entity-down.sql b/database/migrations/sqls/20240529120605-pgwar-entity-down.sql new file mode 100644 index 000000000..f9257ca9d --- /dev/null +++ b/database/migrations/sqls/20240529120605-pgwar-entity-down.sql @@ -0,0 +1,29 @@ +-- Revert trigger and trigger function for after_delete_resource +------------------------------------------------------------- +DROP TRIGGER after_delete_resource ON information.resource; + +DROP FUNCTION pgwar.after_delete_resource; + +-- Revert triggers and trigger function for after_upsert_resource +-------------------------------------------------------------- +DROP TRIGGER after_update_resource ON information.resource; + +DROP TRIGGER after_insert_resource ON information.resource; + +DROP FUNCTION pgwar.after_upsert_resource; + +-- Revert function to update pgwar from resource +---------------------------------------------- +DROP FUNCTION pgwar.update_from_resource; + +-- Revert function to upsert fk_project, pk_entity, fk_class on pgwar.entity_preview +----------------------------------------------------------------------------- +DROP FUNCTION pgwar.upsert_entity_preview_fk_class; + +-- Revert table pgwar.entity_preview +------------------------------ +DROP TABLE pgwar.entity_preview; + +-- Revert schema pgwar +------------------------------ +DROP SCHEMA pgwar; \ No newline at end of file diff --git a/database/migrations/sqls/20240529120605-pgwar-entity-up.sql b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql new file mode 100644 index 000000000..127e41bde --- /dev/null +++ b/database/migrations/sqls/20240529120605-pgwar-entity-up.sql @@ -0,0 +1,170 @@ +-- SCHEMA pgwar +------------------------------ +CREATE SCHEMA pgwar; + +-- Table pgwar.entity_preview +------------------------------ +CREATE TABLE IF NOT EXISTS pgwar.entity_preview( + pk_entity integer NOT NULL, + fk_project integer NOT NULL DEFAULT 0, + fk_class integer NOT NULL, + entity_type text, + class_label character varying, + entity_label text, + full_text text, + ts_vector tsvector, + type_label text, + fk_type integer, + time_span jsonb, + first_second bigint, + last_second bigint, + parent_classes jsonb, + ancestor_classes jsonb, + tmsp_fk_class_modification timestamp with time zone, + tmsp_fk_type_modification timestamp with time zone, + tmsp_entity_label_modification timestamp with time zone, + tmsp_last_modification timestamp with time zone, + CONSTRAINT entity_preview_pkey PRIMARY KEY (pk_entity, fk_project) +); + +-- Function to upsert fk_project, pk_entity, fk_class on pgwar.entity_preview +----------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.upsert_entity_preview_fk_class(entity_id int, project_id int, class_id int) + RETURNS VOID + AS $$ +BEGIN + INSERT INTO pgwar.entity_preview(pk_entity, fk_project, fk_class, tmsp_fk_class_modification) + VALUES(entity_id, project_id, class_id, CURRENT_TIMESTAMP) + ON CONFLICT(pk_entity, fk_project) + DO UPDATE SET + -- ... or update the fk_class + fk_class = EXCLUDED.fk_class, + tmsp_fk_class_modification = CURRENT_TIMESTAMP + WHERE + -- ... where it is distinct from previous value + entity_preview.fk_class IS DISTINCT FROM EXCLUDED.fk_class; +END; +$$ +LANGUAGE plpgsql; + + + +-- Function to update pgwar from resource +---------------------------------------------- +CREATE FUNCTION pgwar.update_from_resource(NEW_RES information.resource) + RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + + + -- if it is in at least one project ... + IF EXISTS( + SELECT + pk_entity + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW_RES.pk_entity + AND is_in_project IS TRUE) THEN + -- ... insert missing project entities or update existing, in case fk_class differs + PERFORM + pgwar.upsert_entity_preview_fk_class(fk_entity, fk_project, NEW_RES.fk_class) + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW_RES.pk_entity + AND is_in_project IS TRUE; + -- ... insert missing community entity or update existing, in case fk_class differs + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_RES.pk_entity, 0, NEW_RES.fk_class); + END IF; + -- if hidden for toolbox community ... + IF(NEW_RES.community_visibility ->> 'toolbox')::bool IS FALSE THEN + -- ... delete potentially unallowed community entities + DELETE FROM pgwar.entity_preview + WHERE fk_project = 0 + AND pk_entity = NEW_RES.pk_entity; + END IF; +END; +$$; + +-- Trigger function after_upsert_resource +---------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_resource() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + -- insert project entities + INSERT INTO pgwar.entity_preview(pk_entity, fk_project, fk_class, tmsp_fk_class_modification) + SELECT newtab.pk_entity, ipr.fk_project, newtab.fk_class, CURRENT_TIMESTAMP + FROM newtab, + projects.info_proj_rel ipr + WHERE ipr.fk_entity = newtab.pk_entity + AND ipr.is_in_project IS TRUE + ON CONFLICT(pk_entity, fk_project) + DO UPDATE SET + -- ... or update the fk_class + fk_class = EXCLUDED.fk_class, + tmsp_fk_class_modification = CURRENT_TIMESTAMP + WHERE + -- ... where it is distinct from previous value + entity_preview.fk_class IS DISTINCT FROM EXCLUDED.fk_class; + + -- insert community entities + INSERT INTO pgwar.entity_preview(pk_entity, fk_project, fk_class, tmsp_fk_class_modification) + SELECT DISTINCT ON (newtab.pk_entity) + newtab.pk_entity, 0, newtab.fk_class, CURRENT_TIMESTAMP + FROM newtab, + projects.info_proj_rel ipr + WHERE ipr.fk_entity = newtab.pk_entity + AND ipr.is_in_project IS TRUE + ON CONFLICT(pk_entity, fk_project) + DO UPDATE SET + -- ... or update the fk_class + fk_class = EXCLUDED.fk_class, + tmsp_fk_class_modification = CURRENT_TIMESTAMP + WHERE + -- ... where it is distinct from previous value + entity_preview.fk_class IS DISTINCT FROM EXCLUDED.fk_class; + + -- delete potentially unallowed community entities + DELETE FROM pgwar.entity_preview ep + USING newtab + WHERE (newtab.community_visibility ->> 'toolbox')::bool IS FALSE + AND newtab.pk_entity = ep.pk_entity + AND ep.fk_project = 0; + + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_insert_resource + AFTER INSERT ON information.resource + REFERENCING NEW TABLE AS newtab + EXECUTE FUNCTION pgwar.after_upsert_resource(); + +CREATE TRIGGER after_update_resource + AFTER UPDATE ON information.resource + REFERENCING NEW TABLE AS newtab + EXECUTE FUNCTION pgwar.after_upsert_resource(); + +-- Trigger function after_delete_resource +---------------------------------------------- +CREATE FUNCTION pgwar.after_delete_resource() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + DELETE FROM pgwar.entity_preview + WHERE pk_entity = OLD.pk_entity; + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_delete_resource + AFTER DELETE ON information.resource + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_resource(); + diff --git a/database/migrations/sqls/20240530193851-pgwar-statements-down.sql b/database/migrations/sqls/20240530193851-pgwar-statements-down.sql new file mode 100644 index 000000000..ea352f283 --- /dev/null +++ b/database/migrations/sqls/20240530193851-pgwar-statements-down.sql @@ -0,0 +1,63 @@ +------ Drop triggers after upsert and delete on literal tables --------------------------------- +--------------------------------------------------------------------------------------------- +DROP TRIGGER IF EXISTS after_upsert_appellation ON information.appellation; +DROP TRIGGER IF EXISTS after_upsert_dimension ON information.dimension; +DROP TRIGGER IF EXISTS after_upsert_lang_string ON information.lang_string; +DROP TRIGGER IF EXISTS after_upsert_language ON information.language; +DROP TRIGGER IF EXISTS after_upsert_place ON information.place; +DROP TRIGGER IF EXISTS after_upsert_time_primitive ON information.time_primitive; +DROP TRIGGER IF EXISTS after_upsert_cell ON tables.cell; + +DROP TRIGGER IF EXISTS after_delete_appellation ON information.appellation; +DROP TRIGGER IF EXISTS after_delete_dimension ON information.dimension; +DROP TRIGGER IF EXISTS after_delete_lang_string ON information.lang_string; +DROP TRIGGER IF EXISTS after_delete_language ON information.language; +DROP TRIGGER IF EXISTS after_delete_place ON information.place; +DROP TRIGGER IF EXISTS after_delete_time_primitive ON information.time_primitive; +DROP TRIGGER IF EXISTS after_delete_cell ON tables.cell; + +DROP TRIGGER IF EXISTS after_upsert_statement ON information.statement; +DROP TRIGGER IF EXISTS after_delete_statement ON information.statement; + +------ Drop trigger functions ----------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +DROP FUNCTION IF EXISTS pgwar.after_upsert_object_info(); +DROP FUNCTION IF EXISTS pgwar.after_upsert_object_tables_cell(); +DROP FUNCTION IF EXISTS pgwar.after_delete_object_info(); +DROP FUNCTION IF EXISTS pgwar.after_delete_object_tables_cell(); +DROP FUNCTION IF EXISTS pgwar.after_upsert_statement(); +DROP FUNCTION IF EXISTS pgwar.after_delete_statement(); + +------ Drop upsert_statement function --------------------------------------------------------- +--------------------------------------------------------------------------------------------- +DROP FUNCTION IF EXISTS pgwar.upsert_statement(pgwar.statement); + +------ Drop pgwar.statement table ------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +DROP TABLE IF EXISTS pgwar.statement; + +------ Drop custom functions ------------------------------------------------------------------ +--------------------------------------------------------------------------------------------- +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.appellation); +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.place); +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.language); +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.time_primitive); +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.lang_string); +DROP FUNCTION IF EXISTS pgwar.get_value_object(tables.cell); +DROP FUNCTION IF EXISTS pgwar.get_value_object(information.dimension); + +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.appellation); +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.place); +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.language); +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.time_primitive); +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.lang_string); +DROP FUNCTION IF EXISTS pgwar.get_value_label(tables.cell); +DROP FUNCTION IF EXISTS pgwar.get_value_label(information.dimension); + +DROP FUNCTION IF EXISTS pgwar.update_from_statement(information.statement); + +------ Drop functions in commons schema ------------------------------------------------------- +--------------------------------------------------------------------------------------------- +DROP FUNCTION IF EXISTS commons.julian_second__to_iso_8601(bigint); +DROP FUNCTION IF EXISTS commons.julian_day_to_gregorian_pretty(integer); +DROP FUNCTION IF EXISTS commons.time_primitive__pretty_json(information.time_primitive); diff --git a/database/migrations/sqls/20240530193851-pgwar-statements-up.sql b/database/migrations/sqls/20240530193851-pgwar-statements-up.sql new file mode 100644 index 000000000..d50e22bde --- /dev/null +++ b/database/migrations/sqls/20240530193851-pgwar-statements-up.sql @@ -0,0 +1,683 @@ +------ get_value_object() ------------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +-- Function to get value_object json from information.appellation +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(appe information.appellation) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'string', + jsonb_build_object( + 'pkEntity', + appe.pk_entity, + 'fkClass', + appe.fk_class, + 'string', + appe.string + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from information.place +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(place information.place) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'geometry', + jsonb_build_object( + 'pkEntity', + place.pk_entity, + 'fkClass', + place.fk_class, + 'geoJSON', + ST_AsGeoJSON(place.geo_point::geometry)::jsonb + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from information.language +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(language information.language) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'language', + jsonb_build_object( + 'pkEntity', + language .pk_entity, + 'fkClass', + language .fk_class, + 'label', + language .notes, + 'iso6391', + trim(language .iso6391), + 'iso6392b', + trim(language .iso6392b), + 'iso6392t', + trim(language .iso6392t) + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from information.time_primitive +-------------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(time_primitive information.time_primitive) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'timePrimitive', + commons.time_primitive__pretty_json(time_primitive) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from information.lang_string +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(lang_string information.lang_string) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'langString', + jsonb_build_object( + 'pkEntity', + lang_string.pk_entity, + 'fkClass', + lang_string.fk_class, + 'string', + lang_string.string, + 'fkLanguage', + lang_string.fk_language + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from tables.cell +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(cell tables.cell) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'cell', + jsonb_build_object( + 'pkCell', + cell.pk_cell, + 'fkClass', + cell.fk_class, + 'numericValue', + cell.numeric_value, + 'stringValue', + cell.string_value, + 'fkRow', + cell.fk_row, + 'fkColumn', + cell.fk_column + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_object json from information.dimension +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_object(dimension information.dimension) RETURNS JSONB AS $$ +BEGIN RETURN jsonb_build_object( + 'dimension', + jsonb_build_object( + 'pkEntity', + dimension.pk_entity, + 'fkClass', + dimension.fk_class, + 'numericValue', + dimension.numeric_value, + 'fkMeasurementUnit', + dimension.fk_measurement_unit + ) + ); + +END; + +$$ LANGUAGE plpgsql; + +------ get_value_label() -------------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +-- Function to get value_label from information.appellation +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(appe information.appellation) RETURNS text AS $$ +BEGIN RETURN appe.string; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from information.place +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(place information.place) RETURNS text AS $$ +BEGIN RETURN format( + 'WGS84: %s°, %s°', + ST_X(place.geo_point::geometry), + ST_Y(place.geo_point::geometry) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from information.language +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(language information.language) RETURNS text AS $$ +BEGIN RETURN coalesce( + language .notes, + trim(language .pk_language) + ); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from information.time_primitive +-------------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(time_primitive information.time_primitive) RETURNS text AS $$ +DECLARE date_string varchar; + +BEGIN IF time_primitive.calendar = 'gregorian' THEN -- generate gregorian calendar string +SELECT to_char( + (('J' || time_primitive.julian_day)::timestamp), + 'YYYY-MM-DD' + ) INTO date_string; + +ELSE -- generate julian calendar string +SELECT concat( + to_char(t.year, 'fm0000'), + '-', + to_char(t.month, 'fm00'), + '-', + to_char(t.day, 'fm00') + ) INTO date_string +FROM commons.julian_cal__year_month_day(time_primitive.julian_day) t; + +END IF; + +-- add duration +RETURN concat( + date_string, + ' (', + time_primitive.duration, + ')' +); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from information.lang_string +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(lang_string information.lang_string) RETURNS text AS $$ +BEGIN RETURN lang_string.string; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from tables.cell +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(cell tables.cell) RETURNS text AS $$ +BEGIN RETURN coalesce(cell.string_value, cell.numeric_value::text); + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get value_label from information.dimension +----------------------------------------------------------------- +CREATE +OR REPLACE FUNCTION pgwar.get_value_label(dimension information.dimension) RETURNS text AS $$ +BEGIN RETURN dimension.numeric_value; + +END; + +$$ LANGUAGE plpgsql; + +-- Fix commons.julian_second__to_iso_8601() to prefix BC dates with '-' +----------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION commons.julian_second__to_iso_8601( + julian_second bigint) + RETURNS text + LANGUAGE 'sql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + SELECT + CASE + WHEN (julian_second / 86400) < 1721426 THEN '-' || to_char((('J' ||(julian_second / 86400)::text)::timestamp +(julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') + ELSE to_char((('J' ||(julian_second / 86400)::text)::timestamp +(julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') + END +$BODY$; + +-- Create commons.julian_day_to_gregorian_pretty to convert julian day into gregorian pretty string +--------------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION commons.julian_day_to_gregorian_pretty(julian_day INTEGER) +RETURNS TEXT AS $$ +DECLARE + formatted_date TEXT; +BEGIN + SELECT CASE + WHEN julian_day < 1721426 THEN '-' || TO_CHAR(('J' || julian_day)::timestamp, 'YYYY-MM-DD') + ELSE TO_CHAR(('J' || julian_day)::timestamp, 'YYYY-MM-DD') + END + INTO formatted_date; + RETURN formatted_date; +END; +$$ LANGUAGE plpgsql; + +-- Fix commons.time_primitive__pretty_json to prefix gregorian strings with '-' for BC dates +-------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION commons.time_primitive__pretty_json( + time_primitive information.time_primitive) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ +DECLARE + from_day int; + from_second bigint; + from_julian_cal varchar; + from_gregorian_cal varchar; + from_gregorian_cal_iso8601 varchar; + to_day int; + to_second bigint; + to_julian_cal varchar; + to_gregorian_cal varchar; + to_gregorian_cal_iso8601 varchar; + label varchar; +BEGIN + from_day = time_primitive.julian_day; + SELECT + commons.time_primitive__get_first_second(from_day) INTO from_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO from_julian_cal + FROM + commons.julian_cal__year_month_day(from_day) t; + SELECT + commons.julian_day_to_gregorian_pretty(from_day) INTO from_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(from_second) INTO from_gregorian_cal_iso8601; + SELECT + commons.time_primitive__get_to_day(from_day, time_primitive.duration, time_primitive.calendar) INTO to_day; + SELECT + commons.time_primitive__get_first_second(to_day) INTO to_second; + SELECT + concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO to_julian_cal + FROM + commons.julian_cal__year_month_day(to_day) t; + SELECT + commons.julian_day_to_gregorian_pretty(to_day) INTO to_gregorian_cal; + SELECT + commons.julian_second__to_iso_8601(to_second) INTO to_gregorian_cal_iso8601; + SELECT + CASE WHEN time_primitive.calendar = 'gregorian' THEN + concat(from_gregorian_cal, ' (', time_primitive.duration, ')') + ELSE + concat(from_julian_cal, ' (', time_primitive.duration, ')') + END INTO label; + RETURN jsonb_build_object('pkEntity', time_primitive.pk_entity, 'fkClass', time_primitive.fk_class, 'julianDay', time_primitive.julian_day, 'duration', time_primitive.duration, 'calendar', time_primitive.calendar::text, 'label', label, 'from', jsonb_build_object('julianDay', from_day, 'julianSecond', from_second, 'calGregorian', from_gregorian_cal, 'calGregorianIso8601', from_gregorian_cal_iso8601, 'calJulian', from_julian_cal), 'to', jsonb_build_object('julianDay', to_day, 'julianSecond', to_second, 'calGregorian', to_gregorian_cal, 'calGregorianIso8601', to_gregorian_cal_iso8601, 'calJulian', to_julian_cal)); +END; +$BODY$; +------ Table pgwar.statement ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.statement( + pk_entity int NOT NULL PRIMARY KEY, + fk_subject_info int NOT NULL, + fk_property int NOT NULL, + fk_object_info int, + fk_object_tables_cell bigint, + object_label varchar(100), + object_value jsonb +); +------ Table pgwar.statement ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- + +CREATE OR REPLACE FUNCTION pgwar.upsert_statement(stmt pgwar.statement) + RETURNS VOID + AS $$ +BEGIN + INSERT INTO pgwar.statement(pk_entity,fk_subject_info,fk_property,fk_object_info,fk_object_tables_cell,object_label,object_value) + VALUES( + stmt.pk_entity, + stmt.fk_subject_info, + stmt.fk_property, + stmt.fk_object_info, + stmt.fk_object_tables_cell, + stmt.object_label, + stmt.object_value + ) + ON CONFLICT(pk_entity) + DO UPDATE SET + -- ... or update the fk_class + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value + WHERE + -- ... where it is distinct from previous value + statement.fk_subject_info IS DISTINCT FROM EXCLUDED.fk_subject_info OR + statement.fk_property IS DISTINCT FROM EXCLUDED.fk_property OR + statement.fk_object_info IS DISTINCT FROM EXCLUDED.fk_object_info OR + statement.fk_object_tables_cell IS DISTINCT FROM EXCLUDED.fk_object_tables_cell OR + statement.object_label IS DISTINCT FROM EXCLUDED.object_label OR + statement.object_value IS DISTINCT FROM EXCLUDED.object_value; +END; +$$ +LANGUAGE plpgsql; + +------ Function to update pgwar from a statement -------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.update_from_statement(NEW_STMT information.statement) + RETURNS void + LANGUAGE plpgsql + AS $$ +DECLARE + entity information.resource; + appellation information.appellation; + dimension information.dimension; + lang_string information.lang_string; + language information.language; + place information.place; + time_primitive information.time_primitive; + cell tables.cell; +BEGIN + + -- get the referenced appellation... + SELECT * INTO appellation FROM information.appellation WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF appellation.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(appellation), + pgwar.get_value_object(appellation) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced dimension... + SELECT * INTO dimension FROM information.dimension WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF dimension.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(dimension), + pgwar.get_value_object(dimension) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced lang_string... + SELECT * INTO lang_string FROM information.lang_string WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF lang_string.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(lang_string), + pgwar.get_value_object(lang_string) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced dimension... + SELECT * INTO language FROM information.language WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF language.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(language), + pgwar.get_value_object(language) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced place... + SELECT * INTO place FROM information.place WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF place.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(place), + pgwar.get_value_object(place) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced time_primitive... + SELECT * INTO time_primitive FROM information.time_primitive WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF time_primitive.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(time_primitive), + pgwar.get_value_object(time_primitive) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + -- get the referenced cell... + SELECT * INTO cell FROM tables.cell WHERE pk_cell = NEW_STMT.fk_object_tables_cell; + -- ...if not null... + IF cell.pk_cell IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell, + pgwar.get_value_label(cell), + pgwar.get_value_object(cell) + )::pgwar.statement); + -- return! + RETURN; + END IF; + + + + -- get the referenced entity... + SELECT * INTO entity FROM information.resource WHERE pk_entity = NEW_STMT.fk_object_info; + -- ...if not null... + IF entity.pk_entity IS NOT NULL THEN + -- create a pgwar.statement + PERFORM pgwar.upsert_statement((NEW_STMT.pk_entity,NEW_STMT.fk_subject_info,NEW_STMT.fk_property,NEW_STMT.fk_object_info,NEW_STMT.fk_object_tables_cell,NULL,NULL)::pgwar.statement); + -- return! + RETURN; + END IF; + +END; +$$; + +------ Trigger function after upsert statement table ------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_statement() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + PERFORM pgwar.update_from_statement(NEW); + + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_upsert_statement + AFTER INSERT OR UPDATE ON information.statement + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_statement(); + +------ Trigger after delete statement table ------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.after_delete_statement() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +BEGIN + DELETE FROM pgwar.statement + WHERE pk_entity = OLD.pk_entity; + + RETURN OLD; +END; +$$; + +CREATE TRIGGER after_delete_statement + AFTER DELETE ON information.statement + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_statement(); + + + +------ Trigger after delete on literal table ------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.after_delete_object_info() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE +BEGIN + DELETE FROM pgwar.statement + WHERE fk_object_info = OLD.pk_entity; + RETURN OLD; +END; +$$; +CREATE FUNCTION pgwar.after_delete_object_tables_cell() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE +BEGIN + DELETE FROM pgwar.statement + WHERE fk_object_tables_cell = OLD.pk_cell; + RETURN OLD; +END; +$$; + +CREATE TRIGGER after_delete_appellation + AFTER DELETE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_dimension + AFTER DELETE ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_lang_string + AFTER DELETE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_language + AFTER DELETE ON information.language + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_place + AFTER DELETE ON information.place + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_time_primitive + AFTER DELETE ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_info(); + +CREATE TRIGGER after_delete_cell + AFTER DELETE ON tables.cell + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_delete_object_tables_cell(); + + +------ Trigger after upsert literal table ------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_object_info() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE +BEGIN + PERFORM pgwar.upsert_statement((stmt.pk_entity,stmt.fk_subject_info,stmt.fk_property,stmt.fk_object_info,stmt.fk_object_tables_cell, + pgwar.get_value_label(NEW), + pgwar.get_value_object(NEW) + )::pgwar.statement) + FROM information.statement stmt + WHERE fk_object_info = NEW.pk_entity; + RETURN NEW; +END; +$$; + +CREATE FUNCTION pgwar.after_upsert_object_tables_cell() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $$ +DECLARE +BEGIN + PERFORM pgwar.upsert_statement((stmt.pk_entity,stmt.fk_subject_info,stmt.fk_property,stmt.fk_object_info,stmt.fk_object_tables_cell, + pgwar.get_value_label(NEW), + pgwar.get_value_object(NEW) + )::pgwar.statement) + FROM information.statement stmt + WHERE fk_object_tables_cell = NEW.pk_cell; + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_upsert_appellation + AFTER INSERT OR UPDATE ON information.appellation + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_dimension + AFTER INSERT OR UPDATE ON information.dimension + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_lang_string + AFTER INSERT OR UPDATE ON information.lang_string + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_language + AFTER INSERT OR UPDATE ON information.language + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_place + AFTER INSERT OR UPDATE ON information.place + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_time_primitive + AFTER INSERT OR UPDATE ON information.time_primitive + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_info(); + +CREATE TRIGGER after_upsert_cell + AFTER INSERT OR UPDATE ON tables.cell + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_upsert_object_tables_cell(); + diff --git a/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql b/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql new file mode 100644 index 000000000..592a27906 --- /dev/null +++ b/database/migrations/sqls/20240606082339-pgwar-project-statements-down.sql @@ -0,0 +1,21 @@ +-- Triggers +---------------------------------------------- +DROP TRIGGER after_modify_info_proj_rel ON projects.info_proj_rel; +DROP TRIGGER after_upsert_pgw_statement ON pgwar.statement; +DROP TRIGGER after_delete_pgw_statement ON pgwar.statement; +DROP TRIGGER last_modification_tmsp ON pgwar.project_statements; +DROP TRIGGER after_delete_project_statements ON pgwar.project_statements; + +-- Functions +---------------------------------------------- +DROP FUNCTION pgwar.after_modify_info_proj_rel(); +DROP FUNCTION pgwar.update_from_info_proj_rel(projects.info_proj_rel, boolean); +DROP FUNCTION pgwar.after_upsert_pgw_statement(); +DROP FUNCTION pgwar.after_delete_pgw_statement(); +DROP FUNCTION pgwar.handle_project_statements_delete(); +DROP FUNCTION pgwar.upsert_project_statements(pgwar.project_statements); + +-- Tables +---------------------------------------------- +DROP TABLE pgwar.project_statements; +DROP TABLE pgwar.project_statements_deleted; \ No newline at end of file diff --git a/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql new file mode 100644 index 000000000..0f4296b6c --- /dev/null +++ b/database/migrations/sqls/20240606082339-pgwar-project-statements-up.sql @@ -0,0 +1,296 @@ +------ Table pgwar.project_statements ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.project_statements( + pk_entity integer NOT NULL, + fk_project integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + fk_object_tables_cell bigint, + ord_num_of_domain numeric, + ord_num_of_range numeric, + object_label varchar(100), + object_value jsonb, + tmsp_last_modification timestamp with time zone, + PRIMARY KEY (pk_entity, fk_project) +); + +-- Function to upsert on pgwar.project_statements +----------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.upsert_project_statements(ps pgwar.project_statements) + RETURNS VOID +AS $$ +BEGIN + INSERT INTO pgwar.project_statements( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value + ) + VALUES( + ps.pk_entity, + ps.fk_project, + ps.fk_subject_info, + ps.fk_property, + ps.fk_object_info, + ps.fk_object_tables_cell, + ps.ord_num_of_domain, + ps.ord_num_of_range, + ps.object_label, + ps.object_value + ) + ON CONFLICT(pk_entity, fk_project) + DO UPDATE SET + -- ... or update the pgwar.statement + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + ord_num_of_domain = EXCLUDED.ord_num_of_domain, + ord_num_of_range = EXCLUDED.ord_num_of_range, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value + WHERE + -- ... where it is distinct from previous value + project_statements.fk_subject_info IS DISTINCT FROM EXCLUDED.fk_subject_info OR + project_statements.fk_property IS DISTINCT FROM EXCLUDED.fk_property OR + project_statements.fk_object_info IS DISTINCT FROM EXCLUDED.fk_object_info OR + project_statements.fk_object_tables_cell IS DISTINCT FROM EXCLUDED.fk_object_tables_cell OR + project_statements.ord_num_of_domain IS DISTINCT FROM EXCLUDED.ord_num_of_domain OR + project_statements.ord_num_of_range IS DISTINCT FROM EXCLUDED.ord_num_of_range OR + project_statements.object_label IS DISTINCT FROM EXCLUDED.object_label OR + project_statements.object_value IS DISTINCT FROM EXCLUDED.object_value; +END; +$$ +LANGUAGE plpgsql; + +-- Function update_from_info_proj_rel +---------------------------------------------- +CREATE FUNCTION pgwar.update_from_info_proj_rel(NEW_OLD projects.info_proj_rel, is_upsert bool) + RETURNS void + LANGUAGE plpgsql + AS $$ +DECLARE + entity information.resource; + statement pgwar.statement; +BEGIN + + -- get the referenced pgwar.statement + SELECT * + INTO statement + FROM pgwar.statement stmt + WHERE stmt.pk_entity = NEW_OLD.fk_entity; + + -- if pgwar.statement is referenced by info_proj_rel.fk_entity + IF statement.pk_entity IS NOT NULL THEN + + -- if upsert ... + IF is_upsert IS TRUE THEN + -- ... upsert the project statements + PERFORM + pgwar.upsert_project_statements(( + NEW_OLD.fk_entity, + NEW_OLD.fk_project, + statement.fk_subject_info, + statement.fk_property, + statement.fk_object_info, + statement.fk_object_tables_cell, + NEW_OLD.ord_num_of_domain::numeric, + NEW_OLD.ord_num_of_range::numeric, + statement.object_label, + statement.object_value, + NULL)::pgwar.project_statements + ); + ELSE + -- ... delete the project_statements + DELETE FROM pgwar.project_statements + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = NEW_OLD.fk_project; + END IF; + ELSE + + -- get the referenced information.resource + SELECT * + INTO entity + FROM information.resource + WHERE pk_entity = NEW_OLD.fk_entity; + -- if the referenced item is an entity + IF entity.pk_entity IS NOT NULL THEN + + -- if upsert ... + IF is_upsert IS TRUE THEN + -- ... upsert the project entity + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_OLD.fk_entity, NEW_OLD.fk_project, entity.fk_class); + -- if allowed ... + IF (entity.community_visibility ->> 'toolbox')::bool IS TRUE THEN + -- ... upsert the community entity + PERFORM + pgwar.upsert_entity_preview_fk_class(NEW_OLD.fk_entity, 0, entity.fk_class); + END IF; + ELSE + -- ... delete the project entity + DELETE FROM pgwar.entity_preview + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = NEW_OLD.fk_project; + -- ... check if community entity has to be deleted + IF NOT EXISTS ( + SELECT + pk_entity + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW_OLD.fk_entity + AND is_in_project IS TRUE) THEN + -- ... delete the community entity + DELETE FROM pgwar.entity_preview + WHERE pk_entity = NEW_OLD.fk_entity + AND fk_project = 0; + END IF; + END IF; + END IF; + + END IF; +END; +$$; + +-- Trigger function after_modify_info_proj_rel +---------------------------------------------- +CREATE FUNCTION pgwar.after_modify_info_proj_rel() + RETURNS TRIGGER + LANGUAGE plpgsql +AS $$ +DECLARE + info_proj_rel projects.info_proj_rel; + is_upsert boolean; + statement pgwar.statement; +BEGIN + info_proj_rel := COALESCE(NEW,OLD); + + SELECT (NEW.is_in_project IS TRUE AND TG_OP != 'DELETE') INTO is_upsert; + + PERFORM pgwar.update_from_info_proj_rel(info_proj_rel, is_upsert); + + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_modify_info_proj_rel + AFTER INSERT OR UPDATE OR DELETE ON projects.info_proj_rel + FOR EACH ROW + EXECUTE FUNCTION pgwar.after_modify_info_proj_rel(); + +-- Trigger function after_upsert_pgw_statement +---------------------------------------------- +CREATE FUNCTION pgwar.after_upsert_pgw_statement() + RETURNS TRIGGER + LANGUAGE plpgsql +AS $$ +BEGIN + -- if it is in at least one project ... + IF EXISTS( + SELECT + pk_entity + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW.pk_entity + AND is_in_project IS TRUE) THEN + -- ... insert missing project statements or update existing, in case statement differs + PERFORM + pgwar.upsert_project_statements(( + NEW.pk_entity, + fk_project, + NEW.fk_subject_info, + NEW.fk_property, + NEW.fk_object_info, + NEW.fk_object_tables_cell, + ord_num_of_domain::numeric, + ord_num_of_range::numeric, + NEW.object_label, + NEW.object_value, + NULL)::pgwar.project_statements + ) + FROM + projects.info_proj_rel + WHERE + fk_entity = NEW.pk_entity + AND is_in_project IS TRUE; + END IF; + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_upsert_pgw_statement + AFTER INSERT OR UPDATE ON pgwar.statement + FOR EACH ROW +EXECUTE FUNCTION pgwar.after_upsert_pgw_statement(); + +-- Trigger function after_delete_pgw_statement +---------------------------------------------- +CREATE FUNCTION pgwar.after_delete_pgw_statement() + RETURNS TRIGGER + LANGUAGE plpgsql +AS $$ +BEGIN + DELETE FROM pgwar.project_statements + WHERE pk_entity = OLD.pk_entity; + RETURN NEW; +END; +$$; + +CREATE TRIGGER after_delete_pgw_statement + AFTER DELETE ON pgwar.statement + FOR EACH ROW +EXECUTE FUNCTION pgwar.after_delete_pgw_statement(); + +-- add trigger for last_modification_tmsp +CREATE OR REPLACE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON pgwar.project_statements + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + +------ Table pgwar.project_statements_deleted ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +-- this table is used by the fulltext cron job to find entities that need an fulltext update +-- because they are the subject or object of a deleted project statement +CREATE TABLE IF NOT EXISTS pgwar.project_statements_deleted( + pk_entity integer NOT NULL, + fk_project integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + object_value jsonb, + tmsp_deletion timestamp with time zone, + PRIMARY KEY (pk_entity, fk_project) +); + +CREATE OR REPLACE FUNCTION pgwar.handle_project_statements_delete() +RETURNS TRIGGER AS $$ +BEGIN + -- Insert or update the deleted row in pgwar.project_statements_deleted + INSERT INTO pgwar.project_statements_deleted (pk_entity, fk_project, fk_subject_info, fk_property, fk_object_info, object_value, tmsp_deletion) + VALUES (OLD.pk_entity, OLD.fk_project, OLD.fk_subject_info, OLD.fk_property, OLD.fk_object_info, OLD.object_value, CURRENT_TIMESTAMP) + ON CONFLICT (pk_entity, fk_project) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + object_value = EXCLUDED.object_value, + tmsp_deletion = EXCLUDED.tmsp_deletion; + + RETURN OLD; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER after_delete_project_statements +AFTER DELETE ON pgwar.project_statements +FOR EACH ROW +EXECUTE FUNCTION pgwar.handle_project_statements_delete(); diff --git a/database/migrations/sqls/20240606151841-pgwar-community-statements-down.sql b/database/migrations/sqls/20240606151841-pgwar-community-statements-down.sql new file mode 100644 index 000000000..4df971dcd --- /dev/null +++ b/database/migrations/sqls/20240606151841-pgwar-community-statements-down.sql @@ -0,0 +1,22 @@ +-- Step 1: Drop views +DROP VIEW pgwar.v_statements_combined; +DROP VIEW pgwar.v_statements_deleted_combined; + +-- Step 2: Drop functions +DROP FUNCTION pgwar.update_community_statements_from_upserts; +DROP FUNCTION pgwar.update_community_statements_from_deletes; + +-- Step 3: Drop triggers +DROP TRIGGER after_delete_community_statements ON pgwar.community_statements; + +-- Step 4: Drop function +DROP FUNCTION pgwar.handle_community_statements_delete; + +-- Step 5: Drop tables +DROP TABLE pgwar.community_statements_deleted; +DROP TABLE pgwar.community_statements; +DROP TABLE pgwar.offsets; + +-- Step 6: Drop indexes +DROP INDEX pgwar.project_statements_tmsp_last_modification_idx; +DROP INDEX pgwar.project_statements_deleted_tmsp_deletion_idx; diff --git a/database/migrations/sqls/20240606151841-pgwar-community-statements-up.sql b/database/migrations/sqls/20240606151841-pgwar-community-statements-up.sql new file mode 100644 index 000000000..a6f3cadf4 --- /dev/null +++ b/database/migrations/sqls/20240606151841-pgwar-community-statements-up.sql @@ -0,0 +1,347 @@ +------ Table pgwar.community_statements ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.community_statements( + pk_entity integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + fk_object_tables_cell bigint, + ord_num_of_domain numeric, + ord_num_of_range numeric, + object_label varchar(100), + object_value jsonb, + tmsp_last_modification timestamp with time zone, + PRIMARY KEY (pk_entity) +); + +------ Table pgwar.community_statements ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +-- this table is used by the fulltext cron job to find entities that need an fulltext update +-- because they are the subject or object of a deleted community statement +CREATE TABLE IF NOT EXISTS pgwar.community_statements_deleted( + pk_entity integer NOT NULL, + fk_subject_info integer, + fk_property integer NOT NULL, + fk_object_info integer, + object_value jsonb, + tmsp_deletion timestamp with time zone, + PRIMARY KEY (pk_entity) +); + +CREATE OR REPLACE FUNCTION pgwar.handle_community_statements_delete() +RETURNS TRIGGER AS $$ +BEGIN + -- Insert or update the deleted row in pgwar.community_statements_deleted + INSERT INTO pgwar.community_statements_deleted (pk_entity, fk_subject_info, fk_property, fk_object_info, object_value, tmsp_deletion) + VALUES (OLD.pk_entity, OLD.fk_subject_info, OLD.fk_property, OLD.fk_object_info, OLD.object_value, CURRENT_TIMESTAMP) + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + object_value = EXCLUDED.object_value, + tmsp_deletion = CURRENT_TIMESTAMP; + + RETURN OLD; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER after_delete_community_statements +AFTER DELETE ON pgwar.community_statements +FOR EACH ROW +EXECUTE FUNCTION pgwar.handle_community_statements_delete(); + +------ View pgwar.v_statements_combined ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE VIEW pgwar.v_statements_combined AS +SELECT + pk_entity, + 0 as fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification +FROM pgwar.community_statements +UNION ALL +SELECT + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification +FROM pgwar.project_statements; + + +------ View pgwar.v_statements_deleted_combined ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE VIEW pgwar.v_statements_deleted_combined AS +SELECT + pk_entity, + 0 as fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value, + tmsp_deletion +FROM pgwar.community_statements_deleted +UNION ALL +SELECT + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value, + tmsp_deletion +FROM pgwar.project_statements_deleted; + + +------ Table pgwar.offsets ------------------------------------------------------------------ +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.offsets( + job_name text, + offset_tmsp timestamp with time zone, + PRIMARY KEY (job_name) +); + +CREATE INDEX IF NOT EXISTS project_statements_tmsp_last_modification_idx +ON pgwar.project_statements USING btree +(tmsp_last_modification ASC NULLS LAST); + +------ Function to update community statements from inserted or updated project statements -- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.update_community_statements_from_upserts() +RETURNS void AS $$ +DECLARE + _job_name text; +BEGIN + _job_name := 'update-community-statements-from-upserts'; + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- identify updated project statements + WITH + upserted_p_stmts AS ( + SELECT pk_entity, + max(tmsp_last_modification) new_offset_tmsp + FROM ( + SELECT pk_entity, tmsp_last_modification + FROM + pgwar.project_statements + WHERE tmsp_last_modification > ( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = 'update-community-statements-from-upserts' + ) + ORDER BY tmsp_last_modification ASC + ) AS modified + GROUP BY pk_entity + ), + insert_community_statements AS ( + -- insert or update community statements + INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification + ) + SELECT + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + avg(p_stmt.ord_num_of_domain) AS ord_num_of_domain, + avg(p_stmt.ord_num_of_range) AS ord_num_of_range, + p_stmt.object_label, + p_stmt.object_value, + upserted_p_stmts.new_offset_tmsp AS tmsp_last_modification + FROM pgwar.project_statements p_stmt, + upserted_p_stmts + WHERE p_stmt.pk_entity = upserted_p_stmts.pk_entity + GROUP BY + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + p_stmt.object_label, + p_stmt.object_value, + upserted_p_stmts.new_offset_tmsp + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + ord_num_of_domain = EXCLUDED.ord_num_of_domain, + ord_num_of_range = EXCLUDED.ord_num_of_range, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value, + tmsp_last_modification = EXCLUDED.tmsp_last_modification + -- return the tmsp_last_modification which equals new_offset_tmsp + RETURNING tmsp_last_modification + ) + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = new_offset.tmsp_last_modification + FROM ( + SELECT tmsp_last_modification + FROM insert_community_statements + LIMIT 1 + ) new_offset + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + + +CREATE INDEX IF NOT EXISTS project_statements_deleted_tmsp_deletion_idx +ON pgwar.project_statements_deleted USING btree +(tmsp_deletion ASC NULLS LAST); + +------ Function to update community statements from deleted project statements -- +--------------------------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.update_community_statements_from_deletes() +RETURNS void AS $$ +DECLARE + _job_name text; +BEGIN + _job_name := 'update-community-statements-from-deletes'; + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- identify updated project statements + WITH deleted_p_stmts AS ( + SELECT + pk_entity, + max(tmsp_deletion) new_offset_tmsp + FROM ( + SELECT pk_entity, tmsp_deletion + FROM + pgwar.project_statements_deleted + WHERE tmsp_deletion > ( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = 'update-community-statements-from-deletes' + ) + ORDER BY tmsp_deletion ASC + ) AS modified + GROUP BY pk_entity + ), + insert_community_statements AS ( + -- insert or update community statements + INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + ord_num_of_domain, + ord_num_of_range, + object_label, + object_value, + tmsp_last_modification + ) + SELECT + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + avg(p_stmt.ord_num_of_domain) AS ord_num_of_domain, + avg(p_stmt.ord_num_of_range) AS ord_num_of_range, + p_stmt.object_label, + p_stmt.object_value, + deleted_p_stmts.new_offset_tmsp AS tmsp_last_modification + FROM pgwar.project_statements p_stmt, + deleted_p_stmts + WHERE p_stmt.pk_entity = deleted_p_stmts.pk_entity + GROUP BY + p_stmt.pk_entity, + p_stmt.fk_subject_info, + p_stmt.fk_property, + p_stmt.fk_object_info, + p_stmt.fk_object_tables_cell, + p_stmt.object_label, + p_stmt.object_value, + deleted_p_stmts.new_offset_tmsp + ON CONFLICT (pk_entity) + DO UPDATE SET + fk_subject_info = EXCLUDED.fk_subject_info, + fk_property = EXCLUDED.fk_property, + fk_object_info = EXCLUDED.fk_object_info, + fk_object_tables_cell = EXCLUDED.fk_object_tables_cell, + ord_num_of_domain = EXCLUDED.ord_num_of_domain, + ord_num_of_range = EXCLUDED.ord_num_of_range, + object_label = EXCLUDED.object_label, + object_value = EXCLUDED.object_value, + tmsp_last_modification = EXCLUDED.tmsp_last_modification + -- return the tmsp_last_modification which equals new_offset_tmsp + RETURNING tmsp_last_modification + ), + delete_community_statements AS ( + DELETE FROM pgwar.community_statements + WHERE pk_entity IN (SELECT pk_entity FROM deleted_p_stmts) + AND pk_entity NOT IN ( + SELECT DISTINCT ps.pk_entity + FROM pgwar.project_statements ps, + deleted_p_stmts d + WHERE ps.pk_entity = d.pk_entity + ) + ) + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = new_offset.tmsp_last_modification + FROM ( + SELECT tmsp_last_modification + FROM insert_community_statements + LIMIT 1 + ) new_offset + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + +/** +* Indexes +**/ + +CREATE INDEX IF NOT EXISTS community_statements_fk_object_info_fk_property_idx + ON pgwar.community_statements(fk_object_info,fk_property); + +CREATE INDEX IF NOT EXISTS community_statements_fk_subject_info_fk_property_dx + ON pgwar.community_statements(fk_subject_info,fk_property); diff --git a/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql b/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql new file mode 100644 index 000000000..23b0c9a4b --- /dev/null +++ b/database/migrations/sqls/20240612071824-pgwar-fulltext-down.sql @@ -0,0 +1,31 @@ +-- Drop Index +DROP INDEX IF EXISTS pgwar.entity_full_text_tmsp_last_modification_idx; + +-- Drop triggers +DROP TRIGGER after_upsert_entity_full_text ON pgwar.entity_full_text; + +-- Drop functions +DROP FUNCTION pgwar.update_entity_preview_full_text(); +DROP FUNCTION pgwar.update_full_texts(int); +DROP FUNCTION pgwar.get_outdated_full_texts(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_del(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt(int); +DROP FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt(int); +DROP FUNCTION pgwar.get_project_full_text(int, int); +DROP FUNCTION pgwar.get_project_lang_code(int); +DROP FUNCTION pgwar.get_property_inverse_label(int, text); +DROP FUNCTION pgwar.get_property_label(int, text); +DROP FUNCTION pgwar.get_label_of_incoming_field(int, int, int, int); +DROP FUNCTION pgwar.get_label_of_outgoing_field(int, int, int, int); +DROP FUNCTION pgwar.get_target_label_of_field(int, int, jsonb); +DROP FUNCTION pgwar.get_target_labels_of_incoming_field(int, int, int, int); +DROP FUNCTION pgwar.get_target_labels_of_outgoing_field(int, int, int, int); + +-- Drop tables +DROP TABLE pgwar.entity_full_text; + +-- Drop extension +DROP EXTENSION dblink; diff --git a/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql b/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql new file mode 100644 index 000000000..176436264 --- /dev/null +++ b/database/migrations/sqls/20240612071824-pgwar-fulltext-up.sql @@ -0,0 +1,664 @@ +-- create dblink extension for accessing database with pg_cron +CREATE EXTENSION dblink; + +/*** +* Functions for the creation of fulltext +***/ + + +-- get target labels of incoming field +CREATE OR REPLACE FUNCTION pgwar.get_target_labels_of_incoming_field( + entity_id INT, + project_id INT, + property_id INT, + limit_count INT +) +RETURNS TABLE(label VARCHAR) AS $$ +DECLARE + labels VARCHAR[]; + pstmt RECORD; + proj_entity_label VARCHAR; + comm_entity_label VARCHAR; +BEGIN + labels := '{}'; + + FOR pstmt IN + SELECT * + FROM pgwar.v_statements_combined + WHERE + fk_object_info = entity_id + AND fk_project = project_id + AND fk_property = property_id + ORDER BY ord_num_of_domain ASC, tmsp_last_modification DESC + LIMIT limit_count + LOOP + SELECT entity_label INTO proj_entity_label + FROM pgwar.entity_preview + WHERE fk_project = project_id AND pk_entity = pstmt.fk_subject_info; + + IF proj_entity_label IS NOT NULL THEN + labels := array_append(labels, proj_entity_label); + ELSE + SELECT entity_label INTO comm_entity_label + FROM pgwar.entity_preview + WHERE fk_project = 0 AND pk_entity = pstmt.fk_subject_info; + + IF comm_entity_label IS NOT NULL THEN + labels := array_append(labels, comm_entity_label); + END IF; + END IF; + END LOOP; + + RETURN QUERY + SELECT unnest(labels); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION pgwar.get_target_labels_of_outgoing_field( + entity_id INT, + project_id INT, + property_id INT, + limit_count INT +) +RETURNS TABLE(label VARCHAR) AS $$ +DECLARE + labels VARCHAR[]; + pstmt RECORD; + obj_label VARCHAR; + proj_entity_label VARCHAR; + comm_entity_label VARCHAR; +BEGIN + labels := '{}'; + + FOR pstmt IN + SELECT * + FROM pgwar.v_statements_combined + WHERE + fk_subject_info = entity_id + AND fk_project = project_id + AND fk_property = property_id + ORDER BY ord_num_of_range ASC, tmsp_last_modification DESC + LIMIT limit_count + LOOP + obj_label := pstmt.object_label; + + IF obj_label IS NOT NULL THEN + labels := array_append(labels, obj_label); + ELSE + SELECT entity_label INTO proj_entity_label + FROM pgwar.entity_preview + WHERE fk_project = project_id AND pk_entity = pstmt.fk_object_info; + + IF proj_entity_label IS NOT NULL THEN + labels := array_append(labels, proj_entity_label); + ELSE + SELECT entity_label INTO comm_entity_label + FROM pgwar.entity_preview + WHERE fk_project = 0 AND pk_entity = pstmt.fk_object_info; + + IF comm_entity_label IS NOT NULL THEN + labels := array_append(labels, comm_entity_label); + END IF; + END IF; + END IF; + END LOOP; + + RETURN QUERY + SELECT unnest(labels); +END; +$$ LANGUAGE plpgsql; + +-- get target label of field +CREATE OR REPLACE FUNCTION pgwar.get_target_label_of_field(entity_id int, project_id int, field jsonb) +RETURNS text AS $$ +DECLARE + is_outgoing bool; + property_id int; + limit_count int; + label text; +BEGIN + is_outgoing := (field->'isOutgoing')::bool; + property_id := (field->'fkProperty')::int; + limit_count := (field->'nrOfStatementsInLabel')::int; + + + IF is_outgoing IS TRUE THEN + SELECT pgwar.get_label_of_outgoing_field(entity_id, project_id, property_id, limit_count) INTO label; + ELSE + SELECT pgwar.get_label_of_incoming_field(entity_id, project_id, property_id, limit_count) INTO label; + END IF; + + RETURN label; +END; +$$ LANGUAGE plpgsql; + + +-- get label of outgoing field +CREATE OR REPLACE FUNCTION pgwar.get_label_of_outgoing_field( + entity_id INT, + project_id INT, + property_id INT, + limit_count INT +) +RETURNS text AS $$ +DECLARE + label text; +BEGIN + SELECT string_agg(labels.label, ', ') INTO label + FROM pgwar.get_target_labels_of_outgoing_field(entity_id, project_id, property_id, limit_count) AS labels; + RETURN label; +END; +$$ LANGUAGE plpgsql; + +-- get label of incoming field +CREATE OR REPLACE FUNCTION pgwar.get_label_of_incoming_field( + entity_id INT, + project_id INT, + property_id INT, + limit_count INT +) +RETURNS text AS $$ +DECLARE + label text; +BEGIN + SELECT string_agg(labels.label, ', ') INTO label + FROM pgwar.get_target_labels_of_incoming_field(entity_id, project_id, property_id, limit_count) AS labels; + RETURN label; +END; +$$ LANGUAGE plpgsql; + + +-- get the label of a property in the language (or in the english fallback) +CREATE OR REPLACE FUNCTION pgwar.get_property_label(property_id int, lang_code text) +RETURNS text AS $$ +DECLARE + label text; +BEGIN + -- get newest label in requested language + SELECT dfh_property_label INTO label + FROM data_for_history.api_property + WHERE dfh_pk_property = property_id + AND dfh_property_label_language = lang_code + ORDER BY tmsp_last_dfh_update DESC + LIMIT 1; + + IF label IS NOT NULL THEN RETURN label; END IF; + + -- get newest label in english + SELECT dfh_property_label INTO label + FROM data_for_history.api_property + WHERE dfh_pk_property = property_id + AND dfh_property_label_language = 'en' + ORDER BY tmsp_last_dfh_update DESC + LIMIT 1; + + RETURN label; + +END; +$$ LANGUAGE plpgsql; + + +-- get the inverse label of a property in the language (or in the english fallback) +CREATE OR REPLACE FUNCTION pgwar.get_property_inverse_label(property_id int, lang_code text) +RETURNS text AS $$ +DECLARE + label text; +BEGIN + -- get newest inverse label in requested language + SELECT dfh_property_inverse_label INTO label + FROM data_for_history.api_property + WHERE dfh_pk_property = property_id + AND dfh_property_label_language = lang_code + ORDER BY tmsp_last_dfh_update DESC + LIMIT 1; + + IF label IS NOT NULL THEN RETURN label; END IF; + + -- get newest inverse label in english + SELECT dfh_property_inverse_label INTO label + FROM data_for_history.api_property + WHERE dfh_pk_property = property_id + AND dfh_property_label_language = 'en' + ORDER BY tmsp_last_dfh_update DESC + LIMIT 1; + + RETURN label; + +END; +$$ LANGUAGE plpgsql; + +-- get project language code (useful for joining OntoME language codes) +CREATE OR REPLACE FUNCTION pgwar.get_project_lang_code(project_id int) +RETURNS text AS $$ +DECLARE + lang_code text; +BEGIN + -- get language code of the project language + SELECT trim(iso6391) INTO lang_code + FROM information.language lang, + projects.project pro + WHERE pro.pk_entity = project_id + AND pro.fk_language = lang.pk_entity + LIMIT 1; + + RETURN lang_code; + +END; +$$ LANGUAGE plpgsql; + +-- create the fulltext of an entity +CREATE OR REPLACE FUNCTION pgwar.get_project_full_text(project_id int, entity_id int) + RETURNS text AS $$ +DECLARE + full_text text := ''; + lang_code text; + fk_property int; + field_string text; + label text; +BEGIN + -- get language code of the project language + lang_code := pgwar.get_project_lang_code(project_id); + + -- Get distinct fk_property values into a temporary table or array + FOR fk_property IN + SELECT DISTINCT stmt.fk_property + FROM pgwar.v_statements_combined AS stmt + WHERE (fk_subject_info = entity_id OR fk_object_info = entity_id) + AND fk_project = project_id + LOOP + -- Get field_string for outgoing fields + SELECT pgwar.get_label_of_outgoing_field(entity_id, project_id, fk_property, 5) INTO label; + IF label IS NOT NULL THEN + SELECT + concat( + pgwar.get_property_label(fk_property, lang_code), + ': ', + label + ) INTO field_string; + ELSE + SELECT pgwar.get_label_of_incoming_field(entity_id, project_id, fk_property, 5) INTO label; + IF label IS NOT NULL THEN + SELECT + concat( + pgwar.get_property_inverse_label(fk_property, lang_code), + ': ', + pgwar.get_label_of_incoming_field(entity_id, project_id, fk_property, 5) + ) INTO field_string; + END IF; + + END IF; + + -- Concatenate field string if not null + IF field_string IS NOT NULL THEN + full_text := full_text || field_string || '\n '; + END IF; + END LOOP; + + RETURN full_text; +END; +$$ LANGUAGE plpgsql; + + +-- create the fulltext of an entity +-- CREATE OR REPLACE FUNCTION pgwar.get_project_full_text_old(project_id int, entity_id int) +-- RETURNS text AS $$ +-- DECLARE +-- full_text text; +-- lang_code text; +-- BEGIN +-- -- get language code of the project language +-- lang_code := pgwar.get_project_lang_code(project_id); +-- +-- WITH fields AS ( +-- SELECT DISTINCT ON (fk_property) +-- concat( +-- pgwar.get_property_label(fk_property, lang_code), +-- ': ', +-- pgwar.get_label_of_outgoing_field(entity_id, project_id, fk_property, 5) +-- ) AS field_string +-- FROM pgwar.v_statements_combined +-- WHERE fk_subject_info = entity_id +-- AND fk_project = project_id +-- UNION +-- SELECT DISTINCT ON (fk_property) +-- concat( +-- pgwar.get_property_inverse_label(fk_property, lang_code), +-- ': ', +-- pgwar.get_label_of_incoming_field(entity_id, project_id, fk_property, 5) +-- ) AS field_string +-- FROM pgwar.v_statements_combined +-- WHERE fk_object_info = entity_id +-- AND fk_project = project_id +-- +-- ) +-- SELECT string_agg(fields.field_string, '\n ') INTO full_text +-- FROM fields; +-- +-- RETURN full_text; +-- END; +-- $$ LANGUAGE plpgsql; + + + +------ Table pgwar.entity_full_text ---------------------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS pgwar.entity_full_text( + pk_entity integer NOT NULL, + fk_project integer NOT NULL, + full_text text, + tmsp_last_modification timestamp with time zone, + PRIMARY KEY (pk_entity, fk_project) +); + +CREATE INDEX IF NOT EXISTS entity_full_text_tmsp_last_modification_idx + ON pgwar.entity_full_text USING btree + (tmsp_last_modification ASC NULLS LAST) + TABLESPACE pg_default; + +-- add trigger for last_modification_tmsp +CREATE OR REPLACE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON pgwar.entity_full_text + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); + + +/*** +* Find outdated full texts in subjects of statements +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt(max_limit int) +RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +BEGIN + RETURN QUERY + -- find subjects of modified statements + SELECT DISTINCT s.pk_entity, s.fk_project + FROM ( + SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project + FROM pgwar.v_statements_combined pstmt + LEFT JOIN pgwar.entity_full_text ftxt + ON pstmt.fk_subject_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + WHERE ftxt.tmsp_last_modification IS NULL + OR ftxt.tmsp_last_modification < pstmt.tmsp_last_modification + ORDER BY pstmt.tmsp_last_modification DESC + LIMIT max_limit + ) AS s; +END; +$$ LANGUAGE plpgsql; +/*** +* Find outdated full texts in objects of statements +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt(max_limit int) +RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +BEGIN + RETURN QUERY + -- find objects of modified statements + SELECT DISTINCT s.pk_entity, s.fk_project + FROM ( + SELECT pstmt.fk_object_info as pk_entity, pstmt.fk_project + FROM pgwar.v_statements_combined pstmt + LEFT JOIN pgwar.entity_full_text ftxt + ON pstmt.fk_object_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + WHERE pstmt.object_value IS NULL + AND (ftxt.tmsp_last_modification IS NULL + OR ftxt.tmsp_last_modification < pstmt.tmsp_last_modification) + ORDER BY pstmt.tmsp_last_modification DESC + LIMIT max_limit + ) AS s; +END; +$$ LANGUAGE plpgsql; + + +/*** +* Find outdated full texts in subjects of statements deleted +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(max_limit int) +RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +BEGIN + RETURN QUERY + -- find subjects of deleted statements + SELECT DISTINCT s.pk_entity, s.fk_project + FROM ( + SELECT pstmt.fk_subject_info as pk_entity, pstmt.fk_project + FROM pgwar.v_statements_deleted_combined pstmt + LEFT JOIN pgwar.entity_full_text ftxt + ON pstmt.fk_subject_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + WHERE ftxt.tmsp_last_modification IS NULL + OR ftxt.tmsp_last_modification < pstmt.tmsp_deletion + ORDER BY pstmt.tmsp_deletion DESC + LIMIT max_limit + ) AS s; +END; +$$ LANGUAGE plpgsql; + + +/*** +* Find outdated full texts in objects of statements deleted +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_del(max_limit int) +RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +BEGIN + RETURN QUERY + -- find objects of deleted statements + SELECT DISTINCT s.pk_entity, s.fk_project + FROM ( + SELECT pstmt.fk_object_info as pk_entity, pstmt.fk_project + FROM pgwar.v_statements_deleted_combined pstmt + LEFT JOIN pgwar.entity_full_text ftxt + ON pstmt.fk_object_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + WHERE pstmt.object_value IS NULL + AND (ftxt.tmsp_last_modification IS NULL + OR ftxt.tmsp_last_modification < pstmt.tmsp_deletion) + ORDER BY pstmt.tmsp_deletion DESC + LIMIT max_limit + ) AS s; +END; +$$ LANGUAGE plpgsql; + +/*** +* Find outdated full texts in subjects of statements with modified dfh-prop +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(max_limit int) + RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +DECLARE + rec RECORD; +BEGIN + -- Step 1: Retrieve filtered ftxt records + CREATE TEMP TABLE tmp_filtered_ftxt AS + SELECT ftxt.pk_entity, ftxt.fk_project + FROM pgwar.entity_full_text ftxt + JOIN data_for_history.api_property dfh_prop + ON ftxt.tmsp_last_modification < dfh_prop.tmsp_last_dfh_update; + + -- Step 2: Use the result from the temporary table to find outdated full texts + FOR rec IN + SELECT DISTINCT + pstmt.fk_subject_info AS pk_entity, + pstmt.fk_project, + dfh_prop.tmsp_last_modification -- Include this in the SELECT list for ordering + FROM + pgwar.v_statements_combined pstmt + JOIN tmp_filtered_ftxt ftxt + ON pstmt.fk_subject_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + JOIN data_for_history.api_property dfh_prop + ON dfh_prop.dfh_pk_property = pstmt.fk_property + ORDER BY dfh_prop.tmsp_last_modification DESC + LIMIT max_limit + LOOP + -- Assign values to the OUT parameters + pk_entity := rec.pk_entity; + fk_project := rec.fk_project; + + -- Return the record + RETURN NEXT; + END LOOP; + + -- Clean up the temporary table + DROP TABLE tmp_filtered_ftxt; + +END; +$$ LANGUAGE plpgsql; + +-- /*** +-- * Find outdated full texts in objects of statements with modified dfh-prop +-- ***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(max_limit int) + RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +DECLARE + rec RECORD; +BEGIN + -- Step 1: Retrieve filtered ftxt records + CREATE TEMP TABLE tmp_filtered_ftxt AS + SELECT ftxt.pk_entity, ftxt.fk_project + FROM pgwar.entity_full_text ftxt + JOIN data_for_history.api_property dfh_prop + ON ftxt.tmsp_last_modification < dfh_prop.tmsp_last_dfh_update; + + -- Step 2: Use the result from the temporary table to find outdated full texts + FOR rec IN + SELECT DISTINCT + pstmt.fk_object_info AS pk_entity, + pstmt.fk_project, + dfh_prop.tmsp_last_modification -- Include this in the SELECT list for ordering + FROM + pgwar.v_statements_combined pstmt + JOIN tmp_filtered_ftxt ftxt + ON pstmt.fk_object_info = ftxt.pk_entity + AND pstmt.fk_project = ftxt.fk_project + JOIN data_for_history.api_property dfh_prop + ON dfh_prop.dfh_pk_property = pstmt.fk_property + WHERE pstmt.object_value IS NULL + ORDER BY dfh_prop.tmsp_last_modification DESC + LIMIT max_limit + LOOP + -- Assign values to the OUT parameters + pk_entity := rec.pk_entity; + fk_project := rec.fk_project; + + -- Return the record + RETURN NEXT; + END LOOP; + + -- Clean up the temporary table + DROP TABLE tmp_filtered_ftxt; + +END; +$$ LANGUAGE plpgsql; + + +/*** +* Function to get outdated full texts +***/ +CREATE OR REPLACE FUNCTION pgwar.get_outdated_full_texts(max_limit int) +RETURNS TABLE(pk_entity integer, fk_project integer) AS $$ +DECLARE + current_set RECORD; + result_set RECORD; + pair_count int; + updated_count int; +BEGIN + pair_count := 0; + + -- Drop the temporary table if it already exists within transaction + DROP TABLE IF EXISTS temp_unique_pairs; + + -- Initialize the temporary table to store unique pairs + CREATE TEMP TABLE temp_unique_pairs ( + pk_entity integer, + fk_project integer, + CONSTRAINT unique_pairs_pk_project UNIQUE (pk_entity, fk_project) + ) ON COMMIT DROP; + + -- Execute functions sequentially and add unique pairs + FOR current_set IN SELECT unnest(array[ + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt', + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt_del', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt_del', + 'pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop', + 'pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop' + ]) AS function_name + LOOP + EXECUTE 'INSERT INTO temp_unique_pairs (pk_entity, fk_project) ' || + 'SELECT pk_entity, fk_project ' || + 'FROM ' || current_set.function_name || '(' || max_limit || ') ' || + 'ON CONFLICT DO NOTHING'; + + -- Update the pair count + SELECT COUNT(*) INTO pair_count FROM temp_unique_pairs; + + -- Check if the limit has been reached + IF pair_count >= max_limit THEN + EXIT; + END IF; + END LOOP; + + RETURN QUERY + SELECT t.pk_entity, t.fk_project + FROM temp_unique_pairs t + LIMIT max_limit; + +END; +$$ LANGUAGE plpgsql; + +/*** +* Update the full texts +***/ + +CREATE OR REPLACE FUNCTION pgwar.update_full_texts(max_limit int) +RETURNS text AS $$ +DECLARE + updated_count int; +BEGIN + + -- Insert or update pgwar.entity_full_text from the outdated full texts + INSERT INTO pgwar.entity_full_text (pk_entity, fk_project, full_text) + SELECT pk_entity, fk_project, pgwar.get_project_full_text(fk_project, pk_entity) + FROM pgwar.get_outdated_full_texts(max_limit) + ON CONFLICT (pk_entity, fk_project) + DO UPDATE + SET full_text = EXCLUDED.full_text + WHERE entity_full_text.full_text IS DISTINCT FROM EXCLUDED.full_text; + + -- Get the number of rows updated + GET DIAGNOSTICS updated_count = ROW_COUNT; + + -- Return the result message + RETURN 'Number of rows updated: ' || updated_count; +END; +$$ LANGUAGE plpgsql; + + +-- Create the trigger function to update entity preview full text +CREATE OR REPLACE FUNCTION pgwar.update_entity_preview_full_text() +RETURNS TRIGGER AS $$ +BEGIN + + UPDATE pgwar.entity_preview ep + SET full_text = newtab.full_text + FROM newtab + WHERE ep.pk_entity = newtab.pk_entity + AND ep.fk_project = newtab.fk_project + AND ep.full_text IS DISTINCT FROM newtab.full_text; + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + + + +-- Create the trigger after_insert_entity_full_text +CREATE TRIGGER after_insert_entity_full_text +AFTER INSERT ON pgwar.entity_full_text +REFERENCING NEW TABLE AS newtab +EXECUTE FUNCTION pgwar.update_entity_preview_full_text(); + +-- Create the trigger after_insert_entity_full_text +CREATE TRIGGER after_update_entity_full_text +AFTER UPDATE ON pgwar.entity_full_text +REFERENCING NEW TABLE AS newtab +EXECUTE FUNCTION pgwar.update_entity_preview_full_text(); \ No newline at end of file diff --git a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql new file mode 100644 index 000000000..07857e05d --- /dev/null +++ b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-down.sql @@ -0,0 +1,49 @@ +/** +* Triggers +**/ + +DROP TRIGGER after_insert_entity_preview ON pgwar.entity_preview; +DROP TRIGGER after_update_entity_preview ON pgwar.entity_preview; +DROP TRIGGER after_delete_entity_preview_01 ON pgwar.entity_preview; +DROP TRIGGER after_insert_project_statement ON pgwar.project_statements; +DROP TRIGGER after_update_project_statement ON pgwar.project_statements; +DROP TRIGGER after_delete_project_statement ON pgwar.project_statements; +DROP TRIGGER on_upsert_entity_label_config ON projects.entity_label_config; + +/*** +* Trigger Functions +***/ + +DROP FUNCTION pgwar.update_entity_label_on_project_statement_upsert; +DROP FUNCTION pgwar.update_entity_label_on_project_statement_delete; +DROP FUNCTION pgwar.update_entity_labels_after_insert; +DROP FUNCTION pgwar.update_entity_labels_after_update; +DROP FUNCTION pgwar.update_entity_labels_after_delete; +DROP FUNCTION pgwar.update_entity_label_on_entity_label_config_change; + +/*** +* Functions +***/ + +DROP FUNCTION pgwar.get_entity_label_config(int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int, int); +DROP FUNCTION pgwar.get_project_entity_label(int, int, jsonb); +DROP FUNCTION pgwar.update_entity_label_of_entity_preview(int, int, text); +DROP FUNCTION pgwar.get_and_update_project_entity_label(int, int); + +/** +* Views +**/ + +DROP VIEW pgwar.v_community_entity_label; + +/** +* Indexes used by get_project_entity_label +**/ + +DROP INDEX pgwar.project_statements_fk_object_info_fk_project_fk_property_idx; +DROP INDEX pgwar.project_statements_fk_subject_info_fk_project_fk_property_dx; +DROP INDEX pgwar.project_statements_fk_project_fk_property_dx; +DROP INDEX pgwar.project_statements_fk_project_dx; +DROP INDEX information.resource_pk_entity_fk_class_dx; diff --git a/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql new file mode 100644 index 000000000..8e850cd78 --- /dev/null +++ b/database/migrations/sqls/20240612071825-pgwar-project-entity-labels-up.sql @@ -0,0 +1,817 @@ +/** +* Indexes used by get_project_entity_label +**/ + +CREATE INDEX IF NOT EXISTS project_statements_fk_object_info_fk_project_fk_property_idx + ON pgwar.project_statements (fk_object_info,fk_project,fk_property); + +CREATE INDEX IF NOT EXISTS project_statements_fk_subject_info_fk_project_fk_property_dx + ON pgwar.project_statements (fk_subject_info,fk_project,fk_property); + +CREATE INDEX IF NOT EXISTS project_statements_fk_project_fk_property_dx + ON pgwar.project_statements (fk_project,fk_property); + +CREATE INDEX IF NOT EXISTS project_statements_fk_project_dx + ON pgwar.project_statements (fk_project); + +CREATE INDEX IF NOT EXISTS resource_pk_entity_fk_class_dx + ON information.resource (pk_entity,fk_class); + +/** +* Views +**/ + +CREATE VIEW pgwar.v_community_entity_label AS +WITH entity_label_counts AS ( + SELECT + ep.pk_entity, + ep.entity_label, + COUNT(*) AS label_count + FROM + pgwar.entity_preview ep + WHERE ep.fk_project != 0 + GROUP BY + ep.pk_entity, ep.entity_label +), +ranked_entity_labels AS ( + SELECT + pk_entity, + entity_label, + label_count, + ROW_NUMBER() OVER (PARTITION BY pk_entity ORDER BY label_count DESC, entity_label) AS rn + FROM + entity_label_counts +) +SELECT + pk_entity, + entity_label +FROM + ranked_entity_labels +WHERE + rn = 1; + + +/*** +* Functions +***/ + +-- get label of project entity +CREATE OR REPLACE FUNCTION pgwar.get_entity_label_config(class_id int, project_id int) +RETURNS jsonb AS $$ +DECLARE + label_config jsonb; +BEGIN + + SELECT config INTO label_config + FROM projects.entity_label_config + WHERE fk_class = class_id + AND fk_project = project_id; + + IF label_config IS NULL THEN + SELECT config INTO label_config + FROM projects.entity_label_config + WHERE fk_class = class_id + AND fk_project = 375669; + END IF; + + RETURN label_config; +END; +$$ LANGUAGE plpgsql; + +-- get entity label or project entity +CREATE OR REPLACE FUNCTION pgwar.get_project_entity_label(entity_id int, project_id int) +RETURNS text AS $$ +DECLARE + class_id int; + label text; +BEGIN + -- get class_id + SELECT fk_class INTO class_id + FROM information.resource + WHERE pk_entity = entity_id; + -- get label + SELECT pgwar.get_project_entity_label(entity_id, project_id, class_id) INTO label; + + RETURN label; +END; +$$ LANGUAGE plpgsql; + +-- get entity label or project entity +CREATE OR REPLACE FUNCTION pgwar.get_project_entity_label(entity_id int, project_id int, class_id int) +RETURNS text AS $$ +DECLARE + label_config jsonb; + label text; +BEGIN + -- get label config + SELECT pgwar.get_entity_label_config(class_id, project_id) INTO label_config; + -- get label + SELECT pgwar.get_project_entity_label(entity_id, project_id, label_config) INTO label; + + RETURN label; +END; +$$ LANGUAGE plpgsql; + +-- get entity label or project entity +CREATE OR REPLACE FUNCTION pgwar.get_project_entity_label(entity_id int, project_id int, label_config jsonb) +RETURNS text AS $$ +DECLARE + label text; +BEGIN + -- join labels of fields + SELECT substring(string_agg( + -- get label per field + pgwar.get_target_label_of_field(entity_id, project_id, part->'field'), + -- separator + ', ' + ), 1, 100) INTO label + FROM + -- expand fields + jsonb_array_elements(label_config->'labelParts') part; + + RETURN label; +END; +$$ LANGUAGE plpgsql; + + +-- update entity label of entity preview, if distinct +CREATE OR REPLACE FUNCTION pgwar.update_entity_label_of_entity_preview(entity_id int, project_id int, new_label text) +RETURNS void AS $$ +BEGIN + UPDATE pgwar.entity_preview + SET entity_label = new_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + WHERE pk_entity = entity_id + AND fk_project = project_id + AND entity_label IS DISTINCT FROM new_label; +END; +$$ LANGUAGE plpgsql; + + + +-- get and update entity label or project entity +CREATE OR REPLACE FUNCTION pgwar.get_and_update_project_entity_label(entity_id int, project_id int) +RETURNS void AS $$ +BEGIN + IF EXISTS( + SELECT + pk_entity + FROM + pgwar.entity_preview + WHERE + pk_entity = entity_id + AND fk_project = project_id) THEN + PERFORM pgwar.update_entity_label_of_entity_preview(entity_id, project_id, pgwar.get_project_entity_label(entity_id, project_id)); + END IF; +END; +$$ LANGUAGE plpgsql; + +/*** +* Trigger Functions +***/ + + +-- Update entity labels on upsert on project statement +CREATE OR REPLACE FUNCTION pgwar.update_entity_label_on_project_statement_upsert() +RETURNS TRIGGER AS $$ +BEGIN + + IF EXISTS( + SELECT ep.pk_entity, ep.fk_project + FROM pgwar.entity_preview ep, + newtab stmt + WHERE stmt.fk_subject_info = ep.pk_entity + AND stmt.fk_project = ep.fk_project + ) THEN + -- Update the label for the subject entity + WITH new_labels AS ( + SELECT newtab.fk_subject_info AS pk_entity, + newtab.fk_project, + pgwar.get_project_entity_label(newtab.fk_subject_info, newtab.fk_project) AS entity_label + FROM newtab + ) + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE new_labels.pk_entity = ep.pk_entity + AND new_labels.fk_project = ep.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + END IF; + + IF EXISTS( + SELECT ep.pk_entity, ep.fk_project + FROM pgwar.entity_preview ep, + newtab stmt + WHERE stmt.fk_object_info = ep.pk_entity + AND stmt.fk_project = ep.fk_project + ) THEN + -- Update the entity labels of the related object entities + WITH new_labels AS ( + SELECT newtab.fk_object_info AS pk_entity, + newtab.fk_project, + pgwar.get_project_entity_label(newtab.fk_object_info, newtab.fk_project) AS entity_label + FROM newtab + WHERE newtab.object_label IS NULL + ) + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE new_labels.pk_entity = ep.pk_entity + AND new_labels.fk_project = ep.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + END IF; + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +-- Update entity labels on delete on project statement +CREATE OR REPLACE FUNCTION pgwar.update_entity_label_on_project_statement_delete() +RETURNS TRIGGER AS $$ +BEGIN + + WITH new_labels AS ( + -- get new labels of subject entities + SELECT oldtab.fk_subject_info AS pk_entity, + oldtab.fk_project, + pgwar.get_project_entity_label(oldtab.fk_subject_info, oldtab.fk_project) AS entity_label + FROM oldtab + UNION + -- get new labels of object entities + SELECT oldtab.fk_object_info AS pk_entity, + oldtab.fk_project, + pgwar.get_project_entity_label(oldtab.fk_object_info, oldtab.fk_project) AS entity_label + FROM oldtab + WHERE oldtab.object_label IS NULL + ) + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE new_labels.pk_entity = ep.pk_entity + AND new_labels.fk_project = ep.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +-- Update entity labels after inserting entity previews +CREATE OR REPLACE FUNCTION pgwar.update_entity_labels_after_insert() +RETURNS TRIGGER AS $$ +BEGIN + + WITH new_labels AS ( + + -- create entity labels of inserted entity + SELECT newtab.pk_entity, + newtab.fk_project, + pgwar.get_project_entity_label(newtab.pk_entity, newtab.fk_project) AS entity_label + FROM newtab + WHERE newtab.fk_project != 0 + ) + -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + + + -- Update community entity labels + WITH uniq_entities AS ( + SELECT DISTINCT pk_entity + FROM newtab + WHERE newtab.fk_project != 0 + ) + UPDATE pgwar.entity_preview ep + SET entity_label = el.entity_label + FROM uniq_entities, + pgwar.v_community_entity_label el + WHERE uniq_entities.pk_entity = el.pk_entity + AND uniq_entities.pk_entity = ep.pk_entity + AND ep.fk_project = 0 + AND ep.entity_label IS DISTINCT FROM el.entity_label; + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION pgwar.update_entity_labels_after_update() +RETURNS TRIGGER AS $$ +DECLARE + is_not_empty BOOLEAN; + to_update_community INTEGER[]; +BEGIN + + IF pg_trigger_depth() > 100 THEN + RETURN NULL; + END IF; + + -- Check if the table is not empty using EXISTS + SELECT EXISTS(SELECT 1 FROM newtab) INTO is_not_empty; + + IF is_not_empty THEN + + -- Create new entity labels after modifying entity preview fk_class + WITH fk_class_modified AS ( + SELECT + ep.pk_entity, + ep.fk_project, + pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label + FROM + pgwar.entity_preview ep + JOIN + newtab ON ep.pk_entity = newtab.pk_entity AND ep.fk_project = newtab.fk_project + JOIN + oldtab ON oldtab.pk_entity = newtab.pk_entity AND oldtab.fk_project = newtab.fk_project + WHERE + ep.fk_project != 0 + AND oldtab.fk_class IS DISTINCT FROM newtab.fk_class -- fk_class changed ! + ) + UPDATE pgwar.entity_preview ep + SET entity_label = fk_class_modified.entity_label + FROM fk_class_modified + WHERE ep.pk_entity = fk_class_modified.pk_entity + AND ep.fk_project = fk_class_modified.fk_project + AND ep.entity_label IS DISTINCT FROM fk_class_modified.entity_label; + + WITH label_changed AS ( + SELECT + newtab.pk_entity, + newtab.fk_project + FROM + newtab + JOIN oldtab + ON oldtab.pk_entity = newtab.pk_entity AND + oldtab.fk_project = newtab.fk_project AND + oldtab.entity_label IS DISTINCT FROM newtab.entity_label -- entity_label changed ! + WHERE + newtab.fk_project != 0 + ), + new_labels AS ( + -- Create entity labels of the related object entities + SELECT stmt.fk_object_info AS pk_entity, + label_changed.fk_project, + pgwar.get_project_entity_label(stmt.fk_object_info, label_changed.fk_project) AS entity_label + FROM pgwar.project_statements stmt, + label_changed + WHERE stmt.fk_subject_info = label_changed.pk_entity + AND stmt.fk_project = label_changed.fk_project + AND stmt.object_label IS NULL + ) + -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label + ; + + + WITH label_changed AS ( + SELECT + newtab.pk_entity, + newtab.fk_project + FROM + newtab + JOIN oldtab + ON oldtab.pk_entity = newtab.pk_entity AND + oldtab.fk_project = newtab.fk_project AND + oldtab.entity_label IS DISTINCT FROM newtab.entity_label -- entity_label changed ! + WHERE + newtab.fk_project != 0 + ), + new_labels AS ( + -- Create entity labels of the related subject entities + SELECT stmt.fk_subject_info AS pk_entity, + label_changed.fk_project, + pgwar.get_project_entity_label(stmt.fk_subject_info, label_changed.fk_project) AS entity_label + FROM pgwar.project_statements stmt, + label_changed + WHERE stmt.fk_object_info = label_changed.pk_entity + AND stmt.fk_project = label_changed.fk_project + AND stmt.object_label IS NULL + ) -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label + ; + + -- get ids that need update of community label + SELECT array_agg(pk_entity) INTO to_update_community + FROM ( + SELECT newtab.pk_entity + FROM + newtab + JOIN oldtab + ON oldtab.pk_entity = newtab.pk_entity AND + oldtab.fk_project = newtab.fk_project AND + oldtab.entity_label IS DISTINCT FROM newtab.entity_label -- entity_label changed ! + WHERE + newtab.fk_project != 0 + GROUP BY newtab.pk_entity + ) as changed; + + UPDATE pgwar.entity_preview ep + SET entity_label = el.entity_label + FROM unnest(to_update_community) as changed_pk_entity(pk_entity), + pgwar.v_community_entity_label el + WHERE changed_pk_entity.pk_entity = el.pk_entity + AND changed_pk_entity.pk_entity = ep.pk_entity + AND ep.fk_project = 0 + AND ep.entity_label IS DISTINCT FROM el.entity_label; + + END IF; + + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION pgwar.update_entity_labels_after_delete() +RETURNS TRIGGER AS $$ +DECLARE + is_not_empty BOOLEAN; +BEGIN + -- Check if the table is not empty using EXISTS + SELECT EXISTS(SELECT 1 FROM oldtab) INTO is_not_empty; + + IF is_not_empty THEN + + WITH new_labels AS ( + + -- Create entity labels of the related object entities + SELECT stmt.fk_object_info AS pk_entity, + oldtab.fk_project, + pgwar.get_project_entity_label(stmt.fk_object_info, oldtab.fk_project) AS entity_label + FROM pgwar.project_statements stmt, + oldtab + WHERE oldtab.entity_label IS NOT NULL + AND oldtab.fk_project != 0 + AND stmt.fk_subject_info = oldtab.pk_entity + AND stmt.fk_project = oldtab.fk_project + AND stmt.object_label IS NULL + UNION ALL + + -- Create entity labels of the related subject entities + SELECT stmt.fk_subject_info AS pk_entity, + oldtab.fk_project, + pgwar.get_project_entity_label(stmt.fk_subject_info, oldtab.fk_project) AS entity_label + FROM pgwar.project_statements stmt, + oldtab + WHERE oldtab.entity_label IS NOT NULL + AND oldtab.fk_project != 0 + AND stmt.fk_object_info = oldtab.pk_entity + AND stmt.fk_project = oldtab.fk_project + AND stmt.object_label IS NULL + ) + -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + + + -- Update community entity labels + WITH uniq_entities AS ( + SELECT DISTINCT pk_entity + FROM oldtab + WHERE oldtab.fk_project != 0 + ) + UPDATE pgwar.entity_preview ep + SET entity_label = el.entity_label + FROM uniq_entities, + pgwar.v_community_entity_label el + WHERE uniq_entities.pk_entity = el.pk_entity + AND uniq_entities.pk_entity = ep.pk_entity + AND ep.fk_project = 0 + AND ep.entity_label IS DISTINCT FROM el.entity_label; + + END IF; + + + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +-- Update entity labels manually based on entity label config changes +CREATE OR REPLACE FUNCTION pgwar.update_entity_label_on_config_change() + RETURNS VOID AS $$ +DECLARE + _job_name text; -- Variable to store the job name + _current_offset timestamp; -- Variable to store the current offset timestam + project_id int; + class_id int; +BEGIN + _job_name := 'update-entity-label-on-config-change'; -- Initialize the job name + + -- Check if the offset for the job is already initialized + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + -- If not, initialize it with a default value + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2024-10-17 00:00:00.000000+00'); + END IF; + + -- Retrieve the current offset timestamp for the job + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + -- Get project_id and class_id from the entity_label_config table + FOR project_id, class_id IN + SELECT fk_project, fk_class + FROM projects.entity_label_config + WHERE tmsp_last_modification > _current_offset + LOOP + IF project_id = 375669 THEN + -- Perform update of entity labels that depend on the default config of project 375669 + WITH new_labels AS ( + SELECT ep.pk_entity, + ep.fk_project, + pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label + FROM pgwar.entity_preview ep + LEFT JOIN projects.entity_label_config c + ON c.fk_class = ep.fk_class + AND c.fk_project = ep.fk_project + WHERE ep.fk_class = class_id + AND ep.fk_project != 0 -- all projects except 0 + AND c.config IS NULL -- take only rows that have no own project config + ) + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE new_labels.pk_entity = ep.pk_entity + AND new_labels.fk_project = ep.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + ELSE + -- Update the project entity labels + WITH new_labels AS ( + SELECT ep.pk_entity, + ep.fk_project, + pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label + FROM pgwar.entity_preview ep + WHERE ep.fk_project != 0 AND ep.fk_project = project_id -- all projects except 0 + ) + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + END IF; + END LOOP; + + -- Update the offset table with the current timestamp to mark the job completion time + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + +-- Update entity_preview label +CREATE OR REPLACE FUNCTION pgwar.update_entity_preview_entity_label() + RETURNS VOID AS $$ +DECLARE + _job_name text; + _current_offset timestamp; +BEGIN + _job_name := 'update-entity-label'; + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- Get the current offset timestamp + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + -- Retrieve and update entity labels for rows inserted/updated after the last offset + WITH new_labels AS ( + -- Select entities that were inserted or updated after the last offset + SELECT ep.pk_entity, + ep.fk_project, + pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label + FROM pgwar.entity_preview ep + WHERE ep.fk_project != 0 + AND (ep.tmsp_entity_label_modification > _current_offset OR ep.tmsp_fk_class_modification > _current_offset OR ep.tmsp_entity_label_modification IS NULL) + ) + -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + -- Update community entity labels + WITH uniq_entities AS ( + SELECT DISTINCT ep.pk_entity + FROM pgwar.entity_preview ep + WHERE ep.fk_project != 0 + AND (ep.tmsp_entity_label_modification > _current_offset OR ep.tmsp_fk_class_modification > _current_offset OR ep.tmsp_entity_label_modification IS NULL) + ) + UPDATE pgwar.entity_preview ep + SET entity_label = el.entity_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + FROM uniq_entities, + pgwar.v_community_entity_label el + WHERE uniq_entities.pk_entity = el.pk_entity + AND uniq_entities.pk_entity = ep.pk_entity + AND ep.fk_project = 0 + AND ep.entity_label IS DISTINCT FROM el.entity_label; + + -- Update the offset table with the current timestamp to mark the job completion time + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + +-- Update entity_preview label +CREATE OR REPLACE FUNCTION pgwar.update_entity_preview_entity_label_after_stmt_delete() + RETURNS VOID AS $$ +DECLARE + _job_name text; + _current_offset timestamp; +BEGIN + _job_name := 'update-entity-label-after-stmt-delete'; + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- Get the current offset timestamp + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + -- Retrieve and update entity labels for rows inserted/updated after the last offset + WITH new_labels AS ( + -- Select entities that have a deleted statement after the last offset + SELECT ep.pk_entity, + ep.fk_project, + pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label + FROM pgwar.entity_preview ep + JOIN pgwar.project_statements ps ON ps.fk_subject_info = ep.pk_entity AND ep.fk_project = ps.fk_project + JOIN pgwar.v_statements_deleted_combined sdc ON sdc.fk_object_info = ps.fk_object_info AND ps.fk_project = sdc.fk_project + WHERE sdc.tmsp_deletion > _current_offset + ) + -- Update the project entity labels + UPDATE pgwar.entity_preview ep + SET entity_label = new_labels.entity_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + FROM new_labels + WHERE ep.pk_entity = new_labels.pk_entity + AND ep.fk_project = new_labels.fk_project + AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; + + -- Update community entity labels + WITH uniq_entities AS ( + SELECT DISTINCT ep.pk_entity + FROM pgwar.entity_preview ep + JOIN pgwar.project_statements ps ON ps.fk_subject_info = ep.pk_entity AND ep.fk_project = ps.fk_project + JOIN pgwar.v_statements_deleted_combined sdc ON sdc.fk_object_info = ps.fk_object_info AND ps.fk_project = sdc.fk_project + WHERE sdc.tmsp_deletion > _current_offset AND ep.fk_project != 0 + ) + UPDATE pgwar.entity_preview ep + SET entity_label = el.entity_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + FROM uniq_entities, + pgwar.v_community_entity_label el + WHERE uniq_entities.pk_entity = el.pk_entity + AND uniq_entities.pk_entity = ep.pk_entity + AND ep.fk_project = 0 + AND ep.entity_label IS DISTINCT FROM el.entity_label; + + -- Update the offset table with the current timestamp to mark the job completion time + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + + +-- -- Update entity labels on change on entity label config +-- CREATE OR REPLACE FUNCTION pgwar.update_entity_label_on_entity_label_config_change() +-- RETURNS TRIGGER AS $$ +-- DECLARE +-- project_id int; +-- class_id int; +-- BEGIN +-- +-- project_id := COALESCE(NEW.fk_project, OLD.fk_project); +-- class_id := COALESCE(NEW.fk_class, OLD.fk_class); +-- +-- IF project_id = 375669 THEN +-- +-- -- perform update of entity labels that depend on the default config of project 375669 +-- WITH new_labels AS ( +-- SELECT ep.pk_entity, +-- ep.fk_project, +-- pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label +-- FROM pgwar.entity_preview ep +-- LEFT JOIN projects.entity_label_config c +-- ON c.fk_class = ep.fk_class +-- AND c.fk_project = ep.fk_project +-- WHERE ep.fk_class = class_id +-- AND ep.fk_project != 0 -- all projects except 0 +-- AND c.config IS NULL -- take only rows that have no own project config +-- ) +-- UPDATE pgwar.entity_preview ep +-- SET entity_label = new_labels.entity_label +-- FROM new_labels +-- WHERE new_labels.pk_entity = ep.pk_entity +-- AND new_labels.fk_project = ep.fk_project +-- AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; +-- +-- ELSE +-- -- Update the project entity labels +-- WITH new_labels AS ( +-- SELECT ep.pk_entity, +-- ep.fk_project, +-- pgwar.get_project_entity_label(ep.pk_entity, ep.fk_project) AS entity_label +-- FROM pgwar.entity_preview ep +-- WHERE ep.fk_project != 0 -- all projects except 0 +-- ) +-- UPDATE pgwar.entity_preview ep +-- SET entity_label = new_labels.entity_label +-- FROM new_labels +-- WHERE ep.pk_entity = new_labels.pk_entity +-- AND ep.fk_project = new_labels.fk_project +-- AND ep.entity_label IS DISTINCT FROM new_labels.entity_label; +-- +-- END IF; +-- +-- RETURN NULL; +-- END; +-- $$ LANGUAGE plpgsql; + + +/*** +* Triggers +***/ + +-- CREATE TRIGGER after_insert_entity_preview +-- AFTER INSERT ON pgwar.entity_preview +-- REFERENCING NEW TABLE AS newtab +-- EXECUTE FUNCTION pgwar.update_entity_labels_after_insert(); + +-- CREATE TRIGGER after_update_entity_preview +-- AFTER UPDATE ON pgwar.entity_preview +-- REFERENCING NEW TABLE AS newtab OLD TABLE AS oldtab +-- EXECUTE FUNCTION pgwar.update_entity_labels_after_update(); + +CREATE TRIGGER after_delete_entity_preview_01 +AFTER DELETE ON pgwar.entity_preview +REFERENCING OLD TABLE AS oldtab +EXECUTE FUNCTION pgwar.update_entity_labels_after_delete(); + +CREATE TRIGGER after_insert_project_statement +AFTER INSERT ON pgwar.project_statements +REFERENCING NEW TABLE AS newtab +EXECUTE FUNCTION pgwar.update_entity_label_on_project_statement_upsert(); + +CREATE TRIGGER after_update_project_statement +AFTER UPDATE ON pgwar.project_statements +REFERENCING NEW TABLE AS newtab +EXECUTE FUNCTION pgwar.update_entity_label_on_project_statement_upsert(); + +CREATE TRIGGER after_delete_project_statement +AFTER DELETE ON pgwar.project_statements +REFERENCING OLD TABLE AS oldtab +EXECUTE FUNCTION pgwar.update_entity_label_on_project_statement_delete(); + +-- CREATE TRIGGER on_upsert_entity_label_config +-- AFTER DELETE OR INSERT OR UPDATE ON projects.entity_label_config +-- FOR EACH ROW +-- EXECUTE FUNCTION pgwar.update_entity_label_on_entity_label_config_change(); \ No newline at end of file diff --git a/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql new file mode 100644 index 000000000..dbe993a66 --- /dev/null +++ b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-down.sql @@ -0,0 +1,2 @@ +ALTER TABLE information.resource +ALTER COLUMN fk_class DROP NOT NULL; diff --git a/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql new file mode 100644 index 000000000..3612f5074 --- /dev/null +++ b/database/migrations/sqls/20240613180752-inf-t-resource-add-fk-class-not-null-up.sql @@ -0,0 +1,6 @@ +UPDATE information.resource +SET fk_class = 0 +WHERE fk_class IS NULL; + +ALTER TABLE information.resource +ALTER COLUMN fk_class SET NOT NULL; \ No newline at end of file diff --git a/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql new file mode 100644 index 000000000..cc698a817 --- /dev/null +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-down.sql @@ -0,0 +1,9 @@ +DROP INDEX pgwar.project_statements_fk_subject_info_idx; +DROP INDEX pgwar.project_statements_fk_object_info_idx; +DROP INDEX pgwar.community_statements_fk_subject_info_idx; +DROP INDEX pgwar.community_statements_fk_object_info_idx; +DROP INDEX pgwar.project_statements_outgoing_order_idx; +DROP INDEX pgwar.community_statements_fk_property_idx; +DROP INDEX pgwar.project_statements_fk_property_idx; +DROP INDEX pgwar.entity_preview_fk_class_idx; +DROP INDEX pgwar.entity_preview_entity_label_idx; \ No newline at end of file diff --git a/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql new file mode 100644 index 000000000..c79f96019 --- /dev/null +++ b/database/migrations/sqls/20240618112815-pgwar-indexes-up.sql @@ -0,0 +1,45 @@ +CREATE INDEX IF NOT EXISTS project_statements_fk_subject_info_idx + ON pgwar.project_statements USING btree + (fk_subject_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_fk_object_info_idx + ON pgwar.project_statements USING btree + (fk_object_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_subject_info_idx + ON pgwar.community_statements USING btree + (fk_subject_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_object_info_idx + ON pgwar.community_statements USING btree + (fk_object_info ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_outgoing_order_idx + ON pgwar.project_statements USING btree + (ord_num_of_range ASC NULLS LAST, tmsp_last_modification DESC NULLS FIRST); + +CREATE INDEX IF NOT EXISTS community_statements_fk_property_idx + ON pgwar.community_statements USING btree + (fk_property ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS project_statements_fk_property_idx + ON pgwar.project_statements USING btree + (fk_property ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS entity_preview_fk_class_idx + ON pgwar.entity_preview USING btree + (fk_class ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS entity_preview_entity_label_idx + ON pgwar.entity_preview USING btree + (entity_label ASC NULLS LAST); + +CREATE INDEX IF NOT EXISTS api_property_tmsp_last_dfh_update_idx + ON data_for_history.api_property USING btree + (tmsp_last_dfh_update DESC NULLS LAST) + TABLESPACE pg_default; + +CREATE INDEX IF NOT EXISTS community_statements_tmsp_last_modification_idx + ON pgwar.community_statements USING btree + (tmsp_last_modification DESC NULLS LAST) + TABLESPACE pg_default; \ No newline at end of file diff --git a/database/migrations/sqls/20240625144815-war-drop-schema-down.sql b/database/migrations/sqls/20240625144815-war-drop-schema-down.sql new file mode 100644 index 000000000..01cc935d0 --- /dev/null +++ b/database/migrations/sqls/20240625144815-war-drop-schema-down.sql @@ -0,0 +1 @@ +-- NO WAY BACK \ No newline at end of file diff --git a/database/migrations/sqls/20240625144815-war-drop-schema-up.sql b/database/migrations/sqls/20240625144815-war-drop-schema-up.sql new file mode 100644 index 000000000..c7bafbf40 --- /dev/null +++ b/database/migrations/sqls/20240625144815-war-drop-schema-up.sql @@ -0,0 +1,5 @@ +DROP SCHEMA IF EXISTS war CASCADE; + +DROP TRIGGER IF EXISTS add_entity_preview_partition ON projects.project; + +DROP FUNCTION IF EXISTS projects.add_entity_preview_partition; \ No newline at end of file diff --git a/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-down.sql b/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-down.sql new file mode 100644 index 000000000..e3e490cc8 --- /dev/null +++ b/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-down.sql @@ -0,0 +1,2 @@ +DROP VIEW pgwar.v_property_preview; +DROP VIEW pgwar.v_class_preview; diff --git a/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-up.sql b/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-up.sql new file mode 100644 index 000000000..7d55976bd --- /dev/null +++ b/database/migrations/sqls/20240626082849-pgwar-property-and-class-views-up.sql @@ -0,0 +1,147 @@ +-- create view v_property_preview +CREATE OR REPLACE VIEW pgwar.v_property_preview AS WITH tw0 AS ( + SELECT project.pk_entity, + project.fk_language + FROM projects.project + UNION ALL + SELECT NULL::integer AS int4, + 18889 + ), + tw1 AS ( + SELECT t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 1 AS rank, + 'project label'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE t1.pk_entity = t2.fk_project + AND t2.fk_dfh_property IS NOT NULL + AND t2.fk_language = t1.fk_language + UNION ALL + SELECT t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 2 AS rank, + 'default project label in default lang'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE 375669 = t2.fk_project + AND t2.fk_dfh_property IS NOT NULL + AND t2.fk_language = t1.fk_language + UNION ALL + SELECT t3.fk_property, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in default lang'::text AS text + FROM tw0 t1, + information.language t2, + data_for_history.v_label t3 + WHERE t3.fk_property IS NOT NULL + AND t3.language::bpchar = t2.iso6391 + AND t3.type = 'label'::text + UNION ALL + SELECT t2.fk_dfh_property AS fk_property, + t1.pk_entity AS fk_project, + t2.string AS label, + 4 AS rank, + 'default project label in en'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE 375669 = t2.fk_project + AND t2.fk_dfh_property IS NOT NULL + AND t2.fk_language = 18889 + UNION ALL + SELECT t3.fk_property, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in en'::text AS text + FROM tw0 t1, + data_for_history.v_label t3 + WHERE t3.fk_property IS NOT NULL + AND t3.language::text = 'en'::text + AND t3.type = 'label'::text + ) +SELECT DISTINCT ON (fk_project, fk_property) fk_property, + fk_project, + label +FROM tw1 +ORDER BY fk_project, + fk_property, + rank; +-- create view v_class_preview +CREATE OR REPLACE VIEW pgwar.v_class_preview AS WITH tw0 AS ( + SELECT project.pk_entity, + project.fk_language + FROM projects.project + UNION ALL + SELECT NULL::integer AS int4, + 18889 + ), + tw1 AS ( + SELECT t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 1 AS rank, + 'project label'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE t1.pk_entity = t2.fk_project + AND t2.fk_dfh_class IS NOT NULL + AND t2.fk_language = t1.fk_language + UNION ALL + SELECT t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 2 AS rank, + 'default project label in default lang'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE 375669 = t2.fk_project + AND t2.fk_dfh_class IS NOT NULL + AND t2.fk_language = t1.fk_language + UNION ALL + SELECT t3.fk_class, + t1.pk_entity AS fk_project, + t3.label, + 3 AS rank, + 'ontome label in default lang'::text AS text + FROM tw0 t1, + information.language t2, + data_for_history.v_label t3 + WHERE t3.fk_class IS NOT NULL + AND t1.fk_language = t2.pk_entity + AND t3.language::bpchar = t2.iso6391 + AND t3.type = 'label'::text + UNION ALL + SELECT t2.fk_dfh_class AS fk_class, + t1.pk_entity AS fk_project, + t2.string AS label, + 4 AS rank, + 'default project label in en'::text AS text + FROM tw0 t1, + projects.text_property t2 + WHERE 375669 = t2.fk_project + AND t2.fk_dfh_class IS NOT NULL + AND t2.fk_language = 18889 + UNION ALL + SELECT t3.fk_class, + t1.pk_entity AS fk_project, + t3.label, + 5 AS rank, + 'ontome label in en'::text AS text + FROM tw0 t1, + data_for_history.v_label t3 + WHERE t3.fk_class IS NOT NULL + AND t3.language::text = 'en'::text + AND t3.type = 'label'::text + ) +SELECT DISTINCT ON (fk_project, fk_class) fk_class, + fk_project, + label +FROM tw1 +ORDER BY fk_project, + fk_class, + rank; diff --git a/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql b/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql new file mode 100644 index 000000000..65cd2b57c --- /dev/null +++ b/database/migrations/sqls/20240627084826-pgwar-field-change-down.sql @@ -0,0 +1,15 @@ +-- Drop Triggers +------------------------------------------------------------- +DROP TRIGGER after_update_field_change ON pgwar.field_change; +DROP TRIGGER after_insert_field_change ON pgwar.field_change; +DROP TRIGGER after_modify_project_statements ON pgwar.project_statements; + +-- Drop Functions +------------------------------------------------------------- +DROP FUNCTION pgwar.field_change_notify_upsert; +DROP FUNCTION pgwar.update_field_change_on_project_statements_modification; +DROP FUNCTION pgwar.upsert_field_change; + +-- Drop Table +------------------------------------------------------------- +DROP TABLE pgwar.field_change; diff --git a/database/migrations/sqls/20240627084826-pgwar-field-change-up.sql b/database/migrations/sqls/20240627084826-pgwar-field-change-up.sql new file mode 100644 index 000000000..853266013 --- /dev/null +++ b/database/migrations/sqls/20240627084826-pgwar-field-change-up.sql @@ -0,0 +1,139 @@ +------ Table pgwar.field_change ----------------------------------------------------- +--------------------------------------------------------------------------------------------- +CREATE TABLE pgwar.field_change +( + fk_project integer NOT NULL, + fk_source_info integer NOT NULL, + fk_source_tables_cell bigint, + fk_property integer NOT NULL, + is_outgoing boolean NOT NULL, + tmsp_last_modification timestamp with time zone, + UNIQUE NULLS NOT DISTINCT(fk_project, fk_source_info, fk_source_tables_cell, fk_property, is_outgoing) +); + +-- Function to upsert on pgwar.field_change +----------------------------------------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.upsert_field_change(fc pgwar.field_change) + RETURNS VOID +AS $$ +BEGIN + INSERT INTO pgwar.field_change( + fk_project, + fk_source_info, + fk_source_tables_cell, + fk_property, + is_outgoing, + tmsp_last_modification + ) + VALUES( + + fc.fk_project, + fc.fk_source_info, + fc.fk_source_tables_cell, + fc.fk_property, + fc.is_outgoing, + fc.tmsp_last_modification + ) + ON CONFLICT(fk_project, fk_source_info, fk_source_tables_cell, fk_property, is_outgoing) + DO UPDATE SET + -- ... or update the pgwar.statement + fk_project = EXCLUDED.fk_project, + fk_source_info = EXCLUDED.fk_source_info, + fk_source_tables_cell = EXCLUDED.fk_source_tables_cell, + fk_property = EXCLUDED.fk_property, + is_outgoing = EXCLUDED.is_outgoing, + tmsp_last_modification = EXCLUDED.tmsp_last_modification + WHERE + -- ... where it is distinct from previous value + field_change.fk_project IS DISTINCT FROM EXCLUDED.fk_project OR + field_change.fk_source_info IS DISTINCT FROM EXCLUDED.fk_source_info OR + field_change.fk_source_tables_cell IS DISTINCT FROM EXCLUDED.fk_source_tables_cell OR + field_change.fk_property IS DISTINCT FROM EXCLUDED.fk_property OR + field_change.is_outgoing IS DISTINCT FROM EXCLUDED.is_outgoing OR + field_change.tmsp_last_modification IS DISTINCT FROM EXCLUDED.tmsp_last_modification; +END; +$$ +LANGUAGE plpgsql; + +-- Function upsert_field_change +---------------------------------------------- +CREATE FUNCTION pgwar.update_field_change_on_project_statements_modification() + RETURNS TRIGGER AS $$ +DECLARE + proj_stmt pgwar.project_statements; +BEGIN + + proj_stmt := COALESCE(NEW, OLD); + --if project statement is a statement with literal + IF proj_stmt.object_value IS NOT NULL THEN + PERFORM + pgwar.upsert_field_change(( + proj_stmt.fk_project, + proj_stmt.fk_subject_info, + NULL, + proj_stmt.fk_property, + true, + proj_stmt.tmsp_last_modification + )::pgwar.field_change); + --else if project statement is a statement with entity + ELSE + PERFORM + pgwar.upsert_field_change(( + proj_stmt.fk_project, + proj_stmt.fk_subject_info, + NULL, + proj_stmt.fk_property, + true, + proj_stmt.tmsp_last_modification + )::pgwar.field_change); + + PERFORM + pgwar.upsert_field_change(( + proj_stmt.fk_project, + proj_stmt.fk_object_info, + proj_stmt.fk_object_tables_cell, + proj_stmt.fk_property, + false, + proj_stmt.tmsp_last_modification + )::pgwar.field_change); + END IF; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + + +CREATE CONSTRAINT TRIGGER after_modify_project_statements + AFTER INSERT OR UPDATE OR DELETE ON pgwar.project_statements + DEFERRABLE + FOR EACH ROW EXECUTE PROCEDURE pgwar.update_field_change_on_project_statements_modification(); + +-- Function pgwar.field_change_notify_upsert +---------------------------------------------- +CREATE OR REPLACE FUNCTION pgwar.field_change_notify_upsert() + RETURNS trigger + LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE + item json; +BEGIN + FOR item in SELECT row_to_json(new_table) FROM new_table + LOOP + PERFORM pg_notify('field_change'::text, item::text); + end LOOP; + RETURN NEW; +END; +$BODY$; + +CREATE TRIGGER after_insert_field_change + AFTER INSERT + ON pgwar.field_change + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT +EXECUTE FUNCTION pgwar.field_change_notify_upsert(); + +CREATE TRIGGER after_update_field_change + AFTER UPDATE + ON pgwar.field_change + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT +EXECUTE FUNCTION pgwar.field_change_notify_upsert(); \ No newline at end of file diff --git a/database/migrations/sqls/20240627125256-pgwar-add-notifications-down.sql b/database/migrations/sqls/20240627125256-pgwar-add-notifications-down.sql new file mode 100644 index 000000000..f893006e3 --- /dev/null +++ b/database/migrations/sqls/20240627125256-pgwar-add-notifications-down.sql @@ -0,0 +1,6 @@ +DROP TRIGGER after_insert_on_entity_preview ON pgwar.entity_preview; +DROP TRIGGER after_update_on_entity_preview ON pgwar.entity_preview; +DROP TRIGGER last_modification_tmsp ON pgwar.entity_preview; +DROP FUNCTION pgwar.entity_previews_notify_upsert(); +DROP FUNCTION pgwar.entity_previews_notify_update(); + diff --git a/database/migrations/sqls/20240627125256-pgwar-add-notifications-up.sql b/database/migrations/sqls/20240627125256-pgwar-add-notifications-up.sql new file mode 100644 index 000000000..28017fc3e --- /dev/null +++ b/database/migrations/sqls/20240627125256-pgwar-add-notifications-up.sql @@ -0,0 +1,74 @@ +CREATE OR REPLACE FUNCTION pgwar.entity_previews_notify_upsert() + RETURNS trigger + LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE + notification text; +BEGIN + + + SELECT DISTINCT tmsp_last_modification::text into notification + FROM new_table + WHERE tmsp_last_modification is not null + LIMIT 1; + + IF notification IS NOT NULL THEN + PERFORM pg_notify('entity_previews_updated'::text, notification); + END IF; + +RETURN NEW; +END; +$BODY$; + +CREATE OR REPLACE FUNCTION pgwar.entity_previews_notify_update() + RETURNS trigger + LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE + notification text; +BEGIN + + +SELECT DISTINCT new_table.tmsp_last_modification::text into notification +FROM new_table, + old_table +WHERE new_table.pk_entity = old_table.pk_entity +AND new_table.fk_project = old_table.fk_project +AND new_table.tmsp_last_modification is not null +AND ( + new_table.fk_class IS DISTINCT FROM old_table.fk_class OR + new_table.class_label IS DISTINCT FROM old_table.class_label OR + new_table.entity_label IS DISTINCT FROM old_table.entity_label OR + new_table.entity_type IS DISTINCT FROM old_table.entity_type OR + new_table.type_label IS DISTINCT FROM old_table.type_label OR + new_table.fk_type IS DISTINCT FROM old_table.fk_type +) +LIMIT 1; + + if notification is not null then + PERFORM pg_notify('entity_previews_updated'::text, notification); + end if; + +RETURN NEW; +END; +$BODY$; + +CREATE TRIGGER after_insert_on_entity_preview + AFTER INSERT + ON pgwar.entity_preview + REFERENCING NEW TABLE AS new_table + FOR EACH STATEMENT + EXECUTE FUNCTION pgwar.entity_previews_notify_upsert(); + +CREATE TRIGGER after_update_on_entity_preview + AFTER UPDATE + ON pgwar.entity_preview + REFERENCING NEW TABLE AS new_table OLD TABLE AS old_table + FOR EACH STATEMENT + EXECUTE FUNCTION pgwar.entity_previews_notify_update(); + +CREATE TRIGGER last_modification_tmsp + BEFORE INSERT OR UPDATE + ON pgwar.entity_preview + FOR EACH ROW + EXECUTE FUNCTION commons.tmsp_last_modification(); diff --git a/database/migrations/sqls/20240627141623-pgwar-ts-vector-down.sql b/database/migrations/sqls/20240627141623-pgwar-ts-vector-down.sql new file mode 100644 index 000000000..1a661416e --- /dev/null +++ b/database/migrations/sqls/20240627141623-pgwar-ts-vector-down.sql @@ -0,0 +1,7 @@ +-- Down migration script + +-- Drop the trigger if +DROP TRIGGER on_upsert_entity_preview_set_ts_vector ON pgwar.entity_preview; + +-- Drop the function if +DROP FUNCTION pgwar.entity_preview_ts_vector(); diff --git a/database/migrations/sqls/20240627141623-pgwar-ts-vector-up.sql b/database/migrations/sqls/20240627141623-pgwar-ts-vector-up.sql new file mode 100644 index 000000000..fb47508ed --- /dev/null +++ b/database/migrations/sqls/20240627141623-pgwar-ts-vector-up.sql @@ -0,0 +1,20 @@ +CREATE OR REPLACE FUNCTION pgwar.entity_preview_ts_vector() + RETURNS trigger + LANGUAGE 'plpgsql' +AS $BODY$ + BEGIN NEW.ts_vector = ( + SELECT + setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || + setweight(to_tsvector(coalesce(NEW.type_label, '')), 'B') || + setweight(to_tsvector(coalesce(NEW.class_label, '')), 'B') || + setweight(to_tsvector(coalesce(NEW.full_text, '')), 'C') + ); + RETURN NEW; + END; +$BODY$; + +CREATE TRIGGER on_upsert_entity_preview_set_ts_vector + BEFORE INSERT OR UPDATE OF entity_label, type_label, class_label, full_text + ON pgwar.entity_preview + FOR EACH ROW + EXECUTE FUNCTION pgwar.entity_preview_ts_vector(); \ No newline at end of file diff --git a/database/migrations/sqls/20240627193836-pgwar-entity-class-down.sql b/database/migrations/sqls/20240627193836-pgwar-entity-class-down.sql new file mode 100644 index 000000000..6b5dd25c8 --- /dev/null +++ b/database/migrations/sqls/20240627193836-pgwar-entity-class-down.sql @@ -0,0 +1,11 @@ +-- Drop the function pgwar.update_entity_class() +DROP FUNCTION pgwar.update_entity_class(); + +-- Drop the index on the fk_language column in the projects.project table +DROP INDEX IF EXISTS projects.project_fk_language_idx; + +-- Drop the index on the fk_project column in the pgwar.entity_preview table +DROP INDEX IF EXISTS pgwar.entity_preview_fk_project_idx; + +-- Drop the pgwar.update_entity_class function +DROP FUNCTION IF EXISTS pgwar.update_entity_class(); \ No newline at end of file diff --git a/database/migrations/sqls/20240627193836-pgwar-entity-class-up.sql b/database/migrations/sqls/20240627193836-pgwar-entity-class-up.sql new file mode 100644 index 000000000..a53b16ae1 --- /dev/null +++ b/database/migrations/sqls/20240627193836-pgwar-entity-class-up.sql @@ -0,0 +1,104 @@ +CREATE INDEX project_fk_language_idx ON projects.project(fk_language); + +CREATE INDEX entity_preview_fk_project_idx ON pgwar.entity_preview(fk_project); + +CREATE +OR REPLACE FUNCTION pgwar.update_entity_class() RETURNS void AS $$ +DECLARE + _job_name text; +BEGIN + _job_name := 'update-entity-class'; + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- get current offset + WITH _offset AS ( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ), + project_lang AS ( + -- select project/community id and its language + SELECT + proj.pk_entity as fk_project, + COALESCE(TRIM(iso6391), 'en') lang_code, -- language code or english + proj.tmsp_last_modification AS project_modified, + lang.tmsp_last_modification AS language_modified + FROM projects.project proj + LEFT JOIN information.language lang ON proj.fk_language = lang.pk_entity + WHERE lang.pk_entity = proj.fk_language + UNION + SELECT 0, 'en', NULL, NULL -- add a row for community in english + ), + class_metadata AS ( + -- get the class labels and entity type + SELECT DISTINCT ON (cla.dfh_pk_class, cla.dfh_class_label_language) + cla.dfh_pk_class AS fk_class, + cla.dfh_class_label AS class_label, + cla.dfh_class_label_language as lang_code, + cla.tmsp_last_modification as class_modified, + CASE WHEN 70 = ANY (cla.dfh_parent_classes || cla.dfh_ancestor_classes) + THEN 'peIt' + ELSE 'teEn' + END entity_type, + cla.dfh_parent_classes, + cla.dfh_ancestor_classes + FROM data_for_history.api_class cla + ORDER BY + cla.dfh_pk_class, + cla.dfh_class_label_language, + cla.removed_from_api ASC, -- prioritize false over true + cla.tmsp_last_modification DESC -- prioritize newer labels + + ), + entity_preview_with_class_metadata AS ( + -- join entity previews with class metadata + SELECT + ep.pk_entity, + ep.fk_project, + ep.fk_class, + COALESCE(meta.class_label, meta_en.class_label) AS class_label, + COALESCE(meta.entity_type, meta_en.entity_type) AS entity_type, + COALESCE(meta.dfh_parent_classes, meta_en.dfh_parent_classes) AS dfh_parent_classes, + COALESCE(meta.dfh_ancestor_classes, meta_en.dfh_ancestor_classes) AS dfh_ancestor_classes, + COALESCE(meta.class_modified, meta_en.class_modified) AS class_modified, + project_lang.project_modified, + project_lang.language_modified, + ep.tmsp_fk_class_modification + FROM project_lang + JOIN pgwar.entity_preview ep ON project_lang.fk_project = ep.fk_project + LEFT JOIN class_metadata meta ON ep.fk_class = meta.fk_class AND meta.lang_code = project_lang.lang_code + LEFT JOIN class_metadata meta_en ON ep.fk_class = meta_en.fk_class AND meta_en.lang_code = 'en' + ) + UPDATE pgwar.entity_preview ep + SET class_label = meta.class_label, + entity_type = meta.entity_type, + parent_classes = to_jsonb(meta.dfh_parent_classes), + ancestor_classes = to_jsonb(meta.dfh_ancestor_classes) + FROM entity_preview_with_class_metadata meta, + _offset + WHERE ep.pk_entity = meta.pk_entity + AND ep.fk_project = meta.fk_project + AND ( + meta.class_modified > _offset.offset_tmsp OR + meta.project_modified > _offset.offset_tmsp OR + meta.language_modified > _offset.offset_tmsp OR + meta.tmsp_fk_class_modification > _offset.offset_tmsp + ); + + + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; diff --git a/database/migrations/sqls/20240628121705-pgwar-fk-type-down.sql b/database/migrations/sqls/20240628121705-pgwar-fk-type-down.sql new file mode 100644 index 000000000..efc57dfa9 --- /dev/null +++ b/database/migrations/sqls/20240628121705-pgwar-fk-type-down.sql @@ -0,0 +1,2 @@ +-- Drop the function +DROP FUNCTION pgwar.update_fk_type(); \ No newline at end of file diff --git a/database/migrations/sqls/20240628121705-pgwar-fk-type-up.sql b/database/migrations/sqls/20240628121705-pgwar-fk-type-up.sql new file mode 100644 index 000000000..c5af99297 --- /dev/null +++ b/database/migrations/sqls/20240628121705-pgwar-fk-type-up.sql @@ -0,0 +1,140 @@ +CREATE +OR REPLACE FUNCTION pgwar.update_fk_type() RETURNS void AS $$ +DECLARE + _job_name text; + _current_offset timestamp; +BEGIN + _job_name := 'update-fk-type'; + -- Function logic goes here + + -- initialize offset, if needed + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- get current offset + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + WITH hastypeprop AS ( + -- Select distinct domain class, property ID, and last modification timestamp + -- from the api_property table where the property or its parent/ancestor properties + -- contain the value 2 + SELECT DISTINCT ON (prop.dfh_pk_property) + prop.dfh_property_domain, + prop.dfh_pk_property, + prop.tmsp_last_modification + FROM data_for_history.api_property prop + WHERE + 2 = ANY(prop.dfh_pk_property || (prop.dfh_parent_properties || prop.dfh_ancestor_properties)) + ORDER BY + prop.dfh_pk_property, + prop.tmsp_last_modification DESC + ), + + entity_preview_with_hastypeprop AS ( + -- Join entity_preview with hastypeprop to get entity ID, project ID, and the + -- last modification timestamps of both the fk_class of the entity_preview + -- and the property. + SELECT + ep.pk_entity, + ep.fk_project, + ep.tmsp_fk_class_modification, + prop.dfh_pk_property, + prop.tmsp_last_modification AS prop_modified + FROM + pgwar.entity_preview ep, + hastypeprop prop + WHERE + prop.dfh_property_domain = ep.fk_class + ), + + with_hastypestmt AS ( + -- Join v_statements_combined with entity_preview_with_hastypeprop to get the + -- fk_type and the last modification timestamp of the has-type statement + -- distinct by entity ID, project ID + SELECT DISTINCT ON (typeprop.pk_entity, typeprop.fk_project) + typeprop.pk_entity, + typeprop.fk_project, + stmt.fk_object_info AS fk_type, + stmt.tmsp_last_modification AS stmt_modified + FROM + pgwar.v_statements_combined stmt, + entity_preview_with_hastypeprop typeprop + WHERE + typeprop.pk_entity = stmt.fk_subject_info + AND typeprop.fk_project = stmt.fk_project + AND typeprop.dfh_pk_property = stmt.fk_property + ORDER BY + typeprop.pk_entity, + typeprop.fk_project, + stmt.ord_num_of_range ASC, + stmt.tmsp_last_modification DESC + ), + + with_hastypestmt_del AS ( + -- Join v_statements_deleted_combined with entity_preview_with_hastypeprop to get the + -- deletion timestamp of of the has-type statement + -- distinct by entity ID, project ID + SELECT DISTINCT ON (typeprop.pk_entity, typeprop.fk_project) + typeprop.pk_entity, + typeprop.fk_project, + stmt.tmsp_deletion AS stmt_deleted + FROM + pgwar.v_statements_deleted_combined stmt, + entity_preview_with_hastypeprop typeprop + WHERE + typeprop.pk_entity = stmt.fk_subject_info + AND typeprop.fk_project = stmt.fk_project + AND typeprop.dfh_pk_property = stmt.fk_property + ORDER BY + typeprop.pk_entity, + typeprop.fk_project, + stmt.tmsp_deletion DESC + ) + + -- Final selection combining the previous CTE results with a LEFT JOIN to include + -- all relevant project-entities, the statement with fk_type and timestamps. + -- The WHERE clause ensures that only records modified after the _current_offset + -- and fk_type disctinct from the current fk_type are used for updating + -- the pgwar.entity_preview table + UPDATE pgwar.entity_preview ep + SET fk_type = stmt.fk_type, + tmsp_fk_type_modification = CURRENT_TIMESTAMP + FROM + entity_preview_with_hastypeprop ep_prop + LEFT JOIN + with_hastypestmt stmt + ON ep_prop.pk_entity = stmt.pk_entity + AND ep_prop.fk_project = stmt.fk_project + LEFT JOIN + with_hastypestmt_del stmtdel + ON ep_prop.pk_entity = stmtdel.pk_entity + AND ep_prop.fk_project = stmtdel.fk_project + WHERE + ep.fk_type IS DISTINCT FROM stmt.fk_type + AND + ep.pk_entity = ep_prop.pk_entity + AND + ep.fk_project = ep_prop.fk_project + AND ( + ep_prop.tmsp_fk_class_modification > _current_offset OR + ep_prop.prop_modified > _current_offset OR + stmt.stmt_modified > _current_offset OR + stmtdel.stmt_deleted > _current_offset + ); + + -- set the offset + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; + diff --git a/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql b/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql new file mode 100644 index 000000000..2b69836b5 --- /dev/null +++ b/database/migrations/sqls/20240628133110-pgwar-type-label-down.sql @@ -0,0 +1,3 @@ +-- Drop Functions +------------------------------------------------------------- +DROP FUNCTION pgwar.update_type_label; diff --git a/database/migrations/sqls/20240628133110-pgwar-type-label-up.sql b/database/migrations/sqls/20240628133110-pgwar-type-label-up.sql new file mode 100644 index 000000000..51a40426a --- /dev/null +++ b/database/migrations/sqls/20240628133110-pgwar-type-label-up.sql @@ -0,0 +1,54 @@ +CREATE OR REPLACE FUNCTION pgwar.update_type_label() RETURNS void AS $$ +DECLARE + _job_name text; -- Variable to store the job name + _current_offset timestamp; -- Variable to store the current offset timestamp +BEGIN + _job_name := 'update-type-label'; -- Initialize the job name + + -- Check if the offset for the job is already initialized + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + -- If not, initialize it with a default value + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- Retrieve the current offset timestamp for the job + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + -- Identify the records in the entity_preview table that need updating + WITH to_update AS ( + SELECT + origin.pk_entity, -- Primary key of the entity from the origin table + origin.fk_project, -- Foreign key of the project from the origin table + target.entity_label AS type_label -- Target entity label that will become the type_label of origin + FROM + pgwar.entity_preview origin -- Origin entity preview (having fk_type) + LEFT JOIN + pgwar.entity_preview target ON -- Left join with the same table to find the referenced type entity + origin.fk_type = target.pk_entity AND -- Match type entity on fk_type + origin.fk_project = target.fk_project AND -- Match on project ID + origin.type_label IS DISTINCT FROM target.entity_label -- Ensure the type label is different between origin and target + WHERE + origin.tmsp_fk_type_modification > _current_offset -- Check if origin's fk_type changed since the last offset timestamp + OR target.tmsp_entity_label_modification > _current_offset -- Check if the target's label changed since the last offset timestamp + ) + -- Update the entity_preview table with the new type labels + UPDATE pgwar.entity_preview ep + SET type_label = to_update.type_label + FROM to_update + WHERE ep.pk_entity = to_update.pk_entity + AND ep.fk_project = to_update.fk_project; + + -- Update the offset table with the current timestamp to mark the job completion time + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; diff --git a/server/db-migrate/migrations/sqls/20240709164334-inf-add-indexes-down.sql b/database/migrations/sqls/20240709164334-inf-add-indexes-down.sql similarity index 100% rename from server/db-migrate/migrations/sqls/20240709164334-inf-add-indexes-down.sql rename to database/migrations/sqls/20240709164334-inf-add-indexes-down.sql diff --git a/server/db-migrate/migrations/sqls/20240709164334-inf-add-indexes-up.sql b/database/migrations/sqls/20240709164334-inf-add-indexes-up.sql similarity index 100% rename from server/db-migrate/migrations/sqls/20240709164334-inf-add-indexes-up.sql rename to database/migrations/sqls/20240709164334-inf-add-indexes-up.sql diff --git a/server/db-migrate/migrations/sqls/20190515131648-initialize-beta-schema-down.sql b/database/migrations/sqls/20240711081550-com-f-get-field-pages-down.sql similarity index 100% rename from server/db-migrate/migrations/sqls/20190515131648-initialize-beta-schema-down.sql rename to database/migrations/sqls/20240711081550-com-f-get-field-pages-down.sql diff --git a/database/migrations/sqls/20240711081550-com-f-get-field-pages-up.sql b/database/migrations/sqls/20240711081550-com-f-get-field-pages-up.sql new file mode 100644 index 000000000..d88346ff5 --- /dev/null +++ b/database/migrations/sqls/20240711081550-com-f-get-field-pages-up.sql @@ -0,0 +1,1336 @@ +-- add functions to convert records into json + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row data.digital) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'entity_version', _row.entity_version, 'pk_text', _row.pk_text, 'quill_doc', _row.quill_doc, 'string', _row.string, 'fk_system_type', _row.fk_system_type, 'fk_namespace', _row.fk_namespace + ); + END; +$BODY$; + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.appellation) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'quill_doc', _row.quill_doc, 'fk_class', _row.fk_class, 'string', _row.string + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.language) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'pk_language', _row.pk_language, 'lang_type', _row.lang_type, 'scope', _row.scope, 'iso6392b', _row.iso6392b, 'iso6392t', _row.iso6392t, 'iso6391', _row.iso6391, 'notes', _row.notes + ); + END; +$BODY$; + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.resource) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'community_visibility', _row.community_visibility + ); + END; +$BODY$; + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.v_dimension) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'fk_measurement_unit', _row.fk_measurement_unit, 'numeric_value', _row.numeric_value + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.v_lang_string) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'quill_doc', _row.quill_doc, 'string', _row.string, 'fk_language', _row.fk_language + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.v_place) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'long', _row.long, 'lat', _row.lat, 'fk_class', _row.fk_class + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.v_statement) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_subject_info', _row.fk_subject_info, 'fk_subject_data', _row.fk_subject_data, 'fk_subject_tables_cell', _row.fk_subject_tables_cell, 'fk_subject_tables_row', _row.fk_subject_tables_row, 'fk_property', _row.fk_property, 'fk_property_of_property', _row.fk_property_of_property, 'fk_object_info', _row.fk_object_info, 'fk_object_data', _row.fk_object_data, 'fk_object_tables_cell', _row.fk_object_tables_cell, 'fk_object_tables_row', _row.fk_object_tables_row, 'is_in_project_count', _row.is_in_project_count, 'is_standard_in_project_count', _row.is_standard_in_project_count + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row information.v_time_primitive) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'julian_day', _row.julian_day, 'duration', _row.duration, 'calendar', _row.calendar + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row pgwar.entity_preview) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_project', _row.fk_project, 'fk_class', _row.fk_class, 'class_label', _row.class_label, 'entity_label', _row.entity_label, 'entity_type', _row.entity_type, 'type_label', _row.type_label, 'fk_type', _row.fk_type, 'time_span', _row.time_span, 'first_second', _row.first_second, 'last_second', _row.last_second, 'tmsp_last_modification', _row.tmsp_last_modification + ); + END; +$BODY$; + + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row projects.v_info_proj_rel) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_entity', _row.pk_entity, 'fk_project', _row.fk_project, 'fk_entity', _row.fk_entity, 'fk_entity_version', _row.fk_entity_version, 'fk_entity_version_concat', _row.fk_entity_version_concat, 'is_in_project', _row.is_in_project, 'is_standard_in_project', _row.is_standard_in_project, 'ord_num_of_domain', _row.ord_num_of_domain, 'ord_num_of_range', _row.ord_num_of_range, 'fk_creator', _row.fk_creator, 'fk_last_modifier', _row.fk_last_modifier, 'project_visibility', _row.project_visibility + ); + END; +$BODY$; + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row tables."row") + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_row', _row.pk_row, 'fk_digital', _row.fk_digital, 'position', _row.position + ); + END; +$BODY$; + +CREATE OR REPLACE FUNCTION public.gv_to_jsonb( + _row tables.cell) + RETURNS jsonb + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ + BEGIN + RETURN jsonb_build_object( + 'pk_cell', _row.pk_cell, 'fk_class', _row.fk_class, 'fk_column', _row.fk_column, 'fk_row', _row.fk_row, 'fk_digital', _row.fk_digital, 'string_value', _row.string_value, 'numeric_value', _row.numeric_value + ); + END; +$BODY$; + +-- create function to select statement target +DO $$ BEGIN + CREATE TYPE gv_statement_target AS ( + target_obj jsonb, + target_class int, + target_label text + ); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; + + +CREATE OR REPLACE FUNCTION commons.get_statement_target (_project_id int, _info_id int, _data_id int, _tables_cell_id bigint, _tables_row_id bigint) + RETURNS SETOF gv_statement_target + LANGUAGE plpgsql + AS $func$ +BEGIN + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET LANGUAGE + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('language', gv_to_jsonb (t3)) target_obj, + fk_class target_class, + notes target_label + FROM + information.language t3 + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET APPPELLATION + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('appellation', gv_to_jsonb (t3)) target_obj, + fk_class target_class, + string target_label + FROM + information.appellation t3 + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET LANG_STRING + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('langString', jsonb_build_object('langString', gv_to_jsonb (t3), 'language', language.obj)) target_obj, + fk_class target_class, + concat(t3.string, ' (', language.iso6391, ')' ) target_label + FROM + information.v_lang_string t3 + LEFT JOIN LATERAL ( + -- LANGUAGE OF LANG_STRING + SELECT + gv_to_jsonb (t4) obj, + iso6391 + FROM + information.language t4 + WHERE + t4.pk_entity = t3.fk_language) + LANGUAGE ON + TRUE + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET PLACE + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('place', gv_to_jsonb (t3)) target_obj, + fk_class target_class, + concat('WGS84: ', lat, '°, ', long, '°') target_label + FROM + information.v_place t3 + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET TIME PRIMITIVE + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('timePrimitive', jsonb_build_object('infTimePrimitive', gv_to_jsonb (t3), 'timePrimitive', json_build_object('duration', t3.duration, 'julianDay', t3.julian_day, 'calendar', t3.calendar))) target_obj, + fk_class target_class, + 'todo' target_label + FROM + information.v_time_primitive t3 + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET DIMENSION + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('dimension',jsonb_build_object('dimension', gv_to_jsonb (t3), 'unitPreview', entity_preview.obj)) target_obj, + fk_class target_class, + concat_ws(' ', t3.numeric_value, entity_preview.entity_label) target_label + FROM + information.v_dimension t3 + LEFT JOIN LATERAL ( SELECT DISTINCT ON (pk_entity) + gv_to_jsonb (e.t4) obj, + e.entity_label + FROM ( + --repo version + SELECT + t4, entity_label + FROM + pgwar.entity_preview t4 + WHERE + t4.pk_entity = t3.fk_measurement_unit + AND fk_project = 0 + UNION + --project version + SELECT + t4, entity_label + FROM + pgwar.entity_preview t4 + WHERE + t4.pk_entity = t3.fk_measurement_unit + AND fk_project = _project_id) e) entity_preview ON TRUE + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET ENTITY + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('entity', jsonb_build_object('resource', gv_to_jsonb (t3), 'entityPreview', entity_preview.obj)) target_obj, + fk_class target_class, + entity_preview.entity_label target_label + FROM + information.resource t3 + LEFT JOIN LATERAL ( SELECT DISTINCT ON (pk_entity) + gv_to_jsonb (e.t4) obj, + e.entity_label + FROM ( + --repo version + SELECT + t4, entity_label + FROM + pgwar.entity_preview t4 + WHERE + t4.pk_entity = _info_id + AND fk_project = 0 + UNION + --project version + SELECT + t4, entity_label + FROM + pgwar.entity_preview t4 + WHERE + t4.pk_entity = _info_id + AND fk_project = _project_id) e) entity_preview ON TRUE + WHERE + t3.pk_entity = _info_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET DIGITAL + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('digital', gv_to_jsonb (t3)) target_obj, + 0 target_class, + '' target_label + FROM + data.digital t3 + WHERE + t3.pk_entity = _data_id; + IF FOUND THEN + RETURN; + END IF; + ---------------------------------------------------------------------- + --JOIN STATEMENT'S TARGET CELL + ---------------------------------------------------------------------- + RETURN QUERY + SELECT + jsonb_build_object('cell', gv_to_jsonb (t3)) target_obj, + fk_class target_class, + coalesce(string_value, numeric_value::text) target_label + FROM + tables.cell t3 + WHERE + t3.pk_cell = _tables_cell_id; + IF FOUND THEN + RETURN; + END IF; + + -- Uncomment this block for joining rows and create column row (fk_class) + -- ---------------------------------------------------------------------- + -- --JOIN STATEMENT'S TARGET ROW + -- ---------------------------------------------------------------------- + -- RETURN QUERY + -- SELECT + -- jsonb_build_object('row', gv_to_jsonb (t3)) target_obj, + -- fk_class target_class, + -- 'todo' target_label + -- FROM + -- tables.row t3 + -- WHERE + -- t3.pk_row = _tables_row_id; + -- IF FOUND THEN + -- RETURN; + -- END IF; + ---------------------------------------------------------------------- + --ELSE RETURN 0 ROWS + ---------------------------------------------------------------------- + RETURN; +END +$func$; + +-- add functions to get field pages + + CREATE OR REPLACE FUNCTION commons.field_page_incoming_in_project (_project_id int, _fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statement, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER (ORDER BY ord_num_of_domain ASC NULLS LAST, pk_entity DESC) ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('projRel', gv_to_jsonb (t2), 'isOutgoing', false, 'ordNum', t2.ord_num_of_domain, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t2.ord_num_of_domain, + t1.pk_entity, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + projects.v_info_proj_rel t2, + commons.get_statement_target(_project_id, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_object_info = _source_info_id + AND t1.fk_object_data = _source_data_id + AND t1.fk_object_tables_cell = _source_tables_cell_id + AND t1.fk_object_tables_row = _source_tables_row_id + AND t1.fk_property = _fk_property + -------------------------------------------------------------------------- + -- JOIN STATEMENTS WITH PROJECT RELS + -------------------------------------------------------------------------- + AND t1.pk_entity = t2.fk_entity + AND t2.is_in_project = TRUE + AND t2.fk_project = _project_id + -------------------------------------------------------------------------- + -- order the statements according to order number of target + -------------------------------------------------------------------------- + ORDER BY + t2.ord_num_of_domain ASC NULLS LAST, t1.pk_entity DESC + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + + CREATE OR REPLACE FUNCTION commons.field_page_incoming_in_repo (_fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(0, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_object_info = _source_info_id + AND t1.fk_object_data = _source_data_id + AND t1.fk_object_tables_cell = _source_tables_cell_id + AND t1.fk_object_tables_row = _source_tables_row_id + AND t1.fk_property = _fk_property + AND t1.is_in_project_count > 0 + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + CREATE OR REPLACE FUNCTION commons.field_page_incoming_no_constraint (_fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(0, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_object_info = _source_info_id + AND t1.fk_object_data = _source_data_id + AND t1.fk_object_tables_cell = _source_tables_cell_id + AND t1.fk_object_tables_row = _source_tables_row_id + AND t1.fk_property = _fk_property + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + + CREATE OR REPLACE FUNCTION commons.field_page_incoming_not_in_project (_project_id int, _fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(_project_id, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_object_info = _source_info_id + AND t1.fk_object_data = _source_data_id + AND t1.fk_object_tables_cell = _source_tables_cell_id + AND t1.fk_object_tables_row = _source_tables_row_id + AND t1.fk_property = _fk_property + AND t1.is_in_project_count > 0 + + -------------------------------------------------------------------------- + -- EXCLUDE STATEMENTS REFERENCING HIDDEN ENTITY + -------------------------------------------------------------------------- + AND (t3.target_obj->'entity'->'resource'->'community_visibility'->>'toolbox')::boolean IS DISTINCT FROM false + + AND t1.pk_entity NOT IN ( + -------------------------------------------------------------------------- + -- EXCLUDE STATEMENTS OF PROJECT + -------------------------------------------------------------------------- + SELECT t1.pk_entity + FROM + information.v_statement t1, + projects.v_info_proj_rel t2 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_object_info = _source_info_id + AND t1.fk_object_data = _source_data_id + AND t1.fk_object_tables_cell = _source_tables_cell_id + AND t1.fk_object_tables_row = _source_tables_row_id + AND t1.fk_property = _fk_property + -------------------------------------------------------------------------- + -- JOIN STATEMENTS WITH PROJECT RELS + -------------------------------------------------------------------------- + AND t1.pk_entity = t2.fk_entity + AND t2.is_in_project = TRUE + AND t2.fk_project = _project_id + ) + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + CREATE OR REPLACE FUNCTION commons.field_page_outgoing_in_project (_project_id int, _fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statement, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER (ORDER BY ord_num_of_range ASC NULLS LAST, pk_entity DESC) ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('projRel', gv_to_jsonb (t2), 'isOutgoing', true, 'ordNum', t2.ord_num_of_range, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t2.ord_num_of_range, + t1.pk_entity, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + projects.v_info_proj_rel t2, + commons.get_statement_target(_project_id, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_subject_info = _fk_subject_info + AND t1.fk_subject_data = _fk_subject_data + AND t1.fk_subject_tables_cell = _fk_subject_tables_cell + AND t1.fk_subject_tables_row = _fk_subject_tables_row + AND t1.fk_property = _fk_property + -------------------------------------------------------------------------- + -- JOIN STATEMENTS WITH PROJECT RELS + -------------------------------------------------------------------------- + AND t1.pk_entity = t2.fk_entity + AND t2.is_in_project = TRUE + AND t2.fk_project = _project_id + -------------------------------------------------------------------------- + -- order the statements according to order number of target + -------------------------------------------------------------------------- + ORDER BY + t2.ord_num_of_range ASC NULLS LAST, t1.pk_entity DESC + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + CREATE OR REPLACE FUNCTION commons.field_page_outgoing_in_repo (_fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(0, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_subject_info = _fk_subject_info + AND t1.fk_subject_data = _fk_subject_data + AND t1.fk_subject_tables_cell = _fk_subject_tables_cell + AND t1.fk_subject_tables_row = _fk_subject_tables_row + AND t1.fk_property = _fk_property + AND t1.is_in_project_count > 0 + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + + CREATE OR REPLACE FUNCTION commons.field_page_outgoing_no_constraint (_fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(0, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_subject_info = _fk_subject_info + AND t1.fk_subject_data = _fk_subject_data + AND t1.fk_subject_tables_cell = _fk_subject_tables_cell + AND t1.fk_subject_tables_row = _fk_subject_tables_row + AND t1.fk_property = _fk_property + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + + CREATE OR REPLACE FUNCTION commons.field_page_outgoing_not_in_project (_project_id int, _fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int) + RETURNS TABLE (valid_for timestamp with time zone, paginated_statement json, target_class int, target_entity_id int,ord_num bigint, count int) + LANGUAGE plpgsql + AS $func$ + DECLARE + res jsonb; + BEGIN + RETURN QUERY + -------------------------------------------------------------------------- + -- FINAL SELECT + -------------------------------------------------------------------------- + SELECT + now() valid_for, + stmt.obj paginated_statements, + stmt.target_class, + stmt.target_entity_id, + ROW_NUMBER() OVER () ord_num, + COALESCE(full_count, 0)::int count + FROM ( + -------------------------------------------------------------------------- + -- PAGINATED SELECT + -------------------------------------------------------------------------- + SELECT + json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, + count(*) OVER () AS full_count, + t3.target_class, + (t3.target_obj->'entity'->'resource'->'pk_entity')::int target_entity_id + FROM + information.v_statement t1, + commons.get_statement_target(_project_id, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_subject_info = _fk_subject_info + AND t1.fk_subject_data = _fk_subject_data + AND t1.fk_subject_tables_cell = _fk_subject_tables_cell + AND t1.fk_subject_tables_row = _fk_subject_tables_row + AND t1.fk_property = _fk_property + AND t1.is_in_project_count > 0 + + -------------------------------------------------------------------------- + -- EXCLUDE STATEMENTS REFERENCING HIDDEN ENTITY + -------------------------------------------------------------------------- + AND (t3.target_obj->'entity'->'resource'->'community_visibility'->>'toolbox')::boolean IS DISTINCT FROM false + + AND t1.pk_entity NOT IN ( + -------------------------------------------------------------------------- + -- EXCLUDE STATEMENTS OF PROJECT + -------------------------------------------------------------------------- + SELECT t1.pk_entity + FROM + information.v_statement t1, + projects.v_info_proj_rel t2 + WHERE + -------------------------------------------------------------------------- + -- JOIN SOURCE ENTITY WITH STATEMENTS + -------------------------------------------------------------------------- + t1.fk_subject_info = _fk_subject_info + AND t1.fk_subject_data = _fk_subject_data + AND t1.fk_subject_tables_cell = _fk_subject_tables_cell + AND t1.fk_subject_tables_row = _fk_subject_tables_row + AND t1.fk_property = _fk_property + -------------------------------------------------------------------------- + -- JOIN STATEMENTS WITH PROJECT RELS + -------------------------------------------------------------------------- + AND t1.pk_entity = t2.fk_entity + AND t2.is_in_project = TRUE + AND t2.fk_project = _project_id + ) + + -------------------------------------------------------------------------- + -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS + -- ORDER BY + -- t1.pk_entity DESC + + -------------------------------------------------------------------------- + -- paginate according to the requested limit / offset + -------------------------------------------------------------------------- + LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END + OFFSET _offset) AS stmt; + END + $func$; + +CREATE TYPE field_page_row AS ( + -- this request + pk_project int, + scope_type text, + is_outgoing bool, + fk_property int, + source_info_id int, + source_data_id int, + source_tables_cell_id bigint, + source_tables_row_id bigint, + is_circular bool, + _limit int, + _offset int, + -- resulting statement + paginated_statement json, + ord_num bigint, + count int, + -- child request + child_pk_project int, + child_scope_type text, + child_is_outgoing bool, + child_fk_property int, + child_source_info_id int, + child_source_data_id int, + child_source_tables_cell_id bigint, + child_source_tables_row_id bigint, + child_is_circular bool, + child_limit int, + child_offset int, + child_targets jsonb +); + +---- functions + +CREATE OR REPLACE FUNCTION commons.create_field_page_req( + project_id int, + source_id int, + parent_scope_type text, + nestedReqs jsonb +) +RETURNS TABLE ( + pk_project int, + scope_type text, + is_outgoing bool, + fk_property int, + source_info_id int, + source_data_id int, + source_tables_cell_id bigint, + source_tables_row_id bigint, + is_circular bool, + _limit int, + _offset int, + targets jsonb +) AS $$ +DECLARE + scope_type text; + subReq jsonb; + page jsonb; + targets jsonb; + req jsonb; +BEGIN + -- Generate the scope type of the subpages + IF parent_scope_type = 'notInProject' THEN + scope_type := 'inRepo'; + ELSE + scope_type := parent_scope_type; + END IF; + + RETURN QUERY + SELECT + project_id AS pk_project, + scope_type, + (page_request->'page'->'isOutgoing')::bool is_outgoing, + (page_request->'page'->'property'->'fkProperty')::int AS fk_property, + source_id AS source_info_id, + NULL::int AS source_data_id, + NULL::bigint AS source_tables_cell_id, + NULL::bigint AS source_tables_row_id, + (page_request->'page'->'isCircular')::bool AS is_circular, + (page_request->'page'->'limit')::int AS _limit, + (page_request->'page'->'offset')::int AS _offset, + page_request->'targets' targets + FROM jsonb_array_elements(nestedReqs) page_request; +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION commons.get_field_statements_and_child_requests( + _pk_project int, + _scope_type text, + _is_outgoing bool, + _fk_property int, + _source_info_id int, + _source_data_id int, + _source_tables_cell_id bigint, + _source_tables_row_id bigint, + _is_circular boolean, + __limit int, + __offset int, + _targets jsonb +) +RETURNS SETOF field_page_row AS $$ +DECLARE + coal_source_info_id int; + coal_source_data_id int; + coal_source_tables_cell_id bigint; + coal_source_tables_row_id bigint; +BEGIN + coal_source_info_id := COALESCE(_source_info_id, 0); + coal_source_data_id := COALESCE(_source_data_id, 0); + coal_source_tables_cell_id := COALESCE(_source_tables_cell_id, 0); + coal_source_tables_row_id := COALESCE(_source_tables_row_id, 0); + + RETURN QUERY + SELECT + -- this request + _pk_project AS pk_project, + _scope_type AS scope_type, + _is_outgoing AS is_outgoing, + _fk_property AS fk_property, + _source_info_id AS source_info_id, + _source_data_id AS source_data_id, + _source_tables_cell_id AS source_tables_cell_id, + _source_tables_row_id AS source_tables_row_id, + _is_circular AS is_circular, + __limit AS _limit, + __offset AS _offset, + + -- resulting data + stmt.paginated_statement, + stmt.ord_num, + stmt.count, + + --- resulting child request + child.pk_project AS child_pk_project, + child.scope_type AS child_scope_type, + child.is_outgoing AS child_is_outgoing, + child.fk_property AS child_fk_property, + child.source_info_id AS child_source_info_id, + child.source_data_id AS child_source_data_id, + child.source_tables_cell_id AS child_source_tables_cell_id, + child.source_tables_row_id AS child_source_tables_row_id, + child.is_circular AS child_is_circular, + child._limit AS child_limit, + child._offset AS child_offset, + child.targets AS child_targets + FROM + ( + SELECT * + FROM commons.field_page_incoming_in_project(_pk_project,_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'inProject' AND _is_outgoing IS FALSE + UNION ALL + SELECT * + FROM commons.field_page_outgoing_in_project(_pk_project,_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'inProject' AND _is_outgoing IS TRUE + UNION ALL + + SELECT * + FROM commons.field_page_incoming_not_in_project(_pk_project,_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'notInProject' AND _is_outgoing IS FALSE + UNION ALL + SELECT * + FROM commons.field_page_outgoing_not_in_project(_pk_project,_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'notInProject' AND _is_outgoing IS TRUE + UNION ALL + + SELECT * + FROM commons.field_page_incoming_in_repo(_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'inRepo' AND _is_outgoing IS FALSE + UNION ALL + SELECT * + FROM commons.field_page_outgoing_in_repo(_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'inRepo' AND _is_outgoing IS TRUE + UNION ALL + + SELECT * + FROM commons.field_page_incoming_no_constraint(_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'noContraint' AND _is_outgoing IS FALSE + UNION ALL + SELECT * + FROM commons.field_page_outgoing_no_constraint(_fk_property,coal_source_info_id,coal_source_data_id,coal_source_tables_cell_id,coal_source_tables_row_id,__limit,__offset) + WHERE _scope_type = 'noContraint' AND _is_outgoing IS TRUE + ) + AS stmt + LEFT JOIN LATERAL commons.create_field_page_req( + _pk_project, -- from parent's child request + stmt.target_entity_id, -- from resulting data + _scope_type, -- from parent's child request + _targets->target_class::text->'nestedResource' -- from parent's child request + ) AS child ON TRUE; -- child requests + END; +$$ LANGUAGE plpgsql; + + + +CREATE OR REPLACE FUNCTION commons.get_field_statements_and_child_requests_recursive( + _pk_project int, + _scope_type text, + _is_outgoing bool, + _fk_property int, + _source_info_id int, + _source_data_id int, + _source_tables_cell_id bigint, + _source_tables_row_id bigint, + _is_circular bool, + __limit int, + __offset int, + _targets jsonb, + _parent_rows field_page_row[] +) +RETURNS field_page_row[] AS $$ +DECLARE + rec field_page_row; + _rows field_page_row[]; +BEGIN + -- initialize rows + _rows := _parent_rows; + + FOR rec IN + SELECT * + FROM commons.get_field_statements_and_child_requests( + _pk_project, _scope_type, _is_outgoing, _fk_property, _source_info_id, _source_data_id, _source_tables_cell_id, _source_tables_row_id, _is_circular, __limit, __offset, _targets + ) AS s + LOOP + + IF rec.child_pk_project IS NOT NULL THEN + _rows := _rows || commons.get_field_statements_and_child_requests_recursive( + rec.child_pk_project, rec.child_scope_type, rec.child_is_outgoing, rec.child_fk_property, rec.child_source_info_id, rec.child_source_data_id, rec.child_source_tables_cell_id, rec.child_source_tables_row_id, rec.child_is_circular, rec.child_limit, rec.child_offset, rec.child_targets, + ARRAY[rec] + ); + ELSE + -- append this row to final result + _rows := _rows || rec; + END IF; + + + END LOOP; + + RETURN _rows; + +END; +$$ LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION commons.get_field_page( + page_request jsonb +) +RETURNS jsonb AS $$ +DECLARE + -- request vars + _pkProject int; + _scope_type text; + _isOutgoing bool; + _propertyFkProperty int; + _sourceFkInfo int; + _sourceFkData int; + _sourceFkTablesCell bigint; + _sourceFkTablesRow bigint; + _isCircular bool; + _limit int; + _offset int; + + -- response + _result jsonb; +BEGIN + + -- decompose page request + _pkProject := (page_request->'pkProject')::int; + _isOutgoing := (page_request->'page'->'isOutgoing')::bool; + _propertyFkProperty := (page_request->'page'->'property'->'fkProperty')::int; + _sourceFkInfo := (page_request->'page'->'source'->'fkInfo')::int; + _sourceFkData := (page_request->'page'->'source'->'fkData')::int; + _sourceFkTablesCell := (page_request->'page'->'source'->'fkTablesCell')::bigint; + _sourceFkTablesRow := (page_request->'page'->'source'->'fkTablesRow')::bigint; + _isCircular := (page_request->'page'->'isCircular')::bool; + _limit := (page_request->'page'->'limit')::int; + _offset := (page_request->'page'->'offset')::int; + + -- get the scope type + SELECT key INTO _scope_type + FROM jsonb_object_keys(page_request->'page'->'scope') key + LIMIT 1; + + WITH field_pages_with_statements AS ( + SELECT (unnest(x)).* + FROM commons.get_field_statements_and_child_requests_recursive( + _pkProject, + _scope_type, + _isOutgoing, + _propertyFkProperty, + _sourceFkInfo, + _sourceFkData, + _sourceFkTablesCell, + _sourceFkTablesRow, + _isCircular, + _limit, + _offset, + page_request->'targets', + ARRAY[]::field_page_row[] + ) x + ), + grouped_by_page AS ( + SELECT jsonb_build_object( + 'paginatedStatements', json_agg(DISTINCT fpws.paginated_statement::jsonb), + 'count', fpws.count, + 'validFor', now(), + 'page', jsonb_strip_nulls(jsonb_build_object( + 'source', jsonb_strip_nulls(jsonb_build_object( + 'fkInfo', fpws.source_info_id, + 'fkData', fpws.source_data_id, + 'fkTablesCell', fpws.source_tables_cell_id, + 'fkTablesRow', fpws.source_tables_row_id + )), + 'property', jsonb_build_object( + 'fkProperty', fpws.fk_property + ), + 'isOutgoing', fpws.is_outgoing, + 'isCircular', fpws.is_circular, + 'limit', fpws._limit, + 'offset', fpws._offset, + 'scope', (CASE WHEN fpws.scope_type IN ('inRepo', 'noContraint') + THEN '{"' || fpws.scope_type || '": true }' + ELSE '{"' || fpws.scope_type || '": '|| fpws.pk_project ||'}' + END)::jsonb + )) + ) AS field_page + FROM field_pages_with_statements fpws + GROUP BY + fpws.pk_project, + fpws.scope_type, + fpws.is_outgoing, + fpws.fk_property, + fpws.source_info_id, + fpws.source_data_id, + fpws.source_tables_cell_id, + fpws.source_tables_row_id, + fpws.is_circular, + fpws._limit, + fpws._offset, + fpws.count + ) + SELECT json_agg(field_page) INTO _result + FROM grouped_by_page; + + -- if _result is null then ...? + + IF _result IS NULL THEN + + SELECT jsonb_build_object( + 'paginatedStatements', '[]'::jsonb, + 'count', 0, + 'validFor', now(), + 'page', jsonb_strip_nulls(jsonb_build_object( + 'source', jsonb_strip_nulls(jsonb_build_object( + 'fkInfo', _sourceFkInfo, + 'fkData', _sourceFkData, + 'fkTablesCell', _sourceFkTablesCell, + 'fkTablesRow', _sourceFkTablesRow + )), + 'property', jsonb_build_object( + 'fkProperty', _propertyFkProperty + ), + 'isOutgoing', _isOutgoing, + 'isCircular', _isCircular, + 'limit', _limit, + 'offset', _offset, + 'scope', (CASE WHEN _scope_type IN ('inRepo', 'noContraint') + THEN '{"' || _scope_type || '": true }' + ELSE '{"' || _scope_type || '": '|| _pkProject ||'}' + END)::jsonb + )) + ) INTO _result; + + END IF; + + RETURN _result; + +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION commons.get_field_pages( + page_requests jsonb +) +RETURNS jsonb AS $$ +DECLARE + rec jsonb; + _field_pages jsonb := '[]'::jsonb; +BEGIN + + -- Loop over each element in the JSONB array + FOR rec IN SELECT * FROM jsonb_array_elements(page_requests) + LOOP + -- Process each element + _field_pages := _field_pages || commons.get_field_page(rec); + + END LOOP; + + RETURN jsonb_build_object( + 'subfieldPages', _field_pages + ); + +END; +$$ LANGUAGE plpgsql; + + + + + diff --git a/server/db-migrate/migrations/sqls/20190527083437-pro-add-namespace-down.sql b/database/migrations/sqls/20240725085620-pgwar-time-span-down.sql similarity index 100% rename from server/db-migrate/migrations/sqls/20190527083437-pro-add-namespace-down.sql rename to database/migrations/sqls/20240725085620-pgwar-time-span-down.sql diff --git a/database/migrations/sqls/20240725085620-pgwar-time-span-up.sql b/database/migrations/sqls/20240725085620-pgwar-time-span-up.sql new file mode 100644 index 000000000..fba6ef690 --- /dev/null +++ b/database/migrations/sqls/20240725085620-pgwar-time-span-up.sql @@ -0,0 +1,104 @@ +CREATE OR REPLACE FUNCTION pgwar.update_time_span() RETURNS void AS $$ +DECLARE + _job_name text; -- Variable to store the job name + _current_offset timestamp; -- Variable to store the current offset timestamp +BEGIN + _job_name := 'update-time_span'; -- Initialize the job name + + -- Check if the offset for the job is already initialized + IF NOT EXISTS( + SELECT offset_tmsp + FROM pgwar.offsets + WHERE job_name = _job_name + ) THEN + -- If not, initialize it with a default value + INSERT INTO pgwar.offsets (job_name, offset_tmsp) + VALUES (_job_name, '2000-01-01 00:00:00.000000+00'); + END IF; + + -- Retrieve the current offset timestamp for the job + SELECT offset_tmsp INTO _current_offset + FROM pgwar.offsets + WHERE job_name = _job_name; + + + + WITH ranked_statements AS ( + -- Assign a row number to each statement within the partition of fk_project, fk_subject_info, and fk_property, + -- ordered by the columns you want to prioritize (e.g., timestamps or some other criteria). + SELECT + stmt.fk_project, + stmt.fk_subject_info, + stmt.fk_property, + stmt.object_value, + stmt.tmsp_last_modification AS stmt_modified, + ROW_NUMBER() OVER ( + PARTITION BY stmt.fk_project, stmt.fk_subject_info, stmt.fk_property + ORDER BY stmt.ord_num_of_range ASC, stmt.tmsp_last_modification DESC) AS rn + FROM + pgwar.v_statements_combined stmt + WHERE + stmt.fk_property IN (71,72,150,151,152,153) + ), + time_spans AS ( + -- Select only the first row (rn = 1) from each partition and aggregate results into JSON objects. + SELECT + fk_project, + fk_subject_info, + jsonb_object_agg( + -- key + CASE + WHEN fk_property = 71 THEN 'p81' + WHEN fk_property = 72 THEN 'p82' + WHEN fk_property = 150 THEN 'p81a' + WHEN fk_property = 151 THEN 'p81b' + WHEN fk_property = 152 THEN 'p82a' + WHEN fk_property = 153 THEN 'p82b' + ELSE fk_property::text -- Handle other properties if necessary + END, + -- value + jsonb_build_object( + 'calendar', object_value->'timePrimitive'->'calendar', + 'duration', object_value->'timePrimitive'->'duration', + 'julianDay', object_value->'timePrimitive'->'julianDay' + ) + ) AS time_span, + max(stmt_modified) AS most_recent_stmt_modification, + min(( object_value->'timePrimitive'->'julianDay')::bigint * 24 * 60 * 60) AS first_second, + max((( object_value->'timePrimitive'->'julianDay')::bigint + + CASE + WHEN object_value->'timePrimitive'->'duration' = '"1 day"' THEN 1 + WHEN object_value->'timePrimitive'->'duration' = '"1 month"' THEN 30 + ELSE 365 + END + )* 24 * 60 * 60 ) AS last_second + FROM + ranked_statements + WHERE + rn = 1 + GROUP BY + fk_project, + fk_subject_info + ), + get_time_spans AS ( + SELECT * + FROM time_spans + WHERE most_recent_stmt_modification > '2000-01-01 00:00:00.000000+00' + ) + UPDATE pgwar.entity_preview ep + SET time_span = ts.time_span, + first_second = ts.first_second, + last_second = ts.last_second + FROM get_time_spans ts + WHERE ts.fk_project = ep.fk_project + AND ts.fk_subject_info = ep.pk_entity + AND ep.time_span IS DISTINCT FROM ts.time_span; + + + -- Update the offset table with the current timestamp to mark the job completion time + UPDATE pgwar.offsets + SET offset_tmsp = CURRENT_TIMESTAMP + WHERE job_name = _job_name; + +END; +$$ LANGUAGE plpgsql; diff --git a/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-down.sql b/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-down.sql new file mode 100644 index 000000000..5e7e25bf2 --- /dev/null +++ b/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-down.sql @@ -0,0 +1 @@ +DROP FUNCTION IF EXISTS pgwar.update_entity_label_of_entity_preview(integer, integer, text); \ No newline at end of file diff --git a/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-up.sql b/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-up.sql new file mode 100644 index 000000000..3929c69c2 --- /dev/null +++ b/database/migrations/sqls/20241017094816-pgwar-entity-label-async-update-up.sql @@ -0,0 +1,18 @@ +CREATE OR REPLACE FUNCTION pgwar.update_entity_label_of_entity_preview( + entity_id integer, + project_id integer, + new_label text) + RETURNS void + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE +AS $BODY$ +BEGIN + UPDATE pgwar.entity_preview + SET entity_label = new_label, + tmsp_entity_label_modification = CURRENT_TIMESTAMP + WHERE pk_entity = entity_id + AND fk_project = project_id + AND entity_label IS DISTINCT FROM new_label; +END; +$BODY$; \ No newline at end of file diff --git a/database/pgwar-init-full-texts.sh b/database/pgwar-init-full-texts.sh new file mode 100644 index 000000000..a03a265c2 --- /dev/null +++ b/database/pgwar-init-full-texts.sh @@ -0,0 +1,22 @@ +DB_URL="postgres://postgres:postgres@localhost:5432/toolbox_staging" + +while :; do + # Get the first failed batch + MESSAGE=$(psql $DB_URL --tuples-only --no-align -c " + SELECT pgwar.update_full_texts(10000); + ") + + + # Extract the number from the string using parameter expansion + NUMBER=${MESSAGE#*Number of rows updated: } + + # Check if the number is greater than 0 + if [ "$NUMBER" -gt 0 ]; then + echo "Updated full texts: $NUMBER" + else + echo "All full texts have been updated." + # exit the loop + break + + fi +done \ No newline at end of file diff --git a/database/pgwar-init-project-entities.sh b/database/pgwar-init-project-entities.sh new file mode 100644 index 000000000..5c23a4a01 --- /dev/null +++ b/database/pgwar-init-project-entities.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -e + +# Function to print the current timestamp and message +print_timestamp() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" +} + +# Define the database connection details +DB_URL="postgres://postgres:pw@localhost:5432/filled_db" + + +# Query to get pk_entity values +QUERY="SELECT pk_entity FROM projects.project;" + +# Create initialization table if it doesn't exist +print_timestamp "Creating initialization table if it doesn't exist..." +psql $DB_URL < 3; + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Test 2: assert that entity 1 has "Label 1ter" as community entity label +SELECT is( + ep.entity_label, + 'Label 1ter', + 'Assert community entity preview has Label 1ter after updates' +) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 0; + +-- Delete 6 entity previews +DELETE FROM pgwar.entity_preview +WHERE fk_project > 1; + +-- Test 3: assert that entity 1 has "Label 1" as community entity label +SELECT is( + ep.entity_label, + 'Label 1', + 'Assert community entity preview has Label 1 after deletes' +) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 0; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-entity/test-pgwar-entity.sql b/database/test/integration/pgwar-entity/test-pgwar-entity.sql new file mode 100644 index 000000000..37b89f5c9 --- /dev/null +++ b/database/test/integration/pgwar-entity/test-pgwar-entity.sql @@ -0,0 +1,127 @@ +-- Test the creation of project and community entities +-- after modifying information.resource and projects.info_proj_rel + +-- Start transaction and plan the tests. +BEGIN; +SELECT plan(14); + +------- Prepare required context data ------ + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_language) VALUES ('eng'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, '_p1' FROM information.language; + +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, '_p2' FROM information.language; + +------- INSERT data directly related to this test ----- +-- Insert one entity with a specific class and community visibility +INSERT INTO information.resource(fk_class, community_visibility, notes) +VALUES (11, '{"toolbox":true}', '_1'); + +-- Add the entity to project _p1 +INSERT INTO projects.info_proj_rel(fk_project, fk_entity, is_in_project, notes) +SELECT t1.pk_entity, t2.pk_entity, TRUE, '_ipr1' +FROM projects.project t1, information.resource t2 +WHERE t1.notes = '_p1'; + +-- Add the entity to project _p2 +INSERT INTO projects.info_proj_rel(fk_project, fk_entity, is_in_project, notes) +SELECT t1.pk_entity, t2.pk_entity, TRUE, '_ipr2' +FROM projects.project t1, information.resource t2 +WHERE t1.notes = '_p2'; + +-- Assert a project entity preview is created for project _p1 +SELECT IS (fk_class, 11, 'Assert project entity preview is created') +FROM pgwar.entity_preview t1, projects.project t2 +WHERE t1.fk_project = t2.pk_entity AND t2.notes = '_p1'; + +-- Assert a community entity preview is created +SELECT IS (fk_class, 11, 'Assert community entity preview is created') +FROM pgwar.entity_preview +WHERE fk_project = 0; + +-- Remove the entity from project _p1 +UPDATE projects.info_proj_rel +SET is_in_project = FALSE +WHERE notes = '_ipr1'; + +-- Prepare and assert the project entity preview for project _p1 is deleted +PREPARE get_project_entity_preview AS +SELECT * FROM pgwar.entity_preview t1, projects.project t2 +WHERE t1.fk_project = t2.pk_entity AND t2.notes = $1; + +SELECT is_empty('get_project_entity_preview(''_p1'')', 'Assert entity preview for project _p1 is deleted'); + +-- Assert the project entity preview for project _p2 is not deleted +SELECT isnt_empty('get_project_entity_preview(''_p2'')', 'Assert entity preview for project _p2 is not deleted'); + +-- Assert the community entity preview is still present +PREPARE get_community_entity_preview AS +SELECT * FROM pgwar.entity_preview WHERE fk_project = 0; + +SELECT isnt_empty('get_community_entity_preview', 'Assert community entity preview is still present'); + +-- Remove the entity from project _p2 using DELETE +DELETE FROM projects.info_proj_rel WHERE notes = '_ipr2'; + +-- Assert the project entity preview for project _p2 is deleted +SELECT is_empty('get_project_entity_preview(''_p2'')', 'Assert project entity preview for _p2 is deleted'); + +-- Assert the community entity preview is deleted +SELECT is_empty('get_community_entity_preview', 'Assert community entity preview is deleted'); + +-- Add the entity back to project _p1 +UPDATE projects.info_proj_rel +SET is_in_project = TRUE +WHERE notes = '_ipr1'; + +-- Update the fk_class of the entity +UPDATE information.resource +SET fk_class = 33 +WHERE notes = '_1'; + +-- Assert the fk_class has been updated on the project entity preview for project _p1 +SELECT IS (fk_class, 33, 'Assert fk_class has been updated on project entity preview') +FROM pgwar.entity_preview t1, projects.project t2 +WHERE t1.fk_project = t2.pk_entity AND t2.notes = '_p1'; + +-- Assert the fk_class has been updated on the community entity preview +SELECT IS (fk_class, 33, 'Assert fk_class has been updated on community entity preview') +FROM pgwar.entity_preview +WHERE fk_project = 0; + +-- Remove entity from toolbox community visibility +UPDATE information.resource +SET community_visibility = '{"toolbox":false}' +WHERE notes = '_1'; + +-- Assert the community entity preview is not present +SELECT is_empty('get_community_entity_preview', 'Assert community entity preview is not present'); + +-- Add entity to toolbox community visibility +UPDATE information.resource +SET community_visibility = '{"toolbox":true}' +WHERE notes = '_1'; + +-- Assert the community entity preview is present +SELECT isnt_empty('get_community_entity_preview', 'Assert community entity preview is present'); + +-- Delete the entity from information.resource +DELETE FROM information.resource; + +-- Assert the community entity preview is not present +SELECT is_empty('get_community_entity_preview', 'Assert community entity preview is not present'); + +-- Assert the project entity preview for project _p1 is deleted +SELECT is_empty('get_project_entity_preview(''_p1'')', 'Assert project entity preview for _p1 is deleted'); + +-- Assert the project entity preview for project _p2 is deleted +SELECT is_empty('get_project_entity_preview(''_p2'')', 'Assert project entity preview for _p2 is deleted'); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; diff --git a/database/test/integration/pgwar-field-change/test-pgwar-field-change.sql b/database/test/integration/pgwar-field-change/test-pgwar-field-change.sql new file mode 100644 index 000000000..2f7c6a831 --- /dev/null +++ b/database/test/integration/pgwar-field-change/test-pgwar-field-change.sql @@ -0,0 +1,83 @@ +-- Test the creation of project entity label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(5); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label, + object_value +) +VALUES ( + 1, + 1, + 44, + 55, + 66, + 'Label 1', + '{}'::jsonb +); +-- Test 1: assert that field change has only one row +SELECT is( + count(*)::int, + 1, + 'Assert there is only one row in field_change' + ) +FROM pgwar.field_change; +-- Test 2: Check if field_change contains the correct values +SELECT results_eq( + 'SELECT 1, 44, NULL::bigint, 55, true;', + 'SELECT fk_project, fk_source_info, fk_source_tables_cell, fk_property, is_outgoing FROM pgwar.field_change;', + 'field_change contains the correct data' + ); +DELETE FROM pgwar.field_change; +-- Insert project statement with entity +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + fk_object_tables_cell, + object_value +) +VALUES( + 2, + 1, + 44, + 55, + 66, + 1337, + NULL +); +-- Test 3: assert that field change has 2 rows +SELECT is( + count(*)::int, + 2, + 'Assert there is only one row in field_change' + ) +FROM pgwar.field_change; +-- Test 4: Check if field_change contains the correct values and is_outgoing is TRUE +SELECT results_eq( + 'SELECT 1, 44, NULL::bigint, 55, TRUE;', + 'SELECT fk_project, fk_source_info, fk_source_tables_cell, fk_property, is_outgoing FROM pgwar.field_change WHERE is_outgoing;', + 'field_change contains the correct data' + ); +-- Test 5: Check if field_change contains the correct values and is_outgoing is FALSE +SELECT results_eq( + 'SELECT 1, 66, 1337::bigint, 55, FALSE;', + 'SELECT fk_project, fk_source_info, fk_source_tables_cell, fk_property, is_outgoing FROM pgwar.field_change WHERE is_outgoing IS FALSE;', + 'field_change contains the correct data' + ); + + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-fulltext/test-pgwar-fulltext.sql b/database/test/integration/pgwar-fulltext/test-pgwar-fulltext.sql new file mode 100644 index 000000000..7351e29e9 --- /dev/null +++ b/database/test/integration/pgwar-fulltext/test-pgwar-fulltext.sql @@ -0,0 +1,60 @@ +BEGIN; + +SELECT plan(4); + +-- initialize entity previews +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class) +VALUES (32, 999, 0), + (33, 543, 0); + +-- add full text for two of the entities +INSERT INTO pgwar.entity_full_text (pk_entity, fk_project, full_text) +VALUES (32, 999, 'full-text-a'), + (33, 543, 'full-text-b'); + +SELECT is( + full_text, + 'full-text-a', + 'Assert that full-text-a is inserted into entity_preview table after insert' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 32 + AND fk_project = 999; + +SELECT is( + full_text, + 'full-text-b', + 'Assert that full-text-b is inserted into entity_preview table after insert' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 33 + AND fk_project = 543; + +UPDATE pgwar.entity_full_text +SET full_text = 'foo' +WHERE pk_entity = 33 + AND fk_project = 543; + +SELECT is( + full_text, + 'foo', + 'Assert that foo is inserted into entity_preview table after update' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 33 + AND fk_project = 543; + +SELECT is( + full_text, + 'full-text-a', + 'Assert that entity preview 32-999 is not affected by update' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 32 + AND fk_project = 999; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-fulltext/test-pgwar-project-statements-deleted.sql b/database/test/integration/pgwar-fulltext/test-pgwar-project-statements-deleted.sql new file mode 100644 index 000000000..314045de0 --- /dev/null +++ b/database/test/integration/pgwar-fulltext/test-pgwar-project-statements-deleted.sql @@ -0,0 +1,53 @@ +-- Test the pgwar.project_statements module +BEGIN; + +SELECT plan(4); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (1, 1, 31, 22, 11), + (2, 1, 32, 22, 11), + (3, 1, 33, 22, 11); + +SELECT is( + count(*)::int, + 3, + 'Assert pgwar project statement has three records' + ) +FROM pgwar.project_statements; + +SELECT is( + count(*)::int, + 0, + 'Assert pgwar project statement deleted has 0 records' + ) +FROM pgwar.project_statements_deleted; + +-- delete one project statement +DELETE FROM pgwar.project_statements +WHERE pk_entity = 3; + +SELECT is( + count(*)::int, + 1, + 'Assert pgwar project statement deleted has 1 record' + ) +FROM pgwar.project_statements_deleted; + +SELECT is( + CURRENT_TIMESTAMP, + tmsp_deletion, + 'Assert the deleted record has the transaction timestamp' + ) +FROM pgwar.project_statements_deleted; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label-circular-dependency.sql b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label-circular-dependency.sql new file mode 100644 index 000000000..c9696aa80 --- /dev/null +++ b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label-circular-dependency.sql @@ -0,0 +1,118 @@ +-- This test asserts that two entities whose labels depend on each other will not create an infinite loop +BEGIN; + +SELECT plan(1); + +-- Given this data: +-- "foo" +-- "bar" +-- +-- And given this label configuration: +-- label config of entity 1: [prop 13, prop 11] +-- label config of entity 2: [prop 13i, prop 12] +-- +-- We expect this infinite loop: +-- iteration 1 +-- entity 1: "foo" +-- entity 2: "bar" +-- iteration 2 +-- entity 1: "bar, foo" +-- entity 2: "foo, bar" +-- iteration 3 +-- entity 1: "foo, bar, foo" +-- entity 2: "bar, foo, bar" +-- iteration n +-- entity 1: "foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo" +-- entity 2: "bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar" +-- iteration n+1 +-- entity 1: "bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar" +-- entity 2: "foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo" +-- +-- +--> even though we have a max length of 100 characters, +-- the start of the entity labels will change with each iteration, infinitely. +-- +-- Create project 500 +INSERT INTO projects.project (pk_entity) +VALUES (500); +-- +-- Create entity 1 +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (1, 77); + +-- Create entity 2 +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (2, 88); + +-- Add entities to project 500 +INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) +VALUES (1, 500, true), + (2, 500, true); + +-- Add statments +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES -- "foo" + (201, 500, 1, 11, 98, 'foo'), + -- "bar" + (202, 500, 2, 12, 99, 'bar'), + -- + (203, 500, 1, 13, 2, NULL); + +-- label config of entity 1: [prop 13, prop 11] +INSERT INTO projects.entity_label_config (fk_project, fk_class, config) +VALUES ( + 500, + 77, + '{ + "labelParts": [ + { + "field": {"isOutgoing": true, "fkProperty": 13, "nrOfStatementsInLabel": 1} + }, + { + "field": {"isOutgoing": true, "fkProperty": 11, "nrOfStatementsInLabel": 1} + } + ] + }'::jsonb + ); + +-- label config of entity 2: [prop 13i, prop 12] +INSERT INTO projects.entity_label_config (fk_project, fk_class, config) +VALUES ( + 500, + 88, + '{ + "labelParts": [ + { + "field": {"isOutgoing": false, "fkProperty": 13, "nrOfStatementsInLabel": 1} + }, + { + "field": {"isOutgoing": true, "fkProperty": 12, "nrOfStatementsInLabel": 1} + } + ] + }'::jsonb + ); + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Assert the project entity preview has a label with 100 characters +SELECT ok( + length(ep.entity_label) <= 100, + 'Assert project entity preview has a label with max length of 100 chars.' + ) +FROM pgwar.entity_preview ep + WHERE ep.pk_entity = 1 + AND ep.fk_project = 500; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql new file mode 100644 index 000000000..58d296b8d --- /dev/null +++ b/database/test/integration/pgwar-project-entity-label/test-pgwar-entity-label.sql @@ -0,0 +1,252 @@ +-- Test the creation of project entity label +-- Start transaction and plan the tests. +-- 2 tests have been commented, I never found why they don't pass, even when if I execute them manually and they work... +BEGIN; + +--SELECT plan(8); +SELECT plan(6); + +INSERT INTO projects.project (pk_entity) +VALUES (1); + +-- Add entity 1 +INSERT INTO information.resource (fk_class, notes) +VALUES (77, '_1') RETURNING pk_entity; + +INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) +SELECT pk_entity, + 1, + true +FROM information.resource +WHERE notes = '_1'; + +-- Add entity 2 +INSERT INTO information.resource (fk_class, notes) +VALUES (77, '_2') RETURNING pk_entity; + +INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) +SELECT pk_entity, + 1, + true +FROM information.resource +WHERE notes = '_2'; + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Assert the project entity preview is created with class 77 +SELECT IS ( + ep.fk_class, + 77, + 'Assert project entity preview is created with class 77' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +INSERT INTO projects.entity_label_config (fk_project, fk_class, config) +VALUES ( + 1, + 77, + '{ + "labelParts": [ + { + "field": {"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5} + }, + { + "field": {"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5} + } + ] + }'::jsonb + ); + +-- Insert project statement with entity one as subject and a literal object_label +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +SELECT 1, + 1, + pk_entity, + 55, + 66, + 'Label 1' +FROM information.resource +WHERE notes = '_1'; + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Assert the project entity preview has Label 1 +SELECT IS ( + ep.entity_label, + 'Label 1', + 'Assert project entity preview has Label 1' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +-- Insert project statement with entity two as subject and entity one as object +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +SELECT 2, + 1, + two.pk_entity, + 22, + one.pk_entity, + NULL +FROM information.resource one, + information.resource two +WHERE one.notes = '_1' + AND two.notes = '_2'; + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Assert the project entity preview has Label 1 +SELECT IS ( + ep.entity_label, + 'Label 1', + 'Assert project entity preview has Label 1' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +-- Insert project statement with entity two as subject and a literal object_label +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +SELECT 3, + 1, + pk_entity, + 55, + 66, + 'Label 2' +FROM information.resource +WHERE notes = '_2'; + +SELECT pgwar.update_entity_label_on_config_change(); +SELECT pgwar.update_entity_preview_entity_label(); + +-- Assert the project entity preview has Label 2, Label 1 +SELECT IS ( + ep.entity_label, + 'Label 2, Label 1', + 'Assert project entity preview has Label 2, Label 1' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +-- Modify the entity label config (switching order of fields in labelParts) +UPDATE projects.entity_label_config +SET config = '{ + "labelParts": [ + { + "field": {"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5} + }, + { + "field": {"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5} + } + ] + }'::jsonb +WHERE fk_project = 1 +AND fk_class = 77; + +SELECT pgwar.update_entity_label_on_config_change(); +--SELECT pgwar.update_entity_preview_entity_label(); + + +-- Assert the project entity preview is updated after config change +-- SELECT IS ( +-- ep.entity_label, +-- 'Label 1, Label 2', +-- 'Assert project entity preview is updated after config change' +-- ) +-- FROM pgwar.entity_preview ep, +-- information.resource r +-- WHERE ep.pk_entity = r.pk_entity +-- AND r.notes = '_1' +-- AND ep.fk_project = 1; + +-- DELETE pgwar statement for entity two +DELETE FROM pgwar.project_statements +WHERE pk_entity = 3 +AND fk_project = 1; + +SELECT pgwar.update_entity_preview_entity_label_after_stmt_delete(); + +-- Assert the project entity preview has Label 1 +SELECT IS ( + ep.entity_label, + 'Label 1', + 'Assert project entity preview has Label 1 - Test 6' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +-- Update fk_class +UPDATE information.resource +SET fk_class = 99 +WHERE notes = '_1'; + +SELECT pgwar.update_entity_preview_entity_label(); + +SELECT IS ( + ep.fk_class, + 99, + 'Assert project entity preview has the changed class' + ) +FROM pgwar.entity_preview ep, + information.resource r +WHERE ep.pk_entity = r.pk_entity + AND r.notes = '_1' + AND ep.fk_project = 1; + +-- SELECT IS ( +-- ep.entity_label, +-- NULL, +-- 'Assert project entity preview has NULL after changed class - Test 8' +-- ) +-- FROM pgwar.entity_preview ep, +-- information.resource r +-- WHERE ep.pk_entity = r.pk_entity +-- AND r.notes = '_1' +-- AND ep.fk_project = 1; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql b/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql new file mode 100644 index 000000000..a7793222e --- /dev/null +++ b/database/test/integration/pgwar-project-statements/test-pgwar-project-statements.sql @@ -0,0 +1,149 @@ +-- Test the pgwar.project_statements module +BEGIN; + +SELECT plan(11); + +------- Prepare required context data ------ + +PREPARE get_all_pgwar_project_statements AS +SELECT * +FROM pgwar.project_statements; + +-- Insert a language entry to be used in project +INSERT INTO information.language(pk_language) +VALUES ('eng'); + +-- Insert a project associated with the language +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, + '_p1' +FROM information.language; + +-- Insert one statement +INSERT INTO pgwar.statement( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label, + object_value + ) +VALUES (1, 0, 0, 1, 'foo', '{"foo":"bar"}'); + +-- Add the statement to the project '_p1' in projects.info_proj_rel +INSERT INTO projects.info_proj_rel(fk_project, fk_entity, is_in_project, notes) +SELECT proj.pk_entity, + 1, + TRUE, + '_ipr1' +FROM projects.project proj +WHERE proj.notes = '_p1'; + +SELECT isnt_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty inserting a statement' + ); + +SELECT is( + object_label, + 'foo', + 'Assert project statement has correct object_label' + ) +FROM pgwar.project_statements; + +SELECT ok( + object_value IS NOT NULL, + 'Assert project statement has an object_value' + ) +FROM pgwar.project_statements; + +--Update pgwar.statement +UPDATE pgwar.statement +SET object_label = 'bar' +WHERE pk_entity = 1; + +SELECT is( + object_label, + 'bar', + 'Assert project statement object_label has been updated' + ) +FROM pgwar.project_statements; + +-- Delete the statement +DELETE FROM pgwar.statement; + +SELECT is_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after deleting pgwar statement' + ); + +-- Re-insert one statement +INSERT INTO pgwar.statement( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label, + object_value + ) +VALUES (1, 0, 0, 1, 'foo', '{"foo":"bar"}'); + +SELECT isnt_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty after re-inserting a statement' + ); + +-- Update info_proj_rel _ipr1 ord_num_of_domain and ord_num_of_range +UPDATE projects.info_proj_rel +SET ord_num_of_domain = 1::numeric, + ord_num_of_range = 2::numeric +WHERE notes = '_ipr1'; + +SELECT is( + ord_num_of_domain, + 1::numeric, + 'Assert project statement has correct ord_num_of_domain' + ) +FROM pgwar.project_statements; + +SELECT is( + ord_num_of_range, + 2::numeric, + 'Assert project statement has correct ord_num_of_range' + ) +FROM pgwar.project_statements; + +-- Update info_proj_rel _ipr1 to remove the statement from the project +UPDATE projects.info_proj_rel +SET is_in_project = FALSE +WHERE notes = '_ipr1'; + +SELECT is_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after setting is_in_project to FALSE in info_proj_rel' + ); + +-- Update info_proj_rel _ipr1 to add the statement to the project +UPDATE projects.info_proj_rel +SET is_in_project = TRUE +WHERE notes = '_ipr1'; + +SELECT isnt_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is not empty after setting is_in_project to TRUE in info_proj_rel' + ); + +-- Delete info_proj_rel _ipr1 +DELETE FROM projects.info_proj_rel +WHERE notes = '_ipr1'; + +SELECT is_empty( + 'get_all_pgwar_project_statements', + 'Assert pgwar project statement is empty after deleting info_proj_rel _ipr1' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-appe.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-appe.sql new file mode 100644 index 000000000..93d172225 --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-appe.sql @@ -0,0 +1,80 @@ +-- Test the creation pgwar.statement with appellation +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert an appellation +INSERT INTO information.appellation(string, fk_class, notes) +VALUES ('foo', 0, '_a1'); + +-- Insert one statement referencing appellation '_a1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.appellation +WHERE notes = '_a1'; + +SELECT is( + object_label, + 'foo', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.appellation +SET string = 'bar' +WHERE notes = '_a1'; + +SELECT is( + object_label, + 'bar', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing appellation '_a1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.appellation +WHERE notes = '_a1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.appellation; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-cell.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-cell.sql new file mode 100644 index 000000000..7abcfecff --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-cell.sql @@ -0,0 +1,93 @@ +-- Test the creation pgwar.statement with cell +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert a cell +INSERT INTO tables.cell ( + fk_row, + fk_column, + fk_digital, + entity_version, + string_value, + numeric_value, + fk_class, + notes + ) +VALUES(44, 55, 0, 1, 'foo', 43.21, 88, '_1'); + +-- Insert one statement referencing cell '_1' +INSERT INTO information.statement( + fk_subject_info, + fk_property, + fk_object_tables_cell + ) +SELECT 0, + 0, + pk_cell +FROM tables.cell +WHERE notes = '_1'; + +SELECT is( + object_label, + 'foo', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE tables.cell +SET string_value = 'bar' +WHERE notes = '_1'; + +SELECT is( + object_label, + 'bar', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing cell '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_tables_cell) +SELECT 0, + 0, + pk_cell +FROM tables.cell +WHERE notes = '_1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM tables.cell; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-dimension.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-dimension.sql new file mode 100644 index 000000000..05ad9299c --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-dimension.sql @@ -0,0 +1,93 @@ +-- Test the creation pgwar.statement with dimension +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert a measurement unit +INSERT INTO information.resource(fk_class) +VALUES (0); + +-- Insert a dimension +INSERT INTO information.dimension( + numeric_value, + fk_measurement_unit, + fk_class, + notes + ) +SELECT 43.21, + pk_entity, + 0, + '_1' +FROM information.resource; + +-- Insert one statement referencing dimension '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.dimension +WHERE notes = '_1'; + +SELECT is( + object_label, + '43.21', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.dimension +SET numeric_value = 2 +WHERE notes = '_1'; + +SELECT is( + object_label, + '2', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing dimension '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.dimension +WHERE notes = '_1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.dimension; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-lang-string.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-lang-string.sql new file mode 100644 index 000000000..0bad8d2df --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-lang-string.sql @@ -0,0 +1,95 @@ +-- Test the creation pgwar.statement with lang_string +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +WITH inserted_lang AS ( + -- Insert a language, as required by lang_string + INSERT INTO information.language ( + notes, + iso6391, + iso6392b, + iso6392t, + pk_language, + fk_class + ) + VALUES ('english', 'e', 'en', 'eng', 'eng', 123) RETURNING pk_entity +) -- Insert a lang_string +INSERT INTO information.lang_string (string, fk_language, fk_class, notes) +SELECT 'foo', + inserted_lang.pk_entity, + 123, + '_1' +FROM inserted_lang; + +-- Insert one statement referencing lang_string '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.lang_string +WHERE notes = '_1'; + +SELECT is( + object_label, + 'foo', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.lang_string +SET string = 'bar' +WHERE notes = '_1'; + +SELECT is( + object_label, + 'bar', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing lang_string '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.lang_string +WHERE notes = '_1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.lang_string; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-language.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-language.sql new file mode 100644 index 000000000..b8e358887 --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-language.sql @@ -0,0 +1,80 @@ +-- Test the creation pgwar.statement with language +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert a language +INSERT INTO information.language (notes, iso6391, iso6392b, iso6392t, pk_language, fk_class) +VALUES ('english', 'e', 'en', 'eng', 'eng', 123); + +-- Insert one statement referencing language 'english' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.language +WHERE notes = 'english'; + +SELECT is( + object_label, + 'english', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.language +SET notes = 'bar' +WHERE notes = 'english'; + +SELECT is( + object_label, + 'bar', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing language 'bar' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.language +WHERE notes = 'bar'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.language; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-place.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-place.sql new file mode 100644 index 000000000..a678b10a3 --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-place.sql @@ -0,0 +1,84 @@ +-- Test the creation pgwar.statement with place +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert an place +INSERT INTO information.place (geo_point, fk_class, notes) +VALUES ( + ST_SetSRID(ST_MakePoint(7.123, 3.123), 4326)::geography, + 123, + '_1' + ); + +-- Insert one statement referencing place '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.place +WHERE notes = '_1'; + +SELECT is( + object_label, + 'WGS84: 7.123°, 3.123°', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.place +SET geo_point = ST_SetSRID(ST_MakePoint(17.123, 13.123), 4326)::geography +WHERE notes = '_1'; + +SELECT is( + object_label, + 'WGS84: 17.123°, 13.123°', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing place '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.place +WHERE notes = '_1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.place; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-statement/test-pgwar-statement-with-time-primitive.sql b/database/test/integration/pgwar-statement/test-pgwar-statement-with-time-primitive.sql new file mode 100644 index 000000000..c9bc31d93 --- /dev/null +++ b/database/test/integration/pgwar-statement/test-pgwar-statement-with-time-primitive.sql @@ -0,0 +1,86 @@ +-- Test the creation pgwar.statement with time_primitive +BEGIN; + +SELECT plan(6); + +PREPARE get_all_pgwar_statements AS +SELECT * +FROM pgwar.statement; + +-- Insert an time_primitive +INSERT INTO information.time_primitive (duration, julian_day, calendar, notes) +VALUES ( + '1 day', + 2460461, + 'gregorian', + '_1' + ); + +-- Insert one statement referencing time_primitive '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.time_primitive +WHERE notes = '_1'; + +SELECT is( + object_label, + '2024-05-30 (1 day)', + 'Assert statement has correct object_label' + ) +FROM pgwar.statement; + +SELECT ok( + object_value IS NOT NULL, + 'Assert statement has an object_value' + ) +FROM pgwar.statement; + +-- Update the literal +UPDATE information.time_primitive +SET julian_day = 2236211, + calendar = 'julian' +WHERE notes = '_1'; + +SELECT is( + object_label, + '1410-05-31 (1 day)', + 'Assert statement object_label has been updated' + ) +FROM pgwar.statement; + +-- Delete the statement +DELETE FROM information.statement; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting statement' + ); + +-- Re-insert one statement referencing time_primitive '_1' +INSERT INTO information.statement(fk_subject_info, fk_property, fk_object_info) +SELECT 0, + 0, + pk_entity +FROM information.time_primitive +WHERE notes = '_1'; + +SELECT isnt_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is not empty after re-inserting a statement' + ); + +-- Delete the literal +DELETE FROM information.time_primitive; + +SELECT is_empty( + 'get_all_pgwar_statements', + 'Assert pgwar statement is empty after deleting literal' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-time-span/test-pgwar-time-span.sql b/database/test/integration/pgwar-time-span/test-pgwar-time-span.sql new file mode 100644 index 000000000..b4653abb1 --- /dev/null +++ b/database/test/integration/pgwar-time-span/test-pgwar-time-span.sql @@ -0,0 +1,279 @@ +BEGIN; + +SELECT plan(9); + +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_modify_project_statements +DROP TRIGGER IF EXISTS after_modify_project_statements ON pgwar.project_statements; + +-- initialize entity previews +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class) +VALUES (32, 999, 0), + (33, 999, 0), + (34, 999, 0); + +INSERT INTO pgwar.project_statements (pk_entity, fk_project, fk_subject_info, fk_property, object_value) +VALUES (132, 999, 32, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 year)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 year", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb), + (133, 999, 33, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 month)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 month", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb), + (134, 999, 34, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 day)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 day", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb); + +-- add full text for two of the entities +INSERT INTO pgwar.statement (pk_entity, fk_subject_info, fk_property, object_value) +VALUES (132, 32, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 year)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 year", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb), + (133, 33, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 month)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 month", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb), + (134, 34, 72, '{ + "timePrimitive": { + "to": { + "calJulian": "1890-12-20", + "julianDay": 2411734, + "calGregorian": "1891-01-01", + "julianSecond": 208373817600, + "calGregorianIso8601": "1891-01-01T00:00:00Z" + }, + "from": { + "calJulian": "1889-12-20", + "julianDay": 2411369, + "calGregorian": "1890-01-01", + "julianSecond": 208342281600, + "calGregorianIso8601": "1890-01-01T00:00:00Z" + }, + "label": "1890-01-01 (1 day)", + "fkClass": 335, + "calendar": "gregorian", + "duration": "1 day", + "pkEntity": 835781, + "julianDay": 2411369 + } + }'::jsonb); + +-- run the update task +SELECT pgwar.update_time_span(); + +SELECT is( + time_span, + '{ + "p82": { + "calendar": "gregorian", + "duration": "1 year", + "julianDay": 2411369 + } + }'::jsonb, + 'time span json is correctly constructed' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 32 + AND fk_project = 999; + +SELECT is( + time_span, + '{ + "p82": { + "calendar": "gregorian", + "duration": "1 month", + "julianDay": 2411369 + } + }'::jsonb, + 'time span json is correctly constructed' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 33 + AND fk_project = 999; + +SELECT is( + time_span, + '{ + "p82": { + "calendar": "gregorian", + "duration": "1 day", + "julianDay": 2411369 + } + }'::jsonb, + 'time span json is correctly constructed' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 34 + AND fk_project = 999; + +SELECT is( + first_second, + 208342281600, + 'first_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 32 + AND fk_project = 999; + +SELECT is( + first_second, + 208342281600, + 'first_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 33 + AND fk_project = 999; + +SELECT is( + first_second, + 208342281600, + 'first_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 34 + AND fk_project = 999; + +SELECT is( + last_second, + 208373817600, + 'last_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 32 + AND fk_project = 999; + +SELECT is( + last_second, + 208344873600, + 'last_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 33 + AND fk_project = 999; + +SELECT is( + last_second, + 208342368000, + 'last_second is correct in entity_preview' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 34 + AND fk_project = 999; + + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/integration/pgwar-ts-vector/test-pgwar-ts-vector.sql b/database/test/integration/pgwar-ts-vector/test-pgwar-ts-vector.sql new file mode 100644 index 000000000..5e05056bc --- /dev/null +++ b/database/test/integration/pgwar-ts-vector/test-pgwar-ts-vector.sql @@ -0,0 +1,40 @@ +-- Test the creation of project and community entities +-- after modifying information.resource and projects.info_proj_rel +-- Start transaction and plan the tests. +BEGIN; +SELECT plan(1); + +INSERT INTO projects.project (pk_entity) +VALUES (33); + +INSERT INTO pgwar.entity_preview ( + pk_entity, + fk_project, + fk_class, + entity_label, + class_label, + type_label, + full_text + ) +VALUES ( + 22, + 33, + 0, + 'S. Ziminian', + 'Geographical Place', + 'Parrocchia', + 'S. Ziminian" "Name: S. Ziminian. +Type: Parrocchia.' + ); +-- Assert the fk_class has been updated on the community entity preview +SELECT ok( + ts_vector IS NOT NULL, + 'Assert the ts_vector is set' + ) +FROM pgwar.entity_preview +WHERE fk_project = 33 + AND pk_entity = 22; +-- Finish the tests and clean up. +SELECT * +FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/database/test/performance/check.sql b/database/test/performance/check.sql new file mode 100644 index 000000000..35bd241e9 --- /dev/null +++ b/database/test/performance/check.sql @@ -0,0 +1,12 @@ +-- Dummy-test used to check if the test setup is working +BEGIN; +SELECT plan(1); +SELECT is( + 1, + 1, + 'Assert the test setup is working' + ); +-- Finish the tests and clean up. +SELECT * +FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/database/test/performance/insert-entities.sql b/database/test/performance/insert-entities.sql new file mode 100644 index 000000000..c94d9d59f --- /dev/null +++ b/database/test/performance/insert-entities.sql @@ -0,0 +1,203 @@ +-- Dummy-test used to check if the test setup is working +BEGIN; + +/********* + ***** HELPER FUNCTIONS to create meaningful data + *********/ +-- Function to get the class ID based on the label +CREATE +OR REPLACE FUNCTION commons.get_class_id(label text) RETURNS int AS $$ +BEGIN -- Inspired by https://github.com/geovistory/geovpylib/blob/master/geovpylib/pks/classes.py + IF label = 'person' THEN RETURN 21; + +END IF; + +IF label = 'aial' THEN RETURN 365; + +END IF; + +-- Return NULL if the label does not match +RETURN NULL; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to get the property ID based on the label +CREATE +OR REPLACE FUNCTION commons.get_property_id(label text) RETURNS int AS $$ +BEGIN -- Inspired by https://github.com/geovistory/geovpylib/blob/master/geovpylib/pks/properties.py + IF label = 'aial_isAppelationForLanguageOf_entity' THEN RETURN 1111; + +END IF; + +IF label = 'aial_usedInLanguage_language' THEN RETURN 1112; + +END IF; + +IF label = 'aial_refersToName_appellation' THEN RETURN 1113; + +END IF; + +-- Return NULL if the label does not match +RETURN NULL; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to create a new entity and return its ID. The created entity is added to the project. +CREATE +OR REPLACE FUNCTION commons.create_entity(fk_class int, fk_project int, fk_account int) RETURNS int AS $$ +DECLARE id int; + +BEGIN +INSERT INTO information.resource (fk_class, community_visibility) +VALUES (fk_class, '{"toolbox":true, "dataApi":true}') RETURNING pk_entity INTO id; + +-- Add the created entity to the project +INSERT INTO projects.info_proj_rel ( + fk_entity, + fk_project, + is_in_project, + fk_last_modifier, + fk_creator + ) +SELECT id, + fk_project, + true, + fk_account, + fk_account; + +RETURN id; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to create a new appellation and return its ID +CREATE +OR REPLACE FUNCTION commons.create_appellation(string text) RETURNS int AS $$ +DECLARE id int; + +BEGIN +INSERT INTO information.appellation (string, fk_class) +VALUES (string, 40) RETURNING pk_entity INTO id; + +RETURN id; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to create a new statement and return its ID. The created statement is added to the project. +CREATE +OR REPLACE FUNCTION commons.create_statement( + fk_subject_info int, + fk_property int, + fk_object_info int, + fk_project int, + fk_account int +) RETURNS int AS $$ +DECLARE id int; + +BEGIN +INSERT INTO information.statement ( + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (fk_subject_info, fk_property, fk_object_info) RETURNING pk_entity INTO id; + +-- Add the created statement to the project +INSERT INTO projects.info_proj_rel ( + fk_entity, + fk_project, + is_in_project, + fk_last_modifier, + fk_creator + ) +SELECT id, + fk_project, + true, + fk_account, + fk_account; + +RETURN id; + +END; + +$$ LANGUAGE plpgsql; + +-- Function to create a person entity with a name (aial) and add all created items to the project +CREATE +OR REPLACE FUNCTION commons.create_person(project_id int, account_id int) RETURNS int AS $$ +DECLARE -- Declare variables here + person_id int; + +aial_id int; + +string_id int; + +BEGIN -- Create person +SELECT commons.create_entity( + commons.get_class_id('person'), + project_id, + account_id + ) INTO person_id; + +-- Create appellation in a language (aial) +SELECT commons.create_entity( + commons.get_class_id('aial'), + project_id, + account_id + ) INTO aial_id; + +-- -- Create string +SELECT commons.create_appellation(concat('person ', person_id)) INTO string_id; + +-- -- Create statement aial -> is appellation of -> person +PERFORM commons.create_statement( + aial_id, + commons.get_property_id('aial_isAppelationForLanguageOf_entity'), + person_id, + project_id, + account_id +); + +-- -- Create statement aial -> has name -> string +PERFORM commons.create_statement( + aial_id, + commons.get_property_id('aial_refersToName_appellation'), + string_id, + project_id, + account_id +); + +-- Return the person ID +RETURN person_id; + +END; + +$$ LANGUAGE plpgsql; + +/********* + ***** END OF HELPER FUNCTIONS + *********/ +SELECT plan(1); + +PREPARE create_person AS +SELECT commons.create_person(591, 7); + +SELECT performs_within( + 'create_person', + 10, --avg ms + 10, --within -> max 20 ms + 100, + 'Assert that inserting a person with a name takes less than 20ms' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/performance/load-field-page.sql b/database/test/performance/load-field-page.sql new file mode 100644 index 000000000..0368aec8e --- /dev/null +++ b/database/test/performance/load-field-page.sql @@ -0,0 +1,8024 @@ +BEGIN; + +SELECT plan(1); + +PREPARE load_field_pages AS +SELECT commons.get_field_pages(' +[ + { + "pkProject": 924033, + "targets": { + "365": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "630": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1430 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "40": { + "appellation": "true" + } + }, + "page": { + "property": { + "fkProperty": 1113 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "1": { + "entityPreview": "true" + }, + "5": { + "entityPreview": "true" + }, + "21": { + "entityPreview": "true" + }, + "22": { + "entityPreview": "true" + }, + "41": { + "entityPreview": "true" + }, + "53": { + "entityPreview": "true" + }, + "55": { + "entityPreview": "true" + }, + "60": { + "entityPreview": "true" + }, + "61": { + "entityPreview": "true" + }, + "62": { + "entityPreview": "true" + }, + "63": { + "entityPreview": "true" + }, + "67": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "71": { + "entityPreview": "true" + }, + "78": { + "entityPreview": "true" + }, + "79": { + "entityPreview": "true" + }, + "81": { + "entityPreview": "true" + }, + "212": { + "entityPreview": "true" + }, + "217": { + "entityPreview": "true" + }, + "218": { + "entityPreview": "true" + }, + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "244": { + "entityPreview": "true" + }, + "332": { + "entityPreview": "true" + }, + "340": { + "entityPreview": "true" + }, + "363": { + "entityPreview": "true" + }, + "364": { + "entityPreview": "true" + }, + "365": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + }, + "442": { + "entityPreview": "true" + }, + "443": { + "entityPreview": "true" + }, + "444": { + "entityPreview": "true" + }, + "445": { + "entityPreview": "true" + }, + "449": { + "entityPreview": "true" + }, + "450": { + "entityPreview": "true" + }, + "451": { + "entityPreview": "true" + }, + "452": { + "entityPreview": "true" + }, + "454": { + "entityPreview": "true" + }, + "455": { + "entityPreview": "true" + }, + "456": { + "appellation": "true" + }, + "457": { + "entityPreview": "true" + }, + "459": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + }, + "516": { + "entityPreview": "true" + }, + "518": { + "entityPreview": "true" + }, + "519": { + "entityPreview": "true" + }, + "520": { + "entityPreview": "true" + }, + "521": { + "cell": "true" + }, + "607": { + "entityPreview": "true" + }, + "608": { + "entityPreview": "true" + }, + "629": { + "entityPreview": "true" + }, + "630": { + "entityPreview": "true" + }, + "633": { + "entityPreview": "true" + }, + "634": { + "entityPreview": "true" + }, + "635": { + "entityPreview": "true" + }, + "657": { + "langString": "true" + }, + "676": { + "entityPreview": "true" + }, + "677": { + "entityPreview": "true" + }, + "690": { + "entityPreview": "true" + }, + "698": { + "entityPreview": "true" + }, + "702": { + "entityPreview": "true" + }, + "708": { + "entityPreview": "true" + }, + "712": { + "entityPreview": "true" + }, + "718": { + "entityPreview": "true" + }, + "721": { + "entityPreview": "true" + }, + "722": { + "entityPreview": "true" + }, + "723": { + "entityPreview": "true" + }, + "724": { + "entityPreview": "true" + }, + "725": { + "entityPreview": "true" + }, + "783": { + "entityPreview": "true" + }, + "784": { + "langString": "true" + }, + "785": { + "entityPreview": "true" + }, + "808": { + "entityPreview": "true" + }, + "827": { + "entityPreview": "true" + }, + "838": { + "entityPreview": "true" + }, + "839": { + "entityPreview": "true" + }, + "867": { + "entityPreview": "true" + }, + "868": { + "entityPreview": "true" + }, + "869": { + "entityPreview": "true" + }, + "870": { + "entityPreview": "true" + }, + "871": { + "entityPreview": "true" + }, + "872": { + "entityPreview": "true" + }, + "873": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + }, + "883": { + "entityPreview": "true" + }, + "898": { + "entityPreview": "true" + }, + "899": { + "entityPreview": "true" + }, + "900": { + "entityPreview": "true" + }, + "903": { + "entityPreview": "true" + }, + "904": { + "entityPreview": "true" + }, + "969": { + "entityPreview": "true" + }, + "1076": { + "entityPreview": "true" + }, + "1150": { + "entityPreview": "true" + }, + "1210": { + "entityPreview": "true" + }, + "1295": { + "entityPreview": "true" + }, + "1358": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "54": { + "language": "true" + } + }, + "page": { + "property": { + "fkProperty": 1112 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + }, + "868": { + "nestedResource": [ + { + "targets": { + "869": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1430 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "868": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "868": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "868": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "868": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "40": { + "appellation": "true" + } + }, + "page": { + "property": { + "fkProperty": 1113 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "54": { + "language": "true" + } + }, + "page": { + "property": { + "fkProperty": 1112 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1111 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1762 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1763 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1440 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1943 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1842 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 2283 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 2283 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1499 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1499 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "61": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "61": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "61": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "61": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "61": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 86 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 7 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "633": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1435 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 86 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "63": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "63": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "63": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "63": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "63": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1599 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 88 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 7 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 88 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "633": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "633": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "633": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "633": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "633": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "61": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1435 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1436 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1439 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "629": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1429 + }, + "limit": 5, + "offset": 0, + "isOutgoing": true, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "442": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "608": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1413 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "442": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "442": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "442": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "442": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1189 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1188 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1188 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "212": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "441": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1881 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1178 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1177 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "449": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1066 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 108 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 107 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 108 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "212": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 107 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1177 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "79": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "79": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "79": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "79": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "79": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 134 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 133 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 133 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "78": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "78": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "78": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "78": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "78": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 132 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 131 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 131 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "867": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1837 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "676": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1599 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1597 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1596 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "218": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1595 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "218": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 991 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 13 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1597 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "340": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "340": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "340": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "340": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "340": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1414 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1414 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "808": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "883": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1854 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "808": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "808": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "808": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "808": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1852 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "441": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1851 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1411 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1411 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "244": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "244": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "244": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "244": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "244": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1599 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "217": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 993 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "220": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 992 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "218": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 991 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 13 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + }, + "676": { + "nestedResource": [ + { + "targets": { + "365": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1111 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "899": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1762 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "676": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "363": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1599 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1597 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1596 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "218": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1595 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "218": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 991 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "21": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 13 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + }, + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + }, + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1889 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 72 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 152 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 150 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 151 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 153 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "335": { + "timePrimitive": "true" + } + }, + "page": { + "property": { + "fkProperty": 71 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 13 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "935": { + "nestedResource": [ + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "935": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "1": { + "entityPreview": "true" + }, + "5": { + "entityPreview": "true" + }, + "21": { + "entityPreview": "true" + }, + "22": { + "entityPreview": "true" + }, + "53": { + "entityPreview": "true" + }, + "55": { + "entityPreview": "true" + }, + "60": { + "entityPreview": "true" + }, + "61": { + "entityPreview": "true" + }, + "62": { + "entityPreview": "true" + }, + "63": { + "entityPreview": "true" + }, + "67": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "71": { + "entityPreview": "true" + }, + "78": { + "entityPreview": "true" + }, + "79": { + "entityPreview": "true" + }, + "81": { + "entityPreview": "true" + }, + "212": { + "entityPreview": "true" + }, + "217": { + "entityPreview": "true" + }, + "218": { + "entityPreview": "true" + }, + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "244": { + "entityPreview": "true" + }, + "332": { + "entityPreview": "true" + }, + "340": { + "entityPreview": "true" + }, + "363": { + "entityPreview": "true" + }, + "364": { + "entityPreview": "true" + }, + "365": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + }, + "442": { + "entityPreview": "true" + }, + "443": { + "entityPreview": "true" + }, + "444": { + "entityPreview": "true" + }, + "445": { + "entityPreview": "true" + }, + "449": { + "entityPreview": "true" + }, + "450": { + "entityPreview": "true" + }, + "451": { + "entityPreview": "true" + }, + "452": { + "entityPreview": "true" + }, + "454": { + "entityPreview": "true" + }, + "455": { + "entityPreview": "true" + }, + "459": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + }, + "516": { + "entityPreview": "true" + }, + "518": { + "entityPreview": "true" + }, + "519": { + "entityPreview": "true" + }, + "520": { + "entityPreview": "true" + }, + "607": { + "entityPreview": "true" + }, + "608": { + "entityPreview": "true" + }, + "629": { + "entityPreview": "true" + }, + "630": { + "entityPreview": "true" + }, + "633": { + "entityPreview": "true" + }, + "634": { + "entityPreview": "true" + }, + "635": { + "entityPreview": "true" + }, + "676": { + "entityPreview": "true" + }, + "677": { + "entityPreview": "true" + }, + "690": { + "entityPreview": "true" + }, + "698": { + "entityPreview": "true" + }, + "702": { + "entityPreview": "true" + }, + "708": { + "entityPreview": "true" + }, + "712": { + "entityPreview": "true" + }, + "718": { + "entityPreview": "true" + }, + "721": { + "entityPreview": "true" + }, + "722": { + "entityPreview": "true" + }, + "723": { + "entityPreview": "true" + }, + "724": { + "entityPreview": "true" + }, + "725": { + "entityPreview": "true" + }, + "808": { + "entityPreview": "true" + }, + "827": { + "entityPreview": "true" + }, + "838": { + "entityPreview": "true" + }, + "839": { + "entityPreview": "true" + }, + "867": { + "entityPreview": "true" + }, + "868": { + "entityPreview": "true" + }, + "869": { + "entityPreview": "true" + }, + "871": { + "entityPreview": "true" + }, + "872": { + "entityPreview": "true" + }, + "873": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + }, + "883": { + "entityPreview": "true" + }, + "903": { + "entityPreview": "true" + }, + "904": { + "entityPreview": "true" + }, + "969": { + "entityPreview": "true" + }, + "1076": { + "entityPreview": "true" + }, + "1150": { + "entityPreview": "true" + }, + "1210": { + "entityPreview": "true" + }, + "1295": { + "entityPreview": "true" + }, + "1358": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1877 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "657": { + "langString": "true" + } + }, + "page": { + "property": { + "fkProperty": 1878 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + }, + "968": { + "nestedResource": [ + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "968": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "1": { + "entityPreview": "true" + }, + "5": { + "entityPreview": "true" + }, + "21": { + "entityPreview": "true" + }, + "22": { + "entityPreview": "true" + }, + "53": { + "entityPreview": "true" + }, + "55": { + "entityPreview": "true" + }, + "60": { + "entityPreview": "true" + }, + "61": { + "entityPreview": "true" + }, + "62": { + "entityPreview": "true" + }, + "63": { + "entityPreview": "true" + }, + "67": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "71": { + "entityPreview": "true" + }, + "78": { + "entityPreview": "true" + }, + "79": { + "entityPreview": "true" + }, + "81": { + "entityPreview": "true" + }, + "212": { + "entityPreview": "true" + }, + "217": { + "entityPreview": "true" + }, + "218": { + "entityPreview": "true" + }, + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "244": { + "entityPreview": "true" + }, + "332": { + "entityPreview": "true" + }, + "340": { + "entityPreview": "true" + }, + "363": { + "entityPreview": "true" + }, + "364": { + "entityPreview": "true" + }, + "365": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + }, + "442": { + "entityPreview": "true" + }, + "443": { + "entityPreview": "true" + }, + "444": { + "entityPreview": "true" + }, + "445": { + "entityPreview": "true" + }, + "449": { + "entityPreview": "true" + }, + "450": { + "entityPreview": "true" + }, + "451": { + "entityPreview": "true" + }, + "452": { + "entityPreview": "true" + }, + "454": { + "entityPreview": "true" + }, + "455": { + "entityPreview": "true" + }, + "459": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + }, + "516": { + "entityPreview": "true" + }, + "518": { + "entityPreview": "true" + }, + "519": { + "entityPreview": "true" + }, + "520": { + "entityPreview": "true" + }, + "607": { + "entityPreview": "true" + }, + "608": { + "entityPreview": "true" + }, + "629": { + "entityPreview": "true" + }, + "630": { + "entityPreview": "true" + }, + "633": { + "entityPreview": "true" + }, + "634": { + "entityPreview": "true" + }, + "635": { + "entityPreview": "true" + }, + "676": { + "entityPreview": "true" + }, + "677": { + "entityPreview": "true" + }, + "690": { + "entityPreview": "true" + }, + "698": { + "entityPreview": "true" + }, + "702": { + "entityPreview": "true" + }, + "708": { + "entityPreview": "true" + }, + "712": { + "entityPreview": "true" + }, + "718": { + "entityPreview": "true" + }, + "721": { + "entityPreview": "true" + }, + "722": { + "entityPreview": "true" + }, + "723": { + "entityPreview": "true" + }, + "724": { + "entityPreview": "true" + }, + "725": { + "entityPreview": "true" + }, + "808": { + "entityPreview": "true" + }, + "827": { + "entityPreview": "true" + }, + "838": { + "entityPreview": "true" + }, + "839": { + "entityPreview": "true" + }, + "867": { + "entityPreview": "true" + }, + "868": { + "entityPreview": "true" + }, + "869": { + "entityPreview": "true" + }, + "871": { + "entityPreview": "true" + }, + "872": { + "entityPreview": "true" + }, + "873": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + }, + "883": { + "entityPreview": "true" + }, + "903": { + "entityPreview": "true" + }, + "904": { + "entityPreview": "true" + }, + "969": { + "entityPreview": "true" + }, + "1076": { + "entityPreview": "true" + }, + "1150": { + "entityPreview": "true" + }, + "1210": { + "entityPreview": "true" + }, + "1295": { + "entityPreview": "true" + }, + "1358": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1876 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "898": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1877 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "521": { + "cell": "true" + } + }, + "page": { + "property": { + "fkProperty": 1878 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1876 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "933": { + "nestedResource": [ + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "933": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "1": { + "entityPreview": "true" + }, + "5": { + "entityPreview": "true" + }, + "21": { + "entityPreview": "true" + }, + "22": { + "entityPreview": "true" + }, + "53": { + "entityPreview": "true" + }, + "55": { + "entityPreview": "true" + }, + "60": { + "entityPreview": "true" + }, + "61": { + "entityPreview": "true" + }, + "62": { + "entityPreview": "true" + }, + "63": { + "entityPreview": "true" + }, + "67": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "71": { + "entityPreview": "true" + }, + "78": { + "entityPreview": "true" + }, + "79": { + "entityPreview": "true" + }, + "81": { + "entityPreview": "true" + }, + "212": { + "entityPreview": "true" + }, + "217": { + "entityPreview": "true" + }, + "218": { + "entityPreview": "true" + }, + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "244": { + "entityPreview": "true" + }, + "332": { + "entityPreview": "true" + }, + "340": { + "entityPreview": "true" + }, + "363": { + "entityPreview": "true" + }, + "364": { + "entityPreview": "true" + }, + "365": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + }, + "442": { + "entityPreview": "true" + }, + "443": { + "entityPreview": "true" + }, + "444": { + "entityPreview": "true" + }, + "445": { + "entityPreview": "true" + }, + "449": { + "entityPreview": "true" + }, + "450": { + "entityPreview": "true" + }, + "451": { + "entityPreview": "true" + }, + "452": { + "entityPreview": "true" + }, + "454": { + "entityPreview": "true" + }, + "455": { + "entityPreview": "true" + }, + "459": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + }, + "516": { + "entityPreview": "true" + }, + "518": { + "entityPreview": "true" + }, + "519": { + "entityPreview": "true" + }, + "520": { + "entityPreview": "true" + }, + "607": { + "entityPreview": "true" + }, + "608": { + "entityPreview": "true" + }, + "629": { + "entityPreview": "true" + }, + "630": { + "entityPreview": "true" + }, + "633": { + "entityPreview": "true" + }, + "634": { + "entityPreview": "true" + }, + "635": { + "entityPreview": "true" + }, + "676": { + "entityPreview": "true" + }, + "677": { + "entityPreview": "true" + }, + "690": { + "entityPreview": "true" + }, + "698": { + "entityPreview": "true" + }, + "702": { + "entityPreview": "true" + }, + "708": { + "entityPreview": "true" + }, + "712": { + "entityPreview": "true" + }, + "718": { + "entityPreview": "true" + }, + "721": { + "entityPreview": "true" + }, + "722": { + "entityPreview": "true" + }, + "723": { + "entityPreview": "true" + }, + "724": { + "entityPreview": "true" + }, + "725": { + "entityPreview": "true" + }, + "808": { + "entityPreview": "true" + }, + "827": { + "entityPreview": "true" + }, + "838": { + "entityPreview": "true" + }, + "839": { + "entityPreview": "true" + }, + "867": { + "entityPreview": "true" + }, + "868": { + "entityPreview": "true" + }, + "869": { + "entityPreview": "true" + }, + "871": { + "entityPreview": "true" + }, + "872": { + "entityPreview": "true" + }, + "873": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + }, + "883": { + "entityPreview": "true" + }, + "903": { + "entityPreview": "true" + }, + "904": { + "entityPreview": "true" + }, + "969": { + "entityPreview": "true" + }, + "1076": { + "entityPreview": "true" + }, + "1150": { + "entityPreview": "true" + }, + "1210": { + "entityPreview": "true" + }, + "1295": { + "entityPreview": "true" + }, + "1358": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "456": { + "appellation": "true" + } + }, + "page": { + "property": { + "fkProperty": 1874 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "785": { + "entityPreview": "true" + }, + "899": { + "entityPreview": "true" + }, + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1872 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + }, + "934": { + "nestedResource": [ + { + "targets": { + "900": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1763 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "635": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1440 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "967": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1943 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "41": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1842 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 2283 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "934": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1499 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "1": { + "entityPreview": "true" + }, + "5": { + "entityPreview": "true" + }, + "21": { + "entityPreview": "true" + }, + "22": { + "entityPreview": "true" + }, + "53": { + "entityPreview": "true" + }, + "55": { + "entityPreview": "true" + }, + "60": { + "entityPreview": "true" + }, + "61": { + "entityPreview": "true" + }, + "62": { + "entityPreview": "true" + }, + "63": { + "entityPreview": "true" + }, + "67": { + "entityPreview": "true" + }, + "68": { + "entityPreview": "true" + }, + "71": { + "entityPreview": "true" + }, + "78": { + "entityPreview": "true" + }, + "79": { + "entityPreview": "true" + }, + "81": { + "entityPreview": "true" + }, + "212": { + "entityPreview": "true" + }, + "217": { + "entityPreview": "true" + }, + "218": { + "entityPreview": "true" + }, + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "234": { + "entityPreview": "true" + }, + "244": { + "entityPreview": "true" + }, + "332": { + "entityPreview": "true" + }, + "340": { + "entityPreview": "true" + }, + "363": { + "entityPreview": "true" + }, + "364": { + "entityPreview": "true" + }, + "365": { + "entityPreview": "true" + }, + "441": { + "entityPreview": "true" + }, + "442": { + "entityPreview": "true" + }, + "443": { + "entityPreview": "true" + }, + "444": { + "entityPreview": "true" + }, + "445": { + "entityPreview": "true" + }, + "449": { + "entityPreview": "true" + }, + "450": { + "entityPreview": "true" + }, + "451": { + "entityPreview": "true" + }, + "452": { + "entityPreview": "true" + }, + "454": { + "entityPreview": "true" + }, + "455": { + "entityPreview": "true" + }, + "459": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + }, + "503": { + "entityPreview": "true" + }, + "516": { + "entityPreview": "true" + }, + "518": { + "entityPreview": "true" + }, + "519": { + "entityPreview": "true" + }, + "520": { + "entityPreview": "true" + }, + "607": { + "entityPreview": "true" + }, + "608": { + "entityPreview": "true" + }, + "629": { + "entityPreview": "true" + }, + "630": { + "entityPreview": "true" + }, + "633": { + "entityPreview": "true" + }, + "634": { + "entityPreview": "true" + }, + "635": { + "entityPreview": "true" + }, + "676": { + "entityPreview": "true" + }, + "677": { + "entityPreview": "true" + }, + "690": { + "entityPreview": "true" + }, + "698": { + "entityPreview": "true" + }, + "702": { + "entityPreview": "true" + }, + "708": { + "entityPreview": "true" + }, + "712": { + "entityPreview": "true" + }, + "718": { + "entityPreview": "true" + }, + "721": { + "entityPreview": "true" + }, + "722": { + "entityPreview": "true" + }, + "723": { + "entityPreview": "true" + }, + "724": { + "entityPreview": "true" + }, + "725": { + "entityPreview": "true" + }, + "808": { + "entityPreview": "true" + }, + "827": { + "entityPreview": "true" + }, + "838": { + "entityPreview": "true" + }, + "839": { + "entityPreview": "true" + }, + "867": { + "entityPreview": "true" + }, + "868": { + "entityPreview": "true" + }, + "869": { + "entityPreview": "true" + }, + "871": { + "entityPreview": "true" + }, + "872": { + "entityPreview": "true" + }, + "873": { + "entityPreview": "true" + }, + "874": { + "entityPreview": "true" + }, + "883": { + "entityPreview": "true" + }, + "903": { + "entityPreview": "true" + }, + "904": { + "entityPreview": "true" + }, + "969": { + "entityPreview": "true" + }, + "1076": { + "entityPreview": "true" + }, + "1150": { + "entityPreview": "true" + }, + "1210": { + "entityPreview": "true" + }, + "1295": { + "entityPreview": "true" + }, + "1358": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1875 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + }, + { + "targets": { + "521": { + "cell": "true" + } + }, + "page": { + "property": { + "fkProperty": 1874 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + }, + { + "targets": { + "898": { + "entityPreview": "true" + } + }, + "page": { + "property": { + "fkProperty": 1872 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": false + } + } + ] + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1875 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + }, + { + "pkProject": 924033, + "targets": { + "219": { + "entityPreview": "true" + }, + "220": { + "entityPreview": "true" + }, + "221": { + "entityPreview": "true" + }, + "502": { + "entityPreview": "true" + } + }, + "page": { + "source": { + "fkInfo": 869583 + }, + "property": { + "fkProperty": 1889 + }, + "limit": 5, + "offset": 0, + "isOutgoing": false, + "scope": { + "inProject": 924033 + } + } + } +] +'); + +SELECT performs_within( + 'load_field_pages', + 55, --avg ms + 55, --within -> max 80 ms + 10, -- nr. of repeating + 'Loading the field pages of entity 869583 should be faster than 110 ms' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/performance/update-info-proj-rel.sql b/database/test/performance/update-info-proj-rel.sql new file mode 100644 index 000000000..57c280a78 --- /dev/null +++ b/database/test/performance/update-info-proj-rel.sql @@ -0,0 +1,48 @@ +-- Check performance of updating info_proj_rels +BEGIN; + +-- Drop all triggers except the one for pgwar +DROP TRIGGER IF EXISTS after_epr_upsert ON projects.info_proj_rel; + +--DROP TRIGGER IF EXISTS after_modify_info_proj_rel ON projects.info_proj_rel; +DROP TRIGGER IF EXISTS create_entity_version_key ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS creation_tmsp ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS insert_schema_table_name ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS last_modification_tmsp ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS notify_modification ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS on_upsert ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS update_entity_version_key ON projects.info_proj_rel; + +DROP TRIGGER IF EXISTS versioning_trigger ON projects.info_proj_rel; + +SELECT plan(1); + +-- Prepare procedure to update 10k rows +PREPARE update_info_proj_rels AS WITH updated_rows AS ( + SELECT pk_entity + FROM projects.info_proj_rel + ORDER BY pk_entity + LIMIT 1000 +) +UPDATE projects.info_proj_rel +SET is_in_project = is_in_project +FROM updated_rows +WHERE info_proj_rel.pk_entity = updated_rows.pk_entity; + +-- Assert that it performs ok +SELECT performs_ok( + 'update_info_proj_rels', + 3000, + 'Assert that updating 1000 with a name takes less than 3s' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/check.sql b/database/test/units/check.sql new file mode 100644 index 000000000..35bd241e9 --- /dev/null +++ b/database/test/units/check.sql @@ -0,0 +1,12 @@ +-- Dummy-test used to check if the test setup is working +BEGIN; +SELECT plan(1); +SELECT is( + 1, + 1, + 'Assert the test setup is working' + ); +-- Finish the tests and clean up. +SELECT * +FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/com-get-field-pages-empty.sql b/database/test/units/functions/com-get-field-pages-empty.sql new file mode 100644 index 000000000..acc215bb6 --- /dev/null +++ b/database/test/units/functions/com-get-field-pages-empty.sql @@ -0,0 +1,61 @@ +-- Test the functions converting literal tables to labels +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +/** + * Test the get field pages function + */ +SELECT is( + commons.get_field_pages( + --Req we want test + '[ + { + "pkProject": 345, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "inProject": 345 } + }, + "targets": {} + } + ]' + ), + -- Resp we want + ('{ + "subfieldPages": [ + { + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [], + "count": 0, + "page": { + "source": { + "fkInfo": 1 + }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { + "inProject": 345 + } + } + } + ] + }')::jsonb, + 'Assert the response contains an empty array of paginated statements' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/com-get-field-pages-simple.sql b/database/test/units/functions/com-get-field-pages-simple.sql new file mode 100644 index 000000000..08669effd --- /dev/null +++ b/database/test/units/functions/com-get-field-pages-simple.sql @@ -0,0 +1,150 @@ +-- Test the functions converting literal tables to labels +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +/** + * Add Mock Data + */ +-- Insert a language for the following project +INSERT INTO information.language(pk_entity, pk_language) +VALUES (1234, 'eng'); + +-- Insert a project that we can use to add data to +INSERT INTO projects.project (pk_entity, fk_language) +VALUES (345, 1234); + +-- Insert an entity Person "1" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (1, 21); + +-- Insert an entity Person "2" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (2, 21); + +-- Insert an entity Relationship "3" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (3, 633); + +-- Insert a statement "3" "has partner" "1" +INSERT INTO information.statement ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (101, 3, 1436, 1); + +-- Insert a statement "3" "has partner" "2" +INSERT INTO information.statement ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (102, 3, 1436, 2); + +-- Add everything to the project +INSERT INTO projects.info_proj_rel (pk_entity, fk_entity, fk_project, is_in_project) +VALUES (201, 1, 345, true), + (202, 2, 345, true), + (203, 3, 345, true), + (204, 101, 345, true), + (205, 102, 345, true); + +/** + * Test the get field pages function + */ +SELECT is( + commons.get_field_pages( + --Req we want test + '[ + { + "pkProject": 345, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "inProject": 345 } + }, + "targets": {} + } + ]' + ), + -- Resp we want + ('{ + "subfieldPages": [ + { + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [ + { + "projRel": { + "fk_entity": 101, + "pk_entity": 204, + "fk_project": 345, + "is_in_project": true + }, + "isOutgoing": false, + "target": { + "entity": { + "resource": { + "fk_class": 633, + "pk_entity": 3 + }, + "entityPreview": { + "fk_class": 633, + "pk_entity": 3, + "fk_project": 345, + "tmsp_last_modification": "' || (json_build_object('x', now())->>'x')::text || '" + } + } + }, + "targetClass": 633, + "statement": { + "pk_entity": 101, + "fk_property": 1436, + "fk_object_data": 0, + "fk_object_info": 1, + "fk_subject_data": 0, + "fk_subject_info": 3, + "is_in_project_count": 1, + "fk_object_tables_row": 0, + "fk_object_tables_cell": 0, + "fk_subject_tables_row": 0, + "fk_subject_tables_cell": 0, + "fk_property_of_property": 0, + "is_standard_in_project_count": 0 + } + } + ], + "count": 1, + "page": { + "source": { + "fkInfo": 1 + }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { + "inProject": 345 + } + } + } + ] + }')::jsonb, + 'Assert the 1st level of nesting is loaded' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/com-get-field-pages.sql b/database/test/units/functions/com-get-field-pages.sql new file mode 100644 index 000000000..745afd744 --- /dev/null +++ b/database/test/units/functions/com-get-field-pages.sql @@ -0,0 +1,655 @@ +-- Test the functions converting literal tables to labels +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(4); + +/** + * Add Mock Data + */ +-- Insert a language for the following project +INSERT INTO information.language(pk_entity, pk_language) +VALUES (1234, 'eng'); + +-- Insert a project that we can use to add data to +INSERT INTO projects.project (pk_entity, fk_language) +VALUES (345, 1234); + +-- Insert an entity Person "1" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (1, 21); + +-- Insert an entity Person "2" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (2, 21); + +-- Insert an entity Relationship "3" +INSERT INTO information.resource (pk_entity, fk_class) +VALUES (3, 633); + +-- Insert a statement "3" "has partner" "1" +INSERT INTO information.statement ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (101, 3, 1436, 1); + +-- Insert a statement "3" "has partner" "2" +INSERT INTO information.statement ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (102, 3, 1436, 2); + +-- Add everything to the project +INSERT INTO projects.info_proj_rel (pk_entity, fk_entity, fk_project, is_in_project, ord_num_of_range) +VALUES (201, 1, 345, true, NULL), + (202, 2, 345, true, NULL), + (203, 3, 345, true, NULL), + (204, 101, 345, true, 1), + (205, 102, 345, true, 2); + +SELECT is( + commons.get_field_pages( + ' + [ + { + "pkProject": 345, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "inProject": 345 } + }, + "targets": { + "633": { + "nestedResource": [ + { + "targets": {}, + "page": { + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + } + ] + } + } + } + ]' + ), + ('{ + "subfieldPages": [ + { + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [ + { + "projRel": { + "fk_entity": 101, + "pk_entity": 204, + "fk_project": 345, + "is_in_project": true, + "ord_num_of_range": 1 + }, + "isOutgoing": false, + "target": { + "entity": { + "resource": { + "fk_class": 633, + "pk_entity": 3 + }, + "entityPreview": { + "fk_class": 633, + "pk_entity": 3, + "fk_project": 345, + "tmsp_last_modification": "' || (json_build_object('x', now())->>'x')::text || '" + } + } + }, + "targetClass": 633, + "statement": { + "pk_entity": 101, + "fk_property": 1436, + "fk_object_data": 0, + "fk_object_info": 1, + "fk_subject_data": 0, + "fk_subject_info": 3, + "is_in_project_count": 1, + "fk_object_tables_row": 0, + "fk_object_tables_cell": 0, + "fk_subject_tables_row": 0, + "fk_subject_tables_cell": 0, + "fk_property_of_property": 0, + "is_standard_in_project_count": 0 + } + } + ], + "count": 1, + "page": { + "source": { + "fkInfo": 1 + }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { + "inProject": 345 + } + } + }, + { + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [ + { + "projRel": { + "fk_entity": 101, + "pk_entity": 204, + "fk_project": 345, + "is_in_project": true, + "ord_num_of_range": 1 + }, + "isOutgoing": true, + "ordNum": 1, + "target": { + "entity": { + "resource": { + "fk_class": 21, + "pk_entity": 1 + }, + "entityPreview": { + "fk_class": 21, + "pk_entity": 1, + "fk_project": 345, + "tmsp_last_modification": "' || (json_build_object('x', now())->>'x')::text || '" + } + } + }, + "targetClass": 21, + "statement": { + "pk_entity": 101, + "fk_property": 1436, + "fk_object_data": 0, + "fk_object_info": 1, + "fk_subject_data": 0, + "fk_subject_info": 3, + "is_in_project_count": 1, + "fk_object_tables_row": 0, + "fk_object_tables_cell": 0, + "fk_subject_tables_row": 0, + "fk_subject_tables_cell": 0, + "fk_property_of_property": 0, + "is_standard_in_project_count": 0 + } + } + ], + "count": 2, + "page": { + "source": { + "fkInfo": 3 + }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "scope": { + "inProject": 345 + }, + "isCircular": true + } + } + ] + }' + )::jsonb, + 'Assert the nested resource is loaded recursively in project scope' + ); + + + +SELECT is( + commons.get_field_pages( + ' + [ + { + "pkProject": 99, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "notInProject": 99 } + }, + "targets": { + "633": { + "nestedResource": [ + { + "targets": {}, + "page": { + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + } + ] + } + } + } + ]' + ), + ('{ + "subfieldPages": [ + { + "page": { + "limit": 1, + "scope": { + "inRepo": true + }, + "offset": 0, + "source": { + "fkInfo": 3 + }, + "property": { + "fkProperty": 1436 + }, + "isCircular": true, + "isOutgoing": true + }, + "count": 2, + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [ + { + "target": { + "entity": { + "resource": { + "fk_class": 21, + "pk_entity": 1 + } + } + }, + "statement": { + "pk_entity": 101, + "fk_property": 1436, + "fk_object_data": 0, + "fk_object_info": 1, + "fk_subject_data": 0, + "fk_subject_info": 3, + "is_in_project_count": 1, + "fk_object_tables_row": 0, + "fk_object_tables_cell": 0, + "fk_subject_tables_row": 0, + "fk_subject_tables_cell": 0, + "fk_property_of_property": 0, + "is_standard_in_project_count": 0 + }, + "isOutgoing": true, + "targetClass": 21 + } + ] + }, + { + "page": { + "limit": 1, + "scope": { + "notInProject": 99 + }, + "offset": 0, + "source": { + "fkInfo": 1 + }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false + }, + "count": 1, + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements": [ + { + "target": { + "entity": { + "resource": { + "fk_class": 633, + "pk_entity": 3 + } + } + }, + "statement": { + "pk_entity": 101, + "fk_property": 1436, + "fk_object_data": 0, + "fk_object_info": 1, + "fk_subject_data": 0, + "fk_subject_info": 3, + "is_in_project_count": 1, + "fk_object_tables_row": 0, + "fk_object_tables_cell": 0, + "fk_subject_tables_row": 0, + "fk_subject_tables_cell": 0, + "fk_property_of_property": 0, + "is_standard_in_project_count": 0 + }, + "isOutgoing": false, + "targetClass": 633 + } + ] + } + ] + }' + )::jsonb, + 'Assert the nested resource is loaded recursively not in project scope' + ); + + + +SELECT is( + commons.get_field_pages( + ' + [ + { + "pkProject": 345, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "inRepo": true } + }, + "targets": { + "633": { + "nestedResource": [ + { + "targets": {}, + "page": { + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + } + ] + } + } + } + ]' + ), + ('{ + "subfieldPages":[ + { + "page":{ + "limit":1, + "scope":{ + "inRepo":true + }, + "offset":0, + "source":{ + "fkInfo":1 + }, + "property":{ + "fkProperty":1436 + }, + "isOutgoing":false + }, + "count":1, + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements":[ + { + "target":{ + "entity":{ + "resource":{ + "fk_class":633, + "pk_entity":3 + } + } + }, + "statement":{ + "pk_entity":101, + "fk_property":1436, + "fk_object_data":0, + "fk_object_info":1, + "fk_subject_data":0, + "fk_subject_info":3, + "is_in_project_count":1, + "fk_object_tables_row":0, + "fk_object_tables_cell":0, + "fk_subject_tables_row":0, + "fk_subject_tables_cell":0, + "fk_property_of_property":0, + "is_standard_in_project_count":0 + }, + "isOutgoing":false, + "targetClass":633 + } + ] + }, + { + "page":{ + "limit":1, + "scope":{ + "inRepo":true + }, + "offset":0, + "source":{ + "fkInfo":3 + }, + "property":{ + "fkProperty":1436 + }, + "isCircular":true, + "isOutgoing":true + }, + "count":2, + "validFor": "' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements":[ + { + "target":{ + "entity":{ + "resource":{ + "fk_class":21, + "pk_entity":1 + } + } + }, + "statement":{ + "pk_entity":101, + "fk_property":1436, + "fk_object_data":0, + "fk_object_info":1, + "fk_subject_data":0, + "fk_subject_info":3, + "is_in_project_count":1, + "fk_object_tables_row":0, + "fk_object_tables_cell":0, + "fk_subject_tables_row":0, + "fk_subject_tables_cell":0, + "fk_property_of_property":0, + "is_standard_in_project_count":0 + }, + "isOutgoing":true, + "targetClass":21 + } + ] + } + ] + }' + )::jsonb, + 'Assert the nested resource is loaded recursively for inRepo scope' + ); + + +-- remark: there is a typo in noContraint +SELECT is( + commons.get_field_pages( + ' + [ + { + "pkProject": 345, + "page": { + "source": { "fkInfo": 1 }, + "property": { + "fkProperty": 1436 + }, + "isOutgoing": false, + "limit": 1, + "offset": 0, + "scope": { "noContraint": true } + }, + "targets": { + "633": { + "nestedResource": [ + { + "targets": {}, + "page": { + "property": { + "fkProperty": 1436 + }, + "isOutgoing": true, + "limit": 1, + "offset": 0, + "isCircular": true + } + } + ] + } + } + } + ]' + ), + ('{ + "subfieldPages":[ + { + "page":{ + "limit":1, + "scope":{ + "noContraint":true + }, + "offset":0, + "source":{ + "fkInfo":1 + }, + "property":{ + "fkProperty":1436 + }, + "isOutgoing":false + }, + "count":1, + "validFor":"' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements":[ + { + "target":{ + "entity":{ + "resource":{ + "fk_class":633, + "pk_entity":3 + } + } + }, + "statement":{ + "pk_entity":101, + "fk_property":1436, + "fk_object_data":0, + "fk_object_info":1, + "fk_subject_data":0, + "fk_subject_info":3, + "is_in_project_count":1, + "fk_object_tables_row":0, + "fk_object_tables_cell":0, + "fk_subject_tables_row":0, + "fk_subject_tables_cell":0, + "fk_property_of_property":0, + "is_standard_in_project_count":0 + }, + "isOutgoing":false, + "targetClass":633 + } + ] + }, + { + "page":{ + "limit":1, + "scope":{ + "noContraint":true + }, + "offset":0, + "source":{ + "fkInfo":3 + }, + "property":{ + "fkProperty":1436 + }, + "isCircular":true, + "isOutgoing":true + }, + "count":2, + "validFor":"' || (json_build_object('x', now())->>'x')::text || '", + "paginatedStatements":[ + { + "target":{ + "entity":{ + "resource":{ + "fk_class":21, + "pk_entity":1 + } + } + }, + "statement":{ + "pk_entity":101, + "fk_property":1436, + "fk_object_data":0, + "fk_object_info":1, + "fk_subject_data":0, + "fk_subject_info":3, + "is_in_project_count":1, + "fk_object_tables_row":0, + "fk_object_tables_cell":0, + "fk_subject_tables_row":0, + "fk_subject_tables_cell":0, + "fk_property_of_property":0, + "is_standard_in_project_count":0 + }, + "isOutgoing":true, + "targetClass":21 + } + ] + } + ] + }' + )::jsonb, + 'Assert the nested resource is loaded recursively for no constraint scope' + ); + + + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-entity-label-config-by-class-and-project.sql b/database/test/units/functions/pgwar-get-entity-label-config-by-class-and-project.sql new file mode 100644 index 000000000..7a28d393a --- /dev/null +++ b/database/test/units/functions/pgwar-get-entity-label-config-by-class-and-project.sql @@ -0,0 +1,25 @@ + +BEGIN; +SELECT plan(2); + +INSERT INTO projects.entity_label_config(fk_class, fk_project, config) +VALUES +(1, 2, '{"labelParts":[{"field":{"fkProperty":1111,"isOutgoing":false,"nrOfStatementsInLabel":1},"ordNum":0}]}'), +(1, 375669, '{"labelParts":[{"field":{"fkProperty":3333,"isOutgoing":true,"nrOfStatementsInLabel":2},"ordNum":0}]}'); + +-- Test 1: Check if function returns the correct label config for a given class_id and project_id +SELECT is( + pgwar.get_entity_label_config(1, 2), + '{"labelParts":[{"field":{"fkProperty":1111,"isOutgoing":false,"nrOfStatementsInLabel":1},"ordNum":0}]}'::jsonb, + 'get_entity_label_config returns correct config for class_id 1 and project_id 2' +); + +-- Test 2: Check if function returns the default label config for a given class_id when project_id is not found +SELECT is( + pgwar.get_entity_label_config(1, 999999), + '{"labelParts":[{"field":{"fkProperty":3333,"isOutgoing":true,"nrOfStatementsInLabel":2},"ordNum":0}]}'::jsonb, + 'get_entity_label_config returns default config for class_id 1 when project_id is not found' +); + +SELECT * FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-label-of-incoming-field.sql b/database/test/units/functions/pgwar-get-label-of-incoming-field.sql new file mode 100644 index 000000000..41e57235b --- /dev/null +++ b/database/test/units/functions/pgwar-get-label-of-incoming-field.sql @@ -0,0 +1,69 @@ +BEGIN; +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(2); + +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 11, 'this has no influence'), + (2, 1, 32, 22, 11, 'this has no influence'), + (3, 1, 33, 22, 11, 'this has no influence'), + (4, 1, 34, 22, 11, 'this has no influence'), + (5, 1, 35, 22, 11, 'this has no influence'), + (6, 1, 36, 22, 11, 'this has no influence'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES +(31, 1, 88, 'Entity 31'), +(32, 1, 88, NULL), +(33, 1, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for incoming field +SELECT is( + get_label_of_incoming_field, + 'Entity 31, Entity 33'::text, + 'get_target_labels_of_incoming_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' + ) +FROM pgwar.get_label_of_incoming_field(11, 1, 22, 5); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is( + get_label_of_incoming_field, + NULL, + 'get_label_of_incoming_field returns NULL for entity_id 9999' + ) +FROM pgwar.get_label_of_incoming_field(9999, 1, 22, 5); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-label-of-outgoing-field.sql b/database/test/units/functions/pgwar-get-label-of-outgoing-field.sql new file mode 100644 index 000000000..d6939b80a --- /dev/null +++ b/database/test/units/functions/pgwar-get-label-of-outgoing-field.sql @@ -0,0 +1,67 @@ +BEGIN; + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(2); + +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 11, 22, 31, 'Label 1'), + (2, 1, 11, 22, 32, 'Label 2'), + (3, 1, 11, 22, 33, NULL), + (4, 1, 11, 22, 34, NULL), + (5, 1, 11, 22, 35, 'Label 5'), + (6, 1, 11, 22, 36, 'Label 6'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (33, 1, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for outgoing field +SELECT is( + get_label_of_outgoing_field, + 'Label 1, Label 2, Entity 33, Label 5'::text, + 'get_label_of_outgoing_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' + ) +FROM pgwar.get_label_of_outgoing_field(11, 1, 22, 5); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is( + get_label_of_outgoing_field, + NULL, + 'get_label_of_outgoing_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' + ) +FROM pgwar.get_label_of_outgoing_field(9999, 1, 22, 5); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-most-frequent-entity-label.sql b/database/test/units/functions/pgwar-get-most-frequent-entity-label.sql new file mode 100644 index 000000000..1511bf192 --- /dev/null +++ b/database/test/units/functions/pgwar-get-most-frequent-entity-label.sql @@ -0,0 +1,72 @@ +BEGIN; +SELECT plan(2); + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +-- Insert 7 projects +INSERT INTO projects.project (pk_entity) +VALUES (1), + (2), + (3), + (4), + (5), + (6), + (7); + +-- Insert entity labels +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (1, 1, 77, 'Label 1'), + (1, 2, 77, 'Label 1'), + (1, 3, 77, 'Label 1bis'), + (1, 4, 77, 'Label 1bis'), + (1, 5, 77, 'Label 1bis'), + (1, 6, 77, 'Label 1ter'), + (1, 7, 77, 'Label 1ter'), + (2, 1, 77, 'Label 2'), + (2, 2, 77, 'Label 2'), + (2, 3, 77, 'Label 2bis'), + (2, 4, 77, 'Label 2ter'), + (2, 5, 77, 'Label 2ter'); + +-- Test 1: check entity 1 has 'Label 1bis' as most frequent label +SELECT is( + entity_label, + 'Label 1bis', + 'Assert returned entity_label is "Label 2"' +) +FROM pgwar.v_community_entity_label +WHERE pk_entity = 1; + +-- Test 2: check entity 2 has 'Label 1bis' as most frequent label +SELECT is( + entity_label, + 'Label 2', + 'Assert returned entity_label is "Label 2"' +) +FROM pgwar.v_community_entity_label +WHERE pk_entity = 2; + +SELECT * FROM finish(); +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql new file mode 100644 index 000000000..64ea08fdb --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-by-dfh-prop.sql @@ -0,0 +1,81 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + +-- add full text for all entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (31, 123, 'full-text'), + (11, 123, 'full-text'), + (32, 999, 'full-text'), + (12, 999, 'full-text'), + (33, 543, 'full-text'), + (31, 0, 'full-text'), + (11, 0, 'full-text'), + (32, 0, 'full-text'), + (12, 0, 'full-text'), + (33, 0, 'full-text'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(100); + +-- assert no entity for update found +SELECT is_empty( + 'entities_for_update', + 'Assert no project entity needs update' + ); + +-- Update three dfh-properties +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property + ) +VALUES (clock_timestamp(), 522), + (clock_timestamp(), 523), + (clock_timestamp(), 524); + +SELECT bag_eq( + 'entities_for_update', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', + 'Contains the subject of the statement with modfied property.' + ); + +SELECT is( + count(*)::int, + 1, + 'Assert the limit of 1 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_by_dfh_prop(1); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql new file mode 100644 index 000000000..174224e3b --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt-del.sql @@ -0,0 +1,82 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements_deleted ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_del(100); + +-- Note that (13, 543), (13, 0) is an object_value and does therefore +-- not show up amongst the entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', + 'Contains all 2 pairs of project_id and object entity_id.' + ); + +-- add full text one of the entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (12, 999, 'full-text'), +(12, 0, 'full-text'); + +-- Assert that only two entities remains in entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (11, 123), (11, 0)', + 'Assert that only one entity remains in entities_for_update.' + ); + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (4, 44, 31, 522, 11, NULL), + (5, 44, 32, 523, 12, NULL), + (6, 44, 33, 524, 14, NULL), + (7, 44, 33, 524, 15, NULL), + (8, 44, 33, 524, 16, NULL), + (9, 44, 33, 524, 17, NULL); + +SELECT is( + count(*)::int, + 3, + 'Assert the limit of 3 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt_del(3); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql new file mode 100644 index 000000000..077583a1d --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-objects-of-stmt.sql @@ -0,0 +1,81 @@ +BEGIN; +SELECT plan(3); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt(100); + +-- Note that (13, 543) is an object_value and does therefore +-- not show up amongst the entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (11, 123), (12, 999), (11, 0), (12, 0)', + 'Contains all 2 pairs of project_id and object entity_id.' + ); + +-- add full text of two entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (12, 999, 'full-text'), + (12, 0, 'full-text'); + +-- Assert that only two entity remains in entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (11, 123), (11, 0)', + 'Assert that only two entity remains in entities_for_update.' + ); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (4, 44, 31, 522, 11, NULL), + (5, 44, 32, 523, 12, NULL), + (6, 44, 33, 524, 14, NULL), + (7, 44, 33, 524, 15, NULL), + (8, 44, 33, 524, 16, NULL), + (9, 44, 33, 524, 17, NULL); + +SELECT is( + count(*)::int, + 3, + 'Assert the limit of 3 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_objects_of_stmt(3); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql new file mode 100644 index 000000000..f551fa7b9 --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-by-dfh-prop.sql @@ -0,0 +1,80 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + +-- add full text for all entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (31, 123, 'full-text'), + (11, 123, 'full-text'), + (32, 999, 'full-text'), + (12, 999, 'full-text'), + (33, 543, 'full-text'), + (31, 0, 'full-text'), + (11, 0, 'full-text'), + (32, 0, 'full-text'), + (12, 0, 'full-text'), + (33, 0, 'full-text'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(100); + +-- assert no entity for update found +SELECT is_empty( + 'entities_for_update', + 'Assert no project entity needs update' + ); + +-- Update two dfh-properties +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property + ) +VALUES (clock_timestamp(), 523), +(clock_timestamp(), 524); + +SELECT bag_eq( + 'entities_for_update', + 'VALUES (32, 999), (33, 543), (32, 0), (33, 0)', + 'Contains the subject of the statement with modfied property.' + ); + +SELECT is( + count(*)::int, + 1, + 'Assert the limit of 1 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_by_dfh_prop(1); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql new file mode 100644 index 000000000..299e3ade2 --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt-del.sql @@ -0,0 +1,82 @@ +BEGIN; +SELECT plan(3); + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements_deleted ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(10); + +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123), (32, 999), (33, 543), (31, 0), (32, 0), (33, 0)', + 'Contains all 6 pairs of project_id and subject entity_id.' + ); + +-- add full text for two of the entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (32, 999, 'full-text'), + (33, 543, 'full-text'), + (32, 0, 'full-text'), + (33, 0, 'full-text'); + +-- Assert that only one entity remains in entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123), (31, 0)', + 'Assert that only one entity remains in entities_for_update.' + ); + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (4, 44, 31, 522, 11, NULL), + (5, 44, 32, 523, 12, NULL), + (6, 44, 33, 524, 13, NULL), + (7, 44, 33, 524, 13, NULL), + (8, 44, 33, 524, 13, NULL), + (9, 44, 33, 524, 13, NULL); + +SELECT is( + count(*)::int, + 1, + 'Assert the limit of 1 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt_del(1); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql new file mode 100644 index 000000000..19489f9ec --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts-in-subjects-of-stmt.sql @@ -0,0 +1,82 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 31, 522, 11, NULL), + (2, 32, 523, 12, NULL), + (3, 33, 524, 13, '{}'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(10); + +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123), (32, 999), (33, 543), (31, 0), (32, 0), (33, 0)', + 'Contains all 3 pairs of project_id and subject entity_id.' + ); + +-- add full text for two of the entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (32, 999, 'full-text'), + (33, 543, 'full-text'), + (32, 0, 'full-text'), + (33, 0, 'full-text'); + +-- Assert that only one entity remains in entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123), (31, 0)', + 'Assert that only one entity remains in entities_for_update.' + ); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (4, 44, 31, 522, 11, NULL), + (5, 44, 32, 523, 12, NULL), + (6, 44, 33, 524, 13, NULL), + (7, 44, 33, 524, 13, NULL), + (8, 44, 33, 524, 13, NULL), + (9, 44, 33, 524, 13, NULL); + +SELECT is( + count(*)::int, + 1, + 'Assert the limit of 1 is respected' + ) +FROM pgwar.get_outdated_full_texts_in_subjects_of_stmt(1); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-outdated-full-texts.sql b/database/test/units/functions/pgwar-get-outdated-full-texts.sql new file mode 100644 index 000000000..e6c87fbb9 --- /dev/null +++ b/database/test/units/functions/pgwar-get-outdated-full-texts.sql @@ -0,0 +1,71 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (1, 123, 31, 522, 11, NULL), + (2, 999, 32, 523, 12, NULL), + (3, 543, 33, 524, 13, '{}'); + +PREPARE entities_for_update AS +SELECT pk_entity, + fk_project +FROM pgwar.get_outdated_full_texts(5); + +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123), (11, 123), (32, 999), (12, 999), (33, 543)', + 'Contains all 5 pairs of project_id and subject entity_id.' + ); + +-- add full text for two of the entities +INSERT INTO pgwar.entity_full_text ( + pk_entity, + fk_project, + full_text + ) +VALUES (12, 999, 'full-text'), + (11, 123, 'full-text'), + (32, 999, 'full-text'), + (33, 543, 'full-text'); + +-- Assert that only one entity remains in entities_for_update +SELECT bag_eq( + 'entities_for_update', + 'VALUES (31, 123)', + 'Assert that only one entity remains in entities_for_update.' + ); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_value + ) +VALUES (4, 44, 31, 522, 11, NULL), + (5, 44, 32, 523, 12, NULL), + (6, 44, 33, 524, 13, NULL), + (7, 44, 33, 524, 13, NULL), + (8, 44, 33, 524, 13, NULL), + (9, 44, 33, 524, 13, NULL); + +SELECT is( + count(*)::int, + 3, + 'Assert the limit of 3 is respected' + ) +FROM pgwar.get_outdated_full_texts(3); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-class.sql b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-class.sql new file mode 100644 index 000000000..7c6ba0a2c --- /dev/null +++ b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-class.sql @@ -0,0 +1,105 @@ +BEGIN; + +/** + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + + +SELECT plan(3); + +INSERT INTO information.resource (pk_entity, fk_class) +VALUES(11, 77); + +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 11, 'this has no influence'), + (2, 1, 32, 22, 11, 'this has no influence'), + (3, 1, 33, 22, 11, 'this has no influence'), + (4, 1, 34, 22, 11, 'this has no influence'), + (5, 1, 35, 22, 11, 'this has no influence'), + (6, 1, 36, 22, 11, 'this has no influence'), + (7, 1, 11, 55, 61, 'Label 61'), + (8, 1, 11, 55, 62, 'Label 62'), + (9, 1, 11, 55, 63, NULL), + (10, 1, 11, 55, 64, NULL), + (11, 1, 11, 55, 65, 'Label 65'), + (12, 1, 11, 55, 66, 'Label 66'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'), + (64, 1, 88, 'Entity 64'); + +INSERT INTO projects.entity_label_config (fk_project, fk_class, config) +VALUES ( + 1, + 77, + '{ + "labelParts": [ + { + "field": {"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5} + }, + { + "field": {"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5} + } + ] + }'::jsonb + ); + +-- Test 1: Check if function returns the correct entity label +SELECT is( + pgwar.get_project_entity_label( + 11, + 1, + 77 + ), + 'Entity 31, Entity 33, Label 61, Label 62, Entity 64, Label 65', + 'get_project_entity_label returns correct labels for entity_id 11, project_id 1, and classs_id 77' + ); + +-- Test 2: Check if function handles empty label_config +SELECT is( + pgwar.get_project_entity_label(11, 1, 9999999), + NULL, + 'get_project_entity_label returns NULL for empty label_config' + ); + +-- Test 2: Check if function handles not existing entity +SELECT is( + pgwar.get_project_entity_label(99, 1, 77), + NULL, + 'get_project_entity_label returns NULL for not existing entity' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-config.sql b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-config.sql new file mode 100644 index 000000000..c29d9a10b --- /dev/null +++ b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project-and-config.sql @@ -0,0 +1,97 @@ +BEGIN; + +/** + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(3); + +INSERT INTO information.resource (pk_entity, fk_class) +VALUES(11, 77); + +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 11, 'this has no influence'), + (2, 1, 32, 22, 11, 'this has no influence'), + (3, 1, 33, 22, 11, 'this has no influence'), + (4, 1, 34, 22, 11, 'this has no influence'), + (5, 1, 35, 22, 11, 'this has no influence'), + (6, 1, 36, 22, 11, 'this has no influence'), + (7, 1, 11, 55, 61, 'Label 61'), + (8, 1, 11, 55, 62, 'Label 62'), + (9, 1, 11, 55, 63, NULL), + (10, 1, 11, 55, 64, NULL), + (11, 1, 11, 55, 65, 'Label 65'), + (12, 1, 11, 55, 66, 'Label 66'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'), + (64, 1, 88, 'Entity 64'); + +-- Test 1: Check if function returns the correct entity label +SELECT is( + pgwar.get_project_entity_label( + 11, + 1, + '{ + "labelParts": [ + { + "field": {"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5} + }, + { + "field": {"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5} + } + ] + }'::jsonb + ), + 'Entity 31, Entity 33, Label 61, Label 62, Entity 64, Label 65', + 'get_project_entity_label returns correct labels for entity_id 11, project_id 1, and label_config jsonb' + ); + +-- Test 2: Check if function handles empty label_config +SELECT is( + pgwar.get_project_entity_label(11, 1, NULL), + NULL, + 'get_project_entity_label returns NULL for empty label_config' + ); + +-- Test 2: Check if function handles not existing entity +SELECT is( + pgwar.get_project_entity_label(99, 1, NULL), + NULL, + 'get_project_entity_label returns NULL for not existing entity' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql new file mode 100644 index 000000000..4e27f210f --- /dev/null +++ b/database/test/units/functions/pgwar-get-project-entity-label-by-entity-and-project.sql @@ -0,0 +1,93 @@ +BEGIN; + +/** + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(2); + +INSERT INTO information.resource (pk_entity, fk_class) +VALUES(123, 77); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (123, 1, 77, NULL), + (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'), + (64, 1, 88, 'Entity 64'); + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 123, ''), + (2, 1, 32, 22, 123, ''), + (3, 1, 33, 22, 123, ''), + (4, 1, 34, 22, 123, ''), + (5, 1, 35, 22, 123, ''), + (6, 1, 36, 22, 123, ''), + (7, 1, 123, 55, 61, 'Label 61'), + (8, 1, 123, 55, 62, 'Label 62'), + (9, 1, 123, 55, 63, NULL), + (10, 1, 123, 55, 64, NULL), + (11, 1, 123, 55, 65, 'Label 65'), + (12, 1, 123, 55, 66, 'Label 66'); + +INSERT INTO projects.entity_label_config (fk_project, fk_class, config) +VALUES ( + 1, + 77, + '{ + "labelParts": [ + { + "field": {"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5} + }, + { + "field": {"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5} + } + ] + }'::jsonb + ); + +-- Test 1: Check if function returns the correct entity label +SELECT is( + pgwar.get_project_entity_label(123, 1), + 'Entity 31, Entity 33, Label 61, Label 62, Entity 64, Label 65', + 'get_project_entity_label returns correct label for entity_id and project_id 1' + ); + +-- Test 2: Check if function handles not existing entity +SELECT is( + pgwar.get_project_entity_label(-99, 1), + NULL, + 'get_project_entity_label returns NULL for not existing entity' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-project-full-text.sql b/database/test/units/functions/pgwar-get-project-full-text.sql new file mode 100644 index 000000000..167302a4f --- /dev/null +++ b/database/test/units/functions/pgwar-get-project-full-text.sql @@ -0,0 +1,125 @@ +BEGIN; + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_language, iso6391) +VALUES ('fra', 'fr'), + ('eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, + '_p1' +FROM information.language +WHERE pk_language = 'fra'; + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +SELECT v.pk_entity, + pro.pk_entity, + v.fk_subject_info, + v.fk_property, + v.fk_object_info, + v.object_label +FROM ( + VALUES (1, 31, 22, 11, 'this has no influence'), + (2, 32, 22, 11, 'this has no influence'), + (3, 33, 22, 11, 'this has no influence'), + (4, 34, 22, 11, 'this has no influence'), + (5, 35, 22, 11, 'this has no influence'), + (6, 36, 22, 11, 'this has no influence'), + (7, 11, 55, 61, 'Label 61'), + (8, 11, 55, 62, 'Label 62'), + (9, 11, 55, 63, NULL), + (10, 11, 55, 64, NULL), + (11, 11, 55, 65, 'Label 65'), + (12, 11, 55, 66, 'Label 66') + ) AS v ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ), + projects.project pro +WHERE pro.notes = '_p1'; + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +SELECT v.pk_entity, + pro.pk_entity, + v.fk_class, + v.entity_label +FROM ( + VALUES (31, 88, 'Entity 31'), + (32, 88, NULL), + (33, 88, 'Entity 33'), + (64, 88, 'Entity 64') + ) AS v(pk_entity, fk_class, entity_label), + projects.project pro +WHERE pro.notes = '_p1'; + +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property, + dfh_property_label_language, + dfh_property_label, + dfh_property_inverse_label + ) +VALUES ( + '2024-06-12 07:54:29.142429+00', + 22, + 'fr', + 'possède', + 'est en possession de' + ), + ( + '2024-06-12 07:54:29.142429+00', + 55, + 'fr', + 'bar', + 'bar inverse' + ); + +SELECT plan(1); + +SELECT is( + pgwar.get_project_full_text(pk_entity, 11), + 'est en possession de: Entity 31, Entity 33\n bar: Label 61, Label 62, Entity 64, Label 65\n ', + 'Get the fulltext of entity 11' + ) +FROM projects.project +WHERE notes = '_p1'; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-project-lang-code.sql b/database/test/units/functions/pgwar-get-project-lang-code.sql new file mode 100644 index 000000000..8ea5a643f --- /dev/null +++ b/database/test/units/functions/pgwar-get-project-lang-code.sql @@ -0,0 +1,35 @@ +BEGIN; + +------- Prepare required context data ------ +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_language, iso6391) +VALUES ('ita', 'it'), + ('eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, + '_p1' +FROM information.language +WHERE pk_language = 'ita'; + +SELECT plan(2); + +SELECT is( + pgwar.get_project_lang_code(pk_entity), + 'it', + 'Assert the default language is returned' + ) +FROM projects.project +WHERE notes = '_p1'; + +SELECT is( + pgwar.get_project_lang_code(9999999), + NULL, + 'Assert the NULL language is returned for non-existing project' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-property-inverse-label-by-property-and-language.sql b/database/test/units/functions/pgwar-get-property-inverse-label-by-property-and-language.sql new file mode 100644 index 000000000..bb473b76f --- /dev/null +++ b/database/test/units/functions/pgwar-get-property-inverse-label-by-property-and-language.sql @@ -0,0 +1,58 @@ +BEGIN; + +SELECT plan(4); + +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property, + dfh_property_label_language, + dfh_property_inverse_label + ) +VALUES ( + '2023-06-12 07:54:29.142429+00', + 123, + 'fr', + 'est en propriété de' + ), + ( + '2024-06-12 07:54:29.142429+00', + 123, + 'fr', + 'est en possession de' + ), + ( + '2024-06-12 07:54:29.142429+00', + 123, + 'en', + 'is owned by' + ); + +SELECT is( + 'is owned by', + pgwar.get_property_inverse_label(123, 'en'), + 'Assert the english label is returned' + ); + +SELECT is( + 'est en possession de', + pgwar.get_property_inverse_label(123, 'fr'), + 'Assert the most recent french label is returned' + ); + +SELECT is( + 'is owned by', + pgwar.get_property_inverse_label(123, 'de'), + 'Assert the fallback is english' + ); + +SELECT is( + NULL, + pgwar.get_property_inverse_label(999, 'en'), + 'Assert the NULL is returned for non-existing property' + ); + + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-property-label-by-property-and-language.sql b/database/test/units/functions/pgwar-get-property-label-by-property-and-language.sql new file mode 100644 index 000000000..fd0e2c00c --- /dev/null +++ b/database/test/units/functions/pgwar-get-property-label-by-property-and-language.sql @@ -0,0 +1,57 @@ +BEGIN; + +SELECT plan(4); + +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property, + dfh_property_label_language, + dfh_property_label + ) +VALUES ( + '2023-06-12 07:54:29.142429+00', + 123, + 'fr', + 'dispose de' + ), + ( + '2024-06-12 07:54:29.142429+00', + 123, + 'fr', + 'possède' + ), + ( + '2024-06-12 07:54:29.142429+00', + 123, + 'en', + 'owns' + ); + +SELECT is( + 'owns', + pgwar.get_property_label(123, 'en'), + 'Assert the english label is returned' + ); + +SELECT is( + 'possède', + pgwar.get_property_label(123, 'fr'), + 'Assert the most recent french label is returned' + ); + +SELECT is( + 'owns', + pgwar.get_property_label(123, 'de'), + 'Assert the fallback is english' + ); + +SELECT is( + NULL, + pgwar.get_property_label(999, 'en'), + 'Assert the NULL is returned for non-existing property' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-target-label-of-field.sql b/database/test/units/functions/pgwar-get-target-label-of-field.sql new file mode 100644 index 000000000..3905c1018 --- /dev/null +++ b/database/test/units/functions/pgwar-get-target-label-of-field.sql @@ -0,0 +1,81 @@ +BEGIN; +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(2); + +INSERT INTO pgwar.project_statements + ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 11, 'this has no influence'), + (2, 1, 32, 22, 11, 'this has no influence'), + (3, 1, 33, 22, 11, 'this has no influence'), + (4, 1, 34, 22, 11, 'this has no influence'), + (5, 1, 35, 22, 11, 'this has no influence'), + (6, 1, 36, 22, 11, 'this has no influence'), + (7, 1, 11, 55, 61, 'Label 61'), + (8, 1, 11, 55, 62, 'Label 62'), + (9, 1, 11, 55, 63, NULL), + (10, 1, 11, 55, 64, NULL), + (11, 1, 11, 55, 65, 'Label 65'), + (12, 1, 11, 55, 66, 'Label 66'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'), + (64, 1, 88, 'Entity 64'); + +-- Test 1: Check if function returns the correct target label for an outgoing field +SELECT is( + pgwar.get_target_label_of_field( + 11, + 1, + '{"isOutgoing": true, "fkProperty": 55, "nrOfStatementsInLabel": 5}'::jsonb + ), + 'Label 61, Label 62, Entity 64, Label 65', + 'get_target_label_of_field returns correct labels for entity_id 11, project_id 1, property_id 55, outgoing' + ); + +-- Test 2: Check if function returns the correct target label for an incoming field +SELECT is( + pgwar.get_target_label_of_field( + 11, + 1, + '{"isOutgoing": false, "fkProperty": 22, "nrOfStatementsInLabel": 5}'::jsonb + ), + 'Entity 31, Entity 33', + 'get_target_label_of_field returns correct labels for entity_id 11, project_id 1, property_id 22, incoming' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql b/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql new file mode 100644 index 000000000..73b99a0ad --- /dev/null +++ b/database/test/units/functions/pgwar-get-target-labels-of-incoming-field.sql @@ -0,0 +1,101 @@ +BEGIN; + +/** + * Drop triggers that would reset the entity label to NULL and break the unit test + **/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(4); + +/****** test the project version *****/ +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 31, 22, 11, 'this has no influence'), + (2, 1, 32, 22, 11, 'this has no influence'), + (3, 1, 33, 22, 11, 'this has no influence'), + (4, 1, 34, 22, 11, 'this has no influence'), + (5, 1, 35, 22, 11, 'this has no influence'), + (6, 1, 36, 22, 11, 'this has no influence'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 1, 88, 'Entity 31'), + (32, 1, 88, NULL), + (33, 1, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for incoming field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(11, 1, 22, 5)', + ARRAY [ 'Entity 31', + 'Entity 33' ], + 'get_target_labels_of_incoming_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(99999, 1, 22, 5)', + 'get_target_labels_of_incoming_field returns no labels for entity_id 99999, project_id 1, property_id 22, and limit_count 5' + ); + +/****** test the community version *****/ +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 31, 22, 11, 'this has no influence'), + (2, 32, 22, 11, 'this has no influence'), + (3, 33, 22, 11, 'this has no influence'), + (4, 34, 22, 11, 'this has no influence'), + (5, 35, 22, 11, 'this has no influence'), + (6, 36, 22, 11, 'this has no influence'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 0, 88, 'Entity 31'), + (32, 0, 88, NULL), + (33, 0, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for incoming field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(11, 0, 22, 5)', + ARRAY [ 'Entity 31', + 'Entity 33' ], + 'get_target_labels_of_incoming_field returns correct labels for entity_id 11, project_id 0, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_incoming_field(99999, 0, 22, 5)', + 'get_target_labels_of_incoming_field returns no labels for entity_id 99999, project_id 0, property_id 22, and limit_count 5' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql b/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql new file mode 100644 index 000000000..a874ac8b5 --- /dev/null +++ b/database/test/units/functions/pgwar-get-target-labels-of-outgoing-field.sql @@ -0,0 +1,102 @@ +BEGIN; + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(4); + +/****** test the project version *****/ + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 1, 11, 22, 31, 'Label 1'), + (2, 1, 11, 22, 32, 'Label 2'), + (3, 1, 11, 22, 33, NULL), + (4, 1, 11, 22, 34, NULL), + (5, 1, 11, 22, 35, 'Label 5'), + (6, 1, 11, 22, 36, 'Label 6'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (33, 1, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for outgoing field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(11, 1, 22, 5)', + ARRAY [ 'Label 1', + 'Label 2', + 'Entity 33', + 'Label 5' ], + 'get_target_labels_of_outgoing_field returns correct labels for entity_id 11, project_id 1, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(99999, 1, 22, 5)', + 'get_target_labels_of_outgoing_field returns no labels for entity_id 99999, project_id 1, property_id 22, and limit_count 5' + ); + +/****** test the community version *****/ +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +VALUES (1, 11, 22, 31, 'Label 1'), + (2, 11, 22, 32, 'Label 2'), + (3, 11, 22, 33, NULL), + (4, 11, 22, 34, NULL), + (5, 11, 22, 35, 'Label 5'), + (6, 11, 22, 36, 'Label 6'); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (33, 0, 88, 'Entity 33'); + +-- Test 1: Check if function returns the correct target labels for outgoing field +SELECT results_eq( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(11, 0, 22, 5)', + ARRAY [ 'Label 1', + 'Label 2', + 'Entity 33', + 'Label 5' ], + 'get_target_labels_of_outgoing_field returns correct labels for entity_id 11, project_id 0, property_id 22, and limit_count 5' + ); + +-- Test 2: Check if function handles non-existing entity_id +SELECT is_empty( + 'SELECT label::text FROM pgwar.get_target_labels_of_outgoing_field(99999, 0, 22, 5)', + 'get_target_labels_of_outgoing_field returns no labels for entity_id 99999, project_id 0, property_id 22, and limit_count 5' + ); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-appe.sql b/database/test/units/functions/pgwar-get-value-label-appe.sql new file mode 100644 index 000000000..9186e514a --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-appe.sql @@ -0,0 +1,21 @@ +-- Test the functions converting literal tables to labels +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.appellation (string, fk_class) +VALUES ('foo', 123); + +SELECT is( + pgwar.get_value_label(appe), + 'foo', + 'Assert information.appellation is correctly converted to a label' + ) +FROM information.appellation appe; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-cell.sql b/database/test/units/functions/pgwar-get-value-label-cell.sql new file mode 100644 index 000000000..52f4d4126 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-cell.sql @@ -0,0 +1,29 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO tables.cell ( + fk_row, + fk_column, + fk_digital, + entity_version, + string_value, + numeric_value, + fk_class + ) +VALUES(44, 55, 0, 1, 'foo', 43.21, 88); + +SELECT is( + pgwar.get_value_label(cell), + 'foo', + 'Assert tables.cell is correctly converted to a label' + ) +FROM tables.cell cell; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-dimension.sql b/database/test/units/functions/pgwar-get-value-label-dimension.sql new file mode 100644 index 000000000..a42045ca8 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-dimension.sql @@ -0,0 +1,28 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +WITH m_unit AS ( + INSERT INTO information.resource (fk_class) + VALUES (33) RETURNING pk_entity +) +INSERT INTO information.dimension (numeric_value, fk_measurement_unit, fk_class) +SELECT 43.21, + m_unit.pk_entity, + 123 +FROM m_unit; + +SELECT is( + pgwar.get_value_label(dimension), + '43.21', + 'Assert information.dimension is correctly converted to a label' + ) +FROM information.dimension dimension; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-lang-string.sql b/database/test/units/functions/pgwar-get-value-label-lang-string.sql new file mode 100644 index 000000000..dc927ab8f --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-lang-string.sql @@ -0,0 +1,35 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +WITH inserted_lang AS ( + INSERT INTO information.language ( + notes, + iso6391, + iso6392b, + iso6392t, + pk_language, + fk_class + ) + VALUES ('english', 'e', 'en', 'eng', 'eng', 123) RETURNING pk_entity +) +INSERT INTO information.lang_string (string, fk_language, fk_class) +SELECT 'foo', + inserted_lang.pk_entity, + 123 +FROM inserted_lang; + +SELECT is( + pgwar.get_value_label(lang_string), + 'foo', + 'Assert information.lang_string is correctly converted to a label' + ) +FROM information.lang_string lang_string; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-language.sql b/database/test/units/functions/pgwar-get-value-label-language.sql new file mode 100644 index 000000000..02126dbca --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-language.sql @@ -0,0 +1,21 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.language (notes, iso6391, iso6392b, iso6392t, pk_language, fk_class) +VALUES ('english', 'e', 'en', 'eng', 'eng', 123); + +SELECT is( + pgwar.get_value_label(language), + 'english', + 'Assert information.language is correctly converted to a label' + ) +FROM information.language language; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-place.sql b/database/test/units/functions/pgwar-get-value-label-place.sql new file mode 100644 index 000000000..6bcd84e3b --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-place.sql @@ -0,0 +1,24 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.place (geo_point, fk_class) +VALUES ( + ST_SetSRID(ST_MakePoint(7.123, 3.123), 4326)::geography, + 123 + ); + +SELECT is( + pgwar.get_value_label(place), + 'WGS84: 7.123°, 3.123°', + 'Assert information.place is correctly converted to a label' + ) +FROM information.place place; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-label-time-primitive.sql b/database/test/units/functions/pgwar-get-value-label-time-primitive.sql new file mode 100644 index 000000000..90605e680 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-label-time-primitive.sql @@ -0,0 +1,116 @@ +-- Test the function converting a literal table to a label +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(4); + +-- the below test data was generated with +-- - https://aa.usno.navy.mil/data/JulianDate +-- - https://horoscopes.astro-seek.com/calculate-julian-to-gregorian/ +-- # | julian day | gregorian | julian cal +----- -------------- -------------- --------------- +-- 1 | 2460461 | 2024-05-30 | 2024-05-17 +-- 2 | 2236211 | | 1410-05-31 +-- 3 | 1668612 | | 0145-05-30 BC + +-- Modern date to gregorian calendar +SELECT is( + pgwar.get_value_label( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + NULL, + 2460461, + 'gregorian' + )::information.time_primitive + ), + '2024-05-30 (1 day)', + 'Assert julian day 2460461 is 2024-05-30 in gregorian calendar' + ); + +-- Modern date to julian calendar +SELECT is( + pgwar.get_value_label( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + NULL, + 2460461, + 'julian' + )::information.time_primitive + ), + '2024-05-17 (1 day)', + 'Assert julian day 2460461 is 2024-05-17 in julian calendar' + ); + +-- Middle ages date to julian calendar +SELECT is( + pgwar.get_value_label( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + NULL, + 2236211, + 'julian' + )::information.time_primitive + ), + '1410-05-31 (1 day)', + 'Assert julian day 2236211 is 1410-05-31 in julian calendar' + ); + +-- BC ages date to julian calendar +SELECT is( + pgwar.get_value_label( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + NULL, + 1668612, + 'julian' + )::information.time_primitive + ), + '-0145-05-30 (1 day)', + 'Assert gregorian day 1668612 is 0145-05-30 BC in gregorian calendar' + ); + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-appe.sql b/database/test/units/functions/pgwar-get-value-object-appe.sql new file mode 100644 index 000000000..447e0bc95 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-appe.sql @@ -0,0 +1,27 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.appellation (string, fk_class) +VALUES ('foo', 123); + +SELECT is( + pgwar.get_value_object(appe), + format('{ + "string": { + "pkEntity": %s, + "fkClass": 123, + "string": "foo" + } + }', appe.pk_entity)::jsonb, + 'Assert information.appellation is correctly converted to json' + ) +FROM information.appellation appe; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-cell.sql b/database/test/units/functions/pgwar-get-value-object-cell.sql new file mode 100644 index 000000000..cc0813acd --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-cell.sql @@ -0,0 +1,41 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO tables.cell ( + fk_row, + fk_column, + fk_digital, + entity_version, + string_value, + numeric_value, + fk_class + ) +VALUES(44, 55, 0, 1, 'foo', 43.21, 88); + +SELECT is( + pgwar.get_value_object(cell), + format( + '{ + "cell": { + "pkCell": %s, + "fkClass": 88, + "fkColumn": 55, + "fkRow": 44, + "stringValue": "foo", + "numericValue": 43.21 + } + }', + cell.pk_cell + )::jsonb, + 'Assert tables.cell is correctly converted to json' + ) +FROM tables.cell cell; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-dimension.sql b/database/test/units/functions/pgwar-get-value-object-dimension.sql new file mode 100644 index 000000000..e23b26713 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-dimension.sql @@ -0,0 +1,39 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +WITH m_unit AS ( + INSERT INTO information.resource (fk_class) + VALUES (33) RETURNING pk_entity +) +INSERT INTO information.dimension (numeric_value, fk_measurement_unit, fk_class) +SELECT 43.21, + m_unit.pk_entity, + 123 +FROM m_unit; + +SELECT is( + pgwar.get_value_object(dimension), + format( + '{ + "dimension": { + "pkEntity": %s, + "fkClass": 123, + "fkMeasurementUnit": %s, + "numericValue": 43.21 + } + }', + dimension.pk_entity, + dimension.fk_measurement_unit + )::jsonb, + 'Assert information.dimension is correctly converted to json' + ) +FROM information.dimension dimension; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-lang-string.sql b/database/test/units/functions/pgwar-get-value-object-lang-string.sql new file mode 100644 index 000000000..d024d3244 --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-lang-string.sql @@ -0,0 +1,46 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +WITH inserted_lang AS ( + INSERT INTO information.language ( + notes, + iso6391, + iso6392b, + iso6392t, + pk_language, + fk_class + ) + VALUES ('english', 'e', 'en', 'eng', 'eng', 123) RETURNING pk_entity +) +INSERT INTO information.lang_string (string, fk_language, fk_class) +SELECT 'foo', + inserted_lang.pk_entity, + 123 +FROM inserted_lang; + +SELECT is( + pgwar.get_value_object(lang_string), + format( + '{ + "langString": { + "pkEntity": %s, + "fkClass": 123, + "string": "foo", + "fkLanguage": %s + } + }', + lang_string.pk_entity, + lang_string.fk_language + )::jsonb, + 'Assert information.lang_string is correctly converted to json' + ) +FROM information.lang_string lang_string; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-language.sql b/database/test/units/functions/pgwar-get-value-object-language.sql new file mode 100644 index 000000000..dda1881ee --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-language.sql @@ -0,0 +1,33 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.language (notes, iso6391, iso6392b, iso6392t, pk_language, fk_class) +VALUES ('english', 'e', 'en', 'eng', 'eng', 123); + +SELECT is( + pgwar.get_value_object(language), + format( + '{ + "language": { + "pkEntity": %s, + "fkClass": 123, + "label": "english", + "iso6391": "e", + "iso6392b": "en", + "iso6392t": "eng" + } + }', + language.pk_entity + )::jsonb, + 'Assert information.language is correctly converted to json' + ) +FROM information.language language; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-place.sql b/database/test/units/functions/pgwar-get-value-object-place.sql new file mode 100644 index 000000000..1290060fc --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-place.sql @@ -0,0 +1,33 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(1); + +INSERT INTO information.place (geo_point, fk_class) +VALUES ( + ST_SetSRID(ST_MakePoint(7.123, 3.123), 4326)::geography, + 123 + ); + +SELECT is( + pgwar.get_value_object(place), + format('{ + "geometry": { + "pkEntity": %s, + "fkClass": 123, + "geoJSON": { + "type": "Point", + "coordinates": [7.123, 3.123] + } + } + }', place.pk_entity)::jsonb, + 'Assert information.place is correctly converted to json' + ) +FROM information.place place; + +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-get-value-object-time-primitive.sql b/database/test/units/functions/pgwar-get-value-object-time-primitive.sql new file mode 100644 index 000000000..e7f05d67d --- /dev/null +++ b/database/test/units/functions/pgwar-get-value-object-time-primitive.sql @@ -0,0 +1,204 @@ +-- Test the functions converting literal tables to value object json +-- Start transaction and plan the tests. +BEGIN; + +SELECT plan(4); + +-- the below test data was generated with +-- - https://aa.usno.navy.mil/data/JulianDate +-- - https://horoscopes.astro-seek.com/calculate-julian-to-gregorian/ +-- # | julian day | gregorian | julian cal +----- -------------- -------------- --------------- +-- 1 | 2460461 | 2024-05-30 | 2024-05-17 +-- 2 | 2236211 | | 1410-05-31 +-- 3 | 1668612 | | 0145-05-30 BC + +-- Modern date to gregorian calendar +SELECT is( + pgwar.get_value_object( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + 123, + 2460461, + 'gregorian' + )::information.time_primitive + ), + '{ + "timePrimitive": { + "pkEntity": 1, + "fkClass": 123, + "julianDay": 2460461, + "calendar": "gregorian", + "duration": "1 day", + "label": "2024-05-30 (1 day)", + "from": { + "calJulian": "2024-05-17", + "julianDay": 2460461, + "calGregorian": "2024-05-30", + "julianSecond": 212583830400, + "calGregorianIso8601": "2024-05-30T00:00:00Z" + }, + "to": { + "calJulian": "2024-05-18", + "julianDay": 2460462, + "calGregorian": "2024-05-31", + "julianSecond": 212583916800, + "calGregorianIso8601": "2024-05-31T00:00:00Z" + } + } + }'::jsonb, + 'Assert julian day 2460461 in gregorian is correctly converted to json' + ); +-- Modern date to julian calendar +SELECT is( + pgwar.get_value_object( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + 123, + 2460461, + 'julian' + )::information.time_primitive + ), + '{ + "timePrimitive": { + "pkEntity": 1, + "fkClass": 123, + "julianDay": 2460461, + "calendar": "julian", + "duration": "1 day", + "label": "2024-05-17 (1 day)", + "from": { + "calJulian": "2024-05-17", + "julianDay": 2460461, + "calGregorian": "2024-05-30", + "julianSecond": 212583830400, + "calGregorianIso8601": "2024-05-30T00:00:00Z" + }, + "to": { + "calJulian": "2024-05-18", + "julianDay": 2460462, + "calGregorian": "2024-05-31", + "julianSecond": 212583916800, + "calGregorianIso8601": "2024-05-31T00:00:00Z" + } + } + }'::jsonb, + 'Assert julian day 2460461 in julian is correctly converted to json' + ); + -- Middle ages date to julian calendar +SELECT is( + pgwar.get_value_object( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + 123, + 2236211, + 'julian' + )::information.time_primitive + ), + '{ + "timePrimitive": { + "pkEntity": 1, + "fkClass": 123, + "julianDay": 2236211, + "calendar": "julian", + "duration": "1 day", + "label": "1410-05-31 (1 day)", + "from": { + "calJulian": "1410-05-31", + "julianDay": 2236211, + "calGregorian": "1410-06-09", + "julianSecond": 193208630400, + "calGregorianIso8601": "1410-06-09T00:00:00Z" + }, + "to": { + "calJulian": "1410-06-01", + "julianDay": 2236212, + "calGregorian": "1410-06-10", + "julianSecond": 193208716800, + "calGregorianIso8601": "1410-06-10T00:00:00Z" + } + } + }'::jsonb, + 'Assert julian day 2236211 in julian is correctly converted to json' + ); + -- BC ages date to julian calendar +SELECT is( + pgwar.get_value_object( + ( + 1, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + '1 day', + 123, + 1668612, + 'julian' + )::information.time_primitive + ), + '{ + "timePrimitive": { + "pkEntity": 1, + "fkClass": 123, + "julianDay": 1668612, + "calendar": "julian", + "duration": "1 day", + "label": "-0145-05-30 (1 day)", + "from": { + "calJulian": "-0145-05-30", + "julianDay": 1668612, + "calGregorian": "-0145-05-27", + "julianSecond": 144168076800, + "calGregorianIso8601": "-0145-05-27T00:00:00Z" + }, + "to": { + "calJulian": "-0145-05-31", + "julianDay": 1668613, + "calGregorian": "-0145-05-28", + "julianSecond": 144168163200, + "calGregorianIso8601": "-0145-05-28T00:00:00Z" + } + } + }'::jsonb, + 'Assert julian day 1668612 in julian is correctly converted to json' + ); +-- Finish the tests and clean up. +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql b/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql new file mode 100644 index 000000000..59d89aead --- /dev/null +++ b/database/test/units/functions/pgwar-update-community-statements-from-deletes.sql @@ -0,0 +1,77 @@ +BEGIN; + +SELECT plan(3); + +INSERT INTO pgwar.community_statements ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 99, 22, 11, 0, 0, 'LABEL'), + (2, 66, 22, 11, 4, 3, 'LABEL'), + (3, 44, 22, 11, 4, 3, 'LABEL'); + + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 31, 99, 22, 11, 4, 3, 'LABEL'), + (1, 32, 99, 22, 11, 8, 1, 'LABEL'), + (2, 31, 66, 22, 11, 4, 3, 'LABEL'), + (2, 32, 66, 22, 11, 4, 3, 'LABEL'); + + +INSERT INTO pgwar.project_statements_deleted ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + tmsp_deletion + ) +VALUES + (1, 8765, 99, 22, 11, CURRENT_TIMESTAMP), + (3, 8765, 44, 22, 11, CURRENT_TIMESTAMP); + + +-- run the update task +SELECT pgwar.update_community_statements_from_deletes(); + +SELECT is( + ord_num_of_domain, + 6::numeric, + 'Assert the ord nums are recalculated for community statement with pk_entity 1' +) +FROM pgwar.community_statements +WHERE pk_entity = 1; + +SELECT is_empty( + 'SELECT * FROM pgwar.community_statements WHERE pk_entity = 3;', + 'Assert community statement with pk_entity 3 is deleted' +); + +SELECT is( + offset_tmsp, + CURRENT_TIMESTAMP, + 'Assert that offset is updated' +) +FROM pgwar.offsets +WHERE job_name = 'update-community-statements-from-deletes'; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql b/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql new file mode 100644 index 000000000..a34299168 --- /dev/null +++ b/database/test/units/functions/pgwar-update-community-statements-from-upserts.sql @@ -0,0 +1,55 @@ +BEGIN; + +SELECT plan(3); + + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + ord_num_of_domain, + ord_num_of_range, + object_label + ) +VALUES + (1, 31, 99, 22, 11, 4, 3, 'LABEL'), + (1, 32, 99, 22, 11, 8, 1, 'LABEL'), + (2, 31, 66, 22, 11, 4, 3, 'LABEL'), + (2, 32, 66, 22, 11, 4, 3, 'LABEL'), + (3, 31, 44, 22, 11, 4, 3, 'LABEL'), + (3, 32, 44, 22, 11, 4, 3, 'LABEL'), + (3, 33, 44, 22, 11, 4, 3, 'LABEL'); + +-- run the update task +SELECT pgwar.update_community_statements_from_upserts(); + +SELECT is( + count(*), + 3::bigint, + 'Assert that 3 community statments were created' +) +FROM pgwar.community_statements; + +SELECT is( + ord_num_of_domain, + 6::numeric, + 'Assert that ord_num_of_domain is correctly calulated' +) +FROM pgwar.community_statements +WHERE pk_entity = 1; + + +SELECT is( + offset_tmsp, + CURRENT_TIMESTAMP, + 'Assert that offset is updated' +) +FROM pgwar.offsets +WHERE job_name = 'update-community-statements-from-upserts'; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-entity-class-metadata.sql b/database/test/units/functions/pgwar-update-entity-class-metadata.sql new file mode 100644 index 000000000..8e2d4311f --- /dev/null +++ b/database/test/units/functions/pgwar-update-entity-class-metadata.sql @@ -0,0 +1,224 @@ +BEGIN; + +SELECT plan(10); + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_entity, pk_language, iso6391) +VALUES (44, 'fra', 'fr'), + (55, 'eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(pk_entity, fk_language) +VALUES (33, 44); + +-- Insert class 123 +INSERT INTO data_for_history.api_class ( + dfh_pk_class, + dfh_class_label, + dfh_class_label_language, + dfh_parent_classes, + dfh_ancestor_classes, + removed_from_api, + tmsp_last_modification + ) +VALUES ( + 123, + 'My Class', + 'en', + '{1, 2, 3}', + '{4, 5, 6}', + false, + '2024-01-01 19:46:03.190892+00' + ); + +-- Insert a entity preview of class 123 +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class) +VALUES (66, 33, 123); + +-- run the update task +SELECT pgwar.update_entity_class(); + +/** + * Test if all four columns are set + **/ +SELECT is( + parent_classes, + '[1, 2, 3]', + 'Assert that the parent classes are added' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +SELECT is( + ancestor_classes, + '[4, 5, 6]', + 'Assert that the ancestor classes are added' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +SELECT is( + class_label, + 'My Class', + 'Assert that the class_label is added' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +SELECT is( + entity_type, + 'teEn', + 'Assert that the entit type is added' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +/** + * Test if class_modified timestamp is correctly compared with offset + **/ +-- Insert class 123 with current timestamp +INSERT INTO data_for_history.api_class ( + dfh_pk_class, + dfh_class_label, + dfh_class_label_language, + dfh_parent_classes, + dfh_ancestor_classes, + removed_from_api, + tmsp_last_modification + ) +VALUES ( + 123, + 'Ma classe', + 'fr', + '{1, 2, 3}', + '{4, 5, 6}', + false, + CURRENT_TIMESTAMP + ); + +-- Should not update anything because _offset is CURRENT_TIMESTAMP +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'My Class', + 'Assert that the class_label is unchanged' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +-- artificially set offset to older timestamp +UPDATE pgwar.offsets +SET offset_tmsp = CURRENT_TIMESTAMP - INTERVAL '1 minute'; + +-- Should update because _offset older than CURRENT_TIMESTAMP' +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'Ma classe', + 'Assert that the class_label is updated' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +/** + * Test if project_modified timestamp is correctly compared with offset + **/ +-- change project language +UPDATE projects.project +SET fk_language = 55 +WHERE pk_entity = 33; + +-- Should not update anything because _offset is CURRENT_TIMESTAMP +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'Ma classe', + 'Assert that the class_label is unchanged' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +-- artificially set offset to older timestamp +UPDATE pgwar.offsets +SET offset_tmsp = CURRENT_TIMESTAMP - INTERVAL '1 minute'; + +-- Should update because _offset older than CURRENT_TIMESTAMP' +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'My Class', + 'Assert that the class_label is updated' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +/** + * Test if tmsp_fk_class_modification timestamp is correctly compared with offset + **/ +-- Switch class of entity +SELECT pgwar.upsert_entity_preview_fk_class(66, 33, 456); + +-- Insert class 456 +INSERT INTO data_for_history.api_class ( + dfh_pk_class, + dfh_class_label, + dfh_class_label_language, + dfh_parent_classes, + dfh_ancestor_classes, + removed_from_api, + tmsp_last_modification + ) +VALUES ( + 456, + 'New Class', + 'en', + '{99}', + '{100}', + false, + '2024-01-01 19:46:03.190892+00' + ); + +-- Should not update anything because _offset is CURRENT_TIMESTAMP +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'My Class', + 'Assert that the class_label is unchanged' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +-- artificially set offset to older timestamp +UPDATE pgwar.offsets +SET offset_tmsp = CURRENT_TIMESTAMP - INTERVAL '1 minute'; + +-- Should update class metadata with new class +SELECT pgwar.update_entity_class(); + +SELECT is( + class_label, + 'New Class', + 'Assert that the class_label of new class is set' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-entity-label-of-entity-preview.sql b/database/test/units/functions/pgwar-update-entity-label-of-entity-preview.sql new file mode 100644 index 000000000..de5f42a87 --- /dev/null +++ b/database/test/units/functions/pgwar-update-entity-label-of-entity-preview.sql @@ -0,0 +1,23 @@ +BEGIN; + +SELECT plan(1); + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (31, 1, 88, 'Entity 31'); + +SELECT pgwar.update_entity_label_of_entity_preview(31, 1, 'Foo'); + +-- Test 2: Check if function update entity label +SELECT is( + entity_label, + 'Foo', + 'update_entity_label_of_entity_preview updates entity label' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 31 + AND fk_project = 1; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-fk-type.sql b/database/test/units/functions/pgwar-update-fk-type.sql new file mode 100644 index 000000000..77eb7dc33 --- /dev/null +++ b/database/test/units/functions/pgwar-update-fk-type.sql @@ -0,0 +1,61 @@ +BEGIN; + +SELECT plan(1); + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_entity, pk_language, iso6391) +VALUES (44, 'fra', 'fr'), + (55, 'eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(pk_entity, fk_language) +VALUES (33, 44); + +-- Insert a has type sub property +INSERT INTO data_for_history.api_property ( + dfh_pk_property, + dfh_property_domain, + dfh_parent_properties, + tmsp_last_modification + ) +VALUES ( + 654, + 123, + '{1, 2, 3}', -- 2 = has type + '2024-01-01 19:46:03.190892+00' + ); + +-- Insert a entity preview of class 123 +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class) +VALUES (66, 33, 123); + +-- Insert a statement of has type sub property +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info + ) +VALUES (1, 33, 66, 654, 987654321); + + +-- run the update task +SELECT pgwar.update_fk_type(); + +/** + * Test if all four columns are set + **/ +SELECT is( + fk_type, + 987654321, + 'Assert that the fk_type is updated' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 +AND fk_project = 33; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-full-texts.sql b/database/test/units/functions/pgwar-update-full-texts.sql new file mode 100644 index 000000000..b3b7eeeb9 --- /dev/null +++ b/database/test/units/functions/pgwar-update-full-texts.sql @@ -0,0 +1,126 @@ +BEGIN; + +SELECT plan(1); + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_language, iso6391) +VALUES ('fra', 'fr'), + ('eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(fk_language, notes) +SELECT pk_entity, + '_p1' +FROM information.language +WHERE pk_language = 'fra'; + +INSERT INTO pgwar.project_statements ( + pk_entity, + fk_project, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ) +SELECT v.pk_entity, + pro.pk_entity, + v.fk_subject_info, + v.fk_property, + v.fk_object_info, + v.object_label +FROM ( + VALUES (1, 31, 22, 11, 'this has no influence'), + (2, 32, 22, 11, 'this has no influence'), + (3, 33, 22, 11, 'this has no influence'), + (4, 34, 22, 11, 'this has no influence'), + (5, 35, 22, 11, 'this has no influence'), + (6, 36, 22, 11, 'this has no influence'), + (7, 11, 55, 61, 'Label 61'), + (8, 11, 55, 62, 'Label 62'), + (9, 11, 55, 63, NULL), + (10, 11, 55, 64, NULL), + (11, 11, 55, 65, 'Label 65'), + (12, 11, 55, 66, 'Label 66') + ) AS v ( + pk_entity, + fk_subject_info, + fk_property, + fk_object_info, + object_label + ), + projects.project pro +WHERE pro.notes = '_p1'; + +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +SELECT v.pk_entity, + pro.pk_entity, + v.fk_class, + v.entity_label +FROM ( + VALUES (31, 88, 'Entity 31'), + (32, 88, NULL), + (33, 88, 'Entity 33'), + (64, 88, 'Entity 64') + ) AS v(pk_entity, fk_class, entity_label), + projects.project pro +WHERE pro.notes = '_p1'; + +INSERT INTO data_for_history.api_property( + tmsp_last_dfh_update, + dfh_pk_property, + dfh_property_label_language, + dfh_property_label, + dfh_property_inverse_label + ) +VALUES ( + '2024-06-12 07:54:29.142429+00', + 22, + 'fr', + 'possède', + 'est en possession de' + ), + ( + '2024-06-12 07:54:29.142429+00', + 55, + 'fr', + 'bar', + 'bar inverse' + ); + + +-- create the full texts +SELECT is( + update_full_texts, + 'Number of rows updated: 13', + 'Assert that 13 full texts were updated' +) +FROM pgwar.update_full_texts(100); + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/database/test/units/functions/pgwar-update-type-label.sql b/database/test/units/functions/pgwar-update-type-label.sql new file mode 100644 index 000000000..b1775a010 --- /dev/null +++ b/database/test/units/functions/pgwar-update-type-label.sql @@ -0,0 +1,62 @@ +BEGIN; + +/** +* Drop triggers that would reset the entity label to NULL and break the unit test +**/ +-- Drop trigger after_insert_project_statement +DROP TRIGGER IF EXISTS after_insert_project_statement ON pgwar.project_statements; + +-- Drop trigger after_update_project_statement +DROP TRIGGER IF EXISTS after_update_project_statement ON pgwar.project_statements; + +-- Drop trigger after_delete_project_statement +DROP TRIGGER IF EXISTS after_delete_project_statement ON pgwar.project_statements; + +-- Drop trigger after_insert_entity_preview +DROP TRIGGER IF EXISTS after_insert_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_update_entity_preview +DROP TRIGGER IF EXISTS after_update_entity_preview ON pgwar.entity_preview; + +-- Drop trigger after_delete_entity_preview_01 +DROP TRIGGER IF EXISTS after_delete_entity_preview_01 ON pgwar.entity_preview; + +-- Drop trigger on_upsert_entity_label_config +DROP TRIGGER IF EXISTS on_upsert_entity_label_config ON projects.entity_label_config; + +SELECT plan(1); + +-- Insert a language entry to be used in projects +INSERT INTO information.language(pk_entity, pk_language, iso6391) +VALUES (44, 'fra', 'fr'), + (55, 'eng', 'en'); + +-- Insert two projects associated with the language +INSERT INTO projects.project(pk_entity, fk_language) +VALUES (33, 44); + +-- Insert an entity preview that acts as type +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, entity_label) +VALUES (65, 33, 111, 'City'); + + +-- Insert an entity preview of class 123 that has a fk_type referencing 'City' +INSERT INTO pgwar.entity_preview (pk_entity, fk_project, fk_class, fk_type, tmsp_fk_type_modification) +VALUES (66, 33, 123, 65, CURRENT_TIMESTAMP); + +-- run the update task +SELECT pgwar.update_type_label(); + +SELECT is( + type_label, + 'City', + 'Assert that the type_label is updated' + ) +FROM pgwar.entity_preview +WHERE pk_entity = 66 + AND fk_project = 33; + +SELECT * +FROM finish(); + +ROLLBACK; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ec4a50e34..21349196d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "geovistory-root", - "version": "0.8.2", + "version": "0.8.3-pr-385.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "geovistory-root", - "version": "0.8.2" + "version": "0.8.3-pr-385.0" } } } diff --git a/package.json b/package.json index dcb638762..1431eca85 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "geovistory-root", "description": "root package.json of the monorepo", - "version": "0.8.2", + "version": "0.8.3-pr-385.0", "scripts": {}, "private": true } diff --git a/server/.env.example b/server/.env.example index d2362b9e6..300ce8e0b 100644 --- a/server/.env.example +++ b/server/.env.example @@ -1,22 +1,16 @@ # GEOVISTROY Databases available to select in start scripts -## database with ephemeral data (can anytime be deleted) useful to seed with mock (to testing / developing) -GV_DB_FOR_SEEDING="postgres://postgres:local_pw@localhost:1110/gv_test_db" +## database started with database/dev.sh +GV_DB_DEV="postgres://postgres:pw@localhost:15432/filled_db" -## database with a limited set of data useful to develop without mock -GV_DB_REVIEW_COPY="postgres://postgres:local_pw@localhost:1110/toolbox_db" +## database started with database/test.sh -p +GV_DB_TEST="postgres://postgres:pw@localhost:25432/filled_db" -## database with a a copy of production useful to test development with real data -GV_DB_PROD_COPY="postgres://postgres:local_pw@localhost:1110/gv_prod_copy" - -## schema-only database without data useful to create empty db for seeding -GV_DB_SCHEMA_TEMPLATE="postgres://postgres:local_pw@localhost:1110/gv_template_db" - -## the maintainance database useful to drop or create other databases -GV_DB_MAINTAINANCE="postgres://postgres:local_pw@localhost:1110/gv_postgres" +## a placeholder to be used in case you need to connect to any other db +GV_DB_REMOTE= # instead of appending sslmode=require to the url above, you can set this env var: -#GV_DB_SSL="sslmode=require" +# GV_DB_SSL="sslmode=require" # Mocha Settings MOCHA_DB=DB_FOR_SEEDING @@ -51,7 +45,7 @@ GEOV_EMAIL_PASSWORD=** COMMUNITY_PROJECT_ID=591 # Base URL of the client webserver (e.g.: https://toolbox.geovistory.org/, http://localhost:4200) -CLIENT_URL=http://localhost:1140 +CLIENT_URL=http://localhost:4200 # Base URL of this api server (e.g.: https://toolbox.geovistory.org/api, http://localhost:3000) -SERVER_URL=http://localhost:1130 +SERVER_URL=http://localhost:3000 diff --git a/server/.vscode/launch.json b/server/.vscode/launch.json index d787a942b..ee220b848 100644 --- a/server/.vscode/launch.json +++ b/server/.vscode/launch.json @@ -13,7 +13,7 @@ ], "console": "integratedTerminal", "program": "${workspaceFolder}/scripts/start-webserver.js", - "preLaunchTask": "tsc: watch - tsconfig.json", + "preLaunchTask": "tsc: build - tsconfig.json", "restart": false, "outputCapture": "std", "outFiles": [ diff --git a/server/build-ngx-sdk.sh b/server/build-ngx-sdk.sh index f0043bf65..011443c38 100644 --- a/server/build-ngx-sdk.sh +++ b/server/build-ngx-sdk.sh @@ -1,7 +1,7 @@ rm -r ../client/libs/lib-sdk-lb4/src/lib/sdk-lb4 ############# download the openapi.json ################ -curl http://0.0.0.0:3000/explorer/openapi.json \ +curl http://localhost:3000/explorer/openapi.json \ --output openapi.json ############## create the sdk ################## diff --git a/server/db-migrate/create.sh b/server/db-migrate/create.sh index 178eef0d6..cc704a0b7 100644 --- a/server/db-migrate/create.sh +++ b/server/db-migrate/create.sh @@ -17,6 +17,6 @@ export DB_MIGRATE_URL=$DB_MIGRATE_URL $DIR/../node_modules/.bin/db-migrate \ --config $DIR/config.json \ - --migrations-dir $DIR/migrations \ + --migrations-dir $DIR/../../database/migrations \ --sql-file true \ create "$@" diff --git a/server/db-migrate/down.sh b/server/db-migrate/down.sh index 1c1e98cc2..0dbc0a584 100644 --- a/server/db-migrate/down.sh +++ b/server/db-migrate/down.sh @@ -17,5 +17,5 @@ export DB_MIGRATE_URL=$DB_MIGRATE_URL $DIR/../node_modules/.bin/db-migrate \ --config $DIR/config.json \ - --migrations-dir $DIR/migrations \ + --migrations-dir $DIR/../../database/migrations \ down "$@" diff --git a/server/db-migrate/migrations/20190516074322-inf-v-dimension-find-or-create.js b/server/db-migrate/migrations/20190516074322-inf-v-dimension-find-or-create.js deleted file mode 100644 index 7638ad6e5..000000000 --- a/server/db-migrate/migrations/20190516074322-inf-v-dimension-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516074322-inf-v-dimension-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516074322-inf-v-dimension-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516080250-drop-deprecated-pks-and-sequences.js b/server/db-migrate/migrations/20190516080250-drop-deprecated-pks-and-sequences.js deleted file mode 100644 index 14ddb43e4..000000000 --- a/server/db-migrate/migrations/20190516080250-drop-deprecated-pks-and-sequences.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516080250-drop-deprecated-pks-and-sequences-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516080250-drop-deprecated-pks-and-sequences-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516115013-inf-refactor-text-children.js b/server/db-migrate/migrations/20190516115013-inf-refactor-text-children.js deleted file mode 100644 index c91965347..000000000 --- a/server/db-migrate/migrations/20190516115013-inf-refactor-text-children.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516115013-inf-refactor-text-children-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516115013-inf-refactor-text-children-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516124905-inf-refactor-time-primitive-find-or-create.js b/server/db-migrate/migrations/20190516124905-inf-refactor-time-primitive-find-or-create.js deleted file mode 100644 index 46ab7047e..000000000 --- a/server/db-migrate/migrations/20190516124905-inf-refactor-time-primitive-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516124905-inf-refactor-time-primitive-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516124905-inf-refactor-time-primitive-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516125723-inf-refactor-place-find-or-create.js b/server/db-migrate/migrations/20190516125723-inf-refactor-place-find-or-create.js deleted file mode 100644 index 21e9148cf..000000000 --- a/server/db-migrate/migrations/20190516125723-inf-refactor-place-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516125723-inf-refactor-place-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516125723-inf-refactor-place-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516131842-war-refactor-create-fk-type-fn.js b/server/db-migrate/migrations/20190516131842-war-refactor-create-fk-type-fn.js deleted file mode 100644 index 52ecfcd6e..000000000 --- a/server/db-migrate/migrations/20190516131842-war-refactor-create-fk-type-fn.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516131842-war-refactor-create-fk-type-fn-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516131842-war-refactor-create-fk-type-fn-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190516161645-sys-t-system-relevant-classes.js b/server/db-migrate/migrations/20190516161645-sys-t-system-relevant-classes.js deleted file mode 100644 index d573b1a95..000000000 --- a/server/db-migrate/migrations/20190516161645-sys-t-system-relevant-classes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516161645-sys-t-system-relevant-classes-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190516161645-sys-t-system-relevant-classes-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190524151304-dat-v-digital-version-update.js b/server/db-migrate/migrations/20190524151304-dat-v-digital-version-update.js deleted file mode 100644 index 160a66868..000000000 --- a/server/db-migrate/migrations/20190524151304-dat-v-digital-version-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190524151304-dat-v-digital-version-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190524151304-dat-v-digital-version-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190525081925-sys-v-has-type-preview.js b/server/db-migrate/migrations/20190525081925-sys-v-has-type-preview.js deleted file mode 100644 index 8240e5e00..000000000 --- a/server/db-migrate/migrations/20190525081925-sys-v-has-type-preview.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190525081925-sys-v-has-type-preview-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190525081925-sys-v-has-type-preview-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190526155143-dat-v-digital-update-trigger-fn.js b/server/db-migrate/migrations/20190526155143-dat-v-digital-update-trigger-fn.js deleted file mode 100644 index 3ce9aeaca..000000000 --- a/server/db-migrate/migrations/20190526155143-dat-v-digital-update-trigger-fn.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190526155143-dat-v-digital-update-trigger-fn-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190526155143-dat-v-digital-update-trigger-fn-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190527101826-com-f-improve-string-to-quill-doc.js b/server/db-migrate/migrations/20190527101826-com-f-improve-string-to-quill-doc.js deleted file mode 100644 index fd6a49bd5..000000000 --- a/server/db-migrate/migrations/20190527101826-com-f-improve-string-to-quill-doc.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190527101826-com-f-improve-string-to-quill-doc-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190527101826-com-f-improve-string-to-quill-doc-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190528154133-com-text-drop-default-string-value.js b/server/db-migrate/migrations/20190528154133-com-text-drop-default-string-value.js deleted file mode 100644 index 62fdf745b..000000000 --- a/server/db-migrate/migrations/20190528154133-com-text-drop-default-string-value.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190528154133-com-text-drop-default-string-value-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190528154133-com-text-drop-default-string-value-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property.js b/server/db-migrate/migrations/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property.js deleted file mode 100644 index 76fa316c8..000000000 --- a/server/db-migrate/migrations/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190605133819-inf-add-pe-it-function.js b/server/db-migrate/migrations/20190605133819-inf-add-pe-it-function.js deleted file mode 100644 index 52e102a34..000000000 --- a/server/db-migrate/migrations/20190605133819-inf-add-pe-it-function.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190605133819-inf-add-pe-it-function-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190605133819-inf-add-pe-it-function-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190606100039-dat-t-entity-update.js b/server/db-migrate/migrations/20190606100039-dat-t-entity-update.js deleted file mode 100644 index 36473fd4f..000000000 --- a/server/db-migrate/migrations/20190606100039-dat-t-entity-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606100039-dat-t-entity-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606100039-dat-t-entity-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190606101525-dat-v-chunk-update.js b/server/db-migrate/migrations/20190606101525-dat-v-chunk-update.js deleted file mode 100644 index 25f0841c8..000000000 --- a/server/db-migrate/migrations/20190606101525-dat-v-chunk-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606101525-dat-v-chunk-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606101525-dat-v-chunk-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190606104618-fix-wrong-sequences.js b/server/db-migrate/migrations/20190606104618-fix-wrong-sequences.js deleted file mode 100644 index 1a317aa89..000000000 --- a/server/db-migrate/migrations/20190606104618-fix-wrong-sequences.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606104618-fix-wrong-sequences-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606104618-fix-wrong-sequences-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190606115524-dat-v-digital-update.js b/server/db-migrate/migrations/20190606115524-dat-v-digital-update.js deleted file mode 100644 index 4b229252b..000000000 --- a/server/db-migrate/migrations/20190606115524-dat-v-digital-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606115524-dat-v-digital-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606115524-dat-v-digital-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190606120608-sys-t-system-type-update.js b/server/db-migrate/migrations/20190606120608-sys-t-system-type-update.js deleted file mode 100644 index b080c9a0f..000000000 --- a/server/db-migrate/migrations/20190606120608-sys-t-system-type-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606120608-sys-t-system-type-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190606120608-sys-t-system-type-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190607152916-sys-t-system-type-rename-group-col.js b/server/db-migrate/migrations/20190607152916-sys-t-system-type-rename-group-col.js deleted file mode 100644 index 452c79478..000000000 --- a/server/db-migrate/migrations/20190607152916-sys-t-system-type-rename-group-col.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190607152916-sys-t-system-type-rename-group-col-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190607152916-sys-t-system-type-rename-group-col-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190613134514-add-indexes-on-pk-entity.js b/server/db-migrate/migrations/20190613134514-add-indexes-on-pk-entity.js deleted file mode 100644 index ceabf65aa..000000000 --- a/server/db-migrate/migrations/20190613134514-add-indexes-on-pk-entity.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613134514-add-indexes-on-pk-entity-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613134514-add-indexes-on-pk-entity-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190613204105-add-indexes-on-relevant-fks.js b/server/db-migrate/migrations/20190613204105-add-indexes-on-relevant-fks.js deleted file mode 100644 index e2d34fc99..000000000 --- a/server/db-migrate/migrations/20190613204105-add-indexes-on-relevant-fks.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613204105-add-indexes-on-relevant-fks-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190613204105-add-indexes-on-relevant-fks-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190614053616-war-fix-superfluous-project-previews.js b/server/db-migrate/migrations/20190614053616-war-fix-superfluous-project-previews.js deleted file mode 100644 index 67fc598b4..000000000 --- a/server/db-migrate/migrations/20190614053616-war-fix-superfluous-project-previews.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190614053616-war-fix-superfluous-project-previews-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190614053616-war-fix-superfluous-project-previews-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190618144032-war-rework-create-all.js b/server/db-migrate/migrations/20190618144032-war-rework-create-all.js deleted file mode 100644 index a421545c3..000000000 --- a/server/db-migrate/migrations/20190618144032-war-rework-create-all.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190618144032-war-rework-create-all-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190618144032-war-rework-create-all-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190619094020-war-rework-create-all-2.js b/server/db-migrate/migrations/20190619094020-war-rework-create-all-2.js deleted file mode 100644 index 0d4b711c5..000000000 --- a/server/db-migrate/migrations/20190619094020-war-rework-create-all-2.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190619094020-war-rework-create-all-2-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190619094020-war-rework-create-all-2-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190624081846-query-opimization-1.js b/server/db-migrate/migrations/20190624081846-query-opimization-1.js deleted file mode 100644 index a52cc070a..000000000 --- a/server/db-migrate/migrations/20190624081846-query-opimization-1.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190624081846-query-opimization-1-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190624081846-query-opimization-1-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols.js b/server/db-migrate/migrations/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols.js deleted file mode 100644 index 83968b64a..000000000 --- a/server/db-migrate/migrations/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190715120834-inf-v-role-drop-rank-columns.js b/server/db-migrate/migrations/20190715120834-inf-v-role-drop-rank-columns.js deleted file mode 100644 index b211abfec..000000000 --- a/server/db-migrate/migrations/20190715120834-inf-v-role-drop-rank-columns.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190715120834-inf-v-role-drop-rank-columns-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190715120834-inf-v-role-drop-rank-columns-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190715154925-war-functions-tuning.js b/server/db-migrate/migrations/20190715154925-war-functions-tuning.js deleted file mode 100644 index 00bc25ad5..000000000 --- a/server/db-migrate/migrations/20190715154925-war-functions-tuning.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190715154925-war-functions-tuning-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190715154925-war-functions-tuning-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190717132146-war-trigger-functions-tuning.js b/server/db-migrate/migrations/20190717132146-war-trigger-functions-tuning.js deleted file mode 100644 index 9544e969d..000000000 --- a/server/db-migrate/migrations/20190717132146-war-trigger-functions-tuning.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190717132146-war-trigger-functions-tuning-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190717132146-war-trigger-functions-tuning-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190720123806-inf-f-add-pe-it-to-project-update.js b/server/db-migrate/migrations/20190720123806-inf-f-add-pe-it-to-project-update.js deleted file mode 100644 index b4e20ade2..000000000 --- a/server/db-migrate/migrations/20190720123806-inf-f-add-pe-it-to-project-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190720123806-inf-f-add-pe-it-to-project-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190720123806-inf-f-add-pe-it-to-project-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190720153605-inf-f-add-te-en-to-project.js b/server/db-migrate/migrations/20190720153605-inf-f-add-te-en-to-project.js deleted file mode 100644 index 6f0adbe64..000000000 --- a/server/db-migrate/migrations/20190720153605-inf-f-add-te-en-to-project.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190720153605-inf-f-add-te-en-to-project-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190720153605-inf-f-add-te-en-to-project-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190723083954-dfh-v-property.js b/server/db-migrate/migrations/20190723083954-dfh-v-property.js deleted file mode 100644 index 3fe5ffc6f..000000000 --- a/server/db-migrate/migrations/20190723083954-dfh-v-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190723083954-dfh-v-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190723083954-dfh-v-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190730144210-dat-t-cell-improve-performance.js b/server/db-migrate/migrations/20190730144210-dat-t-cell-improve-performance.js deleted file mode 100644 index 1109d77f9..000000000 --- a/server/db-migrate/migrations/20190730144210-dat-t-cell-improve-performance.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190730144210-dat-t-cell-improve-performance-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190730144210-dat-t-cell-improve-performance-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190730161751-dat-t-text-property-add-fk-entity.js b/server/db-migrate/migrations/20190730161751-dat-t-text-property-add-fk-entity.js deleted file mode 100644 index 216261e46..000000000 --- a/server/db-migrate/migrations/20190730161751-dat-t-text-property-add-fk-entity.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190730161751-dat-t-text-property-add-fk-entity-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190730161751-dat-t-text-property-add-fk-entity-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190802220445-pro-t-property-label.js b/server/db-migrate/migrations/20190802220445-pro-t-property-label.js deleted file mode 100644 index e938a0d0a..000000000 --- a/server/db-migrate/migrations/20190802220445-pro-t-property-label.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190802220445-pro-t-property-label-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190802220445-pro-t-property-label-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190821121040-tab-init-schema.js b/server/db-migrate/migrations/20190821121040-tab-init-schema.js deleted file mode 100644 index da8901f5f..000000000 --- a/server/db-migrate/migrations/20190821121040-tab-init-schema.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821121040-tab-init-schema-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821121040-tab-init-schema-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190821122546-tab-t-row.js b/server/db-migrate/migrations/20190821122546-tab-t-row.js deleted file mode 100644 index 40f1388a5..000000000 --- a/server/db-migrate/migrations/20190821122546-tab-t-row.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821122546-tab-t-row-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821122546-tab-t-row-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190821125131-tab-t-cell.js b/server/db-migrate/migrations/20190821125131-tab-t-cell.js deleted file mode 100644 index fb6230b8f..000000000 --- a/server/db-migrate/migrations/20190821125131-tab-t-cell.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821125131-tab-t-cell-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821125131-tab-t-cell-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190821131321-tab-t-quill-doc-cell.js b/server/db-migrate/migrations/20190821131321-tab-t-quill-doc-cell.js deleted file mode 100644 index c37233cbc..000000000 --- a/server/db-migrate/migrations/20190821131321-tab-t-quill-doc-cell.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821131321-tab-t-quill-doc-cell-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190821131321-tab-t-quill-doc-cell-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190823100949-inf-v-role-and-ea-parse-int.js b/server/db-migrate/migrations/20190823100949-inf-v-role-and-ea-parse-int.js deleted file mode 100644 index 358d251c6..000000000 --- a/server/db-migrate/migrations/20190823100949-inf-v-role-and-ea-parse-int.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190823100949-inf-v-role-and-ea-parse-int-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190823100949-inf-v-role-and-ea-parse-int-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190823200757-war-v-entity-preview-non-recursive.js b/server/db-migrate/migrations/20190823200757-war-v-entity-preview-non-recursive.js deleted file mode 100644 index c9cb0c569..000000000 --- a/server/db-migrate/migrations/20190823200757-war-v-entity-preview-non-recursive.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190823200757-war-v-entity-preview-non-recursive-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190823200757-war-v-entity-preview-non-recursive-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190828144659-dat-index-on-strings.js b/server/db-migrate/migrations/20190828144659-dat-index-on-strings.js deleted file mode 100644 index 56d391044..000000000 --- a/server/db-migrate/migrations/20190828144659-dat-index-on-strings.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828144659-dat-index-on-strings-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828144659-dat-index-on-strings-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190828145011-tab-fn-create-cell-table-update.js b/server/db-migrate/migrations/20190828145011-tab-fn-create-cell-table-update.js deleted file mode 100644 index aa57ac0c4..000000000 --- a/server/db-migrate/migrations/20190828145011-tab-fn-create-cell-table-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828145011-tab-fn-create-cell-table-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828145011-tab-fn-create-cell-table-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190828150816-tab-fn-rebuild-partitioned-table.js b/server/db-migrate/migrations/20190828150816-tab-fn-rebuild-partitioned-table.js deleted file mode 100644 index 4d7a76c51..000000000 --- a/server/db-migrate/migrations/20190828150816-tab-fn-rebuild-partitioned-table.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828150816-tab-fn-rebuild-partitioned-table-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828150816-tab-fn-rebuild-partitioned-table-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190828151011-enitity-and-data-associations.js b/server/db-migrate/migrations/20190828151011-enitity-and-data-associations.js deleted file mode 100644 index b9a13e645..000000000 --- a/server/db-migrate/migrations/20190828151011-enitity-and-data-associations.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828151011-enitity-and-data-associations-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190828151011-enitity-and-data-associations-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20190911070249-dat-vt-index-on-strings.js b/server/db-migrate/migrations/20190911070249-dat-vt-index-on-strings.js deleted file mode 100644 index 6c65ad691..000000000 --- a/server/db-migrate/migrations/20190911070249-dat-vt-index-on-strings.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190911070249-dat-vt-index-on-strings-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190911070249-dat-vt-index-on-strings-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003195445-war-t-entity-preview-non-recursive.js b/server/db-migrate/migrations/20191003195445-war-t-entity-preview-non-recursive.js deleted file mode 100644 index 1caa4b83d..000000000 --- a/server/db-migrate/migrations/20191003195445-war-t-entity-preview-non-recursive.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003195445-war-t-entity-preview-non-recursive-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003195445-war-t-entity-preview-non-recursive-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003200029-war-f-entity-preview-non-recursive-create.js b/server/db-migrate/migrations/20191003200029-war-f-entity-preview-non-recursive-create.js deleted file mode 100644 index 3d1fbf592..000000000 --- a/server/db-migrate/migrations/20191003200029-war-f-entity-preview-non-recursive-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003200029-war-f-entity-preview-non-recursive-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003200029-war-f-entity-preview-non-recursive-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003210727-war-f-entity-preview-non-recursive-create-all.js b/server/db-migrate/migrations/20191003210727-war-f-entity-preview-non-recursive-create-all.js deleted file mode 100644 index c0f2410c2..000000000 --- a/server/db-migrate/migrations/20191003210727-war-f-entity-preview-non-recursive-create-all.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003210727-war-f-entity-preview-non-recursive-create-all-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003210727-war-f-entity-preview-non-recursive-create-all-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003212744-war-f-entity-preview-update-from-non-recursive.js b/server/db-migrate/migrations/20191003212744-war-f-entity-preview-update-from-non-recursive.js deleted file mode 100644 index c19d18b9c..000000000 --- a/server/db-migrate/migrations/20191003212744-war-f-entity-preview-update-from-non-recursive.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003212744-war-f-entity-preview-update-from-non-recursive-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003212744-war-f-entity-preview-update-from-non-recursive-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003212939-war-f-entity-preview-create-temporary.js b/server/db-migrate/migrations/20191003212939-war-f-entity-preview-create-temporary.js deleted file mode 100644 index 0db684651..000000000 --- a/server/db-migrate/migrations/20191003212939-war-f-entity-preview-create-temporary.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003212939-war-f-entity-preview-create-temporary-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003212939-war-f-entity-preview-create-temporary-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191003213848-war-f-entity-preview-non-recursive-helpers.js b/server/db-migrate/migrations/20191003213848-war-f-entity-preview-non-recursive-helpers.js deleted file mode 100644 index 067bbd0df..000000000 --- a/server/db-migrate/migrations/20191003213848-war-f-entity-preview-non-recursive-helpers.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003213848-war-f-entity-preview-non-recursive-helpers-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191003213848-war-f-entity-preview-non-recursive-helpers-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191004101109-war-f-entity-preview-non-recursive-upsert.js b/server/db-migrate/migrations/20191004101109-war-f-entity-preview-non-recursive-upsert.js deleted file mode 100644 index ecc30b194..000000000 --- a/server/db-migrate/migrations/20191004101109-war-f-entity-preview-non-recursive-upsert.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004101109-war-f-entity-preview-non-recursive-upsert-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004101109-war-f-entity-preview-non-recursive-upsert-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191004110430-war-f-entity-preview-non-recursive-delete.js b/server/db-migrate/migrations/20191004110430-war-f-entity-preview-non-recursive-delete.js deleted file mode 100644 index e651ccb18..000000000 --- a/server/db-migrate/migrations/20191004110430-war-f-entity-preview-non-recursive-delete.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004110430-war-f-entity-preview-non-recursive-delete-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004110430-war-f-entity-preview-non-recursive-delete-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191004112546-war-tf-info-proj-rel-upsert.js b/server/db-migrate/migrations/20191004112546-war-tf-info-proj-rel-upsert.js deleted file mode 100644 index 1aafd3132..000000000 --- a/server/db-migrate/migrations/20191004112546-war-tf-info-proj-rel-upsert.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004112546-war-tf-info-proj-rel-upsert-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004112546-war-tf-info-proj-rel-upsert-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191004143037-war-f-update-class-labels.js b/server/db-migrate/migrations/20191004143037-war-f-update-class-labels.js deleted file mode 100644 index e94876917..000000000 --- a/server/db-migrate/migrations/20191004143037-war-f-update-class-labels.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004143037-war-f-update-class-labels-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004143037-war-f-update-class-labels-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191004144005-war-cleanup.js b/server/db-migrate/migrations/20191004144005-war-cleanup.js deleted file mode 100644 index 1c459a6c6..000000000 --- a/server/db-migrate/migrations/20191004144005-war-cleanup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004144005-war-cleanup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191004144005-war-cleanup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191007102252-war-split-part-1-and-2.js b/server/db-migrate/migrations/20191007102252-war-split-part-1-and-2.js deleted file mode 100644 index a0e51fd08..000000000 --- a/server/db-migrate/migrations/20191007102252-war-split-part-1-and-2.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191007102252-war-split-part-1-and-2-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191007102252-war-split-part-1-and-2-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191007171501-war-init-entity-previews.js b/server/db-migrate/migrations/20191007171501-war-init-entity-previews.js deleted file mode 100644 index 135fbc2ce..000000000 --- a/server/db-migrate/migrations/20191007171501-war-init-entity-previews.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191007171501-war-init-entity-previews-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191007171501-war-init-entity-previews-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191008134112-com-f-is-numeric.js b/server/db-migrate/migrations/20191008134112-com-f-is-numeric.js deleted file mode 100644 index 649ea77de..000000000 --- a/server/db-migrate/migrations/20191008134112-com-f-is-numeric.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191008134112-com-f-is-numeric-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191008134112-com-f-is-numeric-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191009064252-inf-f-add-pe-it.js b/server/db-migrate/migrations/20191009064252-inf-f-add-pe-it.js deleted file mode 100644 index c9658d8cf..000000000 --- a/server/db-migrate/migrations/20191009064252-inf-f-add-pe-it.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191009064252-inf-f-add-pe-it-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191009064252-inf-f-add-pe-it-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191009083127-war-warehouse-update-request-change.js b/server/db-migrate/migrations/20191009083127-war-warehouse-update-request-change.js deleted file mode 100644 index 51a4033e1..000000000 --- a/server/db-migrate/migrations/20191009083127-war-warehouse-update-request-change.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191009083127-war-warehouse-update-request-change-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191009083127-war-warehouse-update-request-change-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191010155210-war-functions-update.js b/server/db-migrate/migrations/20191010155210-war-functions-update.js deleted file mode 100644 index aec4c739b..000000000 --- a/server/db-migrate/migrations/20191010155210-war-functions-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191010155210-war-functions-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191010155210-war-functions-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191010155211-com-f-clone-project.js b/server/db-migrate/migrations/20191010155211-com-f-clone-project.js deleted file mode 100644 index 4f34ee2c7..000000000 --- a/server/db-migrate/migrations/20191010155211-com-f-clone-project.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191010155211-com-f-clone-project-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191010155211-com-f-clone-project-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191016104029-com-f-julian-calendar-functions.js b/server/db-migrate/migrations/20191016104029-com-f-julian-calendar-functions.js deleted file mode 100644 index dd2aae749..000000000 --- a/server/db-migrate/migrations/20191016104029-com-f-julian-calendar-functions.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016104029-com-f-julian-calendar-functions-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016104029-com-f-julian-calendar-functions-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191016121842-war-add-first-and-last-julian-second.js b/server/db-migrate/migrations/20191016121842-war-add-first-and-last-julian-second.js deleted file mode 100644 index 2c11ec1b7..000000000 --- a/server/db-migrate/migrations/20191016121842-war-add-first-and-last-julian-second.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016121842-war-add-first-and-last-julian-second-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016121842-war-add-first-and-last-julian-second-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191016134407-war-do-update-function.js b/server/db-migrate/migrations/20191016134407-war-do-update-function.js deleted file mode 100644 index c09a57a40..000000000 --- a/server/db-migrate/migrations/20191016134407-war-do-update-function.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016134407-war-do-update-function-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191016134407-war-do-update-function-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191029104556-war-entity-preview-non-rec-create-all-fix.js b/server/db-migrate/migrations/20191029104556-war-entity-preview-non-rec-create-all-fix.js deleted file mode 100644 index be69ebba6..000000000 --- a/server/db-migrate/migrations/20191029104556-war-entity-preview-non-rec-create-all-fix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191029104556-war-entity-preview-non-rec-create-all-fix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191029104556-war-entity-preview-non-rec-create-all-fix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191101150953-sys-t-analysis-type.js b/server/db-migrate/migrations/20191101150953-sys-t-analysis-type.js deleted file mode 100644 index 13d568e59..000000000 --- a/server/db-migrate/migrations/20191101150953-sys-t-analysis-type.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191101150953-sys-t-analysis-type-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191101150953-sys-t-analysis-type-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191101151422-pro-t-analysis.js b/server/db-migrate/migrations/20191101151422-pro-t-analysis.js deleted file mode 100644 index 48707abed..000000000 --- a/server/db-migrate/migrations/20191101151422-pro-t-analysis.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191101151422-pro-t-analysis-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191101151422-pro-t-analysis-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191106183035-ana-f-time-chart-cont.js b/server/db-migrate/migrations/20191106183035-ana-f-time-chart-cont.js deleted file mode 100644 index 5a8f74824..000000000 --- a/server/db-migrate/migrations/20191106183035-ana-f-time-chart-cont.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191106183035-ana-f-time-chart-cont-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191106183035-ana-f-time-chart-cont-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191119144114-war-mv-statement.js b/server/db-migrate/migrations/20191119144114-war-mv-statement.js deleted file mode 100644 index e9f98cad2..000000000 --- a/server/db-migrate/migrations/20191119144114-war-mv-statement.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191119144114-war-mv-statement-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191119144114-war-mv-statement-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191119160856-com-f-analysis-space-time-cont.js b/server/db-migrate/migrations/20191119160856-com-f-analysis-space-time-cont.js deleted file mode 100644 index de0627666..000000000 --- a/server/db-migrate/migrations/20191119160856-com-f-analysis-space-time-cont.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191119160856-com-f-analysis-space-time-cont-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191119160856-com-f-analysis-space-time-cont-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191203145034-com-f-analysis-space-time-cont-2.js b/server/db-migrate/migrations/20191203145034-com-f-analysis-space-time-cont-2.js deleted file mode 100644 index 9783dd605..000000000 --- a/server/db-migrate/migrations/20191203145034-com-f-analysis-space-time-cont-2.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191203145034-com-f-analysis-space-time-cont-2-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191203145034-com-f-analysis-space-time-cont-2-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191205082041-pro-t-class-field-config-update.js b/server/db-migrate/migrations/20191205082041-pro-t-class-field-config-update.js deleted file mode 100644 index 0fc97d1d5..000000000 --- a/server/db-migrate/migrations/20191205082041-pro-t-class-field-config-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191205082041-pro-t-class-field-config-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191205082041-pro-t-class-field-config-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191205174623-inf-migrate-fk-property.js b/server/db-migrate/migrations/20191205174623-inf-migrate-fk-property.js deleted file mode 100644 index 76cd2cc55..000000000 --- a/server/db-migrate/migrations/20191205174623-inf-migrate-fk-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191205174623-inf-migrate-fk-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191205174623-inf-migrate-fk-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206101554-war-f-entity-preview-non-recursive--create.js b/server/db-migrate/migrations/20191206101554-war-f-entity-preview-non-recursive--create.js deleted file mode 100644 index 7b00f81c6..000000000 --- a/server/db-migrate/migrations/20191206101554-war-f-entity-preview-non-recursive--create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206101554-war-f-entity-preview-non-recursive--create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206101554-war-f-entity-preview-non-recursive--create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206111710-war-f-entity-preview-update-queue-worker.js b/server/db-migrate/migrations/20191206111710-war-f-entity-preview-update-queue-worker.js deleted file mode 100644 index 243b4779b..000000000 --- a/server/db-migrate/migrations/20191206111710-war-f-entity-preview-update-queue-worker.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206111710-war-f-entity-preview-update-queue-worker-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206111710-war-f-entity-preview-update-queue-worker-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206112815-war-f-entity-preview-non-recursive--create-all.js b/server/db-migrate/migrations/20191206112815-war-f-entity-preview-non-recursive--create-all.js deleted file mode 100644 index 5fe6c645c..000000000 --- a/server/db-migrate/migrations/20191206112815-war-f-entity-preview-non-recursive--create-all.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206112815-war-f-entity-preview-non-recursive--create-all-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206112815-war-f-entity-preview-non-recursive--create-all-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206113445-war-f-entity-preview--refresh-all.js b/server/db-migrate/migrations/20191206113445-war-f-entity-preview--refresh-all.js deleted file mode 100644 index 5876ab4c5..000000000 --- a/server/db-migrate/migrations/20191206113445-war-f-entity-preview--refresh-all.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206113445-war-f-entity-preview--refresh-all-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206113445-war-f-entity-preview--refresh-all-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206130212-war-f-do-updates-for-time-after.js b/server/db-migrate/migrations/20191206130212-war-f-do-updates-for-time-after.js deleted file mode 100644 index 0706dab5f..000000000 --- a/server/db-migrate/migrations/20191206130212-war-f-do-updates-for-time-after.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206130212-war-f-do-updates-for-time-after-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206130212-war-f-do-updates-for-time-after-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191206134715-inf-v-role.js b/server/db-migrate/migrations/20191206134715-inf-v-role.js deleted file mode 100644 index 74040a755..000000000 --- a/server/db-migrate/migrations/20191206134715-inf-v-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206134715-inf-v-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191206134715-inf-v-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191211080436-dfh-v-class.js b/server/db-migrate/migrations/20191211080436-dfh-v-class.js deleted file mode 100644 index fc0cf0a70..000000000 --- a/server/db-migrate/migrations/20191211080436-dfh-v-class.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191211080436-dfh-v-class-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191211080436-dfh-v-class-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191211130640-inf-f-add-functions.js b/server/db-migrate/migrations/20191211130640-inf-f-add-functions.js deleted file mode 100644 index 1da41d392..000000000 --- a/server/db-migrate/migrations/20191211130640-inf-f-add-functions.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191211130640-inf-f-add-functions-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191211130640-inf-f-add-functions-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191212080452-dfh-t-api-profile.js b/server/db-migrate/migrations/20191212080452-dfh-t-api-profile.js deleted file mode 100644 index de3bb939a..000000000 --- a/server/db-migrate/migrations/20191212080452-dfh-t-api-profile.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212080452-dfh-t-api-profile-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212080452-dfh-t-api-profile-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191212084248-pro-t-dfh-profile-proj-rel.js b/server/db-migrate/migrations/20191212084248-pro-t-dfh-profile-proj-rel.js deleted file mode 100644 index d7d99ae3d..000000000 --- a/server/db-migrate/migrations/20191212084248-pro-t-dfh-profile-proj-rel.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212084248-pro-t-dfh-profile-proj-rel-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212084248-pro-t-dfh-profile-proj-rel-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191212161931-dfh-t-api-classes-profile.js b/server/db-migrate/migrations/20191212161931-dfh-t-api-classes-profile.js deleted file mode 100644 index be975cdc3..000000000 --- a/server/db-migrate/migrations/20191212161931-dfh-t-api-classes-profile.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212161931-dfh-t-api-classes-profile-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212161931-dfh-t-api-classes-profile-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191212162208-dfh-t-api-properties-profile.js b/server/db-migrate/migrations/20191212162208-dfh-t-api-properties-profile.js deleted file mode 100644 index b85602f7f..000000000 --- a/server/db-migrate/migrations/20191212162208-dfh-t-api-properties-profile.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212162208-dfh-t-api-properties-profile-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191212162208-dfh-t-api-properties-profile-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191212162209-dfh-f-udate-api-tables.js b/server/db-migrate/migrations/20191212162209-dfh-f-udate-api-tables.js deleted file mode 100644 index 4214bb7a7..000000000 --- a/server/db-migrate/migrations/20191212162209-dfh-f-udate-api-tables.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join( - __dirname, - 'sqls', - '20191212162209-dfh-f-udate-api-tables-up.sql' - ); - return new Promise(function(resolve, reject) { - fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join( - __dirname, - 'sqls', - '20191212162209-dfh-f-udate-api-tables-down.sql' - ); - return new Promise(function(resolve, reject) { - fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20191213104121-dfh-v-profile.js b/server/db-migrate/migrations/20191213104121-dfh-v-profile.js deleted file mode 100644 index b1d694bc8..000000000 --- a/server/db-migrate/migrations/20191213104121-dfh-v-profile.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213104121-dfh-v-profile-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213104121-dfh-v-profile-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191213131829-dfh-v-label.js b/server/db-migrate/migrations/20191213131829-dfh-v-label.js deleted file mode 100644 index 040f31b15..000000000 --- a/server/db-migrate/migrations/20191213131829-dfh-v-label.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213131829-dfh-v-label-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213131829-dfh-v-label-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191213132001-dfh-v-class.js b/server/db-migrate/migrations/20191213132001-dfh-v-class.js deleted file mode 100644 index a6618ea32..000000000 --- a/server/db-migrate/migrations/20191213132001-dfh-v-class.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213132001-dfh-v-class-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213132001-dfh-v-class-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191213134241-dfh-v-property.js b/server/db-migrate/migrations/20191213134241-dfh-v-property.js deleted file mode 100644 index 215f79005..000000000 --- a/server/db-migrate/migrations/20191213134241-dfh-v-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213134241-dfh-v-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213134241-dfh-v-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191213135247-pro-t-dfh-class-proj-rel-data-migration.js b/server/db-migrate/migrations/20191213135247-pro-t-dfh-class-proj-rel-data-migration.js deleted file mode 100644 index c3b351a3a..000000000 --- a/server/db-migrate/migrations/20191213135247-pro-t-dfh-class-proj-rel-data-migration.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213135247-pro-t-dfh-class-proj-rel-data-migration-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191213135247-pro-t-dfh-class-proj-rel-data-migration-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191214182047-pro-t-text-property-extention.js b/server/db-migrate/migrations/20191214182047-pro-t-text-property-extention.js deleted file mode 100644 index e86365a9f..000000000 --- a/server/db-migrate/migrations/20191214182047-pro-t-text-property-extention.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191214182047-pro-t-text-property-extention-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191214182047-pro-t-text-property-extention-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191218124631-pro-class-field-config-reset.js b/server/db-migrate/migrations/20191218124631-pro-class-field-config-reset.js deleted file mode 100644 index cd9570e43..000000000 --- a/server/db-migrate/migrations/20191218124631-pro-class-field-config-reset.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191218124631-pro-class-field-config-reset-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191218124631-pro-class-field-config-reset-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191218210956-war-f-create-non-recursive.js b/server/db-migrate/migrations/20191218210956-war-f-create-non-recursive.js deleted file mode 100644 index 019f4c010..000000000 --- a/server/db-migrate/migrations/20191218210956-war-f-create-non-recursive.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191218210956-war-f-create-non-recursive-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191218210956-war-f-create-non-recursive-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191223123045-war-update.js b/server/db-migrate/migrations/20191223123045-war-update.js deleted file mode 100644 index 9770ae982..000000000 --- a/server/db-migrate/migrations/20191223123045-war-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191223123045-war-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191223123045-war-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191227215440-inf-d-migrate-has-type-to-role.js b/server/db-migrate/migrations/20191227215440-inf-d-migrate-has-type-to-role.js deleted file mode 100644 index 3feeb3e21..000000000 --- a/server/db-migrate/migrations/20191227215440-inf-d-migrate-has-type-to-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191227215440-inf-d-migrate-has-type-to-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191227215440-inf-d-migrate-has-type-to-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191229104108-war-drop-old-warehouse.js b/server/db-migrate/migrations/20191229104108-war-drop-old-warehouse.js deleted file mode 100644 index 438c00646..000000000 --- a/server/db-migrate/migrations/20191229104108-war-drop-old-warehouse.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229104108-war-drop-old-warehouse-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229104108-war-drop-old-warehouse-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191229114550-war-v-ent-ass-per-proj-and-repo.js b/server/db-migrate/migrations/20191229114550-war-v-ent-ass-per-proj-and-repo.js deleted file mode 100644 index f32508330..000000000 --- a/server/db-migrate/migrations/20191229114550-war-v-ent-ass-per-proj-and-repo.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229114550-war-v-ent-ass-per-proj-and-repo-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229114550-war-v-ent-ass-per-proj-and-repo-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191229154824-pro-dfh-relations-cleanup.js b/server/db-migrate/migrations/20191229154824-pro-dfh-relations-cleanup.js deleted file mode 100644 index 3c0a16268..000000000 --- a/server/db-migrate/migrations/20191229154824-pro-dfh-relations-cleanup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229154824-pro-dfh-relations-cleanup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191229154824-pro-dfh-relations-cleanup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191230141529-war-v-property-preview.js b/server/db-migrate/migrations/20191230141529-war-v-property-preview.js deleted file mode 100644 index eb7a96eda..000000000 --- a/server/db-migrate/migrations/20191230141529-war-v-property-preview.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191230141529-war-v-property-preview-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191230141529-war-v-property-preview-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191230163403-pro-f-deactivate-ontome-profile.js b/server/db-migrate/migrations/20191230163403-pro-f-deactivate-ontome-profile.js deleted file mode 100644 index e60364162..000000000 --- a/server/db-migrate/migrations/20191230163403-pro-f-deactivate-ontome-profile.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191230163403-pro-f-deactivate-ontome-profile-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191230163403-pro-f-deactivate-ontome-profile-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20191231135724-inf-f-add-entity-functions.js b/server/db-migrate/migrations/20191231135724-inf-f-add-entity-functions.js deleted file mode 100644 index 7bdeece21..000000000 --- a/server/db-migrate/migrations/20191231135724-inf-f-add-entity-functions.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191231135724-inf-f-add-entity-functions-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20191231135724-inf-f-add-entity-functions-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200101195804-war-again.js b/server/db-migrate/migrations/20200101195804-war-again.js deleted file mode 100644 index 8fc1847ec..000000000 --- a/server/db-migrate/migrations/20200101195804-war-again.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200101195804-war-again-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200101195804-war-again-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200102163813-com-f-rename-warehouse-to-war.js b/server/db-migrate/migrations/20200102163813-com-f-rename-warehouse-to-war.js deleted file mode 100644 index 55eefe797..000000000 --- a/server/db-migrate/migrations/20200102163813-com-f-rename-warehouse-to-war.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200102163813-com-f-rename-warehouse-to-war-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200102163813-com-f-rename-warehouse-to-war-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200103153746-inf-change-class-constraint.js b/server/db-migrate/migrations/20200103153746-inf-change-class-constraint.js deleted file mode 100644 index 43d86d61a..000000000 --- a/server/db-migrate/migrations/20200103153746-inf-change-class-constraint.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200103153746-inf-change-class-constraint-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200103153746-inf-change-class-constraint-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200103160115-inf-change-property-constraint.js b/server/db-migrate/migrations/20200103160115-inf-change-property-constraint.js deleted file mode 100644 index 54326020d..000000000 --- a/server/db-migrate/migrations/20200103160115-inf-change-property-constraint.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200103160115-inf-change-property-constraint-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200103160115-inf-change-property-constraint-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200104103447-inf-f-temporal-entity-find-or-create.js b/server/db-migrate/migrations/20200104103447-inf-f-temporal-entity-find-or-create.js deleted file mode 100644 index de60708d7..000000000 --- a/server/db-migrate/migrations/20200104103447-inf-f-temporal-entity-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104103447-inf-f-temporal-entity-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104103447-inf-f-temporal-entity-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200104131225-war-f-entity-label.js b/server/db-migrate/migrations/20200104131225-war-f-entity-label.js deleted file mode 100644 index 730779863..000000000 --- a/server/db-migrate/migrations/20200104131225-war-f-entity-label.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104131225-war-f-entity-label-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104131225-war-f-entity-label-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200104190944-inf-f-temporal-entity-find-or-create.js b/server/db-migrate/migrations/20200104190944-inf-f-temporal-entity-find-or-create.js deleted file mode 100644 index 4934cf595..000000000 --- a/server/db-migrate/migrations/20200104190944-inf-f-temporal-entity-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104190944-inf-f-temporal-entity-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200104190944-inf-f-temporal-entity-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200108171858-inf-entity-find-or-create.js b/server/db-migrate/migrations/20200108171858-inf-entity-find-or-create.js deleted file mode 100644 index b7555beec..000000000 --- a/server/db-migrate/migrations/20200108171858-inf-entity-find-or-create.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200108171858-inf-entity-find-or-create-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200108171858-inf-entity-find-or-create-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200121163602-dfh-v-property-add-generic-prop-1111.js b/server/db-migrate/migrations/20200121163602-dfh-v-property-add-generic-prop-1111.js deleted file mode 100644 index 1fffccb41..000000000 --- a/server/db-migrate/migrations/20200121163602-dfh-v-property-add-generic-prop-1111.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200121163602-dfh-v-property-add-generic-prop-1111-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200121163602-dfh-v-property-add-generic-prop-1111-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224145951-war-t-enriched-node-add-tmsp.js b/server/db-migrate/migrations/20200224145951-war-t-enriched-node-add-tmsp.js deleted file mode 100644 index d4e2a4399..000000000 --- a/server/db-migrate/migrations/20200224145951-war-t-enriched-node-add-tmsp.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224145951-war-t-enriched-node-add-tmsp-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224145951-war-t-enriched-node-add-tmsp-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224150459-war-f-enriched-nodes--create-some.js b/server/db-migrate/migrations/20200224150459-war-f-enriched-nodes--create-some.js deleted file mode 100644 index 29127bc38..000000000 --- a/server/db-migrate/migrations/20200224150459-war-f-enriched-nodes--create-some.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224150459-war-f-enriched-nodes--create-some-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224150459-war-f-enriched-nodes--create-some-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224152248-war-f-enriched-nodes--upsert-some.js b/server/db-migrate/migrations/20200224152248-war-f-enriched-nodes--upsert-some.js deleted file mode 100644 index 227c80d1d..000000000 --- a/server/db-migrate/migrations/20200224152248-war-f-enriched-nodes--upsert-some.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224152248-war-f-enriched-nodes--upsert-some-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224152248-war-f-enriched-nodes--upsert-some-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224161046-war-v-class-label.js b/server/db-migrate/migrations/20200224161046-war-v-class-label.js deleted file mode 100644 index 53f80cb8f..000000000 --- a/server/db-migrate/migrations/20200224161046-war-v-class-label.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224161046-war-v-class-label-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224161046-war-v-class-label-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224162153-war-f-edges--upsert-some.js b/server/db-migrate/migrations/20200224162153-war-f-edges--upsert-some.js deleted file mode 100644 index f2a9746fe..000000000 --- a/server/db-migrate/migrations/20200224162153-war-f-edges--upsert-some.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224162153-war-f-edges--upsert-some-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224162153-war-f-edges--upsert-some-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200224174424-war-f-do-updates-for-difference-since.js b/server/db-migrate/migrations/20200224174424-war-f-do-updates-for-difference-since.js deleted file mode 100644 index 0d12feeb1..000000000 --- a/server/db-migrate/migrations/20200224174424-war-f-do-updates-for-difference-since.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224174424-war-f-do-updates-for-difference-since-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200224174424-war-f-do-updates-for-difference-since-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200225122737-war-f-enriched-nodes--create-all.js b/server/db-migrate/migrations/20200225122737-war-f-enriched-nodes--create-all.js deleted file mode 100644 index 82758f28b..000000000 --- a/server/db-migrate/migrations/20200225122737-war-f-enriched-nodes--create-all.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225122737-war-f-enriched-nodes--create-all-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225122737-war-f-enriched-nodes--create-all-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200225123546-war-f-nodes-and-edges--update-all.js b/server/db-migrate/migrations/20200225123546-war-f-nodes-and-edges--update-all.js deleted file mode 100644 index 00c9f36c2..000000000 --- a/server/db-migrate/migrations/20200225123546-war-f-nodes-and-edges--update-all.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join( - __dirname, - 'sqls', - '20200225123546-war-f-nodes-and-edges--update-all-up.sql' - ); - return new Promise(function(resolve, reject) { - fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join( - __dirname, - 'sqls', - '20200225123546-war-f-nodes-and-edges--update-all-down.sql' - ); - return new Promise(function(resolve, reject) { - fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20200225132753-war-fix-small-indexes.js b/server/db-migrate/migrations/20200225132753-war-fix-small-indexes.js deleted file mode 100644 index dc490a7b9..000000000 --- a/server/db-migrate/migrations/20200225132753-war-fix-small-indexes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225132753-war-fix-small-indexes-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225132753-war-fix-small-indexes-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200225134631-war-cleanup.js b/server/db-migrate/migrations/20200225134631-war-cleanup.js deleted file mode 100644 index ddaa65f07..000000000 --- a/server/db-migrate/migrations/20200225134631-war-cleanup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225134631-war-cleanup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200225134631-war-cleanup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200226163610-pro-delete-constraint.js b/server/db-migrate/migrations/20200226163610-pro-delete-constraint.js deleted file mode 100644 index 49087c358..000000000 --- a/server/db-migrate/migrations/20200226163610-pro-delete-constraint.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200226163610-pro-delete-constraint-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200226163610-pro-delete-constraint-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200305122338-dfh-t-property-of-property.js b/server/db-migrate/migrations/20200305122338-dfh-t-property-of-property.js deleted file mode 100644 index 689de22a6..000000000 --- a/server/db-migrate/migrations/20200305122338-dfh-t-property-of-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200305122338-dfh-t-property-of-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200305122338-dfh-t-property-of-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200305125536-inf-t-statement-of-statement.js b/server/db-migrate/migrations/20200305125536-inf-t-statement-of-statement.js deleted file mode 100644 index a196cf648..000000000 --- a/server/db-migrate/migrations/20200305125536-inf-t-statement-of-statement.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200305125536-inf-t-statement-of-statement-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200305125536-inf-t-statement-of-statement-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200309143420-dat-t-column-rework.js b/server/db-migrate/migrations/20200309143420-dat-t-column-rework.js deleted file mode 100644 index abb67724e..000000000 --- a/server/db-migrate/migrations/20200309143420-dat-t-column-rework.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200309143420-dat-t-column-rework-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200309143420-dat-t-column-rework-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200309151359-dat-t-cell-and-row.js b/server/db-migrate/migrations/20200309151359-dat-t-cell-and-row.js deleted file mode 100644 index 00ab2f0ff..000000000 --- a/server/db-migrate/migrations/20200309151359-dat-t-cell-and-row.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200309151359-dat-t-cell-and-row-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200309151359-dat-t-cell-and-row-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200318131855-inf-t-merge-ea-to-role.js b/server/db-migrate/migrations/20200318131855-inf-t-merge-ea-to-role.js deleted file mode 100644 index 98935f08c..000000000 --- a/server/db-migrate/migrations/20200318131855-inf-t-merge-ea-to-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318131855-inf-t-merge-ea-to-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318131855-inf-t-merge-ea-to-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200318133353-inf-d-copy-ea-to-role.js b/server/db-migrate/migrations/20200318133353-inf-d-copy-ea-to-role.js deleted file mode 100644 index e42fa920c..000000000 --- a/server/db-migrate/migrations/20200318133353-inf-d-copy-ea-to-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318133353-inf-d-copy-ea-to-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318133353-inf-d-copy-ea-to-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role.js b/server/db-migrate/migrations/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role.js deleted file mode 100644 index dffc899c5..000000000 --- a/server/db-migrate/migrations/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200320105024-com-f-clone-sandbox-ea-to-role.js b/server/db-migrate/migrations/20200320105024-com-f-clone-sandbox-ea-to-role.js deleted file mode 100644 index db0af9b0b..000000000 --- a/server/db-migrate/migrations/20200320105024-com-f-clone-sandbox-ea-to-role.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200320105024-com-f-clone-sandbox-ea-to-role-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200320105024-com-f-clone-sandbox-ea-to-role-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200320134917-inf-ea-to-role-cleanup.js b/server/db-migrate/migrations/20200320134917-inf-ea-to-role-cleanup.js deleted file mode 100644 index 8424f0874..000000000 --- a/server/db-migrate/migrations/20200320134917-inf-ea-to-role-cleanup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200320134917-inf-ea-to-role-cleanup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200320134917-inf-ea-to-role-cleanup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200323141313-cleanup-data-related-to-digitals.js b/server/db-migrate/migrations/20200323141313-cleanup-data-related-to-digitals.js deleted file mode 100644 index c03921eff..000000000 --- a/server/db-migrate/migrations/20200323141313-cleanup-data-related-to-digitals.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200323141313-cleanup-data-related-to-digitals-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200323141313-cleanup-data-related-to-digitals-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200326064159-inf-t-lang-string.js b/server/db-migrate/migrations/20200326064159-inf-t-lang-string.js deleted file mode 100644 index 8e5c0196a..000000000 --- a/server/db-migrate/migrations/20200326064159-inf-t-lang-string.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200326064159-inf-t-lang-string-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200326064159-inf-t-lang-string-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200326120045-inf-t-drop-statement-of-statement.js b/server/db-migrate/migrations/20200326120045-inf-t-drop-statement-of-statement.js deleted file mode 100644 index 92bb182a6..000000000 --- a/server/db-migrate/migrations/20200326120045-inf-t-drop-statement-of-statement.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200326120045-inf-t-drop-statement-of-statement-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200326120045-inf-t-drop-statement-of-statement-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200403122139-dfh-property-of-property.js b/server/db-migrate/migrations/20200403122139-dfh-property-of-property.js deleted file mode 100644 index b85f6fe69..000000000 --- a/server/db-migrate/migrations/20200403122139-dfh-property-of-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200403122139-dfh-property-of-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200403122139-dfh-property-of-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200421133152-inf-f-add-te-en.js b/server/db-migrate/migrations/20200421133152-inf-f-add-te-en.js deleted file mode 100644 index d8b969c79..000000000 --- a/server/db-migrate/migrations/20200421133152-inf-f-add-te-en.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200421133152-inf-f-add-te-en-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200421133152-inf-f-add-te-en-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200512124546-inf-t-role-renaming.js b/server/db-migrate/migrations/20200512124546-inf-t-role-renaming.js deleted file mode 100644 index 3b8110c4a..000000000 --- a/server/db-migrate/migrations/20200512124546-inf-t-role-renaming.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200512124546-inf-t-role-renaming-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200512124546-inf-t-role-renaming-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200701063201-lb3-account-to-lb4-accountCredentials.js b/server/db-migrate/migrations/20200701063201-lb3-account-to-lb4-accountCredentials.js deleted file mode 100644 index f0cfe6b73..000000000 --- a/server/db-migrate/migrations/20200701063201-lb3-account-to-lb4-accountCredentials.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200701063201-lb3-account-to-lb4-accountCredentials-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200701063201-lb3-account-to-lb4-accountCredentials-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200709093513-inf-v-entity-class-map.js b/server/db-migrate/migrations/20200709093513-inf-v-entity-class-map.js deleted file mode 100644 index f997c2c5a..000000000 --- a/server/db-migrate/migrations/20200709093513-inf-v-entity-class-map.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200709093513-inf-v-entity-class-map-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200709093513-inf-v-entity-class-map-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200713203022-sys-t-config.js b/server/db-migrate/migrations/20200713203022-sys-t-config.js deleted file mode 100644 index 9212b0357..000000000 --- a/server/db-migrate/migrations/20200713203022-sys-t-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200713203022-sys-t-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200713203022-sys-t-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200722072503-inf-f-find-or-create-language.js b/server/db-migrate/migrations/20200722072503-inf-f-find-or-create-language.js deleted file mode 100644 index e158c5988..000000000 --- a/server/db-migrate/migrations/20200722072503-inf-f-find-or-create-language.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200722072503-inf-f-find-or-create-language-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200722072503-inf-f-find-or-create-language-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200813120000-hotfix-statement-vt-trigger.js b/server/db-migrate/migrations/20200813120000-hotfix-statement-vt-trigger.js deleted file mode 100644 index ed46ec5e8..000000000 --- a/server/db-migrate/migrations/20200813120000-hotfix-statement-vt-trigger.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200813120000-hotfix-statement-vt-trigger-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200813120000-hotfix-statement-vt-trigger-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200819090548-pro-t-text-property-vt.js b/server/db-migrate/migrations/20200819090548-pro-t-text-property-vt.js deleted file mode 100644 index c146aa7b3..000000000 --- a/server/db-migrate/migrations/20200819090548-pro-t-text-property-vt.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200819090548-pro-t-text-property-vt-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200819090548-pro-t-text-property-vt-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200820140830-com-f-update-notification.js b/server/db-migrate/migrations/20200820140830-com-f-update-notification.js deleted file mode 100644 index e6d1e772f..000000000 --- a/server/db-migrate/migrations/20200820140830-com-f-update-notification.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200820140830-com-f-update-notification-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200820140830-com-f-update-notification-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200824104247-war-t-class-label.js b/server/db-migrate/migrations/20200824104247-war-t-class-label.js deleted file mode 100644 index 2a47fc1d4..000000000 --- a/server/db-migrate/migrations/20200824104247-war-t-class-label.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200824104247-war-t-class-label-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200824104247-war-t-class-label-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200831161624-pro-t-entity-label-config.js b/server/db-migrate/migrations/20200831161624-pro-t-entity-label-config.js deleted file mode 100644 index cc3ad9fcd..000000000 --- a/server/db-migrate/migrations/20200831161624-pro-t-entity-label-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200831161624-pro-t-entity-label-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200831161624-pro-t-entity-label-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20200916124242-add-entity-label-config.js b/server/db-migrate/migrations/20200916124242-add-entity-label-config.js deleted file mode 100644 index e0d15b83b..000000000 --- a/server/db-migrate/migrations/20200916124242-add-entity-label-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200916124242-add-entity-label-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20200916124242-add-entity-label-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20201029150441-dfh-v-property.js b/server/db-migrate/migrations/20201029150441-dfh-v-property.js deleted file mode 100644 index 488bf3cc7..000000000 --- a/server/db-migrate/migrations/20201029150441-dfh-v-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201029150441-dfh-v-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201029150441-dfh-v-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20201119144352-factoid-role-into-property.js b/server/db-migrate/migrations/20201119144352-factoid-role-into-property.js deleted file mode 100644 index 81e5216e4..000000000 --- a/server/db-migrate/migrations/20201119144352-factoid-role-into-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201119144352-factoid-role-into-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201119144352-factoid-role-into-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20201120133344-war-t-entity-preview-trigger.js b/server/db-migrate/migrations/20201120133344-war-t-entity-preview-trigger.js deleted file mode 100644 index 2f683351e..000000000 --- a/server/db-migrate/migrations/20201120133344-war-t-entity-preview-trigger.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201120133344-war-t-entity-preview-trigger-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201120133344-war-t-entity-preview-trigger-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20201120145612-cleanup.js b/server/db-migrate/migrations/20201120145612-cleanup.js deleted file mode 100644 index efac12a9f..000000000 --- a/server/db-migrate/migrations/20201120145612-cleanup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201120145612-cleanup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201120145612-cleanup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20201209105833-war-t-entity-preview-column-project.js b/server/db-migrate/migrations/20201209105833-war-t-entity-preview-column-project.js deleted file mode 100644 index d3da9a143..000000000 --- a/server/db-migrate/migrations/20201209105833-war-t-entity-preview-column-project.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201209105833-war-t-entity-preview-column-project-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20201209105833-war-t-entity-preview-column-project-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210106102327-update-vt-trigger-for-factoids.js b/server/db-migrate/migrations/20210106102327-update-vt-trigger-for-factoids.js deleted file mode 100644 index a3e7b3227..000000000 --- a/server/db-migrate/migrations/20210106102327-update-vt-trigger-for-factoids.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210106102327-update-vt-trigger-for-factoids-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210106102327-update-vt-trigger-for-factoids-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108143510-war-f-drop.js b/server/db-migrate/migrations/20210108143510-war-f-drop.js deleted file mode 100644 index a540397bc..000000000 --- a/server/db-migrate/migrations/20210108143510-war-f-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108143510-war-f-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108143510-war-f-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108143515-war-t-statements.js b/server/db-migrate/migrations/20210108143515-war-t-statements.js deleted file mode 100644 index fa309c512..000000000 --- a/server/db-migrate/migrations/20210108143515-war-t-statements.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108143515-war-t-statements-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108143515-war-t-statements-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108144400-war-t-enriched-node-drop.js b/server/db-migrate/migrations/20210108144400-war-t-enriched-node-drop.js deleted file mode 100644 index 5935da537..000000000 --- a/server/db-migrate/migrations/20210108144400-war-t-enriched-node-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108144400-war-t-enriched-node-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108144400-war-t-enriched-node-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108144402-war-t-edge-drop.js b/server/db-migrate/migrations/20210108144402-war-t-edge-drop.js deleted file mode 100644 index 75074a6f6..000000000 --- a/server/db-migrate/migrations/20210108144402-war-t-edge-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108144402-war-t-edge-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108144402-war-t-edge-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108150147-war-t-node-drop.js b/server/db-migrate/migrations/20210108150147-war-t-node-drop.js deleted file mode 100644 index 553549541..000000000 --- a/server/db-migrate/migrations/20210108150147-war-t-node-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108150147-war-t-node-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108150147-war-t-node-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210108150318-war-t-update-log-drop.js b/server/db-migrate/migrations/20210108150318-war-t-update-log-drop.js deleted file mode 100644 index e4c09cfcf..000000000 --- a/server/db-migrate/migrations/20210108150318-war-t-update-log-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108150318-war-t-update-log-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210108150318-war-t-update-log-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210112201048-sys-t-analysis-type-drop.js b/server/db-migrate/migrations/20210112201048-sys-t-analysis-type-drop.js deleted file mode 100644 index ce0602269..000000000 --- a/server/db-migrate/migrations/20210112201048-sys-t-analysis-type-drop.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210112201048-sys-t-analysis-type-drop-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210112201048-sys-t-analysis-type-drop-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210115115621-war-t-statement-uniq.js b/server/db-migrate/migrations/20210115115621-war-t-statement-uniq.js deleted file mode 100644 index 8ff2992af..000000000 --- a/server/db-migrate/migrations/20210115115621-war-t-statement-uniq.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115115621-war-t-statement-uniq-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115115621-war-t-statement-uniq-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210115172750-com-f-time-primitive-pretty.js b/server/db-migrate/migrations/20210115172750-com-f-time-primitive-pretty.js deleted file mode 100644 index 3ac9ae7a0..000000000 --- a/server/db-migrate/migrations/20210115172750-com-f-time-primitive-pretty.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115172750-com-f-time-primitive-pretty-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115172750-com-f-time-primitive-pretty-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210115201042-war-t-statement-add-object-value.js b/server/db-migrate/migrations/20210115201042-war-t-statement-add-object-value.js deleted file mode 100644 index 7764954b4..000000000 --- a/server/db-migrate/migrations/20210115201042-war-t-statement-add-object-value.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115201042-war-t-statement-add-object-value-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210115201042-war-t-statement-add-object-value-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210121134436-inf-data-add-missing-calendar.js b/server/db-migrate/migrations/20210121134436-inf-data-add-missing-calendar.js deleted file mode 100644 index 6a5d43359..000000000 --- a/server/db-migrate/migrations/20210121134436-inf-data-add-missing-calendar.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210121134436-inf-data-add-missing-calendar-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210121134436-inf-data-add-missing-calendar-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210129140325-sys-config-change.js b/server/db-migrate/migrations/20210129140325-sys-config-change.js deleted file mode 100644 index 416113526..000000000 --- a/server/db-migrate/migrations/20210129140325-sys-config-change.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210129140325-sys-config-change-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210129140325-sys-config-change-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210210153312-creation-of-tables-config.js b/server/db-migrate/migrations/20210210153312-creation-of-tables-config.js deleted file mode 100644 index 98de4b877..000000000 --- a/server/db-migrate/migrations/20210210153312-creation-of-tables-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210210153312-creation-of-tables-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210210153312-creation-of-tables-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210304071020-dfh-v-property-improvement.js b/server/db-migrate/migrations/20210304071020-dfh-v-property-improvement.js deleted file mode 100644 index 8723a22ef..000000000 --- a/server/db-migrate/migrations/20210304071020-dfh-v-property-improvement.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210304071020-dfh-v-property-improvement-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210304071020-dfh-v-property-improvement-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210316190319-inf-text-prop-to-lang-string.js b/server/db-migrate/migrations/20210316190319-inf-text-prop-to-lang-string.js deleted file mode 100644 index 0656cdac4..000000000 --- a/server/db-migrate/migrations/20210316190319-inf-text-prop-to-lang-string.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210316190319-inf-text-prop-to-lang-string-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210316190319-inf-text-prop-to-lang-string-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210325224809-sys-config-update.js b/server/db-migrate/migrations/20210325224809-sys-config-update.js deleted file mode 100644 index 501bfcaec..000000000 --- a/server/db-migrate/migrations/20210325224809-sys-config-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210325224809-sys-config-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210325224809-sys-config-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210416202742-change-sys-config.js b/server/db-migrate/migrations/20210416202742-change-sys-config.js deleted file mode 100644 index 03b11a5e2..000000000 --- a/server/db-migrate/migrations/20210416202742-change-sys-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210416202742-change-sys-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210416202742-change-sys-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210423083104-dfh-t-api-property-update.js b/server/db-migrate/migrations/20210423083104-dfh-t-api-property-update.js deleted file mode 100644 index cf971e04d..000000000 --- a/server/db-migrate/migrations/20210423083104-dfh-t-api-property-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210423083104-dfh-t-api-property-update-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210423083104-dfh-t-api-property-update-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210429100404-partition-tables-row.js b/server/db-migrate/migrations/20210429100404-partition-tables-row.js deleted file mode 100644 index 2d6aa19ba..000000000 --- a/server/db-migrate/migrations/20210429100404-partition-tables-row.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210429100404-partition-tables-row-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210429100404-partition-tables-row-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210505080407-inf-t-resource.js b/server/db-migrate/migrations/20210505080407-inf-t-resource.js deleted file mode 100644 index 17bfab65d..000000000 --- a/server/db-migrate/migrations/20210505080407-inf-t-resource.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210505080407-inf-t-resource-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210505080407-inf-t-resource-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210516190526-war-t-field-change.js b/server/db-migrate/migrations/20210516190526-war-t-field-change.js deleted file mode 100644 index a169f2e69..000000000 --- a/server/db-migrate/migrations/20210516190526-war-t-field-change.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210516190526-war-t-field-change-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210516190526-war-t-field-change-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210602123515-table-editing-correction.js b/server/db-migrate/migrations/20210602123515-table-editing-correction.js deleted file mode 100644 index f37a2785a..000000000 --- a/server/db-migrate/migrations/20210602123515-table-editing-correction.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210602123515-table-editing-correction-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210602123515-table-editing-correction-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210708095207-inf-v-entity-class-map.js b/server/db-migrate/migrations/20210708095207-inf-v-entity-class-map.js deleted file mode 100644 index 6ba368fcd..000000000 --- a/server/db-migrate/migrations/20210708095207-inf-v-entity-class-map.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708095207-inf-v-entity-class-map-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708095207-inf-v-entity-class-map-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210708183326-inf-t-resource-add-visibility-field.js b/server/db-migrate/migrations/20210708183326-inf-t-resource-add-visibility-field.js deleted file mode 100644 index fe1f6b31e..000000000 --- a/server/db-migrate/migrations/20210708183326-inf-t-resource-add-visibility-field.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708183326-inf-t-resource-add-visibility-field-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708183326-inf-t-resource-add-visibility-field-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210708183712-pro-t-info-proj-rel.js b/server/db-migrate/migrations/20210708183712-pro-t-info-proj-rel.js deleted file mode 100644 index 669ce94ef..000000000 --- a/server/db-migrate/migrations/20210708183712-pro-t-info-proj-rel.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708183712-pro-t-info-proj-rel-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210708183712-pro-t-info-proj-rel-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20210819120553-war-t-entity-preview-key-column.js b/server/db-migrate/migrations/20210819120553-war-t-entity-preview-key-column.js deleted file mode 100644 index 662d6506d..000000000 --- a/server/db-migrate/migrations/20210819120553-war-t-entity-preview-key-column.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210819120553-war-t-entity-preview-key-column-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20210819120553-war-t-entity-preview-key-column-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211007090627-add-title-comment-to-factoids.js b/server/db-migrate/migrations/20211007090627-add-title-comment-to-factoids.js deleted file mode 100644 index 44f62619b..000000000 --- a/server/db-migrate/migrations/20211007090627-add-title-comment-to-factoids.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211007090627-add-title-comment-to-factoids-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211007090627-add-title-comment-to-factoids-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211202153801-inf-v-appellation-remove-view.js b/server/db-migrate/migrations/20211202153801-inf-v-appellation-remove-view.js deleted file mode 100644 index 032dbd9c9..000000000 --- a/server/db-migrate/migrations/20211202153801-inf-v-appellation-remove-view.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211202153801-inf-v-appellation-remove-view-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211202153801-inf-v-appellation-remove-view-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211209093129-inf-t-time-primitive-add-cal.js b/server/db-migrate/migrations/20211209093129-inf-t-time-primitive-add-cal.js deleted file mode 100644 index f7aeb5242..000000000 --- a/server/db-migrate/migrations/20211209093129-inf-t-time-primitive-add-cal.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209093129-inf-t-time-primitive-add-cal-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209093129-inf-t-time-primitive-add-cal-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211209103755-inf-v-time-primitive-add-cal.js b/server/db-migrate/migrations/20211209103755-inf-v-time-primitive-add-cal.js deleted file mode 100644 index 8aa748825..000000000 --- a/server/db-migrate/migrations/20211209103755-inf-v-time-primitive-add-cal.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209103755-inf-v-time-primitive-add-cal-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209103755-inf-v-time-primitive-add-cal-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211209105150-com-f-time-primitive-pretty-json.js b/server/db-migrate/migrations/20211209105150-com-f-time-primitive-pretty-json.js deleted file mode 100644 index 65a608da4..000000000 --- a/server/db-migrate/migrations/20211209105150-com-f-time-primitive-pretty-json.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209105150-com-f-time-primitive-pretty-json-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209105150-com-f-time-primitive-pretty-json-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211209105458-pro-t-info-proj-rel-drop-calendar.js b/server/db-migrate/migrations/20211209105458-pro-t-info-proj-rel-drop-calendar.js deleted file mode 100644 index 04baea4f6..000000000 --- a/server/db-migrate/migrations/20211209105458-pro-t-info-proj-rel-drop-calendar.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209105458-pro-t-info-proj-rel-drop-calendar-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211209105458-pro-t-info-proj-rel-drop-calendar-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211220193215-dfh-v-labels-fix.js b/server/db-migrate/migrations/20211220193215-dfh-v-labels-fix.js deleted file mode 100644 index 7970271e1..000000000 --- a/server/db-migrate/migrations/20211220193215-dfh-v-labels-fix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211220193215-dfh-v-labels-fix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211220193215-dfh-v-labels-fix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211223151845-tab-t-cell-add-fk-class.js b/server/db-migrate/migrations/20211223151845-tab-t-cell-add-fk-class.js deleted file mode 100644 index a15da69db..000000000 --- a/server/db-migrate/migrations/20211223151845-tab-t-cell-add-fk-class.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211223151845-tab-t-cell-add-fk-class-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211223151845-tab-t-cell-add-fk-class-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20211228155902-war-t-field-change-add-col.js b/server/db-migrate/migrations/20211228155902-war-t-field-change-add-col.js deleted file mode 100644 index ff1e0b313..000000000 --- a/server/db-migrate/migrations/20211228155902-war-t-field-change-add-col.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211228155902-war-t-field-change-add-col-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20211228155902-war-t-field-change-add-col-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114093806-dfh-t-api-property-add-hierarchy.js b/server/db-migrate/migrations/20220114093806-dfh-t-api-property-add-hierarchy.js deleted file mode 100644 index 9a262ba32..000000000 --- a/server/db-migrate/migrations/20220114093806-dfh-t-api-property-add-hierarchy.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114093806-dfh-t-api-property-add-hierarchy-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114093806-dfh-t-api-property-add-hierarchy-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114094250-dfh-t-api-class-add-hierarchy.js b/server/db-migrate/migrations/20220114094250-dfh-t-api-class-add-hierarchy.js deleted file mode 100644 index 3db3b22c9..000000000 --- a/server/db-migrate/migrations/20220114094250-dfh-t-api-class-add-hierarchy.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114094250-dfh-t-api-class-add-hierarchy-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114094250-dfh-t-api-class-add-hierarchy-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114100023-dfh-t-api-profiles-add-hierarchy.js b/server/db-migrate/migrations/20220114100023-dfh-t-api-profiles-add-hierarchy.js deleted file mode 100644 index e0cd068d4..000000000 --- a/server/db-migrate/migrations/20220114100023-dfh-t-api-profiles-add-hierarchy.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114100023-dfh-t-api-profiles-add-hierarchy-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114100023-dfh-t-api-profiles-add-hierarchy-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114125221-dfh-f-update-profiles.js b/server/db-migrate/migrations/20220114125221-dfh-f-update-profiles.js deleted file mode 100644 index 37a3c6916..000000000 --- a/server/db-migrate/migrations/20220114125221-dfh-f-update-profiles.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114125221-dfh-f-update-profiles-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114125221-dfh-f-update-profiles-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114130505-dfh-f-update-classes.js b/server/db-migrate/migrations/20220114130505-dfh-f-update-classes.js deleted file mode 100644 index 0bccb3867..000000000 --- a/server/db-migrate/migrations/20220114130505-dfh-f-update-classes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114130505-dfh-f-update-classes-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114130505-dfh-f-update-classes-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114131303-dfh-f-update-properties.js b/server/db-migrate/migrations/20220114131303-dfh-f-update-properties.js deleted file mode 100644 index 2961536df..000000000 --- a/server/db-migrate/migrations/20220114131303-dfh-f-update-properties.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114131303-dfh-f-update-properties-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114131303-dfh-f-update-properties-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114161239-dfh-v-class.js b/server/db-migrate/migrations/20220114161239-dfh-v-class.js deleted file mode 100644 index d02826869..000000000 --- a/server/db-migrate/migrations/20220114161239-dfh-v-class.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114161239-dfh-v-class-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114161239-dfh-v-class-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220114161348-dfh-v-property.js b/server/db-migrate/migrations/20220114161348-dfh-v-property.js deleted file mode 100644 index 457937480..000000000 --- a/server/db-migrate/migrations/20220114161348-dfh-v-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114161348-dfh-v-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220114161348-dfh-v-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220117204624-dfh-v-class-up-fix.js b/server/db-migrate/migrations/20220117204624-dfh-v-class-up-fix.js deleted file mode 100644 index 456019461..000000000 --- a/server/db-migrate/migrations/20220117204624-dfh-v-class-up-fix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220117204624-dfh-v-class-up-fix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220117204624-dfh-v-class-up-fix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220126133300-add-indexes.js b/server/db-migrate/migrations/20220126133300-add-indexes.js deleted file mode 100644 index e0c99e80b..000000000 --- a/server/db-migrate/migrations/20220126133300-add-indexes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220126133300-add-indexes-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220126133300-add-indexes-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220203135515-pro-v-info-pro-rel-trigger.js b/server/db-migrate/migrations/20220203135515-pro-v-info-pro-rel-trigger.js deleted file mode 100644 index f13aa12be..000000000 --- a/server/db-migrate/migrations/20220203135515-pro-v-info-pro-rel-trigger.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220203135515-pro-v-info-pro-rel-trigger-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220203135515-pro-v-info-pro-rel-trigger-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220305141243-com-f-clone-project-fix.js b/server/db-migrate/migrations/20220305141243-com-f-clone-project-fix.js deleted file mode 100644 index 87997f92e..000000000 --- a/server/db-migrate/migrations/20220305141243-com-f-clone-project-fix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220305141243-com-f-clone-project-fix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220305141243-com-f-clone-project-fix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220305141244-data-cleanup-chunks.js b/server/db-migrate/migrations/20220305141244-data-cleanup-chunks.js deleted file mode 100644 index f9d673bfc..000000000 --- a/server/db-migrate/migrations/20220305141244-data-cleanup-chunks.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220305141244-data-cleanup-chunks-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220305141244-data-cleanup-chunks-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220312142049-digitals-migrate-definitions.js b/server/db-migrate/migrations/20220312142049-digitals-migrate-definitions.js deleted file mode 100644 index d1bd01b01..000000000 --- a/server/db-migrate/migrations/20220312142049-digitals-migrate-definitions.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220312142049-digitals-migrate-definitions-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220312142049-digitals-migrate-definitions-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220314141559-digitals-migrate-mentionings.js b/server/db-migrate/migrations/20220314141559-digitals-migrate-mentionings.js deleted file mode 100644 index 9a06f3110..000000000 --- a/server/db-migrate/migrations/20220314141559-digitals-migrate-mentionings.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220314141559-digitals-migrate-mentionings-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220314141559-digitals-migrate-mentionings-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220315115101-digitals-migrate-texts.js b/server/db-migrate/migrations/20220315115101-digitals-migrate-texts.js deleted file mode 100644 index 430b5bfd4..000000000 --- a/server/db-migrate/migrations/20220315115101-digitals-migrate-texts.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220315115101-digitals-migrate-texts-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220315115101-digitals-migrate-texts-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220315131122-digitals-text-add-short-title.js b/server/db-migrate/migrations/20220315131122-digitals-text-add-short-title.js deleted file mode 100644 index ccad9ba77..000000000 --- a/server/db-migrate/migrations/20220315131122-digitals-text-add-short-title.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220315131122-digitals-text-add-short-title-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220315131122-digitals-text-add-short-title-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316083216-digitals-text-cleanup.js b/server/db-migrate/migrations/20220316083216-digitals-text-cleanup.js deleted file mode 100644 index 998939c7f..000000000 --- a/server/db-migrate/migrations/20220316083216-digitals-text-cleanup.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316083216-digitals-text-cleanup-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316083216-digitals-text-cleanup-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316091135-digitals-migrate-annotations-in-text.js b/server/db-migrate/migrations/20220316091135-digitals-migrate-annotations-in-text.js deleted file mode 100644 index 861307f49..000000000 --- a/server/db-migrate/migrations/20220316091135-digitals-migrate-annotations-in-text.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316091135-digitals-migrate-annotations-in-text-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316091135-digitals-migrate-annotations-in-text-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316102431-digitals-migrate-tables.js b/server/db-migrate/migrations/20220316102431-digitals-migrate-tables.js deleted file mode 100644 index 484ba4ced..000000000 --- a/server/db-migrate/migrations/20220316102431-digitals-migrate-tables.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316102431-digitals-migrate-tables-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316102431-digitals-migrate-tables-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316105300-digitas-table-add-short-title.js b/server/db-migrate/migrations/20220316105300-digitas-table-add-short-title.js deleted file mode 100644 index 0e1e2e60e..000000000 --- a/server/db-migrate/migrations/20220316105300-digitas-table-add-short-title.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316105300-digitas-table-add-short-title-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316105300-digitas-table-add-short-title-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316105615-digitals-migrate-annotations-in-table.js b/server/db-migrate/migrations/20220316105615-digitals-migrate-annotations-in-table.js deleted file mode 100644 index 4adb6e10c..000000000 --- a/server/db-migrate/migrations/20220316105615-digitals-migrate-annotations-in-table.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316105615-digitals-migrate-annotations-in-table-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316105615-digitals-migrate-annotations-in-table-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220316112234-digitals-update-ord-num.js b/server/db-migrate/migrations/20220316112234-digitals-update-ord-num.js deleted file mode 100644 index 22a2d09be..000000000 --- a/server/db-migrate/migrations/20220316112234-digitals-update-ord-num.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316112234-digitals-update-ord-num-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220316112234-digitals-update-ord-num-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220323190916-sys-t-config-add-notify-trigger.js b/server/db-migrate/migrations/20220323190916-sys-t-config-add-notify-trigger.js deleted file mode 100644 index f73e93a86..000000000 --- a/server/db-migrate/migrations/20220323190916-sys-t-config-add-notify-trigger.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220323190916-sys-t-config-add-notify-trigger-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20220323190916-sys-t-config-add-notify-trigger-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20220408133506-inf-migrate-property-is-about.js b/server/db-migrate/migrations/20220408133506-inf-migrate-property-is-about.js deleted file mode 100644 index 95be7c473..000000000 --- a/server/db-migrate/migrations/20220408133506-inf-migrate-property-is-about.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220408133506-inf-migrate-property-is-about-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220408133506-inf-migrate-property-is-about-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220420113713-war-t-entity-preview-add-gin-index.js b/server/db-migrate/migrations/20220420113713-war-t-entity-preview-add-gin-index.js deleted file mode 100644 index 14d61db0f..000000000 --- a/server/db-migrate/migrations/20220420113713-war-t-entity-preview-add-gin-index.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220420113713-war-t-entity-preview-add-gin-index-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220420113713-war-t-entity-preview-add-gin-index-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220427111358-inf-t-statement-add-idx.js b/server/db-migrate/migrations/20220427111358-inf-t-statement-add-idx.js deleted file mode 100644 index 278fd0fdf..000000000 --- a/server/db-migrate/migrations/20220427111358-inf-t-statement-add-idx.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220427111358-inf-t-statement-add-idx-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220427111358-inf-t-statement-add-idx-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree.js b/server/db-migrate/migrations/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree.js deleted file mode 100644 index 33c326408..000000000 --- a/server/db-migrate/migrations/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20220824080013-com-f-clone-project-fix.js b/server/db-migrate/migrations/20220824080013-com-f-clone-project-fix.js deleted file mode 100644 index 7e4275f63..000000000 --- a/server/db-migrate/migrations/20220824080013-com-f-clone-project-fix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220824080013-com-f-clone-project-fix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20220824080013-com-f-clone-project-fix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230202080447-add-primary-keys-for-replica-identity.js b/server/db-migrate/migrations/20230202080447-add-primary-keys-for-replica-identity.js deleted file mode 100644 index 38196e058..000000000 --- a/server/db-migrate/migrations/20230202080447-add-primary-keys-for-replica-identity.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202080447-add-primary-keys-for-replica-identity-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202080447-add-primary-keys-for-replica-identity-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230202150611-add-entity-preview-template-table.js b/server/db-migrate/migrations/20230202150611-add-entity-preview-template-table.js deleted file mode 100644 index 25ee6a9b0..000000000 --- a/server/db-migrate/migrations/20230202150611-add-entity-preview-template-table.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202150611-add-entity-preview-template-table-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202150611-add-entity-preview-template-table-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230202150806-war-f-create-sink-table-entity-preview.js b/server/db-migrate/migrations/20230202150806-war-f-create-sink-table-entity-preview.js deleted file mode 100644 index 3bdf6f027..000000000 --- a/server/db-migrate/migrations/20230202150806-war-f-create-sink-table-entity-preview.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202150806-war-f-create-sink-table-entity-preview-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202150806-war-f-create-sink-table-entity-preview-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230202151106-war-f-switch-entity-preview-table.js b/server/db-migrate/migrations/20230202151106-war-f-switch-entity-preview-table.js deleted file mode 100644 index 7782ef07f..000000000 --- a/server/db-migrate/migrations/20230202151106-war-f-switch-entity-preview-table.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202151106-war-f-switch-entity-preview-table-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202151106-war-f-switch-entity-preview-table-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230202151301-war-t-entity-preview-rename.js b/server/db-migrate/migrations/20230202151301-war-t-entity-preview-rename.js deleted file mode 100644 index c38719bed..000000000 --- a/server/db-migrate/migrations/20230202151301-war-t-entity-preview-rename.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202151301-war-t-entity-preview-rename-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230202151301-war-t-entity-preview-rename-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230209103227-war-adapt-field-change-to-ts.js b/server/db-migrate/migrations/20230209103227-war-adapt-field-change-to-ts.js deleted file mode 100644 index 18659797a..000000000 --- a/server/db-migrate/migrations/20230209103227-war-adapt-field-change-to-ts.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230209103227-war-adapt-field-change-to-ts-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230209103227-war-adapt-field-change-to-ts-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230308121239-com-f-clone-sandbox.js b/server/db-migrate/migrations/20230308121239-com-f-clone-sandbox.js deleted file mode 100644 index 285ad5de4..000000000 --- a/server/db-migrate/migrations/20230308121239-com-f-clone-sandbox.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230308121239-com-f-clone-sandbox-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230308121239-com-f-clone-sandbox-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230311122107-war-v-statements.js b/server/db-migrate/migrations/20230311122107-war-v-statements.js deleted file mode 100644 index ec8bc6dbf..000000000 --- a/server/db-migrate/migrations/20230311122107-war-v-statements.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230311122107-war-v-statements-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230311122107-war-v-statements-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230615145144-war-t-entity-preview-template-indexes.js b/server/db-migrate/migrations/20230615145144-war-t-entity-preview-template-indexes.js deleted file mode 100644 index 1b0bc819c..000000000 --- a/server/db-migrate/migrations/20230615145144-war-t-entity-preview-template-indexes.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230615145144-war-t-entity-preview-template-indexes-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230615145144-war-t-entity-preview-template-indexes-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230615145659-inf-t-appellation-vt-remove-index.js b/server/db-migrate/migrations/20230615145659-inf-t-appellation-vt-remove-index.js deleted file mode 100644 index b49be17cd..000000000 --- a/server/db-migrate/migrations/20230615145659-inf-t-appellation-vt-remove-index.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230615145659-inf-t-appellation-vt-remove-index-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230615145659-inf-t-appellation-vt-remove-index-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230627104438-add-indexes.js b/server/db-migrate/migrations/20230627104438-add-indexes.js deleted file mode 100644 index 13ed5c044..000000000 --- a/server/db-migrate/migrations/20230627104438-add-indexes.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20230627104438-add-indexes-up.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports.down = function (db) { - var filePath = path.join( - __dirname, - 'sqls', - '20230627104438-add-indexes-down.sql', - ); - return new Promise(function (resolve, reject) { - fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) { - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }).then(function (data) { - return db.runSql(data); - }); -}; - -exports._meta = { - version: 1, -}; diff --git a/server/db-migrate/migrations/20230727091628-war-t-entity-preview-partitioning.js b/server/db-migrate/migrations/20230727091628-war-t-entity-preview-partitioning.js deleted file mode 100644 index bc4011183..000000000 --- a/server/db-migrate/migrations/20230727091628-war-t-entity-preview-partitioning.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727091628-war-t-entity-preview-partitioning-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727091628-war-t-entity-preview-partitioning-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230727092320-war-f-create-sink-table-entity-preview.js b/server/db-migrate/migrations/20230727092320-war-f-create-sink-table-entity-preview.js deleted file mode 100644 index 0c7e69383..000000000 --- a/server/db-migrate/migrations/20230727092320-war-f-create-sink-table-entity-preview.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727092320-war-f-create-sink-table-entity-preview-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727092320-war-f-create-sink-table-entity-preview-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230727102618-pro-t-projects-add-entity-preview-partition-trigger.js b/server/db-migrate/migrations/20230727102618-pro-t-projects-add-entity-preview-partition-trigger.js deleted file mode 100644 index 50142275f..000000000 --- a/server/db-migrate/migrations/20230727102618-pro-t-projects-add-entity-preview-partition-trigger.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727102618-pro-t-projects-add-entity-preview-partition-trigger-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727102618-pro-t-projects-add-entity-preview-partition-trigger-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230727152222-war-f-switch-entity-preview-table.js b/server/db-migrate/migrations/20230727152222-war-f-switch-entity-preview-table.js deleted file mode 100644 index 1aaed44fa..000000000 --- a/server/db-migrate/migrations/20230727152222-war-f-switch-entity-preview-table.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727152222-war-f-switch-entity-preview-table-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230727152222-war-f-switch-entity-preview-table-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230815102214-com-f-analysis-temporal-distribution.js b/server/db-migrate/migrations/20230815102214-com-f-analysis-temporal-distribution.js deleted file mode 100644 index c36ea5e07..000000000 --- a/server/db-migrate/migrations/20230815102214-com-f-analysis-temporal-distribution.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230815102214-com-f-analysis-temporal-distribution-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230815102214-com-f-analysis-temporal-distribution-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230815102806-com-f-analysis-time-chart-cont--czml-time-values.js b/server/db-migrate/migrations/20230815102806-com-f-analysis-time-chart-cont--czml-time-values.js deleted file mode 100644 index 19e751528..000000000 --- a/server/db-migrate/migrations/20230815102806-com-f-analysis-time-chart-cont--czml-time-values.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230815102806-com-f-analysis-time-chart-cont--czml-time-values-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230815102806-com-f-analysis-time-chart-cont--czml-time-values-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230823080214-war-f-remove-unused-functions.js b/server/db-migrate/migrations/20230823080214-war-f-remove-unused-functions.js deleted file mode 100644 index 717d2dc85..000000000 --- a/server/db-migrate/migrations/20230823080214-war-f-remove-unused-functions.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230823080214-war-f-remove-unused-functions-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230823080214-war-f-remove-unused-functions-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/20230907152905-com-f-hotfix.js b/server/db-migrate/migrations/20230907152905-com-f-hotfix.js deleted file mode 100644 index 89263486b..000000000 --- a/server/db-migrate/migrations/20230907152905-com-f-hotfix.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230907152905-com-f-hotfix-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20230907152905-com-f-hotfix-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163000-schemas.js b/server/db-migrate/migrations/_migration_archive/20171022163000-schemas.js deleted file mode 100644 index 84675c28f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163000-schemas.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE SCHEMA IF NOT EXISTS commons; - - CREATE SCHEMA IF NOT EXISTS information; - - CREATE SCHEMA IF NOT EXISTS data_for_history; - - CREATE SCHEMA IF NOT EXISTS che; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP SCHEMA commons; - - DROP SCHEMA information; - - DROP SCHEMA data_for_history; - - DROP SCHEMA che; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163020-extensions.js b/server/db-migrate/migrations/_migration_archive/20171022163020-extensions.js deleted file mode 100644 index 518785ea1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163020-extensions.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - --CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - --COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; --- - --CREATE EXTENSION IF NOT EXISTS temporal_tables WITH SCHEMA public; - --COMMENT ON EXTENSION temporal_tables IS 'temporal tables'; - `; - - db.runSql(sql, callback) -}; - -exports.down = function(db, callback) { - const sql = ` - --DROP EXTENSION IF EXISTS plpgsql; - --DROP EXTENSION IF EXISTS temporal_tables; - `; - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163021-com-functions.js b/server/db-migrate/migrations/_migration_archive/20171022163021-com-functions.js deleted file mode 100644 index cf995aa96..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163021-com-functions.js +++ /dev/null @@ -1,308 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - --- Create the nwe versioning() function (schema public) - - CREATE OR REPLACE FUNCTION versioning() - RETURNS TRIGGER AS $$ - DECLARE - sys_period text; - history_table text; - manipulate jsonb; - commonColumns text[]; - time_stamp_to_use timestamptz := current_timestamp; - range_lower timestamptz; - transaction_info txid_snapshot; - existing_range tstzrange; - holder record; - holder2 record; - pg_version integer; - BEGIN - -- version 0.2.0 - - IF TG_WHEN != 'BEFORE' OR TG_LEVEL != 'ROW' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired BEFORE ROW'; - END IF; - - IF TG_OP != 'INSERT' AND TG_OP != 'UPDATE' AND TG_OP != 'DELETE' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired for INSERT or UPDATE or DELETE'; - END IF; - - IF TG_NARGS != 3 THEN - RAISE INVALID_PARAMETER_VALUE USING - MESSAGE = 'wrong number of parameters for function "versioning"', - HINT = 'expected 3 parameters but got ' || TG_NARGS; - END IF; - - sys_period := TG_ARGV[0]; - history_table := TG_ARGV[1]; - - -- check if sys_period exists on original table - SELECT atttypid, attndims INTO holder FROM pg_attribute WHERE attrelid = TG_RELID AND attname = sys_period AND NOT attisdropped; - IF NOT FOUND THEN - RAISE 'column "%" of relation "%" does not exist', sys_period, TG_TABLE_NAME USING - ERRCODE = 'undefined_column'; - END IF; - IF holder.atttypid != to_regtype('tstzrange') THEN - IF holder.attndims > 0 THEN - RAISE 'system period column "%" of relation "%" is not a range but an array', sys_period, TG_TABLE_NAME USING - ERRCODE = 'datatype_mismatch'; - END IF; - - SELECT rngsubtype INTO holder2 FROM pg_range WHERE rngtypid = holder.atttypid; - IF FOUND THEN - RAISE 'system period column "%" of relation "%" is not a range of timestamp with timezone but of type %', sys_period, TG_TABLE_NAME, format_type(holder2.rngsubtype, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - RAISE 'system period column "%" of relation "%" is not a range but type %', sys_period, TG_TABLE_NAME, format_type(holder.atttypid, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN - -- Ignore rows already modified in this transaction - transaction_info := txid_current_snapshot(); - IF OLD.xmin::text >= (txid_snapshot_xmin(transaction_info) % (2^32)::bigint)::text - AND OLD.xmin::text <= (txid_snapshot_xmax(transaction_info) % (2^32)::bigint)::text THEN - IF TG_OP = 'DELETE' THEN - RETURN OLD; - END IF; - - RETURN NEW; - END IF; - - SELECT current_setting('server_version_num')::integer - INTO pg_version; - - -- to support postgres < 9.6 - IF pg_version < 90600 THEN - -- check if history table exits - IF to_regclass(history_table::cstring) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - ELSE - IF to_regclass(history_table) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - END IF; - - -- check if history table has sys_period - IF NOT EXISTS(SELECT * FROM pg_attribute WHERE attrelid = history_table::regclass AND attname = sys_period AND NOT attisdropped) THEN - RAISE 'history relation "%" does not contain system period column "%"', history_table, sys_period USING - HINT = 'history relation must contain system period column with the same name and data type as the versioned one'; - END IF; - - EXECUTE format('SELECT $1.%I', sys_period) USING OLD INTO existing_range; - - IF existing_range IS NULL THEN - RAISE 'system period column "%" of relation "%" must not be null', sys_period, TG_TABLE_NAME USING - ERRCODE = 'null_value_not_allowed'; - END IF; - - IF isempty(existing_range) OR NOT upper_inf(existing_range) THEN - RAISE 'system period column "%" of relation "%" contains invalid value', sys_period, TG_TABLE_NAME USING - ERRCODE = 'data_exception', - DETAIL = 'valid ranges must be non-empty and unbounded on the high side'; - END IF; - - IF TG_ARGV[2] = 'true' THEN - -- mitigate update conflicts - range_lower := lower(existing_range); - IF range_lower >= time_stamp_to_use THEN - time_stamp_to_use := range_lower + interval '1 microseconds'; - END IF; - END IF; - - WITH history AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT - history.attname AS history_name, - main.attname AS main_name, - history.atttypid AS history_type, - main.atttypid AS main_type - INTO holder - FROM history - INNER JOIN main - ON history.attname = main.attname - WHERE - history.atttypid != main.atttypid; - - IF FOUND THEN - RAISE 'column "%" of relation "%" is of type % but column "%" of history relation "%" is of type %', - holder.main_name, TG_TABLE_NAME, format_type(holder.main_type, null), holder.history_name, history_table, format_type(holder.history_type, null) - USING ERRCODE = 'datatype_mismatch'; - END IF; - - WITH history AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT array_agg(quote_ident(history.attname)) INTO commonColumns - FROM history - INNER JOIN main - ON history.attname = main.attname - AND history.attname != sys_period; - - EXECUTE ('INSERT INTO ' || - CASE split_part(history_table, '.', 2) - WHEN '' THEN - quote_ident(history_table) - ELSE - quote_ident(split_part(history_table, '.', 1)) || '.' || quote_ident(split_part(history_table, '.', 2)) - END || - '(' || - array_to_string(commonColumns , ',') || - ',' || - quote_ident(sys_period) || - ') VALUES ($1.' || - array_to_string(commonColumns, ',$1.') || - ',tstzrange($2, $3, ''[)''))') - USING OLD, range_lower, time_stamp_to_use; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'INSERT' THEN - manipulate := jsonb_set('{}'::jsonb, ('{' || sys_period || '}')::text[], to_jsonb(tstzrange(time_stamp_to_use, null, '[)'))); - - RETURN jsonb_populate_record(NEW, manipulate); - END IF; - - RETURN OLD; - END; - $$ LANGUAGE plpgsql; - - - - CREATE FUNCTION commons.tmsp_creation () - RETURNS TRIGGER LANGUAGE 'plpgsql' - AS - $BODY$ - BEGIN - NEW.tmsp_creation = NOW(); - RETURN NEW; - END; - $BODY$; - - - CREATE FUNCTION commons.tmsp_last_modification() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN NEW.tmsp_last_modification = NOW(); - RETURN NEW; - END; - $BODY$; - - - CREATE FUNCTION commons.insert_schema_table_name() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - -- source https://www.postgresql.org/docs/current/static/plpgsql-trigger.html - BEGIN - NEW.schema_name = TG_TABLE_SCHEMA; - NEW.table_name = TG_TABLE_NAME; - RETURN NEW; - END; - $BODY$; - - - CREATE OR REPLACE FUNCTION commons.create_entity_version_key() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - BEGIN - NEW.entity_version = 1; - RETURN NEW; - END; - $BODY$; - - - CREATE OR REPLACE FUNCTION commons.update_entity_version_key() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - BEGIN - NEW.entity_version := NEW.entity_version + 1; - RETURN NEW; - END; - $BODY$; - - - - -- Function: split fk_entity_version_concat in fk_entity_version and fk_entity - - CREATE FUNCTION commons.evpr_fk_entity_fk_entity_version() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - NEW.fk_entity = split_part(NEW.fk_entity_version_concat, '_', 1)::integer; - NEW.fk_entity_version = split_part(NEW.fk_entity_version_concat, '_', 2)::integer; - - RETURN NEW; - END; - $BODY$; - `; - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP FUNCTION commons.tmsp_creation(); - DROP FUNCTION commons.tmsp_last_modification(); - DROP FUNCTION commons.insert_schema_table_name(); - DROP FUNCTION commons.create_entity_version_key(); - DROP FUNCTION commons.update_entity_version_key(); - DROP FUNCTION commons.evpr_fk_entity_fk_entity_version(); - - `; - - db.runSql(sql, callback); - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163022-com-t-language.js b/server/db-migrate/migrations/_migration_archive/20171022163022-com-t-language.js deleted file mode 100644 index d931c746a..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163022-com-t-language.js +++ /dev/null @@ -1,85 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: commons.language - - CREATE TABLE commons.language - ( - pk_language character(3) PRIMARY KEY, -- iso_lang - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3), - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.language - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.language - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: commons.language_vt - - CREATE TABLE commons.language_vt (LIKE commons.language); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.language - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.language_vt', true - ); - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.language; - DROP TABLE commons.language_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163023-dfh-t-entity.js b/server/db-migrate/migrations/_migration_archive/20171022163023-dfh-t-entity.js deleted file mode 100644 index 7cdae0d98..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163023-dfh-t-entity.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE TABLE data_for_history.entity - ( - pk_entity serial PRIMARY KEY, - schema_name varchar, - table_name varchar, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP TABLE data_for_history.entity; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163024-dfh-t-class-profile-view.js b/server/db-migrate/migrations/_migration_archive/20171022163024-dfh-t-class-profile-view.js deleted file mode 100644 index 6dad10026..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163024-dfh-t-class-profile-view.js +++ /dev/null @@ -1,85 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE TABLE data_for_history.class_profile_view - ( - fk_class integer, - identifier_in_namespace text, - class_standard_label varchar, - fk_system_type integer, - type_label varchar, - root_namespace text, - profile_association_type varchar, - fk_profile integer, - profile_label varchar, - is_enabled_in_profile BOOLEAN, - tmsp_last_dfh_update timestamptz - ) - INHERITS (data_for_history.entity); - - - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.class_profile_view FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.class_profile_view_vt (LIKE data_for_history.class_profile_view); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.class_profile_view - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.class_profile_view_vt', true - ); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP TABLE data_for_history.class_profile_view; - - DROP TABLE data_for_history.class_profile_view_vt; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163025-dfh-t-class.js b/server/db-migrate/migrations/_migration_archive/20171022163025-dfh-t-class.js deleted file mode 100644 index 1f765f959..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163025-dfh-t-class.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.class -( - pk_class integer, - identifier_in_namespace text, - data_for_history_id VARCHAR(7) NOT NULL UNIQUE, - standard_label varchar(500), - fk_system_type integer, - tmsp_last_dfh_update timestamptz -) -INHERITS (data_for_history.entity); - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.class - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - -CREATE TRIGGER last_modification_tmsp -BEFORE INSERT OR UPDATE - ON data_for_history.class - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.class FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- versioning - -CREATE TABLE data_for_history.class_vt (LIKE data_for_history.class); - -CREATE TRIGGER versioning_trigger -BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.class -FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.class_vt', true -); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE data_for_history.class; - DROP TABLE data_for_history.class_vt; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163027-dfh-t-property.js b/server/db-migrate/migrations/_migration_archive/20171022163027-dfh-t-property.js deleted file mode 100644 index 3aa9a0d01..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163027-dfh-t-property.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.property ( - pk_property serial PRIMARY KEY, - data_for_history_id VARCHAR(7) NOT NULL UNIQUE, - standard_label text - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.property FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.property_vt (LIKE data_for_history.property); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.property_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.property; - DROP TABLE IF EXISTS data_for_history.property_vt; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163030-pub-t-account.js b/server/db-migrate/migrations/_migration_archive/20171022163030-pub-t-account.js deleted file mode 100644 index 730e75a7e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163030-pub-t-account.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - - CREATE TABLE public.account - ( - realm text, - username text UNIQUE, - password text NOT NULL, - email text NOT NULL UNIQUE, - emailverified boolean, - verificationtoken text, - id serial PRIMARY KEY - ) - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.account; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163040-pub-t-access-token.js b/server/db-migrate/migrations/_migration_archive/20171022163040-pub-t-access-token.js deleted file mode 100644 index da5002da2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163040-pub-t-access-token.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE TABLE public.accesstoken - ( - id text PRIMARY KEY, - ttl integer DEFAULT 1209600, - scopes text, - created timestamp with time zone, - userid integer REFERENCES account (id) - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.accesstoken; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163050-pub-t-role.js b/server/db-migrate/migrations/_migration_archive/20171022163050-pub-t-role.js deleted file mode 100644 index 74a94fb32..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163050-pub-t-role.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - //TODO decide if the REFERERENCED cols should have a ON DELETE Action - // see: https://www.postgresql.org/docs/current/static/ddl-constraints.html - const sql = ` - CREATE TABLE public.role - ( - id serial PRIMARY KEY, - name text NOT NULL, - description text, - created timestamp with time zone, - modified timestamp with time zone - ) - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.role; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163100-pub-t-role-mapping.js b/server/db-migrate/migrations/_migration_archive/20171022163100-pub-t-role-mapping.js deleted file mode 100644 index e93ba228f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163100-pub-t-role-mapping.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - //TODO decide if the REFERERENCED cols should have a ON DELETE Action - // see: https://www.postgresql.org/docs/current/static/ddl-constraints.html - const sql = ` - CREATE TABLE public.rolemapping - ( - id serial PRIMARY KEY, - principaltype text, - principalid text, - roleid integer REFERENCES public.role (id) - ) - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.rolemapping; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163110-pub-t-acl.js b/server/db-migrate/migrations/_migration_archive/20171022163110-pub-t-acl.js deleted file mode 100644 index 150b379a2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163110-pub-t-acl.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - //TODO decide if the REFERERENCED cols should have a ON DELETE Action - // see: https://www.postgresql.org/docs/current/static/ddl-constraints.html - const sql = ` - CREATE TABLE public.acl - ( - model text, - property text, - accesstype text, - permission text, - principaltype text, - principalid text, - id serial PRIMARY KEY - ) - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.acl; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163130-com-t-entity.js b/server/db-migrate/migrations/_migration_archive/20171022163130-com-t-entity.js deleted file mode 100644 index 2cb0a13d2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163130-com-t-entity.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE commons.entity - ( - pk_entity serial PRIMARY KEY, - schema_name character varying COLLATE pg_catalog."default", - table_name character varying COLLATE pg_catalog."default" - ); - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.entity; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163140-com-t-label.js b/server/db-migrate/migrations/_migration_archive/20171022163140-com-t-label.js deleted file mode 100644 index 0ec48fa91..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163140-com-t-label.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: commons.label - - CREATE TABLE commons.label - ( - pk_entity integer, - schema_name character varying, - table_name character varying, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - pk_label serial PRIMARY KEY, - label text, - fk_system_type integer, - fk_language character(3) REFERENCES commons.language(pk_language), - fk_entity integer, - notes text, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ) - INHERITS (commons.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.label - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON commons.label - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.label - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: commons.label_vt - - CREATE TABLE commons.label_vt (LIKE commons.label); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.label - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.label_vt', true - ); - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.label; - DROP TABLE commons.label_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163200-com-t-project.js b/server/db-migrate/migrations/_migration_archive/20171022163200-com-t-project.js deleted file mode 100644 index b95f00012..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163200-com-t-project.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE commons.project - ( - pk_project serial PRIMARY KEY, - pk_entity integer, - schema_name character varying, - table_name character varying, - fk_creator integer REFERENCES public.account (id), - fk_last_modifier integer REFERENCES public.account (id), - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - fk_language character(3) REFERENCES commons.language (pk_language), - notes text, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ) - INHERITS (commons.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - -- DROP TRIGGER creation_tmsp ON commons.project; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.project - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON commons.project; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON commons.project - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON commons.project; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.project - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: commons.project_vt - - CREATE TABLE commons.project_vt (LIKE commons.project); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.project - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.project_vt', true - ); - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.project; - DROP TABLE commons.project_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163210-com-t-system-type.js b/server/db-migrate/migrations/_migration_archive/20171022163210-com-t-system-type.js deleted file mode 100644 index 7cc0a2121..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163210-com-t-system-type.js +++ /dev/null @@ -1,99 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: commons.system_type - - CREATE TABLE commons.system_type - ( - pk_entity integer, - schema_name character varying, - table_name character varying, - pk_system_type serial PRIMARY KEY, - st_schema_name character varying, - st_table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ) - INHERITS (commons.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - -- DROP TRIGGER creation_tmsp ON commons.system_type; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON commons.system_type; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON commons.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON commons.system_type; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: commons.system_type_vt - - CREATE TABLE commons.system_type_vt (LIKE commons.system_type); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.system_type - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.system_type_vt', true - ); - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.system_type; - DROP TABLE commons.system_type_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163220-com-t-text-property.js b/server/db-migrate/migrations/_migration_archive/20171022163220-com-t-text-property.js deleted file mode 100644 index 1f33914d7..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163220-com-t-text-property.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: commons.text_property - - CREATE TABLE commons.text_property - ( - pk_entity integer, - schema_name character varying, - table_name character varying, - pk_text_property serial PRIMARY KEY, - text_property text, - text_property_xml xml, - fk_system_type integer, - fk_language character(3) REFERENCES commons.language (pk_language), - fk_entity integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ) - INHERITS (commons.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - -- DROP TRIGGER creation_tmsp ON commons.text_property; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON commons.text_property; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON commons.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON commons.text_property; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: commons.text_property_vt - - CREATE TABLE commons.text_property_vt (LIKE commons.text_property); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.text_property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.text_property_vt', true - ); `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE commons.text_property; - DROP TABLE commons.text_property_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163230-com-v-system-type-label-text-property.js b/server/db-migrate/migrations/_migration_archive/20171022163230-com-v-system-type-label-text-property.js deleted file mode 100644 index 9569959b8..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163230-com-v-system-type-label-text-property.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE OR REPLACE VIEW commons.v_system_type_label_text_property AS - SELECT t1.pk_entity, - t1.pk_system_type, - t1.st_schema_name, - t1.st_table_name, - t2.label, - t2.fk_language AS lang_label, - t3.text_property, - t3.fk_language AS lang_text_property - FROM commons.system_type t1 - LEFT JOIN commons.label t2 ON t2.fk_entity = t1.pk_entity - LEFT JOIN commons.text_property t3 ON t3.fk_entity = t1.pk_entity; - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP VIEW commons.v_system_type_label_text_property; - ` - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163240-com-v-project-label-text-property.js b/server/db-migrate/migrations/_migration_archive/20171022163240-com-v-project-label-text-property.js deleted file mode 100644 index f721bf9c1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163240-com-v-project-label-text-property.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE OR REPLACE VIEW commons.v_project_label_text_property AS - SELECT - t1.pk_project, - t1.pk_entity, - t1.fk_language AS lang_project, - t2.label, - t2.fk_language AS lang_label, - t3.text_property, - t3.fk_language AS lang_text_property - FROM commons.project t1 - LEFT JOIN commons.label t2 ON t2.fk_entity = t1.pk_entity - LEFT JOIN commons.text_property t3 ON t3.fk_entity = t1.pk_entity; - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP VIEW commons.v_project_label_text_property; - ` - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171022163250-pub-t-account-project-rel.js b/server/db-migrate/migrations/_migration_archive/20171022163250-pub-t-account-project-rel.js deleted file mode 100644 index 105e28441..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171022163250-pub-t-account-project-rel.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - //TODO decide if the REFERERENCED cols should have a ON DELETE Action - // see: https://www.postgresql.org/docs/current/static/ddl-constraints.html - const sql = ` - CREATE TABLE public.account_project_rel - ( - account_id integer NOT NULL REFERENCES public.account (id), - fk_project integer NOT NULL REFERENCES commons.project (pk_project), - role text NOT NULL, - id serial PRIMARY KEY - ) - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE public.account_project_rel; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084353-inf-t-entity.js b/server/db-migrate/migrations/_migration_archive/20171028084353-inf-t-entity.js deleted file mode 100644 index 9e331b071..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084353-inf-t-entity.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE information.entity - ( - pk_entity serial PRIMARY KEY, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.entity; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084403-inf-t-appellation.js b/server/db-migrate/migrations/_migration_archive/20171028084403-inf-t-appellation.js deleted file mode 100644 index d16d3b698..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084403-inf-t-appellation.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.appellation - - CREATE TABLE information.appellation - ( - pk_appellation serial PRIMARY KEY, - appellation_label jsonb, - fk_class VARCHAR(7) NOT NULL REFERENCES data_for_history.class (data_for_history_id) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.appellation_vt - - CREATE TABLE information.appellation_vt (LIKE information.appellation); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.appellation - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.appellation_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.appellation; - DROP TABLE information.appellation_vt; - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084426-inf-t-dating.js b/server/db-migrate/migrations/_migration_archive/20171028084426-inf-t-dating.js deleted file mode 100644 index 33ed9f5ef..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084426-inf-t-dating.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.dating - - CREATE TABLE information.dating - ( - pk_dating serial PRIMARY KEY, - date_iso_value jsonb, - comment text, - fk_system_type integer - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON information.dating; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON information.dating; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.dating_vt - - CREATE TABLE information.dating_vt (LIKE information.dating); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.dating - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.dating_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.dating; - - DROP TABLE information.dating_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084441-inf-t-entity-association.js b/server/db-migrate/migrations/_migration_archive/20171028084441-inf-t-entity-association.js deleted file mode 100644 index 248ca83b8..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084441-inf-t-entity-association.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.entity_association - - CREATE TABLE information.entity_association - ( - pk_entity_association serial PRIMARY KEY, - fk_domain_entity integer, - fk_range_entity integer, - fk_property VARCHAR(7) REFERENCES data_for_history.property (data_for_history_id) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.entity_association - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON information.entity_association; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.entity_association - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON information.entity_association; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.entity_association - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - - -- Table: information.entity_association_vt - - CREATE TABLE information.entity_association_vt (LIKE information.entity_association); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.entity_association - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.entity_association_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.entity_association - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.entity_association - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.entity_association; - - DROP TABLE information.entity_association_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084517-inf-t-persistent-item.js b/server/db-migrate/migrations/_migration_archive/20171028084517-inf-t-persistent-item.js deleted file mode 100644 index d3de8c6ea..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084517-inf-t-persistent-item.js +++ /dev/null @@ -1,102 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.persistent_item - - CREATE TABLE information.persistent_item - ( - entity_version integer, - pk_persistent_item serial PRIMARY KEY, - fk_class VARCHAR(7) REFERENCES data_for_history.class (data_for_history_id) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.persistent_item - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.persistent_item - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.persistent_item - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.persistent_item_vt - - CREATE TABLE information.persistent_item_vt (LIKE information.persistent_item); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.persistent_item - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.persistent_item_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.persistent_item - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.persistent_item - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.persistent_item; - - DROP TABLE information.persistent_item_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084530-inf-t-role.js b/server/db-migrate/migrations/_migration_archive/20171028084530-inf-t-role.js deleted file mode 100644 index 7b6b1f9cb..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084530-inf-t-role.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.role - - CREATE TABLE information.role - ( - pk_role serial PRIMARY KEY, - fk_entity integer, - fk_temporal_entity integer, - fk_property VARCHAR(7) REFERENCES data_for_history.property (data_for_history_id) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.role - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.role - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.role - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.role_vt - - CREATE TABLE information.role_vt (LIKE information.role); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.role - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.role_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.role - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.role - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.role; - - DROP TABLE information.role_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084548-inf-t-sourcing.js b/server/db-migrate/migrations/_migration_archive/20171028084548-inf-t-sourcing.js deleted file mode 100644 index 7696a027f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084548-inf-t-sourcing.js +++ /dev/null @@ -1,104 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.sourcing - -CREATE TABLE information.sourcing -( - pk_sourcing serial PRIMARY KEY, - fk_source integer, - fk_entity integer, - fk_system_type integer, - position_in_source text COLLATE pg_catalog."default" -) - INHERITS (information.entity) -WITH ( - OIDS = FALSE -) -TABLESPACE pg_default; - - --- Trigger: creation_tmsp - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.sourcing - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - --- Trigger: insert_schema_table_name - -CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.sourcing - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - --- Trigger: last_modification_tmsp - -CREATE TRIGGER last_modification_tmsp -BEFORE INSERT OR UPDATE - ON information.sourcing - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.sourcing_vt - - CREATE TABLE information.sourcing_vt (LIKE information.sourcing); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.sourcing - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.sourcing_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.sourcing - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.sourcing - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.sourcing; - - DROP TABLE information.sourcing_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084601-inf-t-temporal-entity.js b/server/db-migrate/migrations/_migration_archive/20171028084601-inf-t-temporal-entity.js deleted file mode 100644 index 1fa0f40a2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084601-inf-t-temporal-entity.js +++ /dev/null @@ -1,103 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.temporal_entity - - CREATE TABLE information.temporal_entity - ( - entity_version integer, - pk_temporal_entity serial PRIMARY KEY, - fk_class VARCHAR(7) REFERENCES data_for_history.class (data_for_history_id) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.temporal_entity_vt - - CREATE TABLE information.temporal_entity_vt (LIKE information.temporal_entity); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.temporal_entity - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.temporal_entity_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.temporal_entity; - - DROP TABLE information.temporal_entity_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171028084613-inf-t-temporal-text-property.js b/server/db-migrate/migrations/_migration_archive/20171028084613-inf-t-temporal-text-property.js deleted file mode 100644 index 7e72d734b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171028084613-inf-t-temporal-text-property.js +++ /dev/null @@ -1,106 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.text_property - - CREATE TABLE information.text_property - ( - pk_text_property serial PRIMARY KEY, - text_property text COLLATE pg_catalog."default", - text_property_xml xml, - fk_system_type integer, - fk_language character(3) COLLATE pg_catalog."default", - fk_entity integer - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.text_property_vt - - CREATE TABLE information.text_property_vt (LIKE information.text_property); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.text_property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.text_property_vt', true - ); - - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.text_property; - - DROP TABLE information.text_property_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171102141517-inf-t-language.js b/server/db-migrate/migrations/_migration_archive/20171102141517-inf-t-language.js deleted file mode 100644 index 09941ae80..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171102141517-inf-t-language.js +++ /dev/null @@ -1,106 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.language - - CREATE TABLE information.language - ( - pk_language character(3) PRIMARY KEY, -- iso_lang - fk_class VARCHAR(7) REFERENCES data_for_history.class (data_for_history_id), - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.language - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.language - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.language - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Table: information.language_vt - - CREATE TABLE information.language_vt (LIKE information.language); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.language - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.language_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.language - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.language - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - `; - - db.runSql(sql, callback); -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.language; - DROP TABLE information.language_vt; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171121172031-inf-v-project-persistent-item.js b/server/db-migrate/migrations/_migration_archive/20171121172031-inf-v-project-persistent-item.js deleted file mode 100644 index 47f12de06..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171121172031-inf-v-project-persistent-item.js +++ /dev/null @@ -1,140 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - --- --CREATE VIEW OF PERSISTENT ITEMS PER PROJECT --- --- CREATE OR REPLACE VIEW information.v_project_persistent_item AS --- SELECT piv.*, --- epr.fk_project, --- epr.is_in_project, --- epr.is_standard_in_project, --- epr.is_in_project_true_tmsp --- FROM information.entity_project_rel epr --- JOIN ( SELECT persistent_item.* --- FROM information.persistent_item --- UNION --- SELECT persistent_item_vt.* --- FROM information.persistent_item_vt --- ) piv ON piv.pk_entity = epr.fk_entity AND lower(piv.sys_period) = epr.is_in_project_true_tmsp; --- --- --- --- --- --CREATE INSERT FUNCTION --- CREATE OR REPLACE FUNCTION information.v_project_persistent_item_insert() --- RETURNS trigger AS --- $BODY$ --- BEGIN --- WITH insert_peit AS ( --- INSERT INTO information.persistent_item (fk_class,notes) --- VALUES(NEW.fk_class, NEW.notes) --- RETURNING pk_entity, lower(sys_period) as tmsp --- ) --- INSERT INTO information.entity_project_rel(fk_entity,fk_project,is_in_project,is_standard_in_project, is_in_project_true_tmsp) --- VALUES( --- ( --- SELECT pk_entity --- FROM insert_peit --- ), --- NEW.fk_project, --- NEW.is_in_project, --- NEW.is_standard_in_project, --- ( --- SELECT tmsp --- FROM insert_peit --- ) --- ); --- --- RETURN NEW; --- END; --- $BODY$ --- --- LANGUAGE plpgsql VOLATILE --- COST 100; --- --- --CREATE INSERT TRIGGER --- --- CREATE TRIGGER on_insert --- INSTEAD OF INSERT --- ON information.v_project_persistent_item --- FOR EACH ROW --- EXECUTE PROCEDURE information.v_project_persistent_item_insert(); --- --- --- --CREATE UPDATE FUNCTION --- CREATE OR REPLACE FUNCTION information.v_project_persistent_item_update() --- RETURNS trigger AS --- $BODY$ --- BEGIN --- IF NEW.fk_class <> OLD.fk_class OR NEW.notes <> OLD.notes THEN --- WITH update_peit AS ( --- UPDATE information.persistent_item --- SET fk_class = NEW.fk_class, --- notes = NEW.notes --- WHERE pk_entity = NEW.pk_entity --- RETURNING pk_entity,lower(sys_period) as tmsp --- ) --- UPDATE information.entity_project_rel --- SET --- is_in_project = NEW.is_in_project, --- is_standard_in_project = NEW.is_standard_in_project, --- is_in_project_true_tmsp = ( --- SELECT tmsp --- FROM update_peit --- ) --- WHERE fk_entity = NEW.pk_entity AND fk_project = NEW.fk_project; --- ELSE --- UPDATE information.entity_project_rel --- SET --- is_in_project = NEW.is_in_project, --- is_standard_in_project = NEW.is_standard_in_project --- WHERE fk_entity = NEW.pk_entity AND fk_project = NEW.fk_project; --- END IF; --- --- RETURN NEW; --- END; --- $BODY$ --- --- LANGUAGE plpgsql VOLATILE --- COST 100; --- --- --CREATE UPDATE TRIGGER --- CREATE TRIGGER on_update --- INSTEAD OF UPDATE --- ON information.v_project_persistent_item --- FOR EACH ROW --- EXECUTE PROCEDURE information.v_project_persistent_item_update(); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` --- DROP TRIGGER IF EXISTS on_update ON information.v_project_persistent_item; --- DROP TRIGGER IF EXISTS on_insert ON information.v_project_persistent_item; --- DROP FUNCTION IF EXISTS information.v_project_persistent_item_update(); --- DROP FUNCTION IF EXISTS information.v_project_persistent_item_insert(); --- DROP VIEW IF EXISTS information.v_project_persistent_item; - ` - db.runSql(sql, callback) -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171129202522-inf-t-entity-version-project-rel.js b/server/db-migrate/migrations/_migration_archive/20171129202522-inf-t-entity-version-project-rel.js deleted file mode 100644 index 5124f5a45..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171129202522-inf-t-entity-version-project-rel.js +++ /dev/null @@ -1,120 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Table: information.entity_version_project_rel - - CREATE TABLE information.entity_version_project_rel - ( - pk_entity_version_project_rel serial PRIMARY KEY, - fk_project integer REFERENCES commons.project (pk_project), - fk_entity integer, - fk_entity_version integer, - fk_entity_version_concat TEXT, - is_in_project boolean, - is_standard_in_project boolean, - UNIQUE (fk_entity_version_concat, fk_project), - UNIQUE (fk_entity, fk_project) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - -- DROP TRIGGER insert_schema_table_name ON information.entity_version_project_rel; - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - -- DROP TRIGGER last_modification_tmsp ON information.entity_version_project_rel; - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.entity_version_project_rel_vt - - CREATE TABLE information.entity_version_project_rel_vt (LIKE information.entity_version_project_rel); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.entity_version_project_rel - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.entity_version_project_rel_vt', true - ); - - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- Trigger: on_upsert - - CREATE TRIGGER on_upsert - BEFORE INSERT OR UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.entity_version_project_rel; - - DROP TABLE information.entity_version_project_rel_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171129213359-inf-v-persistent-item-version.js b/server/db-migrate/migrations/_migration_archive/20171129213359-inf-v-persistent-item-version.js deleted file mode 100644 index b3ad75b96..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171129213359-inf-v-persistent-item-version.js +++ /dev/null @@ -1,162 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - -- create view - - CREATE OR REPLACE VIEW information.v_persistent_item_version AS - -- union all versions - WITH versions AS - ( - SELECT persistent_item.pk_entity, - true AS is_latest_version, - persistent_item.entity_version, - persistent_item.pk_persistent_item, - persistent_item.fk_class, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period - FROM information.persistent_item - UNION - SELECT persistent_item_vt.pk_entity, - false AS is_latest_version, - persistent_item_vt.entity_version, - persistent_item_vt.pk_persistent_item, - persistent_item_vt.fk_class, - persistent_item_vt.notes, - persistent_item_vt.fk_creator, - persistent_item_vt.fk_last_modifier, - persistent_item_vt.tmsp_creation, - persistent_item_vt.tmsp_last_modification, - persistent_item_vt.sys_period - FROM information.persistent_item_vt - ), - -- count for each version is_in_project as is_in_project_count - statistics AS - ( - SELECT DISTINCT versions.pk_entity, - versions.pk_persistent_item, - versions.fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions.is_latest_version, - epr.fk_entity_version_concat - FROM versions - LEFT JOIN ( SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - GROUP BY versions.pk_entity, versions.pk_persistent_item, versions.is_latest_version, versions.fk_class, epr.fk_entity_version_concat - ORDER BY versions.pk_entity, epr.fk_entity_version_concat - ), - -- Get the favorite version of each entity. The favorite version is - -- the version with the highest is_in_project_count, and if two or more - -- versions have the same is_in_project_count, it takes the latest - -- created version as favorite. - favorites AS - ( - SELECT DISTINCT ON (pk_entity) pk_entity, is_in_project_count, fk_entity_version_concat, projects - FROM statistics - WHERE is_in_project_count > 0 - ORDER BY pk_entity, is_in_project_count DESC, fk_entity_version_concat desc - ) - -- Left outer join of all versions with the favorites and create flag is_commity_favorite - SELECT - versions.pk_entity, - versions.entity_version, - concat(versions.pk_entity || '_' || versions.entity_version) pk_entity_version_concat, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - favorites.projects, - versions.fk_class, - versions.is_latest_version, - (SELECT favorites.is_in_project_count IS NOT NULL)::boolean as is_community_favorite - FROM versions - LEFT OUTER JOIN favorites - ON favorites.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_creation DESC; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_persistent_item_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.persistent_item SET - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.persistent_item (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_version_insert(); - ` - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - const sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_persistent_item_version; - DROP FUNCTION IF EXISTS information.v_persistent_item_version_insert(); - DROP VIEW IF EXISTS information.v_persistent_item_version; - ` - db.runSql(sql, callback) - }; - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20171201134335-fdw-init.js b/server/db-migrate/migrations/_migration_archive/20171201134335-fdw-init.js deleted file mode 100644 index 36218d30e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171201134335-fdw-init.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - -- CREATE EXTENSION IF NOT EXISTS postgres_fdw; - -- SELECT * FROM pg_extension; --- - -- CREATE SERVER dfh_publi - -- FOREIGN DATA WRAPPER postgres_fdw - -- OPTIONS (host 'bhp-publi.ish-lyon.cnrs.fr', dbname 'crm_hist_extension', port '9375'); --- --- - -- --DROP USER MAPPING IF EXISTS FOR PUBLIC SERVER publi_dfh_profiles; --- - -- CREATE USER MAPPING FOR postgres SERVER dfh_publi -- FOR PUBLIC - -- OPTIONS ("user" 'utilisateur_dfh', password 'ipo9X!L0w'); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - -- DROP USER MAPPING FOR postgres SERVER dfh_publi; --- - -- DROP USER MAPPING IF EXISTS FOR PUBLIC SERVER publi_dfh_profiles; --- - -- DROP SERVER dfh_publi; --- - -- DROP EXTENSION IF EXISTS postgres_fdw; - ` - db.runSql(sql, callback) -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171201135332-che-v-api-class-profile-project.js b/server/db-migrate/migrations/_migration_archive/20171201135332-che-v-api-class-profile-project.js deleted file mode 100644 index bf02b0504..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171201135332-che-v-api-class-profile-project.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE FOREIGN TABLE che.v_api_class_profile_project - ( - pk_class integer, - identifier_in_namespace text, - class_label varchar, - fk_system_type integer, - type_label varchar, - root_namespace text, - pk_profile integer, - profile_label varchar, - pk_project integer, - project_label varchar - ) - SERVER dfh_publi OPTIONS (schema_name 'api', table_name 'v_class_profile_project'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP FOREIGN TABLE che.v_api_class_profile_project; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171201135600-che-v-api-property-profile-project.js b/server/db-migrate/migrations/_migration_archive/20171201135600-che-v-api-property-profile-project.js deleted file mode 100644 index b223417c6..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171201135600-che-v-api-property-profile-project.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE FOREIGN TABLE che.v_api_property_profile_project - ( - has_domain integer, - has_range integer, - identifier_in_namespace text, - pk_property integer, - standard_label varchar, - root_namespace text, - pk_profile integer, - profile_label varchar, - pk_project integer, - project_label varchar - ) - - SERVER dfh_publi OPTIONS (schema_name 'api', table_name 'v_property_profile_project') ; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP FOREIGN TABLE che.v_api_property_profile_project; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171201135716-che-v-api-property-all-profile-project.js b/server/db-migrate/migrations/_migration_archive/20171201135716-che-v-api-property-all-profile-project.js deleted file mode 100644 index d2f5abbce..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171201135716-che-v-api-property-all-profile-project.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE FOREIGN TABLE che.v_api_property_all_profile_project( - has_domain integer NULL, - has_range integer NULL, - identifier_in_namespace text NULL COLLATE pg_catalog."default", - pk_property integer NULL, - pk_inherited_property integer NULL, - standard_label character varying NULL COLLATE pg_catalog."default", - root_namespace text NULL COLLATE pg_catalog."default", - pk_profile integer NULL, - profile_label character varying NULL COLLATE pg_catalog."default", - pk_project integer NULL, - project_label character varying NULL COLLATE pg_catalog."default" - ) - SERVER dfh_publi - OPTIONS (schema_name 'api', table_name 'v_property_all_profile_project'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP FOREIGN TABLE che.v_api_property_all_profile_project; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171201135857-che-t-class.js b/server/db-migrate/migrations/_migration_archive/20171201135857-che-t-class.js deleted file mode 100644 index 19e342368..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171201135857-che-t-class.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE FOREIGN TABLE che.class - ( - pk_class integer, - identifier_in_namespace text, - fk_system_type integer, - standard_label varchar(500) - ) - - SERVER dfh_publi OPTIONS (schema_name 'che', table_name 'class') ; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP FOREIGN TABLE che.class; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20171204072553-inf-v-role-version.js b/server/db-migrate/migrations/_migration_archive/20171204072553-inf-v-role-version.js deleted file mode 100644 index 094935e50..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171204072553-inf-v-role-version.js +++ /dev/null @@ -1,172 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- create view - - CREATE OR REPLACE VIEW information.v_role_version AS - WITH versions AS ( - - SELECT role.pk_entity, - true AS is_latest_version, - role.entity_version, - role.pk_role, - role.fk_property, - role.fk_entity, - role.fk_temporal_entity, - role.notes, - role.fk_creator, - role.fk_last_modifier, - role.tmsp_creation, - role.tmsp_last_modification, - role.sys_period - FROM information.role - UNION - SELECT role_vt.pk_entity, - false AS is_latest_version, - role_vt.entity_version, - role_vt.pk_role, - role_vt.fk_property, - role_vt.fk_entity, - role_vt.fk_temporal_entity, - role_vt.notes, - role_vt.fk_creator, - role_vt.fk_last_modifier, - role_vt.tmsp_creation, - role_vt.tmsp_last_modification, - role_vt.sys_period - FROM information.role_vt - - ), statistics AS ( - SELECT DISTINCT - versions_1.pk_entity, - versions_1.pk_role, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - GROUP BY - versions_1.pk_entity, - versions_1.pk_role, - versions_1.is_latest_version, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_property, - versions.fk_entity, - versions.fk_temporal_entity, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_role_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.role SET - notes = NEW.notes, - fk_property = NEW.fk_property, - fk_entity = NEW.fk_entity, - fk_temporal_entity = NEW.fk_temporal_entity - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.role (notes, fk_property, fk_entity, fk_temporal_entity) - VALUES(NEW.notes, NEW.fk_property, NEW.fk_entity, NEW.fk_temporal_entity) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_version_insert(); - ` - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - const sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_role_version; - DROP FUNCTION IF EXISTS information.v_role_version_insert(); - DROP VIEW IF EXISTS information.v_role_version; - ` - db.runSql(sql, callback) - }; - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20171204074228-inf-v-temporal-entity-version.js b/server/db-migrate/migrations/_migration_archive/20171204074228-inf-v-temporal-entity-version.js deleted file mode 100644 index 5c22ea401..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171204074228-inf-v-temporal-entity-version.js +++ /dev/null @@ -1,163 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- create view - - - CREATE OR REPLACE VIEW information.v_temporal_entity_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_temporal_entity, - fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_temporal_entity, - fk_class, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_temporal_entity, - versions.fk_class, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_temporal_entity_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.temporal_entity SET - notes = NEW.notes, - fk_class = NEW.fk_class - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.temporal_entity (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_version_insert(); - ` - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - const sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_temporal_entity_version; - DROP FUNCTION IF EXISTS information.v_temporal_entity_version_insert(); - DROP VIEW IF EXISTS information.v_temporal_entity_version; - ` - db.runSql(sql, callback) - }; - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20171204122838-inf-v-appellation-version.js b/server/db-migrate/migrations/_migration_archive/20171204122838-inf-v-appellation-version.js deleted file mode 100644 index bb82bed0f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171204122838-inf-v-appellation-version.js +++ /dev/null @@ -1,169 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- create view - - - CREATE OR REPLACE VIEW information.v_appellation_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_appellation, - fk_class, - appellation_label, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_appellation, - fk_class, - appellation_label, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_class, - versions.appellation_label, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - -- create function on insert - - CREATE FUNCTION information.v_appellation_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.appellation SET - appellation_label = NEW.appellation_label, - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.appellation (notes, fk_class, appellation_label) - VALUES(NEW.notes, NEW.fk_class, NEW.appellation_label) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_version_insert(); - - ` - - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - const sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_appellation_version; - DROP FUNCTION IF EXISTS information.v_appellation_version_insert(); - DROP VIEW IF EXISTS information.v_appellation_version; - ` - db.runSql(sql, callback) - }; - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20171204163808-inf-v-language-version.js b/server/db-migrate/migrations/_migration_archive/20171204163808-inf-v-language-version.js deleted file mode 100644 index 5fdc31a67..000000000 --- a/server/db-migrate/migrations/_migration_archive/20171204163808-inf-v-language-version.js +++ /dev/null @@ -1,210 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- create view - - CREATE OR REPLACE VIEW information.v_language_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_language, - versions.fk_class, - versions.lang_type, - versions.scope, - versions.iso6392b, - versions.iso6392t, - versions.iso6391, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_language_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.language SET - notes = NEW.notes, - fk_class = NEW.fk_class, - lang_type = NEW.lang_type, - scope = NEW.scope, - iso6392b = NEW.iso6392b, - iso6392t = NEW.iso6392t, - iso6391 = NEW.iso6391 - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.language ( - pk_language, - notes, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES( - NEW.pk_language, - NEW.notes, - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_language_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_language_version_insert(); - ` - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - const sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_language_version; - DROP FUNCTION IF EXISTS information.v_language_version_insert(); - DROP VIEW IF EXISTS information.v_language_version; - ` - db.runSql(sql, callback) - }; - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20180207115147-dfh-t-entity-update.js b/server/db-migrate/migrations/_migration_archive/20180207115147-dfh-t-entity-update.js deleted file mode 100644 index 1d0f76323..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180207115147-dfh-t-entity-update.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - /* - According to inheritance functioning in postgreSQL 9.6 this column is merged - with the existing ones having the same name and type: - - merging definition of column "tmsp_last_dfh_update" for child "class_profile_view" - - merging definition of column "tmsp_last_dfh_update" for child "class" - - It is therefore not necessary to drop them in the tables and the present data should be - preserved (this behaviour concerning existing data was not tested) - */ - ALTER TABLE data_for_history.entity - ADD COLUMN tmsp_last_dfh_update timestamptz; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.entity - DROP COLUMN tmsp_last_dfh_update; - - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180207115246-dfh-t-class-profile-view-update.js b/server/db-migrate/migrations/_migration_archive/20180207115246-dfh-t-class-profile-view-update.js deleted file mode 100644 index 70c76411c..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180207115246-dfh-t-class-profile-view-update.js +++ /dev/null @@ -1,166 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN fk_class TO dfh_fk_class; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN identifier_in_namespace TO dfh_identifier_in_namespace; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN class_standard_label TO dfh_class_standard_label; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN fk_system_type TO dfh_fk_system_type; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN type_label TO dfh_type_label; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN root_namespace TO dfh_root_namespace; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN profile_association_type TO dfh_profile_association_type; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN fk_profile TO dfh_fk_profile; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN profile_label TO dfh_profile_label; - - - ALTER TABLE data_for_history.class_profile_view - ADD COLUMN removed_from_api boolean; - - -- versioning - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN fk_class TO dfh_fk_class; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN identifier_in_namespace TO dfh_identifier_in_namespace; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN class_standard_label TO dfh_class_standard_label; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN fk_system_type TO dfh_fk_system_type; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN type_label TO dfh_type_label; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN root_namespace TO dfh_root_namespace; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN profile_association_type TO dfh_profile_association_type; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN fk_profile TO dfh_fk_profile; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN profile_label TO dfh_profile_label; - - - ALTER TABLE data_for_history.class_profile_view_vt - ADD COLUMN removed_from_api boolean; - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_fk_class TO fk_class; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_identifier_in_namespace TO identifier_in_namespace; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_class_standard_label TO class_standard_label; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_fk_system_type TO fk_system_type; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_type_label TO type_label; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_root_namespace TO root_namespace; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_profile_association_type TO profile_association_type; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_fk_profile TO fk_profile; - - ALTER TABLE data_for_history.class_profile_view - RENAME COLUMN dfh_profile_label TO profile_label; - - - ALTER TABLE data_for_history.class_profile_view - DROP COLUMN removed_from_api; - - --versioning - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_fk_class TO fk_class; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_identifier_in_namespace TO identifier_in_namespace; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_class_standard_label TO class_standard_label; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_fk_system_type TO fk_system_type; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_type_label TO type_label; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_root_namespace TO root_namespace; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_profile_association_type TO profile_association_type; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_fk_profile TO fk_profile; - - ALTER TABLE data_for_history.class_profile_view_vt - RENAME COLUMN dfh_profile_label TO profile_label; - - - ALTER TABLE data_for_history.class_profile_view_vt - DROP COLUMN removed_from_api; - - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180207115247-dfh-t-class-update.js b/server/db-migrate/migrations/_migration_archive/20180207115247-dfh-t-class-update.js deleted file mode 100644 index 4790f1a63..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180207115247-dfh-t-class-update.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.class - RENAME COLUMN pk_class TO dfh_pk_class; - - ALTER TABLE data_for_history.class - RENAME COLUMN identifier_in_namespace TO dfh_identifier_in_namespace; - - ALTER TABLE data_for_history.class - RENAME COLUMN standard_label TO dfh_standard_label; - - ALTER TABLE data_for_history.class - RENAME COLUMN fk_system_type TO dfh_fk_system_type; - ---versioning - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN pk_class TO dfh_pk_class; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN identifier_in_namespace TO dfh_identifier_in_namespace; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN standard_label TO dfh_standard_label; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN fk_system_type TO dfh_fk_system_type; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class - RENAME COLUMN dfh_pk_class TO pk_class; - - ALTER TABLE data_for_history.class - RENAME COLUMN dfh_identifier_in_namespace TO identifier_in_namespace; - - ALTER TABLE data_for_history.class - RENAME COLUMN dfh_standard_label TO standard_label; - - ALTER TABLE data_for_history.class - RENAME COLUMN dfh_fk_system_type TO fk_system_type; - - --versioning - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN dfh_pk_class TO pk_class; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN dfh_identifier_in_namespace TO identifier_in_namespace; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN dfh_standard_label TO standard_label; - - ALTER TABLE data_for_history.class_vt - RENAME COLUMN dfh_fk_system_type TO fk_system_type; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180208154751-dfh-t-label.js b/server/db-migrate/migrations/_migration_archive/20180208154751-dfh-t-label.js deleted file mode 100644 index 4d0ba3650..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180208154751-dfh-t-label.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.label -( - dfh_pk_label integer, - dfh_label text, - dfh_language_iso_code varchar, - dfh_is_standard_label_for_language boolean, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_system_type integer, - dfh_fk_profile integer, - dfh_creation_time timestamp, - dfh_modification_time timestamp - -) -INHERITS (data_for_history.entity); - - - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - -CREATE TRIGGER last_modification_tmsp -BEFORE INSERT OR UPDATE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.label FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- versioning - -CREATE TABLE data_for_history.label_vt (LIKE data_for_history.label); - -CREATE TRIGGER versioning_trigger -BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.label -FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.label_vt', true -); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE data_for_history.label CASCADE; - DROP TABLE data_for_history.label_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180209155138-dfh-t-text-property.js b/server/db-migrate/migrations/_migration_archive/20180209155138-dfh-t-text-property.js deleted file mode 100644 index 2b914b913..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180209155138-dfh-t-text-property.js +++ /dev/null @@ -1,84 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.text_property -( - dfh_pk_text_property integer, - dfh_text_property text, - dfh_fk_text_property_type integer, - dfh_language_iso_code varchar, - dfh_creation_time timestamp, - dfh_modification_time timestamp, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_system_type integer, - dfh_fk_entity_association integer, - dfh_fk_profile integer, - dfh_fk_is_subclass_of integer -) -INHERITS (data_for_history.entity); - - - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - -CREATE TRIGGER last_modification_tmsp -BEFORE INSERT OR UPDATE - ON data_for_history.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.text_property FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- versioning - -CREATE TABLE data_for_history.text_property_vt (LIKE data_for_history.text_property); - -CREATE TRIGGER versioning_trigger -BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.text_property -FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.text_property_vt', true -); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE data_for_history.text_property CASCADE; - DROP TABLE data_for_history.text_property_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180219125147-dfh-t-property-drop.js b/server/db-migrate/migrations/_migration_archive/20180219125147-dfh-t-property-drop.js deleted file mode 100644 index b3f417730..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180219125147-dfh-t-property-drop.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - DROP TABLE IF EXISTS data_for_history.property CASCADE; - DROP TABLE IF EXISTS data_for_history.property_vt CASCADE; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180219161027-dfh-t-property-new.js b/server/db-migrate/migrations/_migration_archive/20180219161027-dfh-t-property-new.js deleted file mode 100644 index 0dd885e4a..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180219161027-dfh-t-property-new.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE data_for_history.property ( - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_creation_time timestamp, - dfh_modification_time timestamp, - dfh_domain_instances_cardinality smallint, - dfh_range_instances_cardinality smallint, - dfh_standard_label varchar(500) - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.property FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.property_vt (LIKE data_for_history.property); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.property_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.property CASCADE; - DROP TABLE IF EXISTS data_for_history.property_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220160640-dfh-t-class-make-pk-unique.js b/server/db-migrate/migrations/_migration_archive/20180220160640-dfh-t-class-make-pk-unique.js deleted file mode 100644 index fae19abad..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220160640-dfh-t-class-make-pk-unique.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - -- add unique constraint to pk - ALTER TABLE data_for_history.class - ADD CONSTRAINT unique_dfh_pk_class - UNIQUE (dfh_pk_class); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - -- drop unique constraint to pk - ALTER TABLE data_for_history.class - DROP CONSTRAINT unique_dfh_pk_class; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220160743-inf-t-persistent-item-fk-class-update.js b/server/db-migrate/migrations/_migration_archive/20180220160743-inf-t-persistent-item-fk-class-update.js deleted file mode 100644 index 35ba1f659..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220160743-inf-t-persistent-item-fk-class-update.js +++ /dev/null @@ -1,358 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - - -- Drop forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.persistent_item - DROP CONSTRAINT persistent_item_fk_class_fkey; - - -- Drop view depending on persistent_item/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_persistent_item_version; - DROP FUNCTION IF EXISTS information.v_persistent_item_version_insert(); - DROP VIEW IF EXISTS information.v_persistent_item_version; - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.persistent_item - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Add foreign key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.persistent_item - ADD CONSTRAINT persistent_item_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (dfh_pk_class); - - -- versioning - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.persistent_item_vt - ALTER COLUMN fk_class TYPE integer USING NULL; - - - -- create the view again - - CREATE OR REPLACE VIEW information.v_persistent_item_version AS - -- union all versions - WITH versions AS - ( - SELECT persistent_item.pk_entity, - true AS is_latest_version, - persistent_item.entity_version, - persistent_item.pk_persistent_item, - persistent_item.fk_class, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period - FROM information.persistent_item - UNION - SELECT persistent_item_vt.pk_entity, - false AS is_latest_version, - persistent_item_vt.entity_version, - persistent_item_vt.pk_persistent_item, - persistent_item_vt.fk_class, - persistent_item_vt.notes, - persistent_item_vt.fk_creator, - persistent_item_vt.fk_last_modifier, - persistent_item_vt.tmsp_creation, - persistent_item_vt.tmsp_last_modification, - persistent_item_vt.sys_period - FROM information.persistent_item_vt - ), - -- count for each version is_in_project as is_in_project_count - statistics AS - ( - SELECT DISTINCT versions.pk_entity, - versions.pk_persistent_item, - versions.fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions.is_latest_version, - epr.fk_entity_version_concat - FROM versions - LEFT JOIN ( SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - GROUP BY versions.pk_entity, versions.pk_persistent_item, versions.is_latest_version, versions.fk_class, epr.fk_entity_version_concat - ORDER BY versions.pk_entity, epr.fk_entity_version_concat - ), - -- Get the favorite version of each entity. The favorite version is - -- the version with the highest is_in_project_count, and if two or more - -- versions have the same is_in_project_count, it takes the latest - -- created version as favorite. - favorites AS - ( - SELECT DISTINCT ON (pk_entity) pk_entity, is_in_project_count, fk_entity_version_concat, projects - FROM statistics - WHERE is_in_project_count > 0 - ORDER BY pk_entity, is_in_project_count DESC, fk_entity_version_concat desc - ) - -- Left outer join of all versions with the favorites and create flag is_commity_favorite - SELECT - versions.pk_entity, - versions.entity_version, - concat(versions.pk_entity || '_' || versions.entity_version) pk_entity_version_concat, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - favorites.projects, - versions.fk_class, - versions.is_latest_version, - (SELECT favorites.is_in_project_count IS NOT NULL)::boolean as is_community_favorite - FROM versions - LEFT OUTER JOIN favorites - ON favorites.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_creation DESC; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_persistent_item_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.persistent_item SET - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.persistent_item (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_version_insert(); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.persistent_item - DROP CONSTRAINT persistent_item_fk_class_fkey; - - -- Drop view depending on persistent_item/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_persistent_item_version; - DROP FUNCTION IF EXISTS information.v_persistent_item_version_insert(); - DROP VIEW IF EXISTS information.v_persistent_item_version; - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.persistent_item - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - -- Add forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.persistent_item - ADD CONSTRAINT persistent_item_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (data_for_history_id); - - - -- versioning - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.persistent_item_vt - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - -- create the view again - - CREATE OR REPLACE VIEW information.v_persistent_item_version AS - -- union all versions - WITH versions AS - ( - SELECT persistent_item.pk_entity, - true AS is_latest_version, - persistent_item.entity_version, - persistent_item.pk_persistent_item, - persistent_item.fk_class, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period - FROM information.persistent_item - UNION - SELECT persistent_item_vt.pk_entity, - false AS is_latest_version, - persistent_item_vt.entity_version, - persistent_item_vt.pk_persistent_item, - persistent_item_vt.fk_class, - persistent_item_vt.notes, - persistent_item_vt.fk_creator, - persistent_item_vt.fk_last_modifier, - persistent_item_vt.tmsp_creation, - persistent_item_vt.tmsp_last_modification, - persistent_item_vt.sys_period - FROM information.persistent_item_vt - ), - -- count for each version is_in_project as is_in_project_count - statistics AS - ( - SELECT DISTINCT versions.pk_entity, - versions.pk_persistent_item, - versions.fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions.is_latest_version, - epr.fk_entity_version_concat - FROM versions - LEFT JOIN ( SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - GROUP BY versions.pk_entity, versions.pk_persistent_item, versions.is_latest_version, versions.fk_class, epr.fk_entity_version_concat - ORDER BY versions.pk_entity, epr.fk_entity_version_concat - ), - -- Get the favorite version of each entity. The favorite version is - -- the version with the highest is_in_project_count, and if two or more - -- versions have the same is_in_project_count, it takes the latest - -- created version as favorite. - favorites AS - ( - SELECT DISTINCT ON (pk_entity) pk_entity, is_in_project_count, fk_entity_version_concat, projects - FROM statistics - WHERE is_in_project_count > 0 - ORDER BY pk_entity, is_in_project_count DESC, fk_entity_version_concat desc - ) - -- Left outer join of all versions with the favorites and create flag is_commity_favorite - SELECT - versions.pk_entity, - versions.entity_version, - concat(versions.pk_entity || '_' || versions.entity_version) pk_entity_version_concat, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - favorites.projects, - versions.fk_class, - versions.is_latest_version, - (SELECT favorites.is_in_project_count IS NOT NULL)::boolean as is_community_favorite - FROM versions - LEFT OUTER JOIN favorites - ON favorites.fk_entity_version_concat = concat(versions.pk_entity || '_' || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_creation DESC; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_persistent_item_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.persistent_item SET - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.persistent_item (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_version_insert(); - - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220162426-inf-t-temporal-entity-fk-class-update.js b/server/db-migrate/migrations/_migration_archive/20180220162426-inf-t-temporal-entity-fk-class-update.js deleted file mode 100644 index d11c7111a..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220162426-inf-t-temporal-entity-fk-class-update.js +++ /dev/null @@ -1,357 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.temporal_entity - DROP CONSTRAINT temporal_entity_fk_class_fkey; - - -- Drop view depending on temporal_entity/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_temporal_entity_version; - DROP FUNCTION IF EXISTS information.v_temporal_entity_version_insert(); - DROP VIEW IF EXISTS information.v_temporal_entity_version; - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.temporal_entity - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Add foreign key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.temporal_entity - ADD CONSTRAINT temporal_entity_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (dfh_pk_class); - - -- versioning - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.temporal_entity_vt - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Create the view again - - CREATE OR REPLACE VIEW information.v_temporal_entity_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_temporal_entity, - fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_temporal_entity, - fk_class, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_temporal_entity, - versions.fk_class, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_temporal_entity_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.temporal_entity SET - notes = NEW.notes, - fk_class = NEW.fk_class - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.temporal_entity (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_version_insert(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.temporal_entity - DROP CONSTRAINT temporal_entity_fk_class_fkey; - - -- Drop view depending on temporal_entity/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_temporal_entity_version; - DROP FUNCTION IF EXISTS information.v_temporal_entity_version_insert(); - DROP VIEW IF EXISTS information.v_temporal_entity_version; - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.temporal_entity - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - -- Add forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.temporal_entity - ADD CONSTRAINT temporal_entity_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (data_for_history_id); - - - -- versioning - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.temporal_entity_vt - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - - -- Create the view again - - CREATE OR REPLACE VIEW information.v_temporal_entity_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_temporal_entity, - fk_class, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.temporal_entity_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_temporal_entity, - fk_class, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_temporal_entity, - fk_class, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_temporal_entity, - versions.fk_class, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_temporal_entity_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.temporal_entity SET - notes = NEW.notes, - fk_class = NEW.fk_class - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.temporal_entity (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_version_insert(); - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220165245-inf-t-appellation-fk-class-update.js b/server/db-migrate/migrations/_migration_archive/20180220165245-inf-t-appellation-fk-class-update.js deleted file mode 100644 index 05dcd802c..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220165245-inf-t-appellation-fk-class-update.js +++ /dev/null @@ -1,367 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.appellation - DROP CONSTRAINT appellation_fk_class_fkey; - - -- Drop view depending on appellation/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_appellation_version; - DROP FUNCTION IF EXISTS information.v_appellation_version_insert(); - DROP VIEW IF EXISTS information.v_appellation_version; - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.appellation - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Add foreign key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.appellation - ADD CONSTRAINT appellation_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (dfh_pk_class); - - -- versioning - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.appellation_vt - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Create the view again - - - CREATE OR REPLACE VIEW information.v_appellation_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_appellation, - fk_class, - appellation_label, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_appellation, - fk_class, - appellation_label, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_class, - versions.appellation_label, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - -- create function on insert - - CREATE FUNCTION information.v_appellation_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.appellation SET - appellation_label = NEW.appellation_label, - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.appellation (notes, fk_class, appellation_label) - VALUES(NEW.notes, NEW.fk_class, NEW.appellation_label) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_version_insert(); - ` - - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.appellation - DROP CONSTRAINT appellation_fk_class_fkey; - - -- Drop view depending on appellation/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_appellation_version; - DROP FUNCTION IF EXISTS information.v_appellation_version_insert(); - DROP VIEW IF EXISTS information.v_appellation_version; - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.appellation - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - -- Add forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.appellation - ADD CONSTRAINT appellation_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (data_for_history_id); - - - -- versioning - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.appellation_vt - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - - -- Create the view again - - - CREATE OR REPLACE VIEW information.v_appellation_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_appellation, - fk_class, - appellation_label, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.appellation_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_appellation, - fk_class, - appellation_label, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_appellation, - fk_class, - appellation_label, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_class, - versions.appellation_label, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - -- create function on insert - - CREATE FUNCTION information.v_appellation_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.appellation SET - appellation_label = NEW.appellation_label, - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.appellation (notes, fk_class, appellation_label) - VALUES(NEW.notes, NEW.fk_class, NEW.appellation_label) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_version_insert(); - ` - - db.runSql(sql, callback) - - }; - - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20180220165448-inf-t-language-fk-class-update.js b/server/db-migrate/migrations/_migration_archive/20180220165448-inf-t-language-fk-class-update.js deleted file mode 100644 index 9088bd86d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220165448-inf-t-language-fk-class-update.js +++ /dev/null @@ -1,453 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.language - DROP CONSTRAINT language_fk_class_fkey; - - -- Drop view depending on language/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_language_version; - DROP FUNCTION IF EXISTS information.v_language_version_insert(); - DROP VIEW IF EXISTS information.v_language_version; - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.language - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Add foreign key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.language - ADD CONSTRAINT language_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (dfh_pk_class); - - -- versioning - - -- Change data type of column fk_class from varchar(7) to integer - - ALTER TABLE information.language_vt - ALTER COLUMN fk_class TYPE integer USING NULL; - - -- Create the view again - - CREATE OR REPLACE VIEW information.v_language_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_language, - versions.fk_class, - versions.lang_type, - versions.scope, - versions.iso6392b, - versions.iso6392t, - versions.iso6391, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_language_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.language SET - notes = NEW.notes, - fk_class = NEW.fk_class, - lang_type = NEW.lang_type, - scope = NEW.scope, - iso6392b = NEW.iso6392b, - iso6392t = NEW.iso6392t, - iso6391 = NEW.iso6391 - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.language ( - pk_language, - notes, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES( - NEW.pk_language, - NEW.notes, - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_language_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_language_version_insert(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.class/dfh_pk_class - - ALTER TABLE information.language - DROP CONSTRAINT language_fk_class_fkey; - - -- Drop view depending on language/fk_class - - DROP TRIGGER IF EXISTS on_insert ON information.v_language_version; - DROP FUNCTION IF EXISTS information.v_language_version_insert(); - DROP VIEW IF EXISTS information.v_language_version; - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.language - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - -- Add forein key to data_for_history.class/data_for_history_id - - ALTER TABLE information.language - ADD CONSTRAINT language_fk_class_fkey - FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (data_for_history_id); - - - -- versioning - - -- Change data type of column fk_class from integer to varchar(7) - - ALTER TABLE information.language_vt - ALTER COLUMN fk_class TYPE varchar(7) USING NULL; - - - -- Create the view again - - CREATE OR REPLACE VIEW information.v_language_version AS - WITH versions AS ( - - SELECT pk_entity, - true AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language - UNION - SELECT pk_entity, - false AS is_latest_version, - entity_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - notes, - fk_creator, - fk_last_modifier, - tmsp_creation, - tmsp_last_modification, - sys_period - FROM information.language_vt - ), statistics AS ( - SELECT DISTINCT - pk_entity, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( - SELECT - fk_entity_version_concat, - fk_project, - is_in_project, - is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((pk_entity || '_'::text) || entity_version) - GROUP BY - pk_entity, - is_latest_version, - pk_language, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - epr.fk_entity_version_concat - ORDER BY pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.pk_language, - versions.fk_class, - versions.lang_type, - versions.scope, - versions.iso6392b, - versions.iso6392t, - versions.iso6391, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_language_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.language SET - notes = NEW.notes, - fk_class = NEW.fk_class, - lang_type = NEW.lang_type, - scope = NEW.scope, - iso6392b = NEW.iso6392b, - iso6392t = NEW.iso6392t, - iso6391 = NEW.iso6391 - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.language ( - pk_language, - notes, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES( - NEW.pk_language, - NEW.notes, - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_language_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_language_version_insert(); - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220165657-dfh-t-property-make-pk-unique.js b/server/db-migrate/migrations/_migration_archive/20180220165657-dfh-t-property-make-pk-unique.js deleted file mode 100644 index fdcc74f77..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220165657-dfh-t-property-make-pk-unique.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - -- add unique constraint to pk - ALTER TABLE data_for_history.property - ADD CONSTRAINT unique_dfh_pk_property - UNIQUE (dfh_pk_property); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - -- drop unique constraint to pk - ALTER TABLE data_for_history.property - DROP CONSTRAINT unique_dfh_pk_property; - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180220165920-inf-t-role-fk-property-update.js b/server/db-migrate/migrations/_migration_archive/20180220165920-inf-t-role-fk-property-update.js deleted file mode 100644 index e5b1873d5..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220165920-inf-t-role-fk-property-update.js +++ /dev/null @@ -1,366 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - - -- Drop view depending on role/fk_property - - DROP TRIGGER IF EXISTS on_insert ON information.v_role_version; - DROP FUNCTION IF EXISTS information.v_role_version_insert(); - DROP VIEW IF EXISTS information.v_role_version; - - -- Change data type of column fk_property from varchar(7) to integer - - ALTER TABLE information.role - ALTER COLUMN fk_property TYPE integer USING NULL; - - -- Add foreign key to data_for_history.property/dfh_pk_property - - ALTER TABLE information.role - ADD CONSTRAINT role_fk_property_fkey - FOREIGN KEY (fk_property) - REFERENCES data_for_history.property (dfh_pk_property); - - -- versioning - - -- Change data type of column fk_property from varchar(7) to integer - - ALTER TABLE information.role_vt - ALTER COLUMN fk_property TYPE integer USING NULL; - - - -- create the view again - - CREATE OR REPLACE VIEW information.v_role_version AS - WITH versions AS ( - - SELECT role.pk_entity, - true AS is_latest_version, - role.entity_version, - role.pk_role, - role.fk_property, - role.fk_entity, - role.fk_temporal_entity, - role.notes, - role.fk_creator, - role.fk_last_modifier, - role.tmsp_creation, - role.tmsp_last_modification, - role.sys_period - FROM information.role - UNION - SELECT role_vt.pk_entity, - false AS is_latest_version, - role_vt.entity_version, - role_vt.pk_role, - role_vt.fk_property, - role_vt.fk_entity, - role_vt.fk_temporal_entity, - role_vt.notes, - role_vt.fk_creator, - role_vt.fk_last_modifier, - role_vt.tmsp_creation, - role_vt.tmsp_last_modification, - role_vt.sys_period - FROM information.role_vt - - ), statistics AS ( - SELECT DISTINCT - versions_1.pk_entity, - versions_1.pk_role, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - GROUP BY - versions_1.pk_entity, - versions_1.pk_role, - versions_1.is_latest_version, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_property, - versions.fk_entity, - versions.fk_temporal_entity, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_role_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.role SET - notes = NEW.notes, - fk_property = NEW.fk_property, - fk_entity = NEW.fk_entity, - fk_temporal_entity = NEW.fk_temporal_entity - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.role (notes, fk_property, fk_entity, fk_temporal_entity) - VALUES(NEW.notes, NEW.fk_property, NEW.fk_entity, NEW.fk_temporal_entity) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_version_insert(); - - ` - - db.runSql(sql, callback) - - }; - - exports.down = function(db, callback) { - - const sql = ` - - -- Drop forein key to data_for_history.property/dfh_pk_property - - ALTER TABLE information.role - DROP CONSTRAINT role_fk_property_fkey; - - -- Drop view depending on role/fk_property - - DROP TRIGGER IF EXISTS on_insert ON information.v_role_version; - DROP FUNCTION IF EXISTS information.v_role_version_insert(); - DROP VIEW IF EXISTS information.v_role_version; - - -- Change data type of column fk_property from integer to varchar(7) - - ALTER TABLE information.role - ALTER COLUMN fk_property TYPE varchar(7) USING NULL; - - -- versioning - - -- Change data type of column fk_property from integer to varchar(7) - - ALTER TABLE information.role_vt - ALTER COLUMN fk_property TYPE varchar(7) USING NULL; - - -- create the view again - - CREATE OR REPLACE VIEW information.v_role_version AS - WITH versions AS ( - - SELECT role.pk_entity, - true AS is_latest_version, - role.entity_version, - role.pk_role, - role.fk_property, - role.fk_entity, - role.fk_temporal_entity, - role.notes, - role.fk_creator, - role.fk_last_modifier, - role.tmsp_creation, - role.tmsp_last_modification, - role.sys_period - FROM information.role - UNION - SELECT role_vt.pk_entity, - false AS is_latest_version, - role_vt.entity_version, - role_vt.pk_role, - role_vt.fk_property, - role_vt.fk_entity, - role_vt.fk_temporal_entity, - role_vt.notes, - role_vt.fk_creator, - role_vt.fk_last_modifier, - role_vt.tmsp_creation, - role_vt.tmsp_last_modification, - role_vt.sys_period - FROM information.role_vt - - ), statistics AS ( - SELECT DISTINCT - versions_1.pk_entity, - versions_1.pk_role, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(epr.is_standard_in_project) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - GROUP BY - versions_1.pk_entity, - versions_1.pk_role, - versions_1.is_latest_version, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ) - , favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_property, - versions.fk_entity, - versions.fk_temporal_entity, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - - -- create trigger function for insert - - CREATE FUNCTION information.v_role_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.role SET - notes = NEW.notes, - fk_property = NEW.fk_property, - fk_entity = NEW.fk_entity, - fk_temporal_entity = NEW.fk_temporal_entity - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.role (notes, fk_property, fk_entity, fk_temporal_entity) - VALUES(NEW.notes, NEW.fk_property, NEW.fk_entity, NEW.fk_temporal_entity) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_version_insert(); - ` - - db.runSql(sql, callback) - - }; - - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_migration_archive/20180220171107-dfh-t-class-drop-a-col.js b/server/db-migrate/migrations/_migration_archive/20180220171107-dfh-t-class-drop-a-col.js deleted file mode 100644 index 932a9d66e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180220171107-dfh-t-class-drop-a-col.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.class - DROP CONSTRAINT class_data_for_history_id_key; - - ALTER TABLE data_for_history.class - DROP COLUMN data_for_history_id; - - -- versioning - - ALTER TABLE data_for_history.class_vt - DROP COLUMN data_for_history_id; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class - ADD COLUMN data_for_history_id VARCHAR(7); - - ALTER TABLE data_for_history.class - ADD CONSTRAINT class_data_for_history_id_key - UNIQUE (data_for_history_id); - - -- versioning - - ALTER TABLE data_for_history.class_vt - ADD COLUMN data_for_history_id varchar(7); - - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180221133638-dfh-t-property-change-cardinality-cols.js b/server/db-migrate/migrations/_migration_archive/20180221133638-dfh-t-property-change-cardinality-cols.js deleted file mode 100644 index f6023f4ef..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180221133638-dfh-t-property-change-cardinality-cols.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.property - ADD COlUMN dfh_domain_instances_min_quantifier smallint, - ADD COlUMN dfh_domain_instances_max_quantifier smallint, - ADD COlUMN dfh_range_instances_min_quantifier smallint, - ADD COlUMN dfh_range_instances_max_quantifier smallint, - DROP COLUMN dfh_domain_instances_cardinality, - DROP COLUMN dfh_range_instances_cardinality; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.property - DROP COlUMN dfh_domain_instances_min_quantifier, - DROP COlUMN dfh_domain_instances_max_quantifier, - DROP COlUMN dfh_range_instances_min_quantifier, - DROP COlUMN dfh_range_instances_max_quantifier, - ADD COLUMN dfh_domain_instances_cardinality smallint, - ADD COLUMN dfh_range_instances_cardinality smallint; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180222160031-dfh-t-entity-subtables-version-triggers.js b/server/db-migrate/migrations/_migration_archive/20180222160031-dfh-t-entity-subtables-version-triggers.js deleted file mode 100644 index b69e664de..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180222160031-dfh-t-entity-subtables-version-triggers.js +++ /dev/null @@ -1,162 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - - - const sql = ` - - --------- class - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.class - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.class - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - --------- class_profile_view - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - --------- label - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - --------- property - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.property - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - --------- text_property - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - --------- class - - DROP TRIGGER create_entity_version_key ON data_for_history.class; - DROP TRIGGER update_entity_version_key ON data_for_history.class; - - --------- class_profile_view - - DROP TRIGGER create_entity_version_key ON data_for_history.class_profile_view; - DROP TRIGGER update_entity_version_key ON data_for_history.class_profile_view; - - --------- label - - DROP TRIGGER create_entity_version_key ON data_for_history.label; - DROP TRIGGER update_entity_version_key ON data_for_history.label; - - --------- property - - DROP TRIGGER create_entity_version_key ON data_for_history.property; - DROP TRIGGER update_entity_version_key ON data_for_history.property; - - --------- text_property - - DROP TRIGGER create_entity_version_key ON data_for_history.text_property; - DROP TRIGGER update_entity_version_key ON data_for_history.text_property; - - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/20180223192227-dfh-t-profile.js b/server/db-migrate/migrations/_migration_archive/20180223192227-dfh-t-profile.js deleted file mode 100644 index 0e7f87476..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180223192227-dfh-t-profile.js +++ /dev/null @@ -1,93 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE data_for_history.profile ( - dfh_pk_profile integer, - dfh_fk_is_subprofile_of integer, - dfh_standard_label varchar(500), - dfh_fk_project_of_belonging integer, - dfh_start_date date, - dfh_end_date date, - dfh_creation_time timestamp, - dfh_modification_time timestamp - ) - INHERITS (data_for_history.entity); - - ALTER TABLE data_for_history.profile - ADD CONSTRAINT unique_dfh_pk_profile - UNIQUE (dfh_pk_profile); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.profile - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.profile - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.profile FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.profile - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.profile - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE data_for_history.profile_vt (LIKE data_for_history.profile); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.profile - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.profile_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.profile CASCADE; - DROP TABLE IF EXISTS data_for_history.profile_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180223195527-dfh-t-property-profile-view.js b/server/db-migrate/migrations/_migration_archive/20180223195527-dfh-t-property-profile-view.js deleted file mode 100644 index a8f7a16d5..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180223195527-dfh-t-property-profile-view.js +++ /dev/null @@ -1,91 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.property_profile_view ( - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_pk_inherited_property integer, - dfh_standard_label varchar, - dfh_root_namespace text, - dfh_pk_profile integer, - dfh_profile_label varchar, - is_inabled_in_profile boolean, - removed_from_api boolean - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.property_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.property_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.property_profile_view FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.property_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.property_profile_view - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE data_for_history.property_profile_view_vt (LIKE data_for_history.property_profile_view); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.property_profile_view - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.property_profile_view_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.property_profile_view CASCADE; - DROP TABLE IF EXISTS data_for_history.property_profile_view_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226120027-dfh-t-associates-system-type.js b/server/db-migrate/migrations/_migration_archive/20180226120027-dfh-t-associates-system-type.js deleted file mode 100644 index d4797a860..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226120027-dfh-t-associates-system-type.js +++ /dev/null @@ -1,94 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.associates_system_type ( - dfh_pk_associates_system_type integer, - dfh_fk_system_type integer, - dfh_fk_class integer, - dfh_fk_class_type integer, - dfh_fk_property integer, - dfh_fk_property_type integer, - dfh_fk_namespace integer, - dfh_fk_label integer, - dfh_fk_text_property integer, - dfh_fk_project integer, - dfh_fk_profile integer, - dfh_fk_entity_association integer, - is_inabled_in_profile boolean, - removed_from_api boolean default FALSE - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.associates_system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.associates_system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.associates_system_type FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.associates_system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON data_for_history.associates_system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE data_for_history.associates_system_type_vt (LIKE data_for_history.associates_system_type); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.associates_system_type - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.associates_system_type_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.associates_system_type CASCADE; - DROP TABLE IF EXISTS data_for_history.associates_system_type_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226131107-dfh-t-drop-columns-fk-system-type.js b/server/db-migrate/migrations/_migration_archive/20180226131107-dfh-t-drop-columns-fk-system-type.js deleted file mode 100644 index a9a1d2241..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226131107-dfh-t-drop-columns-fk-system-type.js +++ /dev/null @@ -1,77 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.class - DROP COLUMN dfh_fk_system_type; - - ALTER TABLE data_for_history.label - DROP COLUMN dfh_fk_system_type; - - ALTER TABLE data_for_history.text_property - DROP COLUMN dfh_fk_text_property_type; - - - -- versioning - - ALTER TABLE data_for_history.class_vt - DROP COLUMN dfh_fk_system_type; - - ALTER TABLE data_for_history.label_vt - DROP COLUMN dfh_fk_system_type; - - ALTER TABLE data_for_history.text_property_vt - DROP COLUMN dfh_fk_text_property_type; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class - ADD COLUMN dfh_fk_system_type INTEGER; - - ALTER TABLE data_for_history.label - ADD COLUMN dfh_fk_system_type INTEGER; - - ALTER TABLE data_for_history.text_property - ADD COLUMN dfh_fk_text_property_type INTEGER; - - - -- versioning - - ALTER TABLE data_for_history.class_vt - ADD COLUMN dfh_fk_system_type INTEGER; - - ALTER TABLE data_for_history.label_vt - ADD COLUMN dfh_fk_system_type INTEGER; - - ALTER TABLE data_for_history.text_property_vt - ADD COLUMN dfh_fk_text_property_type INTEGER; - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226140507-dfh-t-add-columns-entity.js b/server/db-migrate/migrations/_migration_archive/20180226140507-dfh-t-add-columns-entity.js deleted file mode 100644 index fc83887d1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226140507-dfh-t-add-columns-entity.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.entity - ADD COLUMN is_inabled_in_profile BOOLEAN, - ADD COLUMN removed_from_api BOOLEAN DEFAULT FALSE; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - -- this part won't restore the former existing columns on other tables - ALTER TABLE data_for_history.entity - DROP COLUMN is_inabled_in_profile BOOLEAN, - DROP COLUMN removed_from_api BOOLEAN DEFAULT FALSE; - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226141251-dfh-t-system-type.js b/server/db-migrate/migrations/_migration_archive/20180226141251-dfh-t-system-type.js deleted file mode 100644 index 2b7af3c30..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226141251-dfh-t-system-type.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.system_type -( - dfh_pk_system_type integer, - dfh_used_in_table varchar(250), - dfh_standard_label varchar(500), - dfh_creation_time timestamp, - dfh_modification_time timestamp - -) -INHERITS (data_for_history.entity); - - - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - -CREATE TRIGGER last_modification_tmsp -BEFORE INSERT OR UPDATE - ON data_for_history.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.system_type FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON data_for_history.system_type - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - --- versioning - -CREATE TABLE data_for_history.system_type_vt (LIKE data_for_history.system_type); - -CREATE TRIGGER versioning_trigger -BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.system_type -FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.system_type_vt', true -); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE data_for_history.system_type CASCADE; - DROP TABLE data_for_history.system_type_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226180807-dfh-t-patch_inabled_enabled.js b/server/db-migrate/migrations/_migration_archive/20180226180807-dfh-t-patch_inabled_enabled.js deleted file mode 100644 index 9ca1b4752..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226180807-dfh-t-patch_inabled_enabled.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.class_profile_view DROP COLUMN is_enabled_in_profile; - ALTER TABLE data_for_history.entity RENAME COLUMN is_inabled_in_profile TO is_enabled_in_profile; - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - -- no way back ! - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180226200807-dfh-t-different-patches.js b/server/db-migrate/migrations/_migration_archive/20180226200807-dfh-t-different-patches.js deleted file mode 100644 index 5b5444453..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180226200807-dfh-t-different-patches.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.class - ADD COLUMN dfh_creation_time TIMESTAMP, - ADD COLUMN dfh_modification_time TIMESTAMP; - - ALTER TABLE data_for_history.label ADD COLUMN dfh_fk_system_type INTEGER; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE data_for_history.class - DROP COLUMN dfh_creation_time, - DROP COLUMN dfh_modification_time; - - ALTER TABLE data_for_history.label DROP COLUMN dfh_fk_system_type; - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180227215251-inf-v-role-update.js b/server/db-migrate/migrations/_migration_archive/20180227215251-inf-v-role-update.js deleted file mode 100644 index 1a750b919..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180227215251-inf-v-role-update.js +++ /dev/null @@ -1,124 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - CREATE OR REPLACE VIEW information.v_role_version AS - WITH versions AS ( - SELECT role.pk_entity, - true AS is_latest_version, - role.entity_version, - role.pk_role, - role.fk_property, - role.fk_entity, - role.fk_temporal_entity, - role.notes, - role.fk_creator, - role.fk_last_modifier, - role.tmsp_creation, - role.tmsp_last_modification, - role.sys_period - FROM information.role - UNION - SELECT role_vt.pk_entity, - false AS is_latest_version, - role_vt.entity_version, - role_vt.pk_role, - role_vt.fk_property, - role_vt.fk_entity, - role_vt.fk_temporal_entity, - role_vt.notes, - role_vt.fk_creator, - role_vt.fk_last_modifier, - role_vt.tmsp_creation, - role_vt.tmsp_last_modification, - role_vt.sys_period - FROM information.role_vt - ) - , statistics AS ( - SELECT DISTINCT versions_1.pk_entity, - versions_1.pk_role, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(*) FILTER (where epr.is_standard_in_project = true) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - WHERE epr.is_in_project = true - GROUP BY versions_1.pk_entity, versions_1.pk_role, versions_1.is_latest_version, versions_1.fk_property, versions_1.fk_entity, versions_1.fk_temporal_entity, epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ), - favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.is_standard_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_property, - versions.fk_entity, - versions.fk_temporal_entity, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite, - COALESCE(favorites.is_in_project_count,0) AS is_in_project_count, - COALESCE(favorites.is_standard_in_project_count,0) AS is_standard_in_project_count - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180322144938-inf-t-time-primitive.js b/server/db-migrate/migrations/_migration_archive/20180322144938-inf-t-time-primitive.js deleted file mode 100644 index e7448d00f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180322144938-inf-t-time-primitive.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - -- Table: information.time_primitive - - CREATE TYPE calendar_granularities AS ENUM ('1 year', '1 month', '1 day', '1 hour', '1 minute', '1 second'); - - CREATE TABLE information.time_primitive - ( - pk_time_primitive serial PRIMARY KEY, - begin TIMESTAMP WITHOUT TIME ZONE, - duration calendar_granularities, - fk_class integer REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (information.entity); - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: information.time_primitive_vt - - CREATE TABLE information.time_primitive_vt (LIKE information.time_primitive); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.time_primitive - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.time_primitive_vt', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP TABLE information.time_primitive; - - DROP TABLE information.time_primitive_vt; - - DROP TYPE calendar_granularities; - ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180322152842-inf-v-time-primitive.js b/server/db-migrate/migrations/_migration_archive/20180322152842-inf-v-time-primitive.js deleted file mode 100644 index 270021378..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180322152842-inf-v-time-primitive.js +++ /dev/null @@ -1,173 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = `CREATE OR REPLACE VIEW information.v_time_primitive_version AS - WITH versions AS ( - SELECT time_primitive.pk_entity, - true AS is_latest_version, - time_primitive.entity_version, - time_primitive.pk_time_primitive, - time_primitive.fk_class, - time_primitive.duration, - time_primitive.begin, - time_primitive.notes, - time_primitive.fk_creator, - time_primitive.fk_last_modifier, - time_primitive.tmsp_creation, - time_primitive.tmsp_last_modification, - time_primitive.sys_period - FROM information.time_primitive - UNION - SELECT time_primitive_vt.pk_entity, - false AS is_latest_version, - time_primitive_vt.entity_version, - time_primitive_vt.pk_time_primitive, - time_primitive_vt.fk_class, - time_primitive_vt.duration, - time_primitive_vt.begin, - time_primitive_vt.notes, - time_primitive_vt.fk_creator, - time_primitive_vt.fk_last_modifier, - time_primitive_vt.tmsp_creation, - time_primitive_vt.tmsp_last_modification, - time_primitive_vt.sys_period - FROM information.time_primitive_vt - ) - , statistics AS ( - SELECT DISTINCT versions_1.pk_entity, - versions_1.pk_time_primitive, - versions_1.fk_class, - versions_1.duration, - versions_1.begin, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(*) FILTER (where epr.is_standard_in_project = true) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - WHERE epr.is_in_project = true - GROUP BY versions_1.pk_entity, versions_1.pk_time_primitive, versions_1.is_latest_version, versions_1.fk_class, versions_1.duration, versions_1.begin, epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ), - favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.is_standard_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_class, - versions.duration, - TO_CHAR(versions.begin, 'J') as julian_day, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite, - COALESCE(favorites.is_in_project_count,0) AS is_in_project_count, - COALESCE(favorites.is_standard_in_project_count,0) AS is_standard_in_project_count - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_time_primitive_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.time_primitive SET - fk_class = NEW.fk_class, - notes = NEW.notes, - - --convert given julian day number to timestamp without time zone - begin = to_date(NEW.julian_day::text, 'J'), - duration = NEW.duration - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.time_primitive (notes, fk_class, begin, duration) - - --convert given julian day number to timestamp without time zone - VALUES(NEW.notes, NEW.fk_class, to_date(NEW.julian_day::text, 'J'), NEW.duration) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_time_primitive_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_version_insert(); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - var sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_time_primitive_version; - DROP FUNCTION IF EXISTS information.v_time_primitive_version_insert(); - DROP VIEW IF EXISTS information.v_time_primitive_version; - ` - - - db.runSql(sql, callback) - -}; - diff --git a/server/db-migrate/migrations/_migration_archive/20180327094946-inf-entity-project-rel-patch.js b/server/db-migrate/migrations/_migration_archive/20180327094946-inf-entity-project-rel-patch.js deleted file mode 100644 index 9b40164e3..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180327094946-inf-entity-project-rel-patch.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - CREATE TYPE calendar_type AS ENUM ('gregorian', 'julian'); - - ALTER TABLE information.entity_version_project_rel - ADD COLUMN calendar calendar_type; - - - -- versioning - - ALTER TABLE information.entity_version_project_rel_vt - ADD COLUMN calendar calendar_type; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE information.entity_version_project_rel - DROP COLUMN calendar; - - -- versioning - - ALTER TABLE information.entity_version_project_rel_vt - DROP COLUMN calendar; - - -- type - - DROP TYPE calendar_type; - - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180327100628-inv-v-role-update.js b/server/db-migrate/migrations/_migration_archive/20180327100628-inv-v-role-update.js deleted file mode 100644 index 83785cc61..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180327100628-inv-v-role-update.js +++ /dev/null @@ -1,128 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - CREATE OR REPLACE VIEW information.v_role_version AS - - WITH versions AS ( - SELECT role.pk_entity, - true AS is_latest_version, - role.entity_version, - role.pk_role, - role.fk_property, - role.fk_entity, - role.fk_temporal_entity, - role.notes, - role.fk_creator, - role.fk_last_modifier, - role.tmsp_creation, - role.tmsp_last_modification, - role.sys_period - FROM information.role - UNION - SELECT role_vt.pk_entity, - false AS is_latest_version, - role_vt.entity_version, - role_vt.pk_role, - role_vt.fk_property, - role_vt.fk_entity, - role_vt.fk_temporal_entity, - role_vt.notes, - role_vt.fk_creator, - role_vt.fk_last_modifier, - role_vt.tmsp_creation, - role_vt.tmsp_last_modification, - role_vt.sys_period - FROM information.role_vt - ) - , statistics AS ( - SELECT DISTINCT versions_1.pk_entity, - versions_1.pk_role, - versions_1.fk_property, - versions_1.fk_entity, - versions_1.fk_temporal_entity, - array_agg(epr.fk_project) AS projects, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar , - count(epr.is_in_project) AS is_in_project_count, - count(*) FILTER (where epr.is_standard_in_project = true) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project, - entity_version_project_rel.calendar -- <- new line - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - WHERE epr.is_in_project = true - GROUP BY versions_1.pk_entity, versions_1.pk_role, versions_1.is_latest_version, versions_1.fk_property, versions_1.fk_entity, versions_1.fk_temporal_entity, epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ), - favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.is_standard_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects, - statistics.community_favorite_calendar - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_property, - versions.fk_entity, - versions.fk_temporal_entity, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite, - COALESCE(favorites.is_in_project_count,0) AS is_in_project_count, - COALESCE(favorites.is_standard_in_project_count,0) AS is_standard_in_project_count, - favorites.community_favorite_calendar - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180416171027-dfh-t-inherited-property.js b/server/db-migrate/migrations/_migration_archive/20180416171027-dfh-t-inherited-property.js deleted file mode 100644 index 369e0058e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180416171027-dfh-t-inherited-property.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE data_for_history.inherited_property ( - dfh_pk_inherited_property integer, - dfh_is_originated_from_property integer, - dfh_inherited_from_class integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_creation_time timestamp, - dfh_modification_time timestamp, - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint, - dfh_standard_label varchar(500) - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.inherited_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.inherited_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.inherited_property FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.inherited_property_vt (LIKE data_for_history.inherited_property); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.inherited_property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.inherited_property_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS data_for_history.inherited_property CASCADE; - DROP TABLE IF EXISTS data_for_history.inherited_property_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180526095400-inf-t-digital-object.js b/server/db-migrate/migrations/_migration_archive/20180526095400-inf-t-digital-object.js deleted file mode 100644 index 3387690ae..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180526095400-inf-t-digital-object.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - - -- Table: information.digital_object - - CREATE TABLE information.digital_object - ( - pk_digital_object serial PRIMARY KEY, - js_quill_data json - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.digital_object - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.digital_object - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.digital_object - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - DROP TABLE information.digital_object; - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180526095421-inf-t-chunk.js b/server/db-migrate/migrations/_migration_archive/20180526095421-inf-t-chunk.js deleted file mode 100644 index ff8bbd62b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180526095421-inf-t-chunk.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - - -- Table: information.chunk - - CREATE TABLE information.chunk - ( - pk_chunk serial PRIMARY KEY, - js_quill_data jsonb, - fk_digital_object integer - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.chunk - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.chunk - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.chunk - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - DROP TABLE information.chunk; - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180526100828-inf-t-entity-association-update-fk-property.js b/server/db-migrate/migrations/_migration_archive/20180526100828-inf-t-entity-association-update-fk-property.js deleted file mode 100644 index 061f11cb3..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180526100828-inf-t-entity-association-update-fk-property.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - ALTER TABLE information.entity_association - ALTER COLUMN fk_property TYPE integer USING NULL; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - ALTER TABLE information.entity_association - ALTER COLUMN fk_property TYPE varchar(7) USING NULL; - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180531173438-inf-t-entity-version-project-rel-update-trigger-fn.js b/server/db-migrate/migrations/_migration_archive/20180531173438-inf-t-entity-version-project-rel-update-trigger-fn.js deleted file mode 100644 index 093034d4e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180531173438-inf-t-entity-version-project-rel-update-trigger-fn.js +++ /dev/null @@ -1,107 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - - -- Update the version trigger, so that also fk_entity can be set without versioning - - DROP TRIGGER on_upsert ON information.entity_version_project_rel; - - DROP FUNCTION commons.evpr_fk_entity_fk_entity_version(); - - CREATE FUNCTION commons.evpr_fk_entity_fk_entity_version() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - - BEGIN - - -- Added if condition: - -- only if there is a fk_entity_version_concat, generate fk_entity and fk_entity_version - - IF (NEW.fk_entity_version_concat IS NOT NULL) THEN - NEW.fk_entity = split_part(NEW.fk_entity_version_concat, '_', 1)::integer; - NEW.fk_entity_version = split_part(NEW.fk_entity_version_concat, '_', 2)::integer; - END IF; - - RETURN NEW; - END; - - $BODY$; - - - - CREATE TRIGGER on_upsert - BEFORE INSERT OR UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - -- Update the version trigger, so that also fk_entity can be set without versioning - - DROP TRIGGER on_upsert ON information.entity_version_project_rel; - - DROP FUNCTION commons.evpr_fk_entity_fk_entity_version(); - - CREATE FUNCTION commons.evpr_fk_entity_fk_entity_version() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - - BEGIN - - NEW.fk_entity = split_part(NEW.fk_entity_version_concat, '_', 1)::integer; - NEW.fk_entity_version = split_part(NEW.fk_entity_version_concat, '_', 2)::integer; - - RETURN NEW; - END; - - $BODY$; - - - - CREATE TRIGGER on_upsert - BEFORE INSERT OR UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); ` - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20180606210507-dfh-t-add-column-to-property-drop-inherited-property.js b/server/db-migrate/migrations/_migration_archive/20180606210507-dfh-t-add-column-to-property-drop-inherited-property.js deleted file mode 100644 index 0f1096187..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180606210507-dfh-t-add-column-to-property-drop-inherited-property.js +++ /dev/null @@ -1,102 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - - const sql = ` - ALTER TABLE data_for_history.property - ADD COLUMN dfh_fk_property_of_origin INTEGER; - ALTER TABLE data_for_history.property_vt - ADD COLUMN dfh_fk_property_of_origin INTEGER; - - -- this column name has to be adapted to the new API labelling - ALTER TABLE data_for_history.property_profile_view RENAME COLUMN dfh_pk_inherited_property TO dfh_fk_property_of_origin; - ALTER TABLE data_for_history.property_profile_view_vt RENAME COLUMN dfh_pk_inherited_property TO dfh_fk_property_of_origin; - - -- the data_for_history.inherited_property isn't any more in use, even not in OntoME - DROP TABLE IF EXISTS data_for_history.inherited_property CASCADE; - DROP TABLE IF EXISTS data_for_history.inherited_property_vt CASCADE; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - ALTER TABLE data_for_history.property - DROP COLUMN dfh_fk_property_of_origin; - ALTER TABLE data_for_history.property_vt - DROP COLUMN dfh_fk_property_of_origin; - - ALTER TABLE data_for_history.property_profile_view RENAME COLUMN dfh_fk_property_of_origin TO dfh_pk_inherited_property; - ALTER TABLE data_for_history.property_profile_view_vt RENAME COLUMN dfh_fk_property_of_origin TO dfh_pk_inherited_property; - - CREATE TABLE data_for_history.inherited_property ( - dfh_pk_inherited_property integer, - dfh_is_originated_from_property integer, - dfh_inherited_from_class integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_creation_time timestamp, - dfh_modification_time timestamp, - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint, - dfh_standard_label varchar(500) - ) - INHERITS (data_for_history.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.inherited_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.inherited_property - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.inherited_property FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.inherited_property_vt (LIKE data_for_history.inherited_property); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.inherited_property - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.inherited_property_vt', true - ); - - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180607102656-install-postgis-extension.js b/server/db-migrate/migrations/_migration_archive/20180607102656-install-postgis-extension.js deleted file mode 100644 index 3feac34cb..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180607102656-install-postgis-extension.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - CREATE EXTENSION IF NOT EXISTS postgis; - CREATE EXTENSION IF NOT EXISTS postgis_topology; - CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; - --CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - --DROP EXTENSION postgis_tiger_geocoder; - DROP EXTENSION fuzzystrmatch; - DROP EXTENSION postgis_topology; - DROP EXTENSION postgis; - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180607113910-inf-t-place.js b/server/db-migrate/migrations/_migration_archive/20180607113910-inf-t-place.js deleted file mode 100644 index 26d53a24b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180607113910-inf-t-place.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - - const sql = ` - - -- Table: information.place - - CREATE TABLE information.place - ( - geo_point GEOGRAPHY(POINT,4326), - fk_class integer REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (information.entity) - WITH ( - OIDS = FALSE - ) - TABLESPACE pg_default; - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.place - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.place - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.place - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - - const sql = ` - DROP TABLE information.place; - ` - - db.runSql(sql, callback) - -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180614051817-inf-v-place.js b/server/db-migrate/migrations/_migration_archive/20180614051817-inf-v-place.js deleted file mode 100644 index b8b7ed683..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180614051817-inf-v-place.js +++ /dev/null @@ -1,80 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - - - const sql = ` - -- create view with long, lat columns - - CREATE OR REPLACE VIEW information.v_place AS - select *, ST_X(geo_point::geometry) as long, ST_Y(geo_point::geometry) as lat from information.place; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_place_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - - -- convert long, lat to geography - - insert into information.place (entity_version, geo_point, fk_class) - values (NEW.entity_version,ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, NEW.fk_class) - RETURNING pk_entity INTO result; - - NEW.pk_entity = result; - RETURN NEW; - END; - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_place - FOR EACH ROW - EXECUTE PROCEDURE information.v_place_insert(); - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - var sql = ` - DROP TRIGGER IF EXISTS on_insert ON information.v_place; - DROP FUNCTION IF EXISTS information.v_place_insert(); - DROP VIEW IF EXISTS information.v_place; - ` - - - db.runSql(sql, callback) - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180614051820-seed-com-language.js b/server/db-migrate/migrations/_migration_archive/20180614051820-seed-com-language.js deleted file mode 100644 index d97a506d2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180614051820-seed-com-language.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var iso6393 = require('iso-639-3'); - - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -/** - * Insert all languages from https://www.npmjs.com/package/iso-639-3 - */ -exports.up = function (db, callback) { - - // var sql = `INSERT into commons.language (pk_language, lang_type, scope, iso6392b, iso6392t, iso6391, notes) VALUES `; - - // var rows = []; - - // const escapeSingleQuotes = function(val){ - // if ((typeof val) === 'string') return "'" + val.split("'").join("''") + "'"; - // else return val; - // } - - // for (var i = 0; i < iso6393.length; i++) { - // const row = '(' + - // escapeSingleQuotes(iso6393[i].iso6393) + ',' + - // escapeSingleQuotes(iso6393[i].type) + ',' + - // escapeSingleQuotes(iso6393[i].scope) + ',' + - // escapeSingleQuotes(iso6393[i].iso6392B) + ',' + - // escapeSingleQuotes(iso6393[i].iso6392T) + ',' + - // escapeSingleQuotes(iso6393[i].iso6391) + ',' + - // escapeSingleQuotes(iso6393[i].name) + - // ')'; - // rows.push(row); - // } - - // sql = sql + rows.join(',') + ';'; - - // console.log('run INSERT INTO commons.language with ' + iso6393.length + ' languages'); - - // db.runSql(sql, callback); - db.runSql('', callback); -}; - -exports.down = function (db, callback) { - var sql = 'TRUNCATE commons.language CASCADE' - - db.runSql(sql, callback); - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180614051821-seed-inf-language.js b/server/db-migrate/migrations/_migration_archive/20180614051821-seed-inf-language.js deleted file mode 100644 index 8ba3e8d84..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180614051821-seed-inf-language.js +++ /dev/null @@ -1,66 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var iso6393 = require('iso-639-3'); - - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -/** - * Insert all languages from https://www.npmjs.com/package/iso-639-3 - */ -exports.up = function(db, callback) { - - // var sql = `INSERT into information.language (pk_language, fk_class, lang_type, scope, iso6392b, iso6392t, iso6391, notes) VALUES `; - - // var rows = []; - - // const escapeSingleQuotes = function(val){ - // if ((typeof val) === 'string') return "'" + val.split("'").join("''") + "'"; - // else return val; - // } - - // for (var i = 0; i < iso6393.length; i++) { - // const row = '(' + - // escapeSingleQuotes(iso6393[i].iso6393) + ',' + - // "54," + - // escapeSingleQuotes(iso6393[i].type) + ',' + - // escapeSingleQuotes(iso6393[i].scope) + ',' + - // escapeSingleQuotes(iso6393[i].iso6392B) + ',' + - // escapeSingleQuotes(iso6393[i].iso6392T) + ',' + - // escapeSingleQuotes(iso6393[i].iso6391) + ',' + - // escapeSingleQuotes(iso6393[i].name) + - // ')'; - // rows.push(row); - // } - - // sql = sql + rows.join(',') + ';'; - - // console.log('run INSERT INTO information.language with ' + iso6393.length + ' languages'); - - // db.runSql(sql, callback); - db.runSql('', callback); - -}; - -exports.down = function(db, callback) { - var sql = 'TRUNCATE information.language CASCADE' - - db.runSql(sql, callback); - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180702090240-inf-entity-remove-entity-version-not-null.js b/server/db-migrate/migrations/_migration_archive/20180702090240-inf-entity-remove-entity-version-not-null.js deleted file mode 100644 index f158cca06..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180702090240-inf-entity-remove-entity-version-not-null.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - var sql = ` - -- remove not null contraint of generic entity table - ALTER TABLE information.entity ALTER COLUMN entity_version DROP NOT NULL; - `; - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - var sql = ` - -- add not null contraint of generic entity table - ALTER TABLE information.entity ALTER COLUMN entity_version SET NOT NULL; - ` - - db.runSql(sql, callback); - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180702090245-inf-time-primitive-changes.js b/server/db-migrate/migrations/_migration_archive/20180702090245-inf-time-primitive-changes.js deleted file mode 100644 index e46990968..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180702090245-inf-time-primitive-changes.js +++ /dev/null @@ -1,301 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - var sql = ` - -- remove view v_time_primitive_version - DROP VIEW IF EXISTS information.v_time_primitive_version; - - -- remove trigger function v_time_primitive_version_insert - DROP FUNCTION IF EXISTS information.v_time_primitive_version_insert(); - - -- remove versioning triggers - DROP TRIGGER IF EXISTS versioning_trigger ON information.time_primitive; - DROP TRIGGER IF EXISTS update_entity_version_key ON information.time_primitive; - DROP TRIGGER IF EXISTS create_entity_version_key ON information.time_primitive; - - -- remove version table time_primitive_vt - DROP TABLE IF EXISTS information.time_primitive_vt; - - -- table time_primitive: add 'julian_day' - ALTER TABLE information.time_primitive - ADD COLUMN julian_day integer; - - -- table time_primitive: remove col. 'begin' - ALTER TABLE information.time_primitive - DROP COLUMN begin; - - -- table time_primitive: add unique constraint - Alter table information.time_primitive - ADD CONSTRAINT time_primitive_unique_constraint UNIQUE (julian_day, duration, fk_class); - - -- add view v_time_primitive - CREATE OR REPLACE VIEW information.v_time_primitive AS - SELECT * FROM information.time_primitive; - - -- create v_time_primitive_find_or_create - CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.time_primitive; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.time_primitive ( - julian_day, - duration, - fk_class - ) - VALUES ( - NEW.julian_day, - NEW.duration, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_time_primitive_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_time_primitive - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_find_or_create(); - - `; - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - var sql = ` - - -- remove view v_time_primitive - DROP VIEW IF EXISTS information.v_time_primitive; - - -- remove trigger function v_time_primitive_find_or_create - DROP FUNCTION information.v_time_primitive_find_or_create(); - - -- table time_primitive: remove unique constraint - ALTER TABLE information.time_primitive DROP CONSTRAINT time_primitive_unique_constraint; - - -- change table time_primitive: add col. 'begin' - ALTER TABLE information.time_primitive - ADD COLUMN begin timestamp without time zone; - - -- change table time_primitive: remove 'julian_day' - ALTER TABLE information.time_primitive - DROP COLUMN julian_day; - - -- add version table time_primitive_vt - CREATE TABLE information.time_primitive_vt (LIKE information.time_primitive); - - -- add versioning triggers - -- Trigger: versioning_trigger - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.time_primitive - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.time_primitive_vt', true - ); - - -- Trigger: create_entity_version_key - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.time_primitive - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- add view v_time_primitive_version - CREATE OR REPLACE VIEW information.v_time_primitive_version AS - WITH versions AS ( - SELECT time_primitive.pk_entity, - true AS is_latest_version, - time_primitive.entity_version, - time_primitive.pk_time_primitive, - time_primitive.fk_class, - time_primitive.duration, - time_primitive.begin, - time_primitive.notes, - time_primitive.fk_creator, - time_primitive.fk_last_modifier, - time_primitive.tmsp_creation, - time_primitive.tmsp_last_modification, - time_primitive.sys_period - FROM information.time_primitive - UNION - SELECT time_primitive_vt.pk_entity, - false AS is_latest_version, - time_primitive_vt.entity_version, - time_primitive_vt.pk_time_primitive, - time_primitive_vt.fk_class, - time_primitive_vt.duration, - time_primitive_vt.begin, - time_primitive_vt.notes, - time_primitive_vt.fk_creator, - time_primitive_vt.fk_last_modifier, - time_primitive_vt.tmsp_creation, - time_primitive_vt.tmsp_last_modification, - time_primitive_vt.sys_period - FROM information.time_primitive_vt - ) - , statistics AS ( - SELECT DISTINCT versions_1.pk_entity, - versions_1.pk_time_primitive, - versions_1.fk_class, - versions_1.duration, - versions_1.begin, - array_agg(epr.fk_project) AS projects, - count(epr.is_in_project) AS is_in_project_count, - count(*) FILTER (where epr.is_standard_in_project = true) AS is_standard_in_project_count, - versions_1.is_latest_version, - epr.fk_entity_version_concat - FROM versions versions_1 - LEFT JOIN ( SELECT entity_version_project_rel.fk_entity_version_concat, - entity_version_project_rel.fk_project, - entity_version_project_rel.is_in_project, - entity_version_project_rel.is_standard_in_project - FROM information.entity_version_project_rel) epr ON epr.fk_entity_version_concat = concat((versions_1.pk_entity || '_'::text) || versions_1.entity_version) - WHERE epr.is_in_project = true - GROUP BY versions_1.pk_entity, versions_1.pk_time_primitive, versions_1.is_latest_version, versions_1.fk_class, versions_1.duration, versions_1.begin, epr.fk_entity_version_concat - ORDER BY versions_1.pk_entity, epr.fk_entity_version_concat - ), - favorites AS ( - SELECT DISTINCT ON (statistics.pk_entity) statistics.pk_entity, - statistics.is_in_project_count, - statistics.is_standard_in_project_count, - statistics.fk_entity_version_concat, - statistics.projects - FROM statistics - WHERE statistics.is_in_project_count > 0 - ORDER BY statistics.pk_entity, statistics.is_in_project_count DESC, statistics.fk_entity_version_concat DESC - ) - SELECT versions.pk_entity, - versions.entity_version, - concat((versions.pk_entity || '_'::text) || versions.entity_version) AS pk_entity_version_concat, - favorites.projects, - versions.fk_class, - versions.duration, - TO_CHAR(versions.begin, 'J') as julian_day, - versions.notes, - versions.fk_creator, - versions.fk_last_modifier, - versions.tmsp_creation, - versions.tmsp_last_modification, - versions.sys_period, - versions.is_latest_version, - ( SELECT favorites.is_in_project_count IS NOT NULL) AS is_community_favorite, - COALESCE(favorites.is_in_project_count,0) AS is_in_project_count, - COALESCE(favorites.is_standard_in_project_count,0) AS is_standard_in_project_count - FROM versions - LEFT JOIN favorites ON favorites.fk_entity_version_concat = concat((versions.pk_entity || '_'::text) || versions.entity_version) - ORDER BY versions.pk_entity, versions.tmsp_last_modification DESC; - - - -- create trigger function for insert - - CREATE FUNCTION information.v_time_primitive_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.time_primitive SET - fk_class = NEW.fk_class, - notes = NEW.notes, - - --convert given julian day number to timestamp without time zone - begin = to_date(NEW.julian_day::text, 'J'), - duration = NEW.duration - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.time_primitive (notes, fk_class, begin, duration) - - --convert given julian day number to timestamp without time zone - VALUES(NEW.notes, NEW.fk_class, to_date(NEW.julian_day::text, 'J'), NEW.duration) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_time_primitive_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_version_insert(); - ` - - db.runSql(sql, callback); - -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180703102150-com-t-entity-add-cols.js b/server/db-migrate/migrations/_migration_archive/20180703102150-com-t-entity-add-cols.js deleted file mode 100644 index ac75b6599..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180703102150-com-t-entity-add-cols.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - ALTER TABLE commons.entity - ADD COLUMN entity_version integer; - - ALTER TABLE commons.entity - ADD COLUMN notes text; - - ALTER TABLE commons.entity - ADD COLUMN fk_creator integer; - - ALTER TABLE commons.entity - ADD COLUMN fk_last_modifier integer; - - ALTER TABLE commons.entity - ADD COLUMN tmsp_creation timestamp with time zone DEFAULT now(); - - ALTER TABLE commons.entity - ADD COLUMN tmsp_last_modification timestamp with time zone; - - ALTER TABLE commons.entity - ADD COLUMN sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - ALTER TABLE commons.entity - DROP COLUMN entity_version ; - - ALTER TABLE commons.entity - DROP COLUMN notes ; - - ALTER TABLE commons.entity - DROP COLUMN fk_creator ; - - ALTER TABLE commons.entity - DROP COLUMN fk_last_modifier ; - - ALTER TABLE commons.entity - DROP COLUMN tmsp_creation; - - ALTER TABLE commons.entity - DROP COLUMN tmsp_last_modification; - - ALTER TABLE commons.entity - DROP COLUMN sys_period; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180703102151-com-t-ui-context.js b/server/db-migrate/migrations/_migration_archive/20180703102151-com-t-ui-context.js deleted file mode 100644 index 038c7be14..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180703102151-com-t-ui-context.js +++ /dev/null @@ -1,88 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - CREATE TABLE commons.ui_context ( - label VARCHAR NOT NULL, - description text - ) - INHERITS (commons.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.ui_context - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.ui_context - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON commons.ui_context FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON commons.ui_context - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON commons.ui_context - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE commons.ui_context_vt (LIKE commons.ui_context); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.ui_context - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.ui_context_vt', true - ); - - - insert into commons.ui_context (label, description) - Values - ('View-Repo', 'In public, where data of all projects is shown'), - ('View-Project', 'In public, where data of a project is shown'), - ('Editable', 'In toolbox, where data of a project is shown and ready for editing. Applies also to the dropdown to add a property'), - ('Create', 'In toolbox, when a entity (peIt or TeEn) is created'), - ('Add', 'In toolbox, when a entity (peIt or TeEn) is being added to a project') - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP TABLE IF EXISTS commons.ui_context CASCADE; - DROP TABLE IF EXISTS commons.ui_context_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180703102221-com-t-ui-context-config.js b/server/db-migrate/migrations/_migration_archive/20180703102221-com-t-ui-context-config.js deleted file mode 100644 index 2190869c1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180703102221-com-t-ui-context-config.js +++ /dev/null @@ -1,99 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE commons.ui_context_config ( - fk_ui_context integer NOT NULL, - fk_project integer REFERENCES commons.project (pk_project), - fk_property integer REFERENCES data_for_history.property (dfh_pk_property), - property_is_outgoing boolean, - fk_property_set integer, - fk_class_for_property_set integer, - ord_num integer - ) - INHERITS (commons.entity); - - -- unique indexes instead of unique constraint because of nullable pk_project - -- see: https://stackoverflow.com/questions/8289100/create-unique-constraint-with-null-columns - CREATE UNIQUE INDEX ui_context_config_for_prop_and_proj_uni_idx ON commons.ui_context_config (fk_ui_context, fk_project, fk_property, property_is_outgoing) - WHERE fk_project IS NOT NULL; - - CREATE UNIQUE INDEX ui_context_config_for_prop_no_proj_uni_idx ON commons.ui_context_config (fk_ui_context, fk_property, property_is_outgoing) - WHERE fk_project IS NULL; - - CREATE UNIQUE INDEX ui_context_config_for_prop_set_and_proj_uni_idx ON commons.ui_context_config (fk_ui_context, fk_project, fk_property_set, fk_class_for_property_set) - WHERE fk_project IS NOT NULL; - - CREATE UNIQUE INDEX ui_context_config_for_prop_set_no_proj_uni_idx ON commons.ui_context_config (fk_ui_context, fk_property_set, fk_class_for_property_set) - WHERE fk_project IS NULL; - - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.ui_context_config - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.ui_context_config - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON commons.ui_context_config FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON commons.ui_context_config - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON commons.ui_context_config - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE commons.ui_context_config_vt (LIKE commons.ui_context_config); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.ui_context_config - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.ui_context_config_vt', true - ); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS commons.ui_context_config CASCADE; - DROP TABLE IF EXISTS commons.ui_context_config_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180703102223-com-t-property-set.js b/server/db-migrate/migrations/_migration_archive/20180703102223-com-t-property-set.js deleted file mode 100644 index 840654530..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180703102223-com-t-property-set.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - CREATE TABLE commons.property_set ( - label VARCHAR NOT NULL, - description text - ) - INHERITS (commons.entity); - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.property_set - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.property_set - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON commons.property_set FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON commons.property_set - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON commons.property_set - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE commons.property_set_vt (LIKE commons.property_set); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.property_set - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.property_set_vt', true - ); - - - Insert into commons.property_set ("label",description) - VALUES ('When', 'Existence Time or Time Span of a Temporal Entity') - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE IF EXISTS commons.property_set CASCADE; - DROP TABLE IF EXISTS commons.property_set_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180716153600-inf-t-entity-project-rel-add-ord-num.js b/server/db-migrate/migrations/_migration_archive/20180716153600-inf-t-entity-project-rel-add-ord-num.js deleted file mode 100644 index 94833ba8f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180716153600-inf-t-entity-project-rel-add-ord-num.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - - Alter TABLE information.entity_version_project_rel - ADD COLUMN ord_num integer; - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - Alter TABLE information.entity_version_project_rel - DROP COLUMN ord_num; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823072510-inf-drop-entity-version-key-triggers.js b/server/db-migrate/migrations/_migration_archive/20180823072510-inf-drop-entity-version-key-triggers.js deleted file mode 100644 index 8e6370d5f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823072510-inf-drop-entity-version-key-triggers.js +++ /dev/null @@ -1,98 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -// Array of tables that do not need versioning anymore -const tablesToModify = [ - 'appellation', - 'dating', - 'entity_association', - 'language', - 'persistent_item', - 'role', - 'sourcing', - 'temporal_entity', - 'text_property' -] - -/** - * Function creates a sql statement that removes the versioning for - * the table in schema information with given tableName - * @param string name of table in schema information -*/ -const createSqlStatementUp = (tableName) => { - const upSql = ` - - ----- ${tableName} ----- - - -- Drop Trigger create_entity_version_key - DROP TRIGGER IF EXISTS create_entity_version_key ON information.${tableName}; - - -- Drop Trigger update_entity_version_key - DROP TRIGGER IF EXISTS update_entity_version_key ON information.${tableName}; - - ` - - return upSql; -} - -/** - * Function creates a sql statement that adds the versioning for - * the table in schema information with given tableName - * @param string name of table in schema information -*/ -const createSqlStatementDown = (tableName) => { - const downSql = ` - - ----- ${tableName} ----- - - -- Create Trigger create_entity_version_key - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.${tableName} - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Create Trigger update_entity_version_key - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.${tableName} - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - ` - - return downSql; -} - - -exports.up = function (db, callback) { - - // Creates sql to modify all entity children tables listed in 'tablesToModify' - const sql = tablesToModify.map(tablename => createSqlStatementUp(tablename)).join(''); - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - // creates and concatenates piece of sql for each table in the array 'tablesToModify' - const sql = tablesToModify.map(tablename => createSqlStatementDown(tablename)).join(''); - - db.runSql(sql, callback) -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823083032-inf-drop-entity-version-column.js b/server/db-migrate/migrations/_migration_archive/20180823083032-inf-drop-entity-version-column.js deleted file mode 100644 index 44f69434e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823083032-inf-drop-entity-version-column.js +++ /dev/null @@ -1,102 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -// Array of tables that do not need versioning anymore -const tablesToModify = [ - 'appellation', - 'dating', - 'entity_association', - 'language', - 'persistent_item', - 'role', - 'sourcing', - 'temporal_entity', - 'text_property' -] - -const createSql = (tableName) =>{ - return ` - ALTER TABLE information.${tableName} - DROP COLUMN IF EXISTS entity_version CASCADE; - - ALTER TABLE information.${tableName}_vt - DROP COLUMN IF EXISTS entity_version CASCADE; - ` -} - -exports.up = function (db, callback) { - const sql1 = ` - - -- Create backup col of entity_version column in table entity_version_project_rel - ALTER TABLE information.entity_version_project_rel - ADD COLUMN entity_version_backup integer; - - -- Fill backup col - UPDATE information.entity_version_project_rel SET entity_version_backup=entity_version; - - -- Remove histroy (irreversible) - DELETE FROM information.entity_version_project_rel_vt; - - -- Drop Column entity_version of generic parent table 'entity' - ALTER TABLE information.entity DROP COLUMN entity_version CASCADE; - - -- Drop inherited entity_version column of entity_version_project_rel - ALTER TABLE information.entity_version_project_rel DROP COLUMN IF EXISTS entity_version; - - -- Rename a entity_version_backup to entity_version - ALTER TABLE information.entity_version_project_rel - RENAME COLUMN entity_version_backup to entity_version; - - ` - const sql2 = tablesToModify.map(tableName => createSql(tableName)).join(''); - - const sql = sql1 + sql2; - - db.runSql(sql, callback) - -}; - - -const createSqlDown = (tableName) =>{ - return ` - ALTER TABLE information.${tableName}_vt - ADD COLUMN entity_version integer; - ` -} -exports.down = function (db, callback) { - const sql1 = ` - -- ADD Column entity_version of generic parent table 'entity' - ALTER TABLE information.entity - ADD COLUMN entity_version integer; - - -- Fill default entity_version 1 where empty - UPDATE information.entity - SET entity_version=1 - WHERE entity_version IS NULL; - - ` - - const sql2 = tablesToModify.map(tableName => createSqlDown(tableName)).join(''); - - const sql = sql1 + sql2; - - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823092122-inf-drop-version-trigger-functions.js b/server/db-migrate/migrations/_migration_archive/20180823092122-inf-drop-version-trigger-functions.js deleted file mode 100644 index 662dba7b2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823092122-inf-drop-version-trigger-functions.js +++ /dev/null @@ -1,250 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - const sql = ` - - DROP FUNCTION information.v_appellation_version_insert(); - DROP FUNCTION information.v_language_version_insert(); - DROP FUNCTION information.v_persistent_item_version_insert(); - DROP FUNCTION information.v_role_version_insert(); - DROP FUNCTION information.v_temporal_entity_version_insert(); - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - - CREATE FUNCTION information.v_appellation_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' -AS $BODY$ - - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.appellation SET - appellation_label = NEW.appellation_label, - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.appellation (notes, fk_class, appellation_label) - VALUES(NEW.notes, NEW.fk_class, NEW.appellation_label) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - -$BODY$; - - - - - -CREATE FUNCTION information.v_language_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' -AS $BODY$ - - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.language SET - notes = NEW.notes, - fk_class = NEW.fk_class, - lang_type = NEW.lang_type, - scope = NEW.scope, - iso6392b = NEW.iso6392b, - iso6392t = NEW.iso6392t, - iso6391 = NEW.iso6391 - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.language ( - pk_language, - notes, - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES( - NEW.pk_language, - NEW.notes, - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - -$BODY$; - - - -CREATE FUNCTION information.v_persistent_item_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' -AS $BODY$ - - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.persistent_item SET - fk_class = NEW.fk_class, - notes = NEW.notes - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.persistent_item (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - -$BODY$; - - - -CREATE FUNCTION information.v_role_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' -AS $BODY$ - - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.role SET - notes = NEW.notes, - fk_property = NEW.fk_property, - fk_entity = NEW.fk_entity, - fk_temporal_entity = NEW.fk_temporal_entity - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.role (notes, fk_property, fk_entity, fk_temporal_entity) - VALUES(NEW.notes, NEW.fk_property, NEW.fk_entity, NEW.fk_temporal_entity) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - -$BODY$; - - - -CREATE FUNCTION information.v_temporal_entity_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' -AS $BODY$ - - DECLARE - result text; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.temporal_entity SET - notes = NEW.notes, - fk_class = NEW.fk_class - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.temporal_entity (notes, fk_class) - VALUES(NEW.notes, NEW.fk_class) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - NEW.pk_entity_version_concat = result; - - RETURN NEW; - END; - - -$BODY$; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823092228-inf-v-time-primitive.js b/server/db-migrate/migrations/_migration_archive/20180823092228-inf-v-time-primitive.js deleted file mode 100644 index c8c00d29e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823092228-inf-v-time-primitive.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_time_primitive - CREATE OR REPLACE VIEW information.v_time_primitive AS - SELECT * FROM information.time_primitive; - - -- create v_time_primitive_find_or_create - CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.time_primitive; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.time_primitive ( - julian_day, - duration, - fk_class - ) - VALUES ( - NEW.julian_day, - NEW.duration, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_time_primitive_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_time_primitive - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_time_primitive - DROP VIEW IF EXISTS information.v_time_primitive; - - -- remove trigger function v_time_primitive_find_or_create - DROP FUNCTION information.v_time_primitive_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823093355-inf-v-role.js b/server/db-migrate/migrations/_migration_archive/20180823093355-inf-v-role.js deleted file mode 100644 index 3fa06c189..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823093355-inf-v-role.js +++ /dev/null @@ -1,127 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_role - CREATE OR REPLACE VIEW information.v_role AS - SELECT - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - COALESCE(count(*) FILTER (where epr.is_in_project = true),0) AS is_in_project_count, - COALESCE(count(*) FILTER (where epr.ord_num = 0), 0) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period - FROM information.role as r - LEFT JOIN information.entity_version_project_rel as epr on epr.fk_entity = r.pk_entity - GROUP BY - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period; - - -- create v_role_find_or_create - CREATE OR REPLACE FUNCTION information.v_role_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_role; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.role - WHERE - fk_entity = NEW.fk_entity - AND fk_temporal_entity = NEW.fk_temporal_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.role ( - fk_entity, - fk_temporal_entity, - fk_property - ) - VALUES ( - NEW.fk_entity, - NEW.fk_temporal_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_role - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_role_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_role - DROP VIEW IF EXISTS information.v_role; - - -- remove trigger function v_role_find_or_create - DROP FUNCTION information.v_role_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823094117-inf-v-appellation.js b/server/db-migrate/migrations/_migration_archive/20180823094117-inf-v-appellation.js deleted file mode 100644 index 16e9a5bad..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823094117-inf-v-appellation.js +++ /dev/null @@ -1,117 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- create a function that converts appellation_label to a - -- simpler json object without token id, useful for identification - -- of unique appellations (find or create) - CREATE FUNCTION information.appe_tokens_for_comparision (IN appe_label jsonb, OUT tokens_for_comparision jsonb) - AS $$ - Select array_to_json(array_agg(json_build_object('string',tokens_without_ids.string, 'typeId', tokens_without_ids.typeId)))::jsonb as tokens_for_comparision from - ( - SELECT appe.tokens->>'string' as string, appe.tokens->>'typeId' as typeId - FROM ( - SELECT jsonb_array_elements(appe_label->'tokens') as tokens - ) as appe - ) as tokens_without_ids - $$ LANGUAGE SQL; - - - - -- add view v_appellation - CREATE OR REPLACE VIEW information.v_appellation AS - SELECT * FROM information.appellation; - - -- create v_appellation_find_or_create - CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - information.appe_tokens_for_comparision(appellation_label) = - information.appe_tokens_for_comparision(NEW.appellation_label) - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - appellation_label, - fk_class - ) - VALUES ( - NEW.appellation_label, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_appellation_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_appellation - DROP VIEW IF EXISTS information.v_appellation; - - -- remove trigger function v_appellation_find_or_create - DROP FUNCTION information.v_appellation_find_or_create(); - - -- remove comparision function - DROP FUNCTION information.appe_tokens_for_comparision(IN appe_label jsonb, OUT tokens_for_comparision jsonb); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823120937-inf-v-language.js b/server/db-migrate/migrations/_migration_archive/20180823120937-inf-v-language.js deleted file mode 100644 index 2c64b572d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823120937-inf-v-language.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_language - CREATE OR REPLACE VIEW information.v_language AS - SELECT * FROM information.language; - - -- create v_language_find_or_create - CREATE OR REPLACE FUNCTION information.v_language_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.language; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.language - WHERE - fk_class = NEW.fk_class - AND lang_type = NEW.lang_type - AND scope = NEW.scope - AND iso6392b = NEW.iso6392b - AND iso6392t = NEW.iso6392t - AND iso6391 = NEW.iso6391; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.language ( - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES ( - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_language_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_language - FOR EACH ROW - EXECUTE PROCEDURE information.v_language_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_language - DROP VIEW IF EXISTS information.v_language; - - -- remove trigger function v_language_find_or_create - DROP FUNCTION information.v_language_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823121459-inf-v-persistent-item.js b/server/db-migrate/migrations/_migration_archive/20180823121459-inf-v-persistent-item.js deleted file mode 100644 index 859b59ee1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823121459-inf-v-persistent-item.js +++ /dev/null @@ -1,94 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_persistent_item - CREATE OR REPLACE VIEW information.v_persistent_item AS - SELECT * FROM information.persistent_item; - - -- create v_persistent_item_find_or_create - CREATE OR REPLACE FUNCTION information.v_persistent_item_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.persistent_item; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.persistent_item - WHERE pk_entity = NEW.pk_entity; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.persistent_item ( - fk_class - ) - VALUES ( - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_persistent_item_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_persistent_item - DROP VIEW IF EXISTS information.v_persistent_item; - - -- remove trigger function v_persistent_item_find_or_create - DROP FUNCTION information.v_persistent_item_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823122111-inf-v-temporal-entity.js b/server/db-migrate/migrations/_migration_archive/20180823122111-inf-v-temporal-entity.js deleted file mode 100644 index 977f938f7..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823122111-inf-v-temporal-entity.js +++ /dev/null @@ -1,94 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_temporal_entity - CREATE OR REPLACE VIEW information.v_temporal_entity AS - SELECT * FROM information.temporal_entity; - - -- create v_temporal_entity_find_or_create - CREATE OR REPLACE FUNCTION information.v_temporal_entity_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.temporal_entity; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.temporal_entity - WHERE pk_entity = NEW.pk_entity; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.temporal_entity ( - fk_class - ) - VALUES ( - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_temporal_entity_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_temporal_entity - DROP VIEW IF EXISTS information.v_temporal_entity; - - -- remove trigger function v_temporal_entity_find_or_create - DROP FUNCTION information.v_temporal_entity_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823122247-inf-v-place.js b/server/db-migrate/migrations/_migration_archive/20180823122247-inf-v-place.js deleted file mode 100644 index 78f89e66e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823122247-inf-v-place.js +++ /dev/null @@ -1,134 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_place - CREATE OR REPLACE VIEW information.v_place AS - select - *, - ST_X(geo_point::geometry) as long, - ST_Y(geo_point::geometry) as lat - from information.place; - - -- create v_place_find_or_create - CREATE OR REPLACE FUNCTION information.v_place_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.v_place; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT - *, - NEW.long, - NEW.lat - FROM INTO resulting_row information.place - WHERE geo_point = ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.place ( - geo_point, - fk_class - ) - VALUES ( - ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT - *, - ST_X(geo_point::geometry) as long, - ST_Y(geo_point::geometry) as lat - FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - -- add trigger on insert to execute v_place_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_place - FOR EACH ROW - EXECUTE PROCEDURE information.v_place_find_or_create(); - - -- remmove old insert function - DROP FUNCTION information.v_place_insert(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_place - DROP VIEW IF EXISTS information.v_place; - - -- remove trigger function v_place_find_or_create - DROP FUNCTION information.v_place_find_or_create(); - - -- add old trigger function - CREATE FUNCTION information.v_place_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - - DECLARE - result text; - BEGIN - - -- convert long, lat to geography - - insert into information.place (entity_version, geo_point, fk_class) - values (NEW.entity_version,ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, NEW.fk_class) - RETURNING pk_entity INTO result; - - NEW.pk_entity = result; - RETURN NEW; - END; - - $BODY$; - - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823123835-inf-v-entity-association.js b/server/db-migrate/migrations/_migration_archive/20180823123835-inf-v-entity-association.js deleted file mode 100644 index b127b50c2..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823123835-inf-v-entity-association.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_entity_association - CREATE OR REPLACE VIEW information.v_entity_association AS - SELECT * FROM information.entity_association; - - -- create v_entity_association_find_or_create - CREATE OR REPLACE FUNCTION information.v_entity_association_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.entity_association - WHERE - fk_domain_entity = NEW.fk_domain_entity - AND fk_range_entity = NEW.fk_range_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_domain_entity, - fk_range_entity, - fk_property - ) - VALUES ( - NEW.fk_domain_entity, - NEW.fk_range_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_entity_association_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_entity_association - DROP VIEW IF EXISTS information.v_entity_association; - - -- remove trigger function v_entity_association_find_or_create - DROP FUNCTION information.v_entity_association_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180823124134-inf-t-drop-dating-table.js b/server/db-migrate/migrations/_migration_archive/20180823124134-inf-t-drop-dating-table.js deleted file mode 100644 index 80918abb0..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180823124134-inf-t-drop-dating-table.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - DROP TABLE information.dating; - DROP TABLE information.dating_vt; - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -CREATE TABLE information.dating -( - pk_dating serial Not Null , - date_iso_value jsonb, - comment text COLLATE pg_catalog."default", - fk_system_type integer, - CONSTRAINT dating_pkey PRIMARY KEY (pk_dating) -) - INHERITS (information.entity) -WITH ( - OIDS = FALSE -) -TABLESPACE pg_default; - --- Trigger: creation_tmsp - --- DROP TRIGGER creation_tmsp ON information.dating; - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - --- Trigger: insert_schema_table_name - --- DROP TRIGGER insert_schema_table_name ON information.dating; - -CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - --- Trigger: last_modification_tmsp - --- DROP TRIGGER last_modification_tmsp ON information.dating; - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.dating - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -CREATE TABLE information.dating_vt (LIKE information.dating); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.dating - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.dating_vt', true - ); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180824140843-inf-t-add-version-tables.js b/server/db-migrate/migrations/_migration_archive/20180824140843-inf-t-add-version-tables.js deleted file mode 100644 index 0e88e035a..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180824140843-inf-t-add-version-tables.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -const tableNames = [ - 'chunk', - 'digital_object', - 'place', - 'time_primitive' -] - -const createVtSql=(tablename)=> ` -CREATE TABLE information.${tablename}_vt (LIKE information.${tablename}); - --- Trigger: versioning_trigger - -CREATE TRIGGER versioning_trigger -BEFORE INSERT OR UPDATE OR DELETE ON information.${tablename} -FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.${tablename}_vt', true -); -` - -exports.up = function(db, callback) { - - const sql = tableNames.map(t=>createVtSql(t)).join(''); - - db.runSql(sql, callback) - -}; - - -const dropVtSql=(tablename)=> ` -DROP TABLE information.${tablename}_vt; -DROP TRIGGER versioning_trigger ON information.${tablename}; -` - -exports.down = function(db, callback) { - - const sql = tableNames.map(t=>dropVtSql(t)).join(''); - - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180824142702-inf-v-chunk.js b/server/db-migrate/migrations/_migration_archive/20180824142702-inf-v-chunk.js deleted file mode 100644 index 0335cbffe..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180824142702-inf-v-chunk.js +++ /dev/null @@ -1,102 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_chunk - CREATE OR REPLACE VIEW information.v_chunk AS - SELECT * FROM information.chunk; - - -- create v_chunk_find_or_create - CREATE OR REPLACE FUNCTION information.v_chunk_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_chunk; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.chunk - WHERE - js_quill_data::jsonb = NEW.js_quill_data::jsonb - AND fk_digital_object = NEW.fk_digital_object; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.chunk ( - js_quill_data, - fk_digital_object - ) - VALUES ( - NEW.js_quill_data::jsonb, - NEW.fk_digital_object - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_chunk - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_chunk_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_chunk - FOR EACH ROW - EXECUTE PROCEDURE information.v_chunk_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_chunk - DROP VIEW IF EXISTS information.v_chunk; - - -- remove trigger function v_chunk_find_or_create - DROP FUNCTION information.v_chunk_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180904140701-inf-digital-object-versioning.js b/server/db-migrate/migrations/_migration_archive/20180904140701-inf-digital-object-versioning.js deleted file mode 100644 index 62837c5cc..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180904140701-inf-digital-object-versioning.js +++ /dev/null @@ -1,83 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add entity_version column on table information.digital_object - ------------------------------------------------------------------- - ALTER TABLE information.digital_object - ADD COLUMN entity_version integer default 1; - - ALTER TABLE information.digital_object_vt - ADD COLUMN entity_version integer; - - -- add triggers for entity_version key - ------------------------------------------------------------------- - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON information.digital_object - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON information.digital_object - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- create view with union of all versions - ------------------------------------------------------------------- - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove entity_version column on table information.digital_object - ------------------------------------------------------------------- - ALTER TABLE information.digital_object - DROP COLUMN IF EXISTS entity_version; - ALTER TABLE information.digital_object_vt - DROP COLUMN IF EXISTS entity_version; - - - -- remove triggers for entity_version key - ------------------------------------------------------------------- - - DROP TRIGGER create_entity_version_key - ON information.digital_object; - - DROP TRIGGER update_entity_version_key - ON information.digital_object; - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20180904143243-inf-v-digital-object-versions.js b/server/db-migrate/migrations/_migration_archive/20180904143243-inf-v-digital-object-versions.js deleted file mode 100644 index 7ae266936..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180904143243-inf-v-digital-object-versions.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view that unions all digital_object versions - ------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_digital_object_version AS - SELECT *, concat((v.pk_entity || '_'::text) || v.entity_version) AS pk_entity_version_concat FROM information.digital_object as v - UNION ALL - SELECT *, concat((v.pk_entity || '_'::text) || v.entity_version) AS pk_entity_version_concat FROM information.digital_object_vt as v; - - - - - - - -- add trigger instead of insert or update - ------------------------------------------------------------------- - - -- create trigger function for insert - - CREATE FUNCTION information.v_digital_object_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_concat_pk text; - resulting_row information.v_digital_object_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.digital_object SET - notes = NEW.notes, - js_quill_data = NEW.js_quill_data - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.digital_object (notes, js_quill_data) - VALUES(NEW.notes, NEW.js_quill_data) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row information.v_digital_object_version where pk_entity_version_concat = resulting_concat_pk; - - RETURN resulting_row; - END; - - $BODY$; - - - -- create trigger on insert - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_digital_object_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_digital_object_version_insert(); - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove entity_version column on table information.digital_object - ------------------------------------------------------------------- - DROP VIEW IF EXISTS information.v_digital_object_version; - - - -- remove triggers for entity_version key - ------------------------------------------------------------------- - DROP TRIGGER IF EXISTS on_insert ON information.v_digital_object_version; - DROP FUNCTION information.v_digital_object_version_insert(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20180910111714-replace-temporal-tables-by-function.js b/server/db-migrate/migrations/_migration_archive/20180910111714-replace-temporal-tables-by-function.js deleted file mode 100644 index 986e7b25d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180910111714-replace-temporal-tables-by-function.js +++ /dev/null @@ -1,311 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -const tablesWithVersioningTrigger = [ - 'commons.label', - 'commons.project', - 'commons.system_type', - 'commons.text_property', - 'commons.ui_context', - 'commons.ui_context_config', - 'commons.property_set', - 'data_for_history.class_profile_view', - 'data_for_history.class', - 'data_for_history.label', - 'data_for_history.text_property', - 'data_for_history.property', - 'data_for_history.profile', - 'data_for_history.property_profile_view', - 'data_for_history.associates_system_type', - 'data_for_history.system_type', - 'information.entity_version_project_rel', - 'information.appellation', - 'information.entity_association', - 'information.language', - 'information.persistent_item', - 'information.role', - 'information.sourcing', - 'information.temporal_entity', - 'information.text_property', - 'information.chunk', - 'information.digital_object', - 'information.place', - 'information.time_primitive' -] - - -function createTriggersSql() { - - return tablesWithVersioningTrigger.map(tablename => ` - DROP TRIGGER IF EXISTS versioning_trigger - ON ${tablename}; - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON ${tablename} - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', '${tablename}_vt', 'true'); - - ` - ).join(''); - -} - -/** - * Source of this SQL: - * https://github.com/nearform/temporal_tables/blob/master/versioning_function.sql - */ - -exports.up = function (db, callback) { - const sql = ` - - -- Remove extension temporal_tables - - DROP EXTENSION IF EXISTS temporal_tables CASCADE; - - --- Create the nwe versioning() function (schema public) - - CREATE OR REPLACE FUNCTION versioning() - RETURNS TRIGGER AS $$ - DECLARE - sys_period text; - history_table text; - manipulate jsonb; - commonColumns text[]; - time_stamp_to_use timestamptz := current_timestamp; - range_lower timestamptz; - transaction_info txid_snapshot; - existing_range tstzrange; - holder record; - holder2 record; - pg_version integer; - BEGIN - -- version 0.2.0 - - IF TG_WHEN != 'BEFORE' OR TG_LEVEL != 'ROW' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired BEFORE ROW'; - END IF; - - IF TG_OP != 'INSERT' AND TG_OP != 'UPDATE' AND TG_OP != 'DELETE' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired for INSERT or UPDATE or DELETE'; - END IF; - - IF TG_NARGS != 3 THEN - RAISE INVALID_PARAMETER_VALUE USING - MESSAGE = 'wrong number of parameters for function "versioning"', - HINT = 'expected 3 parameters but got ' || TG_NARGS; - END IF; - - sys_period := TG_ARGV[0]; - history_table := TG_ARGV[1]; - - -- check if sys_period exists on original table - SELECT atttypid, attndims INTO holder FROM pg_attribute WHERE attrelid = TG_RELID AND attname = sys_period AND NOT attisdropped; - IF NOT FOUND THEN - RAISE 'column "%" of relation "%" does not exist', sys_period, TG_TABLE_NAME USING - ERRCODE = 'undefined_column'; - END IF; - IF holder.atttypid != to_regtype('tstzrange') THEN - IF holder.attndims > 0 THEN - RAISE 'system period column "%" of relation "%" is not a range but an array', sys_period, TG_TABLE_NAME USING - ERRCODE = 'datatype_mismatch'; - END IF; - - SELECT rngsubtype INTO holder2 FROM pg_range WHERE rngtypid = holder.atttypid; - IF FOUND THEN - RAISE 'system period column "%" of relation "%" is not a range of timestamp with timezone but of type %', sys_period, TG_TABLE_NAME, format_type(holder2.rngsubtype, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - RAISE 'system period column "%" of relation "%" is not a range but type %', sys_period, TG_TABLE_NAME, format_type(holder.atttypid, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN - -- Ignore rows already modified in this transaction - transaction_info := txid_current_snapshot(); - IF OLD.xmin::text >= (txid_snapshot_xmin(transaction_info) % (2^32)::bigint)::text - AND OLD.xmin::text <= (txid_snapshot_xmax(transaction_info) % (2^32)::bigint)::text THEN - IF TG_OP = 'DELETE' THEN - RETURN OLD; - END IF; - - RETURN NEW; - END IF; - - SELECT current_setting('server_version_num')::integer - INTO pg_version; - - -- to support postgres < 9.6 - IF pg_version < 90600 THEN - -- check if history table exits - IF to_regclass(history_table::cstring) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - ELSE - IF to_regclass(history_table) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - END IF; - - -- check if history table has sys_period - IF NOT EXISTS(SELECT * FROM pg_attribute WHERE attrelid = history_table::regclass AND attname = sys_period AND NOT attisdropped) THEN - RAISE 'history relation "%" does not contain system period column "%"', history_table, sys_period USING - HINT = 'history relation must contain system period column with the same name and data type as the versioned one'; - END IF; - - EXECUTE format('SELECT $1.%I', sys_period) USING OLD INTO existing_range; - - IF existing_range IS NULL THEN - RAISE 'system period column "%" of relation "%" must not be null', sys_period, TG_TABLE_NAME USING - ERRCODE = 'null_value_not_allowed'; - END IF; - - IF isempty(existing_range) OR NOT upper_inf(existing_range) THEN - RAISE 'system period column "%" of relation "%" contains invalid value', sys_period, TG_TABLE_NAME USING - ERRCODE = 'data_exception', - DETAIL = 'valid ranges must be non-empty and unbounded on the high side'; - END IF; - - IF TG_ARGV[2] = 'true' THEN - -- mitigate update conflicts - range_lower := lower(existing_range); - IF range_lower >= time_stamp_to_use THEN - time_stamp_to_use := range_lower + interval '1 microseconds'; - END IF; - END IF; - - WITH history AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT - history.attname AS history_name, - main.attname AS main_name, - history.atttypid AS history_type, - main.atttypid AS main_type - INTO holder - FROM history - INNER JOIN main - ON history.attname = main.attname - WHERE - history.atttypid != main.atttypid; - - IF FOUND THEN - RAISE 'column "%" of relation "%" is of type % but column "%" of history relation "%" is of type %', - holder.main_name, TG_TABLE_NAME, format_type(holder.main_type, null), holder.history_name, history_table, format_type(holder.history_type, null) - USING ERRCODE = 'datatype_mismatch'; - END IF; - - WITH history AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT array_agg(quote_ident(history.attname)) INTO commonColumns - FROM history - INNER JOIN main - ON history.attname = main.attname - AND history.attname != sys_period; - - EXECUTE ('INSERT INTO ' || - CASE split_part(history_table, '.', 2) - WHEN '' THEN - quote_ident(history_table) - ELSE - quote_ident(split_part(history_table, '.', 1)) || '.' || quote_ident(split_part(history_table, '.', 2)) - END || - '(' || - array_to_string(commonColumns , ',') || - ',' || - quote_ident(sys_period) || - ') VALUES ($1.' || - array_to_string(commonColumns, ',$1.') || - ',tstzrange($2, $3, ''[)''))') - USING OLD, range_lower, time_stamp_to_use; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'INSERT' THEN - manipulate := jsonb_set('{}'::jsonb, ('{' || sys_period || '}')::text[], to_jsonb(tstzrange(time_stamp_to_use, null, '[)'))); - - RETURN jsonb_populate_record(NEW, manipulate); - END IF; - - RETURN OLD; - END; - $$ LANGUAGE plpgsql; - - - - -- Add triggers - ` + createTriggersSql(); - - - db.runSql(sql, callback) - -}; - - - -function dropTriggersSql() { - - return tablesWithVersioningTrigger.map(tablename => ` - DROP TRIGGER versioning_trigger ON ${tablename}; - ` - ).join(''); - -} - -exports.down = function (db, callback) { - const sql = ` - -- Drop Sql versioning function - DROP FUNCTION public.versioning() CASCADE; - - -- Add extension temporal_tables - CREATE EXTENSION IF NOT EXISTS temporal_tables WITH SCHEMA public; - COMMENT ON EXTENSION temporal_tables IS 'temporal tables'; - - ` - + createTriggersSql(); - - - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20180910125638-remove-extensions-fuzzymachstr-tiger.js b/server/db-migrate/migrations/_migration_archive/20180910125638-remove-extensions-fuzzymachstr-tiger.js deleted file mode 100644 index f1160e8d6..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180910125638-remove-extensions-fuzzymachstr-tiger.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - --DROP EXTENSION postgis_tiger_geocoder; - DROP EXTENSION fuzzystrmatch; - - --DROP SCHEMA tiger; - --DROP SCHEMA tiger_data; - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; - --CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; - ` - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180921064027-unique-constraints-for-entity-children.js b/server/db-migrate/migrations/_migration_archive/20180921064027-unique-constraints-for-entity-children.js deleted file mode 100644 index 3578e46bc..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180921064027-unique-constraints-for-entity-children.js +++ /dev/null @@ -1,91 +0,0 @@ -'use strict'; -/** - * This Migration adds unique constraints for pk_entity to all tables that inherit from - * an entity table. - * - * This is useful, since it will allow to add foreign key referencing on those - * pk_entity cols. - * - * For getting all tables that inherit from an entity table, run this query: - * - * SELECT cn.nspname AS schema_child, c.relname AS child, pn.nspname AS schema_parent, p.relname AS parent - * FROM pg_inherits - * JOIN pg_class AS c ON (inhrelid=c.oid) - * JOIN pg_class as p ON (inhparent=p.oid) - * JOIN pg_namespace pn ON pn.oid = p.relnamespace - * JOIN pg_namespace cn ON cn.oid = c.relnamespace - * WHERE p.relname = 'entity' - * - * - */ - -var dbm; -var type; -var seed; - -const tables = [ - 'commons.label', - 'commons.project', - 'commons.property_set', - 'commons.system_type', - 'commons.text_property', - 'commons.ui_context', - 'commons.ui_context_config', - 'data_for_history.associates_system_type', - 'data_for_history.class', - 'data_for_history.class_profile_view', - 'data_for_history.label', - 'data_for_history.profile', - 'data_for_history.property', - 'data_for_history.property_profile_view', - 'data_for_history.system_type', - 'data_for_history.text_property', - 'information.appellation', - 'information.chunk', - 'information.digital_object', - 'information.entity_association', - 'information.entity_version_project_rel', - 'information.language', - 'information.persistent_item', - 'information.place', - 'information.role', - 'information.sourcing', - 'information.temporal_entity', - 'information.text_property', - 'information.time_primitive' -] - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = tables.map(tname => ( - `ALTER TABLE ${tname} ADD CONSTRAINT ${tname.replace('.','_')}_pk_entity_unique UNIQUE (pk_entity); - ` - )).join(''); - - - - db.runSql(sql, callback) -}; - -exports.down = function (db, callback) { - const sql = tables.map(tname => ( - `ALTER TABLE ${tname} DROP CONSTRAINT ${tname.replace('.','_')}_pk_entity_unique; - ` - )).join(''); - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180921064028-dfh-t-proj-rel.js b/server/db-migrate/migrations/_migration_archive/20180921064028-dfh-t-proj-rel.js deleted file mode 100644 index 1180e1d6e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180921064028-dfh-t-proj-rel.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE data_for_history.proj_rel - ( - pk_entity integer primary key, - fk_project integer references commons.project (pk_project), - fk_entity integer references data_for_history.class (pk_entity), - is_in_project boolean, - CONSTRAINT data_for_history_proj_rel_pk_entity UNIQUE (pk_entity), - CONSTRAINT proj_rel_unique UNIQUE (fk_entity, fk_project) - ) - INHERITS (data_for_history.entity); - - COMMENT ON TABLE data_for_history.proj_rel IS 'This table relates any child table of the data_for_history.entity to a project.'; - COMMENT ON COLUMN data_for_history.proj_rel.is_in_project IS 'If true, the entity is (added / activated / visible) in the project, if false it is not in the project'; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON data_for_history.proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON data_for_history.proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON data_for_history.proj_rel FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE data_for_history.proj_rel_vt (LIKE data_for_history.proj_rel); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON data_for_history.proj_rel - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'data_for_history.proj_rel_vt', true - ); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE data_for_history.proj_rel CASCADE; - DROP TABLE data_for_history.proj_rel_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180921143129-inf-t-namespace.js b/server/db-migrate/migrations/_migration_archive/20180921143129-inf-t-namespace.js deleted file mode 100644 index 91b471a8d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180921143129-inf-t-namespace.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE information.namespace - ( - pk_entity integer primary key, - fk_root_namespace integer references information.namespace (pk_entity), - fk_project integer references commons.project (pk_project), - standard_label varchar(500), - CONSTRAINT information_namespace_pk_entity_unique UNIQUE (pk_entity) - ) - INHERITS (information.entity); - - COMMENT ON TABLE information.namespace IS 'This table stores namespaces of controlled vocabularies.'; - COMMENT ON COLUMN information.namespace.fk_root_namespace IS 'References the root namespace. If null, the namespace is a root namespace'; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.namespace - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.namespace - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON information.namespace FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE information.namespace_vt (LIKE information.namespace); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.namespace - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.namespace_vt', true - ); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.namespace CASCADE; - DROP TABLE information.namespace_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180921144009-inf-t-type-namespace-rel.js b/server/db-migrate/migrations/_migration_archive/20180921144009-inf-t-type-namespace-rel.js deleted file mode 100644 index 99c613357..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180921144009-inf-t-type-namespace-rel.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - CREATE TABLE information.type_namespace_rel - ( - pk_entity integer primary key, - fk_persistent_item integer references information.persistent_item (pk_entity), - fk_namespace integer references information.namespace (pk_entity), - CONSTRAINT information_type_namespace_rel_pk_entity_unique UNIQUE (pk_entity) - ) - INHERITS (information.entity); - - COMMENT ON TABLE information.type_namespace_rel IS 'This table stores relation between instances of E55 Type and Namespaces.'; - COMMENT ON COLUMN information.type_namespace_rel.fk_persistent_item IS 'References the pk_entity of the persistent_item table.'; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON information.type_namespace_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON information.type_namespace_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON information.type_namespace_rel FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - - -- versioning - - CREATE TABLE information.type_namespace_rel_vt (LIKE information.type_namespace_rel); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON information.type_namespace_rel - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'information.type_namespace_rel_vt', true - ); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - const sql = ` - DROP TABLE information.type_namespace_rel CASCADE; - DROP TABLE information.type_namespace_rel_vt; - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180925154235-inf-t-text-property-change.js b/server/db-migrate/migrations/_migration_archive/20180925154235-inf-t-text-property-change.js deleted file mode 100644 index 15155bbd3..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180925154235-inf-t-text-property-change.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- drop own pk - ALTER TABLE information.text_property DROP COLUMN pk_text_property; - ALTER TABLE information.text_property_vt DROP COLUMN pk_text_property; - - -- drop xml field - ALTER TABLE information.text_property DROP COLUMN text_property_xml; - ALTER TABLE information.text_property_vt DROP COLUMN text_property_xml; - - -- add jsonb field - ALTER TABLE information.text_property ADD COLUMN text_property_quill_doc JSONB; - ALTER TABLE information.text_property_vt ADD COLUMN text_property_quill_doc JSONB; - - -- add fk system type fk-constraint - ALTER TABLE information.text_property ADD CONSTRAINT text_property_fk_system_type_constraint FOREIGN KEY (fk_system_type) REFERENCES commons.system_type (pk_entity); - - -- fk language - ALTER TABLE information.text_property DROP COLUMN fk_language; - ALTER TABLE information.text_property_vt DROP COLUMN fk_language; - ALTER TABLE information.text_property ADD COLUMN fk_language integer; - ALTER TABLE information.text_property_vt ADD COLUMN fk_language integer; - ALTER TABLE information.text_property ADD CONSTRAINT text_property_fk_language_constraint FOREIGN KEY (fk_language) REFERENCES information.language (pk_entity); - - -- fk concerned entity - ALTER TABLE information.text_property RENAME COLUMN fk_entity TO fk_concerned_entity; - ALTER TABLE information.text_property_vt RENAME COLUMN fk_entity TO fk_concerned_entity; - - -- not null constraints - ALTER TABLE information.text_property ALTER COLUMN fk_system_type SET NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN fk_language SET NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN fk_concerned_entity SET NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN text_property_quill_doc SET NOT NULL; - - -- unique identity contraint - ALTER TABLE information.text_property ADD CONSTRAINT text_property_identity_unique UNIQUE (fk_system_type,fk_language,fk_concerned_entity,text_property_quill_doc); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - -- drop not null constraints - ALTER TABLE information.text_property ALTER COLUMN fk_system_type DROP NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN fk_language DROP NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN fk_concerned_entity DROP NOT NULL; - ALTER TABLE information.text_property ALTER COLUMN text_property_quill_doc DROP NOT NULL; - - -- add own pk - ALTER TABLE information.text_property ADD COLUMN pk_text_property SERIAL PRIMARY KEY; - ALTER TABLE information.text_property_vt ADD COLUMN pk_text_property INTEGER; - - -- add xml field - ALTER TABLE information.text_property ADD COLUMN text_property_xml XML; - ALTER TABLE information.text_property_vt ADD COLUMN text_property_xml XML; - - -- DROP jsonb field - ALTER TABLE information.text_property DROP COLUMN text_property_quill_doc; - ALTER TABLE information.text_property_vt DROP COLUMN text_property_quill_doc; - - -- drop fk system type fk-constraint - ALTER TABLE information.text_property DROP CONSTRAINT text_property_fk_system_type_constraint; - - -- fk language - ALTER TABLE information.text_property DROP COLUMN fk_language; - ALTER TABLE information.text_property_vt DROP COLUMN fk_language; - ALTER TABLE information.text_property ADD COLUMN fk_language character(3); - ALTER TABLE information.text_property_vt ADD COLUMN fk_language character(3); - - -- fk concerned entity - ALTER TABLE information.text_property RENAME COLUMN fk_concerned_entity TO fk_entity; - ALTER TABLE information.text_property_vt RENAME COLUMN fk_concerned_entity TO fk_entity; - ALTER TABLE information.text_property DROP CONSTRAINT text_property_fk_concerned_entity_constraint; - - ` - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20180926121751-inf-v-text-property.js b/server/db-migrate/migrations/_migration_archive/20180926121751-inf-v-text-property.js deleted file mode 100644 index 8f9fd2e92..000000000 --- a/server/db-migrate/migrations/_migration_archive/20180926121751-inf-v-text-property.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_text_property - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT * FROM information.text_property; - - -- create v_text_property_find_or_create - CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - text_property_quill_doc::jsonb = NEW.text_property_quill_doc::jsonb - AND fk_system_type = NEW.fk_system_type - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - text_property_quill_doc, - fk_system_type, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.text_property_quill_doc::jsonb, - NEW.fk_system_type, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_text_property_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_text_property - DROP VIEW IF EXISTS information.v_text_property; - - -- remove trigger function v_text_property_find_or_create - DROP FUNCTION information.v_text_property_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181003141321-dfh-t-label-add-columns.js b/server/db-migrate/migrations/_migration_archive/20181003141321-dfh-t-label-add-columns.js deleted file mode 100644 index 042055378..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181003141321-dfh-t-label-add-columns.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ALTER TABLE data_for_history.label ADD COLUMN com_fk_system_type integer REFERENCES commons.system_type (pk_entity); - ALTER TABLE data_for_history.label ADD COLUMN inf_fk_language integer REFERENCES information.language (pk_entity); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - ALTER TABLE data_for_history.label DROP COLUMN com_fk_system_type; - ALTER TABLE data_for_history.label DROP COLUMN inf_fk_language; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181012123251-com-t-property-set-property-rel.js b/server/db-migrate/migrations/_migration_archive/20181012123251-com-t-property-set-property-rel.js deleted file mode 100644 index d05f72a55..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181012123251-com-t-property-set-property-rel.js +++ /dev/null @@ -1,98 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - CREATE TABLE commons.property_set_property_rel ( - fk_property_set integer REFERENCES commons.property_set (pk_entity), - fk_property integer REFERENCES data_for_history.property (dfh_pk_property), - property_is_outgoing BOOLEAN, - ord_num INTEGER - ) - INHERITS (commons.entity); - - ALTER TABLE commons.property_set_property_rel ADD CONSTRAINT commons_property_set_property_rel_pk_entity_unique UNIQUE (pk_entity); - - COMMENT ON TABLE commons.property_set_property_rel IS 'This table stores, what properties are bundled in the property set'; - COMMENT ON COLUMN commons.property_set_property_rel.fk_property IS 'The property belonging to the property set'; - COMMENT ON COLUMN commons.property_set_property_rel.fk_property_set IS 'The property set'; - COMMENT ON COLUMN commons.property_set_property_rel.property_is_outgoing IS 'Wether the property is outgoing, seen from the class that will use it'; - COMMENT ON COLUMN commons.property_set_property_rel.ord_num IS 'The order number of the property within the property set.'; - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON commons.property_set_property_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON commons.property_set_property_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - CREATE TRIGGER insert_schema_table_name BEFORE INSERT - ON commons.property_set_property_rel FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON commons.property_set_property_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON commons.property_set_property_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - -- versioning - - CREATE TABLE commons.property_set_property_rel_vt (LIKE commons.property_set_property_rel); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON commons.property_set_property_rel - FOR EACH ROW EXECUTE PROCEDURE versioning( - 'sys_period', 'commons.property_set_property_rel_vt', true - ); - --- Insert into commons.property_set_property_rel ("fk_property_set","fk_property", "property_is_outgoing") --- VALUES --- (48, 71, true), --- (48, 72, true), --- (48, 150, true), --- (48, 151, true), --- (48, 152, true), --- (48, 153, true); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP TABLE IF EXISTS commons.property_set_property_rel CASCADE; - DROP TABLE IF EXISTS commons.property_set_property_rel_vt CASCADE; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181012185824-inf-v-role-add-ranking.js b/server/db-migrate/migrations/_migration_archive/20181012185824-inf-v-role-add-ranking.js deleted file mode 100644 index b3bd633a7..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181012185824-inf-v-role-add-ranking.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_role - CREATE OR REPLACE VIEW information.v_role AS - WITH role_project_count AS ( - SELECT - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - COALESCE(count(*) FILTER (where epr.is_in_project = true),0) AS is_in_project_count, - COALESCE(count(*) FILTER (where epr.ord_num = 0), 0) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period - FROM information.role as r - LEFT JOIN information.entity_version_project_rel as epr on epr.fk_entity = r.pk_entity - GROUP BY - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period - ) - SELECT - r.*, - - --make a ranking for each property and te_ent - ROW_NUMBER() OVER(PARTITION BY r.fk_temporal_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_te_ent, - p.dfh_range_instances_max_quantifier as range_max_quantifier, - - --make a ranking for each property and pe_it - ROW_NUMBER() OVER(PARTITION BY r.fk_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_pe_it, - p.dfh_domain_instances_max_quantifier as domain_max_quantifier - from role_project_count as r - inner join data_for_history.property as p - on r.fk_property = p.dfh_pk_property; - - - COMMENT ON VIEW information.v_role IS 'If rank_for_te_ent is bigger than range_max_quantifier, the role can be considered a repo-wide alternative from the perspective of the temporal entits. - - If rank_for_pe_it is bigger than domain_max_quantifier, the role can be considered a repo-wide alternative from the perspective of the persistent item.' - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- drop view v_role - DROP VIEW IF EXISTS information.v_role; - - -- revert previous view v_role - CREATE OR REPLACE VIEW information.v_role AS - SELECT - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - COALESCE(count(*) FILTER (where epr.is_in_project = true),0) AS is_in_project_count, - COALESCE(count(*) FILTER (where epr.ord_num = 0), 0) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period - FROM information.role as r - LEFT JOIN information.entity_version_project_rel as epr on epr.fk_entity = r.pk_entity - GROUP BY - r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period; - - - -- add trigger on insert to execute v_role_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_find_or_create(); - - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181012193006-inf-v-entity-association-add-ranking.js b/server/db-migrate/migrations/_migration_archive/20181012193006-inf-v-entity-association-add-ranking.js deleted file mode 100644 index 992447399..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181012193006-inf-v-entity-association-add-ranking.js +++ /dev/null @@ -1,209 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - -- drop view v_entity_association - DROP VIEW IF EXISTS information.v_entity_association; - - -- add view v_entity_association - CREATE OR REPLACE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT - ea.pk_entity, - ea.fk_property, - ea.fk_domain_entity, - ea.fk_range_entity, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - COALESCE(count(*) FILTER (where epr.is_in_project = true),0) AS is_in_project_count - FROM information.entity_association as ea - LEFT JOIN information.entity_version_project_rel as epr on epr.fk_entity = ea.pk_entity - GROUP BY - ea.pk_entity, - ea.fk_property, - ea.fk_domain_entity, - ea.fk_range_entity, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period - ) - SELECT - ea.*, - - --make a ranking for each property and domain_entity - ROW_NUMBER() OVER(PARTITION BY ea.fk_domain_entity, ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier as range_max_quantifier, - - --make a ranking for each property and pe_it - ROW_NUMBER() OVER(PARTITION BY ea.fk_range_entity, ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier as domain_max_quantifier - - from ea_project_count as ea - inner join data_for_history.property as p - on ea.fk_property = p.dfh_pk_property; - - - COMMENT ON VIEW information.v_entity_association IS 'If rank_for_domain is bigger than range_max_quantifier, the entity association can be considered a repo-wide alternative from the perspective of the domain entity. - - If rank_for_range is bigger than domain_max_quantifier, the entity association can be considered a repo-wide alternative from the perspective of the range entity.'; - - - - -- create v_entity_association_find_or_create - CREATE OR REPLACE FUNCTION information.v_entity_association_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.entity_association - WHERE - fk_domain_entity = NEW.fk_domain_entity - AND fk_range_entity = NEW.fk_range_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_domain_entity, - fk_range_entity, - fk_property - ) - VALUES ( - NEW.fk_domain_entity, - NEW.fk_range_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_association - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - -- add trigger on insert to execute v_entity_association_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- drop view v_entity_association - DROP VIEW IF EXISTS information.v_entity_association; - - -- revert previous view v_entity_association - - - -- add view v_entity_association - CREATE OR REPLACE VIEW information.v_entity_association AS - SELECT * FROM information.entity_association; - - -- create v_entity_association_find_or_create - CREATE OR REPLACE FUNCTION information.v_entity_association_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.entity_association - WHERE - fk_domain_entity = NEW.fk_domain_entity - AND fk_range_entity = NEW.fk_range_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_domain_entity, - fk_range_entity, - fk_property - ) - VALUES ( - NEW.fk_domain_entity, - NEW.fk_range_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - - -- add trigger on insert to execute v_entity_association_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181012202236-inf-v-entity-version-project-rel.js b/server/db-migrate/migrations/_migration_archive/20181012202236-inf-v-entity-version-project-rel.js deleted file mode 100644 index e6d389076..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181012202236-inf-v-entity-version-project-rel.js +++ /dev/null @@ -1,133 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- add view v_entity_version_project_rel - CREATE OR REPLACE VIEW information.v_entity_version_project_rel AS - SELECT * FROM information.entity_version_project_rel; - - - - -- create v_entity_version_project_rel_find_or_create - CREATE OR REPLACE FUNCTION information.v_entity_version_project_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_version_project_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE information.entity_version_project_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_version_project_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1 - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - - -- add trigger on insert to execute v_entity_version_project_rel_update_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_version_project_rel_update_or_create(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_entity_version_project_rel - DROP VIEW IF EXISTS information.v_entity_version_project_rel; - - -- remove trigger function v_entity_version_project_rel_update_or_create - DROP FUNCTION information.v_entity_version_project_rel_update_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181017080524-dfh-t-property-add-identity-defining-col.js b/server/db-migrate/migrations/_migration_archive/20181017080524-dfh-t-property-add-identity-defining-col.js deleted file mode 100644 index b8348aa83..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181017080524-dfh-t-property-add-identity-defining-col.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ALTER TABLE data_for_history.property - ADD COLUMN identity_defining BOOLEAN DEFAULT false; - - ALTER TABLE data_for_history.property_vt - ADD COLUMN identity_defining BOOLEAN; - - COMMENT ON COLUMN data_for_history.property.identity_defining IS 'If the value is set to true, this means that this property is relevant for the TeEn identity.'; - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - ALTER TABLE data_for_history.property - DROP COLUMN identity_defining; - - ALTER TABLE data_for_history.property_vt - DROP COLUMN identity_defining; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181031124338-com-rename-to-class-field.js b/server/db-migrate/migrations/_migration_archive/20181031124338-com-rename-to-class-field.js deleted file mode 100644 index b90246338..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181031124338-com-rename-to-class-field.js +++ /dev/null @@ -1,138 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- rename tables (replace property_set with class_field) - - DROP TRIGGER versioning_trigger ON commons.property_set; - - ALTER TABLE commons.property_set - RENAME TO class_field; - - ALTER TABLE commons.property_set_vt - RENAME TO class_field_vt; - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON commons.class_field - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'commons.class_field_vt', 'true'); - - - DROP TRIGGER versioning_trigger ON commons.property_set_property_rel; - - ALTER TABLE commons.property_set_property_rel - RENAME TO class_field_property_rel; - - ALTER TABLE commons.property_set_property_rel_vt - RENAME TO class_field_property_rel_vt; - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON commons.class_field_property_rel - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'commons.class_field_property_rel_vt', 'true'); - - - -- rename columns accordingly - - ALTER TABLE commons.ui_context_config - RENAME COLUMN fk_property_set TO fk_class_field; - - ALTER TABLE commons.ui_context_config_vt - RENAME COLUMN fk_property_set TO fk_class_field; - - ALTER TABLE commons.ui_context_config - RENAME COLUMN fk_class_for_property_set TO fk_class_for_class_field; - - ALTER TABLE commons.ui_context_config_vt - RENAME COLUMN fk_class_for_property_set TO fk_class_for_class_field; - - ALTER TABLE commons.class_field_property_rel - RENAME COLUMN fk_property_set TO fk_class_field; - - ALTER TABLE commons.class_field_property_rel_vt - RENAME COLUMN fk_property_set TO fk_class_field; - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - - -- rename columns accordingly - - ALTER TABLE commons.ui_context_config - RENAME COLUMN fk_class_field TO fk_property_set; - - ALTER TABLE commons.ui_context_config_vt - RENAME COLUMN fk_class_field TO fk_property_set; - - ALTER TABLE commons.ui_context_config - RENAME COLUMN fk_class_for_class_field TO fk_class_for_property_set; - - ALTER TABLE commons.ui_context_config_vt - RENAME COLUMN fk_class_for_class_field TO fk_class_for_property_set; - - ALTER TABLE commons.class_field_property_rel - RENAME COLUMN fk_class_field TO fk_property_set; - - ALTER TABLE commons.class_field_property_rel_vt - RENAME COLUMN fk_class_field TO fk_property_set; - - -- rename tables - - DROP TRIGGER versioning_trigger ON commons.class_field; - - ALTER TABLE commons.class_field - RENAME TO property_set; - - ALTER TABLE commons.class_field_vt - RENAME TO property_set_vt; - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON commons.property_set - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'commons.property_set_vt', 'true'); - - - DROP TRIGGER versioning_trigger ON commons.class_field_property_rel; - - ALTER TABLE commons.class_field_property_rel - RENAME TO property_set_property_rel; - - ALTER TABLE commons.class_field_property_rel_vt - RENAME TO property_set_property_rel_vt; - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON commons.property_set_property_rel - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'commons.property_set_property_rel_vt', 'true'); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181031131549-inf-t-text-property-alter-to-fk-class-field.js b/server/db-migrate/migrations/_migration_archive/20181031131549-inf-t-text-property-alter-to-fk-class-field.js deleted file mode 100644 index d1813826d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181031131549-inf-t-text-property-alter-to-fk-class-field.js +++ /dev/null @@ -1,234 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - INSERT INTO commons.class_field (label, description) - VALUES - ('Short Title', 'Short Title for a class instance (without time information.)'), - ('Exact Reference', 'Exact reference for a F2 Expression (e.g Page "2").)'), - ('Entity Definition', 'Entity Definition. Given that in many cases appellations are not sufficient for an unambiguous identification of resources, these text properties provide definitions in text form.'); - - DELETE FROM information.text_property WHERE fk_system_type = 179; - - ALTER TABLE information.text_property - ADD COLUMN fk_class_field INTEGER REFERENCES commons.class_field (pk_entity); - - ALTER TABLE information.text_property_vt - ADD COLUMN fk_class_field INTEGER; - - ALTER TABLE information.text_property - DROP CONSTRAINT IF EXISTS text_property_fk_system_type_constraint; - - ALTER TABLE information.text_property - DROP CONSTRAINT IF EXISTS text_property_fk_system_type_fkey; - - ALTER TABLE information.text_property DROP CONSTRAINT text_property_identity_unique; - - DROP VIEW information.v_text_property; - - DROP FUNCTION information.v_text_property_find_or_create(); - - ALTER TABLE information.text_property - DROP COLUMN fk_system_type; - - ALTER TABLE information.text_property - ADD CONSTRAINT text_property_identity_unique UNIQUE (fk_class_field, fk_language, fk_concerned_entity, text_property_quill_doc); - - ALTER TABLE information.text_property_vt - DROP COLUMN fk_system_type; - - DELETE FROM commons.system_type WHERE notes = 'Entity Definition Text Property. Given that in many cases appellations are not sufficient for an unambiguous identification of resources, these text properties provide definitions in text form.'; - - - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT * FROM information.text_property; - - CREATE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - text_property_quill_doc::jsonb = NEW.text_property_quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - text_property_quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.text_property_quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - - - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - ALTER TABLE information.text_property - ADD COLUMN fk_system_type INTEGER REFERENCES commons.system_type (pk_entity); - - ALTER TABLE information.text_property_vt - ADD COLUMN fk_system_type INTEGER; - - ALTER TABLE information.text_property - DROP CONSTRAINT text_property_fk_class_field_fkey; - - ALTER TABLE information.text_property DROP CONSTRAINT text_property_identity_unique; - - DROP VIEW information.v_text_property; - - DROP FUNCTION information.v_text_property_find_or_create(); - - ALTER TABLE information.text_property - DROP COLUMN fk_class_field; - - ALTER TABLE information.text_property - ADD CONSTRAINT text_property_identity_unique UNIQUE (fk_system_type, fk_language, fk_concerned_entity, text_property_quill_doc); - - ALTER TABLE information.text_property_vt - DROP COLUMN fk_class_field; - - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT * FROM information.text_property; - - CREATE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - text_property_quill_doc::jsonb = NEW.text_property_quill_doc::jsonb - AND fk_system_type = NEW.fk_system_type - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - text_property_quill_doc, - fk_system_type, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.text_property_quill_doc::jsonb, - NEW.fk_system_type, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - - - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181119112626-com-t-ui-context-config-add-fk-contraint.js b/server/db-migrate/migrations/_migration_archive/20181119112626-com-t-ui-context-config-add-fk-contraint.js deleted file mode 100644 index 381fb6773..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181119112626-com-t-ui-context-config-add-fk-contraint.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ALTER TABLE commons.ui_context_config - ADD CONSTRAINT ui_context_config_fk_ui_context_fkey FOREIGN KEY (fk_ui_context) REFERENCES commons.ui_context (pk_entity); - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - ALTER TABLE commons.ui_context_config - DROP CONSTRAINT ui_context_config_fk_ui_context_fkey; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-appellation-add-string-col.1.js b/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-appellation-add-string-col.1.js deleted file mode 100644 index f103e34aa..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-appellation-add-string-col.1.js +++ /dev/null @@ -1,201 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - --- Function to extract plain string from appellation_label - - CREATE OR REPLACE FUNCTION information.appellation_label_to_string( - appellation_label jsonb, - OUT string text) - RETURNS text - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - SELECT STRING_AGG(l.tokens->>'string', '') - FROM (SELECT jsonb_array_elements(appellation_label->'tokens') as tokens) as l - - $BODY$; - - - -- remove view v_appellation - DROP VIEW IF EXISTS information.v_appellation; - - --- add string col to appellation view - - CREATE OR REPLACE VIEW information.v_appellation AS - SELECT - appellation.pk_entity, - appellation.schema_name, - appellation.table_name, - appellation.notes, - appellation.fk_creator, - appellation.fk_last_modifier, - appellation.tmsp_creation, - appellation.tmsp_last_modification, - appellation.sys_period, - appellation.pk_appellation, - appellation.appellation_label, - appellation.fk_class, - information.appellation_label_to_string(appellation.appellation_label) as string - FROM information.appellation; - - - -- create v_appellation_find_or_create - CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.v_appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - information.appe_tokens_for_comparision(appellation_label) = - information.appe_tokens_for_comparision(NEW.appellation_label) - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - appellation_label, - fk_class - ) - VALUES ( - NEW.appellation_label, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - --- add trigger on insert to execute v_appellation_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_appellation - DROP VIEW IF EXISTS information.v_appellation; - - -- remove the new function - DROP FUNCTION information.appellation_label_to_string(jsonb); - - -- remove trigger function v_appellation_find_or_create - DROP FUNCTION information.v_appellation_find_or_create(); - - -- add view v_appellation - CREATE OR REPLACE VIEW information.v_appellation AS - SELECT * FROM information.appellation; - --- create v_appellation_find_or_create - CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - resulting_row information.appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - information.appe_tokens_for_comparision(appellation_label) = - information.appe_tokens_for_comparision(NEW.appellation_label) - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - appellation_label, - fk_class - ) - VALUES ( - NEW.appellation_label, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - - --- add trigger on insert to execute v_appellation_find_or_create - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-text_property-add-string-col.js b/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-text_property-add-string-col.js deleted file mode 100644 index fb2ee7311..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181120102644-inf-v-text_property-add-string-col.js +++ /dev/null @@ -1,142 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - --- Function to extract plain string from text_property - - CREATE OR REPLACE FUNCTION information.text_property_to_string( - text_property_quill_doc jsonb, - OUT string text) - RETURNS text - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - SELECT STRING_AGG(l.ops->>'insert', '') - FROM (SELECT jsonb_array_elements(text_property_quill_doc->'contents'->'ops') as ops) as l - - $BODY$; - - --- add string col to text_property view - - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT - *, - information.text_property_to_string(text_property_quill_doc) as string - FROM information.text_property; - - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - -- remove view v_text_property - DROP VIEW IF EXISTS information.v_text_property; - - -- remove the new function - DROP FUNCTION information.text_property_to_string(jsonb); - - -- add view v_text_property - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT * FROM information.text_property; - - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT * FROM information.text_property; - - CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - text_property_quill_doc::jsonb = NEW.text_property_quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - text_property_quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.text_property_quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - - - - CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181120132827-com-t-class-field-add-cols.js b/server/db-migrate/migrations/_migration_archive/20181120132827-com-t-class-field-add-cols.js deleted file mode 100644 index 04c91d36e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181120132827-com-t-class-field-add-cols.js +++ /dev/null @@ -1,60 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ALTER TABLE commons.class_field - ADD COLUMN used_table TEXT; - - ALTER TABLE commons.class_field - ADD COLUMN fk_system_type_ng_component INTEGER, - ADD CONSTRAINT fk_system_type_ng_component_fkey FOREIGN KEY (fk_system_type_ng_component) REFERENCES commons.system_type (pk_entity); - - - ALTER TABLE commons.class_field_vt - ADD COLUMN used_table TEXT; - - ALTER TABLE commons.class_field_vt - ADD COLUMN fk_system_type_ng_component INTEGER; - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - ALTER TABLE commons.class_field - DROP COLUMN used_table ; - - ALTER TABLE commons.class_field - DROP COLUMN fk_system_type_ng_component; - - ALTER TABLE commons.class_field_vt - DROP COLUMN used_table ; - - ALTER TABLE commons.class_field_vt - DROP COLUMN fk_system_type_ng_component; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181120175039-inf-t-entity-association-vt.js b/server/db-migrate/migrations/_migration_archive/20181120175039-inf-t-entity-association-vt.js deleted file mode 100644 index 0da818266..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181120175039-inf-t-entity-association-vt.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ALTER TABLE information.entity_association_vt - ALTER COLUMN fk_property SET DATA TYPE integer USING fk_property::integer; - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181120190352-inf-functions-for-pe-it-preview.js b/server/db-migrate/migrations/_migration_archive/20181120190352-inf-functions-for-pe-it-preview.js deleted file mode 100644 index ba4762cac..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181120190352-inf-functions-for-pe-it-preview.js +++ /dev/null @@ -1,275 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - CREATE OR REPLACE FUNCTION information.queryPeItLabel( - param_pk_project integer, - param_pk_entity integer, - param_pk_ui_context integer, - OUT pk_entity integer, - OUT fk_project integer, - OUT fk_class integer, - OUT entity_label text, - OUT class_label varchar, - OUT entity_type text - ) - RETURNS SETOF record - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - WITH appe_string as ( - SELECT pk_entity, string - from information.v_appellation - ), - text_property_string as ( - SELECT txt.pk_entity, txt.fk_concerned_entity, txt.string, epr.fk_project, epr.ord_num as txt_order - from information.v_text_property as txt - INNER JOIN information.entity_version_project_rel as epr on txt.pk_entity = epr.fk_entity - WHERE is_in_project = true AND fk_project = param_pk_project - ORDER BY ord_num - ), - role as ( - SELECT r.pk_entity, r.fk_entity, r.fk_temporal_entity, r.fk_property, epr.fk_project, epr.ord_num as role_order - from information.role as r - INNER JOIN information.entity_version_project_rel as epr on r.pk_entity = epr.fk_entity - WHERE is_in_project = true AND fk_project = param_pk_project - ORDER BY ord_num - ), - persistent_item as ( - SELECT pk_entity, fk_class - from information.v_persistent_item - WHERE pk_entity = param_pk_entity - ), - ordered_fields_per_class AS ( - SELECT c.pk_entity, c.ord_num as field_order, - CASE - WHEN c.property_is_outgoing=true THEN p.dfh_has_domain - WHEN c.property_is_outgoing=false THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END as fk_class, - c.fk_property, - c.property_is_outgoing, - c.fk_class_field, - f.used_table - FROM commons.ui_context_config as c - LEFT JOIN data_for_history.property as p on p.dfh_pk_property = c.fk_property - LEFT JOIN commons.class_field as f on f.pk_entity = c.fk_class_field - WHERE fk_ui_context = param_pk_ui_context - ORDER BY fk_class, ord_num - ), - ordered_pe_it_fields AS ( - SELECT ordered_fields_per_class.* - FROM ordered_fields_per_class - INNER JOIN persistent_item as p on p.fk_class = ordered_fields_per_class.fk_class - LIMIT 1 - ), - ordered_pe_it_roles AS ( - select - pe_it.fk_class, - pe_it.pk_entity, - pi_role.fk_project, - pi_role.fk_entity, - pi_role.fk_temporal_entity, - pi_role.fk_property, - field_order, - pi_role.role_order - from persistent_item as pe_it - -- get the roles of the persistent item that are available in the ordered list of fields for the pe-it class - INNER JOIN ordered_pe_it_fields as pi_fields on pi_fields.fk_class = pe_it.fk_class - INNER JOIN role as pi_role on pi_role.fk_entity = pe_it.pk_entity AND pi_role.fk_property = pi_fields.fk_property - ORDER BY role_order - ), - ordered_pe_it_text_properties AS ( - select - pe_it.fk_class, - pe_it.pk_entity, - pi_txt.fk_project, - pi_txt.pk_entity as txt_pk, - field_order, - pi_txt.txt_order, - pi_txt.string - from persistent_item as pe_it - -- get the roles of the persistent item that are available in the ordered list of fields for the pe-it class - INNER JOIN ordered_pe_it_fields as pi_fields on pi_fields.fk_class = pe_it.fk_class - INNER JOIN text_property_string as pi_txt on pi_txt.fk_concerned_entity = pe_it.pk_entity AND pi_fields.used_table = 'information.text_property' - ORDER BY txt_order - ), - temporal_entity as ( - SELECT teen.pk_entity, teen.fk_class - from information.v_temporal_entity as teen - INNER JOIN ordered_pe_it_roles as teen_r on teen_r.fk_temporal_entity = teen.pk_entity - ), - ordered_te_en_fields AS ( - SELECT ordered_fields_per_class.* - FROM ordered_fields_per_class - INNER JOIN temporal_entity as p on p.fk_class = ordered_fields_per_class.fk_class - LIMIT 1 - ), - ordered_te_ent_roles AS ( - select - te_role.fk_project, - te_role.fk_entity, - te_role.fk_temporal_entity, - te_role.fk_property, - te_fields.field_order, - te_role.role_order, - string - from temporal_entity as te_ent - - -- The following line is for performance tuning only - INNER JOIN ordered_pe_it_roles o_peit_r on o_peit_r.fk_temporal_entity = te_ent.pk_entity - - -- get the roles of the temporal entities that are available in the ordered list of fields for the te-ent class - INNER JOIN ordered_te_en_fields as te_fields on te_fields.fk_class = te_ent.fk_class - INNER JOIN role as te_role on te_role.fk_property = te_fields.fk_property - - ----------------------------------------------------------- - -- get the strings of all related value-like tables - INNER JOIN appe_string on appe_string.pk_entity = te_role.fk_entity - - - -- add here string-selects for: - -- time_primitive - -- place - -- ... - - ----------------------------------------------------------- - - ORDER BY field_order - - ), - string AS ( - SELECT - o_peit_r.pk_entity, - o_peit_r.fk_project, - o_peit_r.fk_class, - o_peit_r.field_order, - o_peit_r.role_order as val_order, - o_teen_r.string - from ordered_pe_it_roles as o_peit_r - LEFT JOIN ordered_te_ent_roles as o_teen_r - ON o_teen_r.fk_temporal_entity = o_peit_r.fk_temporal_entity-- AND o_teen_r.string IS NOT NULL - UNION - SELECT - o_peit_txt.pk_entity, - o_peit_txt.fk_project, - o_peit_txt.fk_class, - o_peit_txt.field_order, - o_peit_txt.txt_order as val_order, - o_peit_txt.string - from ordered_pe_it_text_properties as o_peit_txt - --WHERE o_peit_txt.string IS NOT NULL - ), - class AS ( - SELECT - CASE - WHEN l.dfh_label IS NOT NULL THEN l.dfh_label - ELSE cpv.dfh_class_standard_label - END as class_label, - CASE - WHEN cpv.dfh_fk_system_type = 9 THEN 'teEn' - WHEN cpv.dfh_fk_system_type = 8 THEN 'peIt' - ELSE NULL - END as entity_type, - c.dfh_pk_class - from data_for_history.class as c - inner join string as s on s.fk_class = c.dfh_pk_class - inner join data_for_history.class_profile_view as cpv on c.dfh_pk_class = cpv.dfh_fk_class - left join data_for_history.label as l on l.dfh_fk_class = c.dfh_pk_class AND l.com_fk_system_type = 184 - LIMIT 1 - ), - final_select as ( - select DISTINCT - s.pk_entity, - s.field_order, - s.val_order, - s.fk_project, - s.fk_class, - s.string, - c.class_label, - c.entity_type - from string as s - INNER JOIN class as c on c.dfh_pk_class = s.fk_class - ORDER BY field_order, val_order - LIMIT 1 - ) - select pk_entity, fk_project, fk_class, string as entity_label, class_label, entity_type from final_select; - - - $BODY$; - - CREATE OR REPLACE FUNCTION information.queryPeItPreview( - param_pk_project integer, - param_pk_entity integer, - param_pk_ui_context integer, - OUT pk_entity integer, - OUT fk_project integer, - OUT fk_class integer, - OUT entity_label text, - OUT class_label varchar, - OUT entity_type text, - OUT type_label text - ) - RETURNS SETOF record - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - WITH pe_it_label AS ( - select * - from information.queryPeItLabel(param_pk_project,param_pk_entity,param_pk_ui_context) - ), - associated_type AS ( - select ea.pk_entity, ea.fk_range_entity, ea.fk_domain_entity, ea.fk_property, - (select entity_label from information.queryPeItLabel(param_pk_project, ea.fk_range_entity, param_pk_ui_context)) - from information.entity_association as ea - inner join information.entity_version_project_rel as epr on ea.pk_entity = epr.fk_entity AND epr.is_in_project = true - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) - AND ea.fk_domain_entity = param_pk_entity - ) - select pe_it_label.*, associated_type.entity_label as type_label - from pe_it_label - left join associated_type on associated_type.fk_domain_entity = pe_it_label.pk_entity - - $BODY$; - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP FUNCTION information.querypeitpreview(integer, integer, integer); - DROP FUNCTION information.querypeitlabel(integer, integer, integer); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181204090138-inf-vm-data-unit-preview.js b/server/db-migrate/migrations/_migration_archive/20181204090138-inf-vm-data-unit-preview.js deleted file mode 100644 index d0b41e5ab..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181204090138-inf-vm-data-unit-preview.js +++ /dev/null @@ -1,728 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets a class preview (with label) #1 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_class_preview AS - SELECT DISTINCT ON (dfh_pk_class) - CASE - WHEN l.dfh_label IS NOT NULL THEN l.dfh_label::character varying - ELSE cpv.dfh_class_standard_label - END AS class_label, - CASE - WHEN cpv.dfh_fk_system_type = 9 THEN 'teEn'::text - WHEN cpv.dfh_fk_system_type = 8 THEN 'peIt'::text - ELSE NULL::text - END AS entity_type, - c.dfh_pk_class - FROM data_for_history.class c - JOIN data_for_history.class_profile_view cpv ON c.dfh_pk_class = cpv.dfh_fk_class - LEFT JOIN data_for_history.label l ON l.dfh_fk_class = c.dfh_pk_class AND l.com_fk_system_type = 184 - ORDER BY dfh_pk_class, l.dfh_label; -- This will prefer custom labels over dfh_class_standard_label in distinct clause - - ------------------------------------------------------------------------------------------------------------- --- VIEW that gets ordered fields per class (useful to join data related to class instances in right order) #2 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_ordered_fields_per_class AS - SELECT c.pk_entity, - c.ord_num AS field_order, - CASE - WHEN c.property_is_outgoing = true THEN p.dfh_has_domain - WHEN c.property_is_outgoing = false THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END AS fk_class, - c.fk_property, - c.property_is_outgoing, - c.fk_class_field, - f.used_table - FROM commons.ui_context_config c - LEFT JOIN data_for_history.property p ON p.dfh_pk_property = c.fk_property - LEFT JOIN commons.class_field f ON f.pk_entity = c.fk_class_field - WHERE c.fk_ui_context = 45 - ORDER BY ( - CASE - WHEN c.property_is_outgoing = true THEN p.dfh_has_domain - WHEN c.property_is_outgoing = false THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END), c.ord_num; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per teEn in the repo version #3 - -- Attention: This view gets replaced further below, for some "recursive" join ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_repo AS - SELECT - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - r.rank_for_te_ent as rank, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes) as all_strings - - -- teen - from information.v_temporal_entity as teen - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - WHERE ( r.range_max_quantifier = -1 OR r.rank_for_te_ent <= r.range_max_quantifier ) - AND r.is_in_project_count > 0 - ORDER BY field_order, rank_for_te_ent; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per teEn and project #4 - -- Attention: This view gets replaced further below, for some "recursive" join ------------------------------------------------------------------------------------------------------------- - - CREATE VIEW information.v_te_en_strings_per_field_and_project AS - SELECT - epr.fk_project, - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - epr2.ord_num, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes) as all_strings - - -- teen - from information.v_temporal_entity as teen - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = teen.pk_entity AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = epr.fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - ORDER BY field_order; - ------------------------------------------------------------------------------------------------------------- - -- VIEW that creates time span objects per TeEn, project and repo version #5 ------------------------------------------------------------------------------------------------------------- - CREATE OR REPLACE VIEW information.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive as ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.entity_version_project_rel as epr - INNER JOIN information.v_role as r on r.pk_entity = epr.fk_entity - INNER JOIN information.v_time_primitive as tp on tp.pk_entity = r.fk_entity - WHERE - epr.is_in_project = true - - UNION - - SELECT - r.fk_temporal_entity, - r.fk_property, - null::integer as fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role as r - INNER JOIN information.v_time_primitive as tp on tp.pk_entity = r.fk_entity - AND r.rank_for_te_ent = 1 - ) - select - fk_project, - fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN fk_property=71 THEN 'p81' - WHEN fk_property=72 THEN 'p82' - WHEN fk_property=150 THEN 'p81a' - WHEN fk_property=151 THEN 'p81b' - WHEN fk_property=152 THEN 'p82a' - WHEN fk_property=153 THEN 'p82b' - ELSE fk_property::text - END - - , json_build_object('julianDay', julian_day, 'duration', duration, 'calendar', calendar) ) as time_span - FROM role_with_time_primitive - GROUP BY fk_project, fk_temporal_entity; - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that unions TeEn project and repo version and adds time span objects #6 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_te_en_preview as - WITH teen_with_label as ( - select - teen_strings.fk_project, - teen_strings.pk_entity, - teen_strings.fk_class, - string_agg(string_0, ' ') as entity_label, - string_agg(string_1, ' ') as entity_label_2, - string_agg(all_strings, ', ' ORDER BY field_order) || '.' as full_text, - teen_time_span.time_span - from information.v_te_en_strings_per_field_and_project as teen_strings - LEFT JOIN information.v_te_en_time_span_per_project_and_repo as teen_time_span - ON teen_time_span.fk_project = teen_strings.fk_project AND teen_time_span.fk_temporal_entity = pk_entity - Group By teen_strings.fk_project, pk_entity, fk_class, teen_time_span.time_span - UNION - select - null as fk_project, - teen_strings.pk_entity, - teen_strings.fk_class, - string_agg(string_0, ' ') as entity_label, - string_agg(string_1, ' ') as entity_label_2, - string_agg(all_strings, ', ' ORDER BY field_order) || '.' as full_text, - teen_time_span.time_span - from information.v_te_en_strings_per_field_repo as teen_strings - LEFT JOIN information.v_te_en_time_span_per_project_and_repo as teen_time_span - ON teen_time_span.fk_project IS NULL AND teen_time_span.fk_temporal_entity = pk_entity - Group By pk_entity, fk_class, teen_time_span.time_span - ) - SELECT DISTINCT - teen_with_label.fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - time_span - FROM teen_with_label; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per peIt in the repo version #7 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_pe_it_strings_per_field_repo AS - WITH pi_role as ( - SELECT * - FROM information.v_role as r - WHERE ( r.domain_max_quantifier = -1 OR r.rank_for_pe_it <= r.domain_max_quantifier) - AND r.is_in_project_count > 0 - ) - SELECT DISTINCT - peit.pk_entity, - peit.fk_class, - peit_field.fk_property, - peit_field.field_order, - r.fk_entity, - r.fk_temporal_entity, - ROW_NUMBER () OVER ( - PARTITION BY peit.pk_entity - ORDER BY field_order, r.rank_for_pe_it - ) as rank, - r.range_max_quantifier, - CASE - WHEN field_order=0 THEN COALESCE(teen_preview.entity_label, txt_prop.string )-- add text_property here - ELSE null - END as entity_label, - COALESCE(teen_preview.full_text) as all_strings - - -- peit - from information.v_persistent_item as peit - - -- field - INNER JOIN information.v_ordered_fields_per_class peit_field on peit_field.fk_class = peit.fk_class - - -- role - LEFT JOIN pi_role as r - on peit_field.fk_property = r.fk_property - and peit.pk_entity = r.fk_entity - - ----------------------------------------------------------- - -- get the strings of the teen connected to peit via role - - -- temporal_entity - LEFT JOIN information.v_te_en_preview as teen_preview - ON r.fk_temporal_entity = teen_preview.pk_entity - AND teen_preview.fk_project IS NULL - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to peit - -- text_property - ----------------------------------------------------------- - LEFT JOIN - information.v_text_property txt_prop ON txt_prop.fk_concerned_entity = peit.pk_entity - - ORDER BY pk_entity, field_order; - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per PeIt and project #8 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_pe_it_strings_per_field_and_project AS - SELECT DISTINCT epr.fk_project, - peit.pk_entity, - peit.fk_class, - peit_field.fk_property, - peit_field.field_order, - r.fk_entity, - r.fk_temporal_entity, - epr2.ord_num, - ROW_NUMBER () OVER ( - PARTITION BY peit.pk_entity, epr.fk_project - ORDER BY field_order, epr2.ord_num - ) as rank, - CASE - WHEN peit_field.field_order = 0 THEN COALESCE(teen_preview.entity_label, txt_prop.string) - ELSE NULL::text - END AS entity_label, - COALESCE(teen_preview.full_text, txt_prop.string) AS all_strings - -- peit - FROM information.v_persistent_item peit - JOIN information.entity_version_project_rel epr ON epr.fk_entity = peit.pk_entity - - -- field - JOIN information.v_ordered_fields_per_class peit_field ON peit_field.fk_class = peit.fk_class - -- role - LEFT JOIN information.v_role r ON peit_field.fk_property = r.fk_property AND peit.pk_entity = r.fk_entity - LEFT JOIN information.entity_version_project_rel epr2 ON epr2.fk_entity = r.pk_entity AND epr2.fk_project = epr.fk_project - - ----------------------------------------------------------- - -- get the strings of the teen connected to peit via role - -- temporal_entity - LEFT JOIN information.v_te_en_preview teen_preview ON r.fk_temporal_entity = teen_preview.pk_entity AND teen_preview.fk_project = epr.fk_project - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to peit - -- text_property - LEFT JOIN ( - SELECT * FROM information.v_text_property as t - LEFT JOIN information.entity_version_project_rel epr3 ON epr3.fk_entity = t.pk_entity - ) as txt_prop - ON txt_prop.fk_concerned_entity = peit.pk_entity - AND txt_prop.fk_project = epr.fk_project - AND txt_prop.fk_class_field = peit_field.fk_class_field - ----------------------------------------------------------- - ORDER BY fk_project, field_order, ord_num; - - - - ------------------------------------------------------------------------------------------------------------ - -- VIEW that unions PeIt project and repo version #9 - ------------------------------------------------------------------------------------------------------------ - - CREATE OR REPLACE VIEW information.v_pe_it_preview as - WITH peit_with_label as ( - SELECT - fk_project, - pk_entity, - fk_class, - array_to_string((array_agg(entity_label order by rank))[1:1], '; ') as entity_label, - string_agg(all_strings, ' ') as full_text - from information.v_pe_it_strings_per_field_and_project as strings - WHERE (entity_label is not null OR strings.all_strings is not null) - Group By fk_project, pk_entity, fk_class - - UNION - - SELECT - null::integer as fk_project, - pk_entity, - fk_class, - array_to_string((array_agg(entity_label order by rank))[1:1], '; ') as entity_label, - string_agg(all_strings, ' ') as full_text - from information.v_pe_it_strings_per_field_repo as strings - WHERE (entity_label is not null OR strings.all_strings is not null) - Group By fk_project, pk_entity, fk_class - ) - SELECT DISTINCT - peit_with_label.fk_project, - pk_entity, - fk_class, - entity_label, - full_text - FROM peit_with_label - ORDER BY fk_project; - - - - - ------------------------------------------------------------------------------------------------------------ - -- MATERIALIZED VIEW for data_unit preview #10 - ------------------------------------------------------------------------------------------------------------ - - CREATE MATERIALIZED VIEW information.vm_data_unit_preview as - WITH type_info_per_project AS ( - select distinct ea.fk_domain_entity, type_preview.fk_project, type_preview.entity_label as type_label, type_preview.pk_entity as pk_type - from information.entity_association as ea - inner join information.entity_version_project_rel as epr on ea.pk_entity = epr.fk_entity AND epr.is_in_project = true - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - inner join information.v_pe_it_preview as type_preview on ea.fk_range_entity = type_preview.pk_entity and epr.fk_project = type_preview.fk_project - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) - ), - type_info_per_repo AS ( - select distinct ea.fk_domain_entity, type_preview.entity_label as type_label, ea.rank_for_domain, type_preview.pk_entity as pk_type - from information.v_entity_association as ea - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - inner join information.v_pe_it_preview as type_preview on ea.fk_range_entity = type_preview.pk_entity - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) AND ea.rank_for_domain = 1 - ), - data_unit as ( - select - fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - null::jsonb as time_span - from information.v_pe_it_preview - UNION - select - fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - time_span - from information.v_te_en_preview - ) - select - data_unit.fk_project, - data_unit.pk_entity, - data_unit.fk_class, - data_unit.entity_label, - class_info.class_label, - class_info.entity_type, - COALESCE(type_info_per_project.type_label, type_info_per_repo.type_label) as type_label, - COALESCE(type_info_per_project.pk_type, type_info_per_repo.pk_type) as pk_type, - data_unit.full_text as full_text, - setweight(to_tsvector(coalesce(data_unit.entity_label,'')), 'A') || - setweight(to_tsvector(coalesce(type_info_per_project.type_label, type_info_per_repo.type_label, class_info.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(data_unit.full_text,'')), 'C') - as ts_vector, - time_span - from data_unit - LEFT JOIN type_info_per_project - on type_info_per_project.fk_domain_entity = data_unit.pk_entity - and data_unit.fk_project = type_info_per_project.fk_project - LEFT JOIN type_info_per_repo - on type_info_per_repo.fk_domain_entity = data_unit.pk_entity - and data_unit.fk_project is null - - INNER JOIN information.v_class_preview as class_info on class_info.dfh_pk_class = data_unit.fk_class; - - CREATE UNIQUE INDEX vm_data_unit_preview_unique - ON information.vm_data_unit_preview (pk_entity, fk_project); - - - ------------------------------------------------------------------------------------------------------------ - -- REPLACE VIEW from above, that gets all the labels/strings per teEn and project #11 - -- now with a join to the materialized view in order to add peIt labels to the teEn - ------------------------------------------------------------------------------------------------------------ - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_and_project AS - SELECT - epr.fk_project, - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - epr2.ord_num, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes, peit.entity_label) as all_strings - - -- teen - from information.v_temporal_entity as teen - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = teen.pk_entity AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = epr.fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - LEFT JOIN information.vm_data_unit_preview as peit - ON r.fk_entity = peit.pk_entity AND peit.fk_project = epr.fk_project - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - ORDER BY field_order; - - - - - - ------------------------------------------------------------------------------------------------------------ - -- REPLACE VIEW from above, that gets all the labels/strings of repo #12 - -- now with a join to the materialized view in order to add peIt labels to the teEn - ------------------------------------------------------------------------------------------------------------ - - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_repo AS - SELECT - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - r.rank_for_te_ent as rank, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes, peit.entity_label) as all_strings - - -- teen - from information.v_temporal_entity as teen - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - LEFT JOIN information.vm_data_unit_preview as peit - ON r.fk_entity = peit.pk_entity AND peit.fk_project IS NULL - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - WHERE ( r.range_max_quantifier = -1 OR r.rank_for_te_ent <= r.range_max_quantifier ) - AND r.is_in_project_count > 0 - ORDER BY field_order, rank_for_te_ent; - - - ------------------------------------------------------------------------------------------------------------ - -- TABLE that stores the latest refresh date of information.vm_data_unit_preview - ------------------------------------------------------------------------------------------------------------ - CREATE TABLE commons.vm_refresh_date ( - information_vm_data_unit_preview timestamp with time zone - ); - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION that refreshes information.vm_data_unit_preview, if the latest modification of - -- information.entity_version_project_rel is newer than the latest refresh stored in commons.vm_refresh_date - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION information.refresh_vm_data_unit_preview() - RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - refresh_needed boolean; - refreshed boolean; - BEGIN - - select into refresh_needed ( - ( - select information_vm_data_unit_preview from commons.vm_refresh_date - order by information_vm_data_unit_preview desc - limit 1 - ) - < - ( - select tmsp_last_modification from information.entity_version_project_rel - order by tmsp_last_modification desc - limit 1 - ) - ); - - IF (refresh_needed = true OR refresh_needed IS NULL) THEN - REFRESH MATERIALIZED VIEW CONCURRENTLY information.vm_data_unit_preview; - - INSERT INTO commons.vm_refresh_date (information_vm_data_unit_preview) - VALUES (now()); - - refreshed = true; - ELSE - refreshed = false; - END IF; - - RETURN refreshed; - END $$; - - - - - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP FUNCTION information.refresh_vm_data_unit_preview(); - - DROP TABLE commons.vm_refresh_date; - - DROP MATERIALIZED VIEW IF EXISTS information.vm_data_unit_preview CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_preview CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_preview CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_strings_per_field_and_project CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_strings_per_field_repo CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_strings_per_field_and_project CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_strings_per_field_repo CASCADE; - - DROP VIEW IF EXISTS information.v_ordered_fields_per_class CASCADE; - - DROP VIEW IF EXISTS information.v_class_preview; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181206163400-com-function-for-new-tables.js b/server/db-migrate/migrations/_migration_archive/20181206163400-com-function-for-new-tables.js deleted file mode 100644 index cfb7c3bb1..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181206163400-com-function-for-new-tables.js +++ /dev/null @@ -1,125 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - -- This Function helps to initialize tables that inherit from an entity table: - -- # it adds a unique constraint to pk_entity - -- # it adds a version history table - -- # it adds all triggers for timestamps - - CREATE OR REPLACE FUNCTION commons.init_entity_child_table(schema_and_table_name varchar) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 - VOLATILE - AS $BODY$ - DECLARE - unique_constraint_name varchar; - BEGIN - - -- Create the name of the unique constraint that will be applied to the new table's pk_entity - - SELECT INTO unique_constraint_name replace( schema_and_table_name , '.' , '_' )_pk_entity_unique; - - -- Do the Magic: - - EXECUTE format(' - - -- Add unique constraint to pk_entity of the new table, so that it can be referenced by foreign keys - - ALTER TABLE %1$s ADD CONSTRAINT %2$s_pk_entity_unique UNIQUE (pk_entity); - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name, - unique_constraint_name - - ); - - END - $BODY$; - - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP FUNCTION commons.init_entity_child_table(character varying); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181206163401-sou-schema.js b/server/db-migrate/migrations/_migration_archive/20181206163401-sou-schema.js deleted file mode 100644 index 150ad3b77..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181206163401-sou-schema.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - CREATE SCHEMA IF NOT EXISTS sources; - - ------------------------------------------------------------------------------------------------------------ - -- TABLE entity - ------------------------------------------------------------------------------------------------------------ - - CREATE TABLE sources.entity - ( - pk_entity serial PRIMARY KEY, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) - ); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP TABLE IF EXISTS sources.entity; - DROP SCHEMA IF EXISTS sources; - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181206163402-sou-initial-migration.js b/server/db-migrate/migrations/_migration_archive/20181206163402-sou-initial-migration.js deleted file mode 100644 index 737721d8c..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181206163402-sou-initial-migration.js +++ /dev/null @@ -1,222 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.row (including *_vt) #1 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.row - ( - fk_digital_object INTEGER NOT NULL REFERENCES information.digital_object (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.row'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.column (including *_vt) #2 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.column - ( - fk_digital_object INTEGER NOT NULL REFERENCES information.digital_object (pk_entity), - fk_data_type INTEGER NOT NULL REFERENCES commons.system_type (pk_entity), - fk_metad_data INTEGER NOT NULL REFERENCES commons.system_type (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.column'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.cell (including *_vt) #3 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.cell - ( - fk_column INTEGER NOT NULL REFERENCES sources.column (pk_entity), - fk_row INTEGER NOT NULL REFERENCES sources.row (pk_entity), - value VARCHAR - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.cell'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.factoid_class_dataset_rel (including *_vt) #4 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.factoid_class_dataset_rel - ( - fk_digital_object INTEGER NOT NULL REFERENCES information.digital_object (pk_entity), - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.factoid_class_dataset_rel'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.value_association_columns_rel (including *_vt) #5 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.value_association_columns_rel - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_column INTEGER NOT NULL REFERENCES sources.column (pk_entity), - fk_range_column INTEGER NOT NULL REFERENCES sources.column (pk_entity), - fk_factoid_class_dataset_rel INTEGER NOT NULL REFERENCES sources.factoid_class_dataset_rel (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.value_association_columns_rel'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.class_column_rel (including *_vt) #6 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.class_column_rel - ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class), - fk_column INTEGER NOT NULL REFERENCES sources.column (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.class_column_rel'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.factoid_property_column_rel (including *_vt) #7 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.factoid_property_column_rel - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_column INTEGER NOT NULL REFERENCES sources.column (pk_entity), - fk_factoid_class_dataset_rel INTEGER NOT NULL REFERENCES sources.factoid_class_dataset_rel (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.factoid_property_column_rel'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.factoid (including *_vt) #8 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.factoid - ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.factoid'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.factoid_role (including *_vt) #9 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.factoid_role - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_factoid INTEGER NOT NULL REFERENCES sources.factoid (pk_entity), - fk_range_cell INTEGER NOT NULL REFERENCES sources.cell (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.factoid_role'); - - ------------------------------------------------------------------------------------------------------------- --- TABLE sources.values_association (including *_vt) #10 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE sources.values_association - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_cell INTEGER NOT NULL REFERENCES sources.cell (pk_entity), - fk_range_cell INTEGER NOT NULL REFERENCES sources.cell (pk_entity) - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('sources.values_association'); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - -- #10 - DROP TABLE IF EXISTS sources.values_association; - DROP TABLE IF EXISTS sources.values_association_vt; - - -- #9 - DROP TABLE IF EXISTS sources.factoid_role; - DROP TABLE IF EXISTS sources.factoid_role_vt; - - -- #8 - DROP TABLE IF EXISTS sources.factoid; - DROP TABLE IF EXISTS sources.factoid_vt; - - -- #7 - DROP TABLE IF EXISTS sources.factoid_property_column_rel; - DROP TABLE IF EXISTS sources.factoid_property_column_rel_vt; - - -- #6 - DROP TABLE IF EXISTS sources.class_column_rel; - DROP TABLE IF EXISTS sources.class_column_rel_vt; - - -- #5 - DROP TABLE IF EXISTS sources.value_association_columns_rel; - DROP TABLE IF EXISTS sources.value_association_columns_rel_vt; - - -- #4 - DROP TABLE IF EXISTS sources.factoid_class_dataset_rel; - DROP TABLE IF EXISTS sources.factoid_class_dataset_rel_vt; - - -- #3 - DROP TABLE IF EXISTS sources.cell; - DROP TABLE IF EXISTS sources.cell_vt; - - -- #2 - DROP TABLE IF EXISTS sources.column; - DROP TABLE IF EXISTS sources.column_vt; - - -- #1 - DROP TABLE IF EXISTS sources.row; - DROP TABLE IF EXISTS sources.row_vt; - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20181207130742-com-t-assertion.js b/server/db-migrate/migrations/_migration_archive/20181207130742-com-t-assertion.js deleted file mode 100644 index 80c21ac74..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181207130742-com-t-assertion.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` ------------------------------------------------------------------------------------------------------------- --- TABLE commons.assertion (including *_vt) #1 ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE commons.assertion - ( - fk_is_about_role INTEGER NOT NULL REFERENCES information.role (pk_entity), - fk_is_about_entity_association INTEGER NOT NULL REFERENCES information.entity_association (pk_entity), - - fk_is_based_on_role INTEGER NOT NULL REFERENCES information.role (pk_entity), - fk_is_based_on_entity_association INTEGER NOT NULL REFERENCES information.entity_association (pk_entity), - fk_is_based_on_persistent_item INTEGER NOT NULL REFERENCES information.persistent_item (pk_entity), - - fk_is_based_on_factoid_role INTEGER NOT NULL REFERENCES sources.factoid_role (pk_entity), - fk_is_based_on_cell INTEGER NOT NULL REFERENCES sources.cell (pk_entity), - - fk_assertion_method_type INTEGER NOT NULL REFERENCES information.persistent_item (pk_entity), - - source_reliability INTEGER, - value INTEGER - ) - INHERITS (sources.entity); - - SELECT commons.init_entity_child_table('commons.assertion'); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - - -- #1 - DROP TABLE IF EXISTS commons.assertion; - DROP TABLE IF EXISTS commons.assertion_vt; - - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20181221140510-inf-add-te-en-find-or-create-function.js b/server/db-migrate/migrations/_migration_archive/20181221140510-inf-add-te-en-find-or-create-function.js deleted file mode 100644 index 38f7bf75e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20181221140510-inf-add-te-en-find-or-create-function.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - const sql = ` - - ------------------------------------------------------------------------------------------------------------ - -- Function to check if a teEn with identity defining roles exists - ------------------------------------------------------------------------------------------------------------ - - --DROP FUNCTION information.temporal_entity_find_or_create(integer, jsonb); - CREATE OR REPLACE FUNCTION information.temporal_entity_find_or_create( - param_fk_class integer, - param_roles jsonb) - RETURNS information.temporal_entity - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - - DECLARE - resulting_row information.temporal_entity; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - WITH existing_te_ens as ( - select fk_temporal_entity, array_agg(jsonb_build_object('fk_property',fk_property, 'fk_entity', fk_entity)) identity_defining_roles - from information.role as r - join data_for_history.property as p on p.dfh_pk_property = r.fk_property AND p.identity_defining = true - group by fk_temporal_entity - ), - new_te_en as ( - SELECT array_agg(a.elements::jsonb) roles - FROM - (select 1 x, jsonb_array_elements_text(param_roles) elements) as a - Group by a.x - ) - select teEn.* - from INTO resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - join new_te_en on new_te_en.roles @> existing_te_ens.identity_defining_roles - join information.temporal_entity as teEn on teEn.pk_entity = existing_te_ens.fk_temporal_entity - where teEn.fk_class = param_fk_class; - - - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.temporal_entity ( - fk_class - ) - VALUES ( - param_fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row -- ; - END IF; - - - RETURN resulting_row; - END; - - $BODY$; - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - const sql = ` - DROP FUNCTION information.temporal_entity_find_or_create(integer, jsonb); - ` - db.runSql(sql, callback) -}; - - -exports._meta = { - "version": 1 -}; - - - diff --git a/server/db-migrate/migrations/_migration_archive/20190110170603-create-warehouse-schema.js b/server/db-migrate/migrations/_migration_archive/20190110170603-create-warehouse-schema.js deleted file mode 100644 index aca1ddd40..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190110170603-create-warehouse-schema.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE SCHEMA IF NOT EXISTS warehouse; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - DROP SCHEMA IF EXISTS warehouse; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190110170708-war-class-preview.js b/server/db-migrate/migrations/_migration_archive/20190110170708-war-class-preview.js deleted file mode 100644 index 93f723d37..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190110170708-war-class-preview.js +++ /dev/null @@ -1,170 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - ------------------------------------------------------------------------------------------------------------ - -- TABLE that stores class previews (with label) #1 - ------------------------------------------------------------------------------------------------------------ - - CREATE TABLE warehouse.class_preview AS SELECT * FROM information.v_class_preview; - ALTER TABLE warehouse.class_preview ADD CONSTRAINT dfh_pk_class_unique UNIQUE (dfh_pk_class); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION update_class_preview__on_label_upsert #2 - ------------------------------------------------------------------------------------------------------------ - CREATE FUNCTION warehouse.update_class_preview__on_label_upsert() - RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$ BEGIN - - - -- If it is a geovistory class label - IF ( NEW.dfh_fk_class IS NOT NULL AND NEW.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = NEW.dfh_label - WHERE dfh_pk_class = NEW.dfh_fk_class; - - END IF; - - RETURN NEW; - - END; - $BODY$; - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION update_class_preview__on_label_delete #3 - ------------------------------------------------------------------------------------------------------------ - CREATE FUNCTION warehouse.update_class_preview__on_label_delete() - RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$ BEGIN - - -- If it is a geovistory class label - IF (OLD.dfh_fk_class IS NOT NULL AND OLD.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = ( - SELECT dfh_standard_label - FROM data_for_history.class - WHERE dfh_pk_class = OLD.dfh_fk_class - ) - WHERE dfh_pk_class = OLD.dfh_fk_class; - - END IF; - - RETURN OLD; - - END; - $BODY$; - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_insert_or_update #4 - ------------------------------------------------------------------------------------------------------------ - - CREATE TRIGGER after_insert_or_update - AFTER INSERT OR UPDATE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_label_upsert(); - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_delete #5 - ------------------------------------------------------------------------------------------------------------ - - CREATE TRIGGER after_delete - AFTER DELETE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_label_delete(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER AND TRIGGER FUNCTION update_class_preview__on_class_profile_view_upsert #6 - ------------------------------------------------------------------------------------------------------------ - CREATE FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert() - RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$ - DECLARE - label text; - entity_type text; - BEGIN - - INSERT INTO warehouse.class_preview (dfh_pk_class, class_label, entity_type) - SELECT v.dfh_pk_class, v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ON CONFLICT (dfh_pk_class) - DO - UPDATE - SET (class_label, entity_type) = ( - SELECT v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ); - - RETURN NEW; - - END; - $BODY$; - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_insert_or_update #7 - ------------------------------------------------------------------------------------------------------------ - - CREATE TRIGGER after_insert_or_update - AFTER INSERT OR UPDATE - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_class_profile_view_upsert(); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - -- 7 - DROP TRIGGER after_insert_or_update ON data_for_history.class_profile_view; - - -- 6 - DROP FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert(); - - -- 5 - DROP TRIGGER after_delete ON data_for_history.label; - - -- 4 - DROP TRIGGER after_insert_or_update ON data_for_history.label; - - -- 3 - DROP FUNCTION warehouse.update_class_preview__on_label_delete(); - - -- 2 - DROP FUNCTION warehouse.update_class_preview__on_label_upsert(); - - -- 1 - DROP TABLE warehouse.class_preview;; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190111125322-war-entity-preview-views.js b/server/db-migrate/migrations/_migration_archive/20190111125322-war-entity-preview-views.js deleted file mode 100644 index 9cf011bb5..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190111125322-war-entity-preview-views.js +++ /dev/null @@ -1,551 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - ------------------------------------------------------------------------------------------------------------ - -- REPLACE VEIW v_text_property (add is_in_project_count) - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.text_property, - text_property.fk_concerned_entity, - text_property.text_property_quill_doc, - text_property.fk_language, - text_property.fk_class_field, - information.text_property_to_string(text_property.text_property_quill_doc) AS string, - count(epr.fk_project) is_in_project_count - FROM information.text_property - LEFT JOIN information.entity_version_project_rel as epr - on epr.fk_entity = text_property.pk_entity - and epr.is_in_project = true - GROUP BY ( - text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.text_property, - text_property.fk_concerned_entity, - text_property.text_property_quill_doc, - text_property.fk_language, - text_property.fk_class_field - ); - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_text_properties_per_project_and_repo # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS ( - -- select all text_property per project - SELECT DISTINCT t.*, epr.fk_project, coalesce(epr.fk_project,0) - FROM information.v_text_property t - JOIN information.entity_version_project_rel as epr - on epr.fk_entity = t.pk_entity - and epr.is_in_project = true - - UNION - -- select all roles per repo - SELECT DISTINCT t.*, NULL::INT, 0 - FROM information.v_text_property t - WHERE t.is_in_project_count > 0 - ); - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_roles_per_project_and_repo # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS ( - -- select all roles per project - SELECT DISTINCT r.fk_entity, r.fk_temporal_entity, r.fk_property, epr.fk_project, epr.ord_num rank_for_pe_it, epr.ord_num rank_for_te_ent, coalesce(epr.fk_project,0) project - FROM information.v_role r - LEFT JOIN information.entity_version_project_rel as epr - on epr.fk_entity = r.pk_entity - and epr.is_in_project = true - - UNION - -- select all roles per repo - SELECT DISTINCT r.fk_entity, r.fk_temporal_entity, r.fk_property, NULL::INT, rank_for_pe_it, rank_for_te_ent, 0 - FROM information.v_role r - WHERE r.is_in_project_count > 0 - ); - - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_entities # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_entities AS ( - -- select all TeEn and PeIt per project - SELECT DISTINCT - e.pk_entity, - epr.fk_project, - epr.fk_project project, - CASE WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class ELSE te.fk_class END AS fk_class, - e.table_name, - CASE WHEN (e.table_name = 'persistent_item') THEN 'peIt' WHEN (e.table_name = 'temporal_entity') THEN 'teEn' END as entity_type - FROM information.entity_version_project_rel epr - JOIN information.entity e on e.pk_entity = epr.fk_entity - LEFT JOIN information.persistent_item pi on e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te on e.pk_entity = te.pk_entity - WHERE epr.is_in_project = true - AND e.table_name IN ('temporal_entity', 'persistent_item') - UNION - -- select all TeEn and PeIt per repo - SELECT DISTINCT - e.pk_entity, - NULL::integer as fk_project, - 0, - CASE WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class ELSE te.fk_class END AS fk_class, - e.table_name, - CASE WHEN (e.table_name = 'persistent_item') THEN 'peIt' WHEN (e.table_name = 'temporal_entity') THEN 'teEn' END as entity_type - FROM information.entity e - LEFT JOIN information.persistent_item pi on e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te on e.pk_entity = te.pk_entity - WHERE e.table_name IN ('temporal_entity', 'persistent_item') - - ORDER BY pk_entity - --LIMIT 10 - ); - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_own_entity_label # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ), - first_field AS ( - SELECT e.*, f.fk_property, f.fk_class_field, f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE field_order = 0 - ), - string_from_first_role AS ( - SELECT * FROM ( - SELECT first_field.*, COALESCE(appe.string, lang.notes) as string_from_first_role, - ROW_NUMBER () OVER ( - PARTITION BY first_field.pk_entity, first_field.project - ORDER BY - r.rank_for_pe_it - ) as role_number - FROM first_field - LEFT JOIN warehouse.v_roles_per_project_and_repo as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - and r.fk_project IS NOT DISTINCT FROM first_field.fk_project - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ) AS all_roles - where role_number = 1 - - ), - string_from_first_text_prop AS ( - SELECT * FROM ( - SELECT coalesce(string_from_first_role.fk_project, 0) as p, string_from_first_role.*, txtp.string as string_from_first_text_prop, - ROW_NUMBER () OVER ( - PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project - ORDER BY txtp.tmsp_creation DESC - ) as txtp_number - FROM string_from_first_role - LEFT JOIN warehouse.v_text_properties_per_project_and_repo as txtp - ON string_from_first_role.fk_class_field IS NOT DISTINCT FROM txtp.fk_class_field - AND txtp.fk_concerned_entity = string_from_first_role.pk_entity - AND txtp.fk_project IS NOT DISTINCT FROM string_from_first_role.fk_project - ) as all_txtp - where txtp_number = 1 - ) - SELECT pk_entity, fk_project, COALESCE(string_from_first_role, string_from_first_text_prop) entity_label, project - FROM string_from_first_text_prop - ); - - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_own_full_text # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_own_full_text AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ), - field AS ( - SELECT e.*, f.fk_property, f.fk_class_field, f.fk_class, field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE field_order IS NOT NULL - ), - string_from_role AS ( - SELECT * FROM ( - SELECT field.*, - COALESCE(appe.string, lang.notes) as string, - ROW_NUMBER () OVER ( - PARTITION BY field.pk_entity, field.project - ORDER BY - r.rank_for_pe_it - ) as role_number - FROM field - LEFT JOIN warehouse.v_roles_per_project_and_repo as r - on field.fk_property = r.fk_property - and field.pk_entity = r.fk_temporal_entity - and r.fk_project IS NOT DISTINCT FROM field.fk_project - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ) AS all_roles - - ), - string_from_text_prop AS ( - SELECT * FROM ( - SELECT - field.*, - regexp_replace(txtp.string, E'[\\n\\r]+', '', 'g' ) as string, - ROW_NUMBER () OVER ( - PARTITION BY field.pk_entity, field.project - ORDER BY txtp.tmsp_creation DESC - ) as txtp_number - FROM field - LEFT JOIN warehouse.v_text_properties_per_project_and_repo as txtp - ON field.fk_class_field IS NOT DISTINCT FROM txtp.fk_class_field - AND txtp.fk_concerned_entity = field.pk_entity - AND txtp.fk_project IS NOT DISTINCT FROM field.fk_project - ) as all_txtp - ), - all_stings AS ( - SELECT * - FROM string_from_text_prop - UNION - SELECT * - FROM string_from_role - ), - aggregated AS ( - SELECT pk_entity, fk_project, project, string_agg(string, ', ' ORDER BY field_order) as own_full_text - FROM all_stings - GROUP BY pk_entity, fk_project, project - ) - SELECT * - FROM aggregated - ); - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_fk_entity_label # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ) - SELECT entities.*, a.fk_entity_label - FROM entities - LEFT JOIN - ( - ( - SELECT r.fk_entity as pk_entity, fk_temporal_entity as fk_entity_label, r.fk_project, - ROW_NUMBER () OVER ( - PARTITION BY r.fk_entity, coalesce(r.fk_project, 0) - ORDER BY - r.rank_for_pe_it - ) as rank - FROM warehouse.v_roles_per_project_and_repo r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - ) - UNION - ( - SELECT r.fk_temporal_entity as pk_entity, r.fk_entity as fk_entity_label, r.fk_project, - ROW_NUMBER () OVER ( - PARTITION BY r.fk_temporal_entity, coalesce(r.fk_project, 0) - ORDER BY - r.rank_for_te_ent - ) as rank - FROM warehouse.v_roles_per_project_and_repo r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - ) - ) AS a - ON a.pk_entity = entities.pk_entity AND a.fk_project IS NOT DISTINCT FROM entities.fk_project - WHERE rank = 1 - ); - - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_entity_association_per_project_and_repo # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS ( - -- select all entity_association per project - SELECT DISTINCT ea.pk_entity, ea.fk_range_entity, ea.fk_domain_entity, ea.fk_property, epr.fk_project, epr.ord_num rank_for_domain, epr.ord_num rank_for_range, coalesce(epr.fk_project,0) project - FROM information.v_entity_association ea - LEFT JOIN information.entity_version_project_rel as epr - on epr.fk_entity = ea.pk_entity - and epr.is_in_project = true - - UNION - -- select all entity_association per repo - SELECT DISTINCT ea.pk_entity, ea.fk_range_entity, ea.fk_domain_entity, ea.fk_property, NULL::INT, rank_for_domain, rank_for_range, 0 - FROM information.v_entity_association ea - WHERE ea.is_in_project_count > 0 - ); - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_fk_type # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_fk_type AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ) - SELECT DISTINCT ea.fk_domain_entity pk_entity, ea.fk_project, ea.project, ea.fk_range_entity fk_type - FROM warehouse.v_entity_association_per_project_and_repo ea - JOIN information.entity_version_project_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.rank_for_domain = 1 - ); - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_related_full_texts # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ), - all_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text--, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - -- LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.fk_project IS NULL - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text--, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - -- LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.fk_project IS NULL - ), - agg AS( - select pk_entity, project, fk_project, jsonb_object_agg(all_dependencies.pk_related_full_text::text, '' - -- all_dependencies.own_full_text - ) related_full_texts - FROM all_dependencies - group by pk_entity, project, fk_project - ) - select pk_entity, project, fk_project, related_full_texts - FROM agg - ); - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_entity_preview_non_recursive # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS ( - WITH entities AS ( - SELECT * FROM warehouse.v_entities - ), - add_class_label AS ( - SELECT entities.*, c.class_label - FROM entities - JOIN warehouse.class_preview c - ON c.dfh_pk_class = entities.fk_class - ), - add_own_entity_label AS ( - -- this only adds an entity label if the label is the entities own label (not recursive) - SELECT a.*, l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l - ON a.pk_entity = l.pk_entity - AND a.project = l.project - ), - add_time_span AS ( - SELECT a.*, t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t - ON a.pk_entity = t.fk_temporal_entity - AND a.fk_project IS NOT DISTINCT FROM t.fk_project - ), - add_own_full_text AS ( - SELECT a.*, t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t - ON a.pk_entity = t.pk_entity - AND a.project = t.project - ), - add_fk_entity_label AS ( - SELECT a.*, t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t - ON a.pk_entity = t.pk_entity - AND a.fk_project IS NOT DISTINCT FROM t.fk_project - ), - add_fk_type AS ( - SELECT a.*, t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t - ON a.pk_entity = t.pk_entity - AND a.project = t.project - ) - SELECT * - FROM add_fk_type - ); - - - - ------------------------------------------------------------------------------------------------------------ - -- VEIW v_entity_preview # - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE VIEW warehouse.v_entity_preview AS ( - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.v_entity_preview_non_recursive - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t1.entity_label,t2.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ) - SELECT * FROM add_ts_vector - ); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - - DROP VIEW IF EXISTS warehouse.v_entity_preview; - DROP VIEW IF EXISTS warehouse.v_entity_preview_non_recursive; - DROP VIEW IF EXISTS warehouse.v_fk_type; - DROP VIEW IF EXISTS warehouse.v_entity_association_per_project_and_repo; - DROP VIEW IF EXISTS warehouse.v_related_full_texts; - DROP VIEW IF EXISTS warehouse.v_fk_entity_label; - DROP VIEW IF EXISTS warehouse.v_own_full_text; - DROP VIEW IF EXISTS warehouse.v_own_entity_label; - DROP VIEW IF EXISTS warehouse.v_entities; - DROP VIEW IF EXISTS warehouse.v_roles_per_project_and_repo; - DROP VIEW IF EXISTS warehouse.v_text_properties_per_project_and_repo; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190111125323-war-entity-preview-table.js b/server/db-migrate/migrations/_migration_archive/20190111125323-war-entity-preview-table.js deleted file mode 100644 index ed30fed7b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190111125323-war-entity-preview-table.js +++ /dev/null @@ -1,46 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - ------------------------------------------------------------------------------------------------------------ - -- TABLE that stores entity previews #1 - ------------------------------------------------------------------------------------------------------------ - CREATE TABLE warehouse.entity_preview AS SELECT * FROM warehouse.v_entity_preview; - ALTER TABLE warehouse.entity_preview ADD CONSTRAINT entity_preview_unique UNIQUE (pk_entity, project); - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - -- 1 - DROP TABLE warehouse.entity_preview CASCADE; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190111125324-war-entity-preview-functions.js b/server/db-migrate/migrations/_migration_archive/20190111125324-war-entity-preview-functions.js deleted file mode 100644 index fe279c42f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190111125324-war-entity-preview-functions.js +++ /dev/null @@ -1,1297 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__create_related_full_texts #1 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_related_full_texts( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_related_full_texts jsonb; - param_project INT; - BEGIN - RAISE INFO 'entity_preview__create_related_full_texts pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - param_project = coalesce(param_fk_project, 0); - - ---------------------- REPO AND PROJECT VERSIONS ---------------------- - WITH full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_temporal_entity = param_pk_entity - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_entity = param_pk_entity - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ) - select related_full_texts INTO new_related_full_texts - FROM aggregated_related_full_texts; - - RAISE INFO 'new_related_full_texts: %', new_related_full_texts; - - ----- Insert or update the entity_preview - - PERFORM pk_entity - FROM warehouse.entity_preview pre - WHERE pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project; - - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, related_full_texts) - VALUES (param_pk_entity, param_fk_project, param_project, new_related_full_texts); - - RAISE INFO 'inserted new_related_full_texts: %', new_related_full_texts; - - ELSE - - UPDATE warehouse.entity_preview pre - SET related_full_texts = new_related_full_texts - where pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project - AND ( - pre.related_full_texts @> new_related_full_texts - AND - pre.related_full_texts <@ new_related_full_texts - ) IS DISTINCT FROM true; - - END IF; - - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__create_fk_entity_label #2 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS JSONB AS $$ - DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, r.rank_for_pe_it as rank - FROM information.v_role r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - UNION - ( - SELECT r.fk_entity as pk, r.rank_for_te_ent as rank - FROM information.v_role r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - ) AS a - ORDER BY rank - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_object: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, epr.ord_num - FROM information.role r - JOIN information.entity_version_project_rel epr ON epr.fk_entity = r.pk_entity - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - - UNION - - ( - SELECT r.fk_entity as pk, epr.ord_num - FROM information.role r - JOIN information.entity_version_project_rel epr ON epr.fk_entity = r.pk_entity - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - ) AS a - ORDER BY ord_num - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', old_fk_entity_label, - 'new_val', new_fk_entity_label) - INTO result_info; - - RETURN result_info; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__create_fk_type #3 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS JSONB AS $$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - has_type_properties INT[] = ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_range_entity INTO new_fk_type - FROM information.v_entity_association ea - JOIN information.entity_version_project_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.fk_domain_entity = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_range_entity INTO new_fk_type - FROM information.entity_association ea - JOIN information.entity_version_project_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (has_type_properties) - AND ea.fk_domain_entity = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $$ LANGUAGE plpgsql; - - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_own_entity_label #4 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; - BEGIN - - - - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT ( - SELECT fk_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1 - ) IS NULL - ) THEN - - IF param_fk_project IS NULL THEN - - ---------------------- REPO VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - and r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = param_fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - ORDER BY epr2.ord_num - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - - - - END IF; - - - - - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - - - ----- Insert or update column own_entity_label of table entity_preview - - SELECT entity_label INTO old_own_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - - ELSIF (SELECT (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET entity_label = new_own_entity_label - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; - - END IF; - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_own_full_text #5 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity AND r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY r.rank_for_te_ent - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\\n\\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - -- TODO: Check if we need to exclude textproperties that are in 0 projects$ - -- TODO: Check if we need to order textproperties - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - LEFT JOIN information.entity_version_project_rel as epr ON epr.fk_entity = r.pk_entity - AND epr.fk_project = param_fk_project AND epr.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY epr.ord_num - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\\n\\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity = txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - END IF; - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_dependent_entity_labels #6 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_entity_labels( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_entity_label TEXT; - dependent_entity_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_entity_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_entity_label - SELECT entity_label INTO new_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_entity_label: %', new_entity_label; - - -- update all dependent entity_previews with new_entity_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET entity_label = new_entity_label - WHERE fk_entity_label = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND entity_label IS DISTINCT FROM new_entity_label; - - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_dependent_related_full_texts #7 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_related_full_texts( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_related_full_texts of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_own_full_text - SELECT own_full_text INTO new_own_full_text - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - - -- update all related_full_texts with new_own_full_text (if DISTINCT) - UPDATE warehouse.entity_preview - SET related_full_texts = ( - SELECT jsonb_set( - related_full_texts, - array_agg(param_pk_entity::text), - to_jsonb(new_own_full_text) - ) - ) - WHERE related_full_texts ? param_pk_entity::text - AND related_full_texts->>param_pk_entity::text IS DISTINCT FROM new_own_full_text - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_dependent_class_labels #8 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_class_labels( - pk_class integer, - param_class_label TEXT default NULL - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_class_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_class_labels of pk_entity: %', pk_class; - - -- get new_class_label - IF (param_class_label IS NULL) THEN - SELECT class_label INTO new_class_label - FROM warehouse.class_preview - WHERE dfh_pk_class = pk_class; - ELSE - new_class_label = param_class_label; - END IF; - - RAISE INFO 'new_class_label: %', new_class_label; - - -- update all dependent entity_previews with new_class_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET class_label = new_class_label - WHERE fk_class = pk_class - AND class_label IS DISTINCT FROM new_class_label; - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_dependent_type_labels #9 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_type_labels( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_type_label TEXT; - dependent_type_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_type_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_type_label - SELECT entity_label INTO new_type_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_type_label: %', new_type_label; - - -- update all dependent entity_previews with new_type_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET type_label = new_type_label - WHERE fk_type = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND type_label IS DISTINCT FROM new_type_label; - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__fill_time_span #10 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - new_time_span jsonb; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_time_span - SELECT time_span INTO new_time_span - FROM information.v_te_en_time_span_per_project_and_repo - WHERE fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_time_span: %', new_time_span; - - -- update this entity_preview with new_time_span - UPDATE warehouse.entity_preview - SET time_span = new_time_span - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__create #11 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create( - param_pk_entity integer, - param_fk_project integer - ) - RETURNS BOOLEAN AS $$ - DECLARE - e warehouse.v_entities; - c warehouse.class_preview; - p INT; - BEGIN - - ---------- upsert the unchagable rows ---------- - - p = coalesce(param_fk_project, 0); - - SELECT * INTO e - FROM warehouse.v_entities - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - SELECT * INTO c - FROM warehouse.class_preview as cpre - WHERE cpre.dfh_pk_class = e.fk_class; - - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label) - VALUES ( - param_pk_entity, - param_fk_project, - p, -- project - e.fk_class, - e.entity_type, - c.class_label - ) - ON CONFLICT (pk_entity, project) - DO - UPDATE - SET fk_class = e.fk_class, entity_type = e.entity_type, class_label = c.class_label - WHERE entity_preview.pk_entity = param_pk_entity AND entity_preview.project = p; - - - ---------- first create the dependency indexes ---------- - - PERFORM warehouse.entity_preview__create_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_type(param_pk_entity, param_fk_project); - - ---------- second fill the own entity_label and own_full_text ---------- - - PERFORM warehouse.entity_preview__fill_own_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_own_full_text(param_pk_entity, param_fk_project); - - - ---------- third fill the dependencies ---------- - - PERFORM warehouse.entity_preview__fill_dependent_entity_labels(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_type_labels(param_pk_entity, param_fk_project); - - RETURN true; - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION entity_preview__create_all #12 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all() - RETURNS BOOLEAN AS $$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - CREATE TABLE warehouse.temp AS SELECT * FROM warehouse.v_entity_preview; - - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.temp - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM warehouse.previews_non_recursive t1 - LEFT JOIN warehouse.previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $$ LANGUAGE plpgsql; - - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION #13 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.notify_fn_call(channel TEXT, fn_name TEXT, fn_params TEXT[]) - RETURNS BOOLEAN AS $$ - DECLARE - fn_concat TEXT; - BEGIN - - fn_concat = fn_name || '(' || array_to_string(fn_params, ',', 'NULL'::text) || ')'; - - PERFORM pg_notify( - channel, - json_build_object('fn', fn_concat)::text - ); - - RETURN TRUE; - - END; - $$ LANGUAGE plpgsql; - - - ------------------------------------------------------------------------------------------------------------ - -- FUNCTION needs_update #14 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.needs_update(fn_name TEXT, fn_params TEXT[]) - RETURNS BOOLEAN AS $$ - DECLARE - fn_name_concat TEXT; - BEGIN - - fn_name_concat = array_to_string(ARRAY['warehouse.', fn_name],''); - - PERFORM warehouse.notify_fn_call('warehouse_update_request'::text, fn_name_concat, fn_params); - - RETURN TRUE; - - END; - $$ LANGUAGE plpgsql; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - -- 14 - DROP FUNCTION warehouse.needs_update(text, text[]); - - -- 13 - DROP FUNCTION warehouse.notify_fn_call(text, text, text[]); - - -- 12 - DROP FUNCTION warehouse.entity_preview__create_all(); - - -- 11 - DROP FUNCTION warehouse.entity_preview__create(integer, integer); - - -- 10 - DROP FUNCTION warehouse.entity_preview__fill_time_span(integer, integer); - - -- 9 - DROP FUNCTION warehouse.entity_preview__fill_dependent_type_labels(integer, integer); - - -- 8 - DROP FUNCTION warehouse.entity_preview__fill_dependent_class_labels(integer, text); - - -- 7 - DROP FUNCTION warehouse.entity_preview__fill_dependent_related_full_texts(integer, integer); - - -- 6 - DROP FUNCTION warehouse.entity_preview__fill_dependent_entity_labels(integer, integer); - - -- 5 - DROP FUNCTION warehouse.entity_preview__fill_own_full_text(integer, integer); - - -- 4 - DROP FUNCTION warehouse.entity_preview__fill_own_entity_label(integer, integer); - - -- 3 - DROP FUNCTION warehouse.entity_preview__create_fk_type(integer, integer); - - -- 2 - DROP FUNCTION warehouse.entity_preview__create_fk_entity_label(integer, integer); - - -- 1 - DROP FUNCTION warehouse.entity_preview__create_related_full_texts(integer, integer); - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190114114351-war-entity-preview-trigger-functions.js b/server/db-migrate/migrations/_migration_archive/20190114114351-war-entity-preview-trigger-functions.js deleted file mode 100644 index 3e45abeee..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190114114351-war-entity-preview-trigger-functions.js +++ /dev/null @@ -1,376 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__upsert_entity_preview #1 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_domain_entity INT; - _fk_range_entity INT; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - PERFORM - - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_domain_entity into _fk_domain_entity - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_range_entity into _fk_range_entity - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_domain_entity: %, fk_range_entity: %, fk_project: %', _fk_domain_entity, _fk_range_entity, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_domain_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_domain_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_range_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_range_entity::text, NULL::text]); - - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $BODY$; - - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__get_entity_label #2 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__get_entity_label() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_entity_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_entity_label IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET entity_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_entity_label - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $BODY$; - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__get_type_label #3 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__get_type_label() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_type_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_type IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET type_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_type - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $BODY$; - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__concat_full_text #4 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__concat_full_text() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__concat_full_text; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - - SELECT string_agg into NEW.full_text from ( - SELECT 1, string_agg(txt, ', ' ORDER BY rank) from ( - SELECT rank, txt - FROM ( - select 1 rank, coalesce(NEW.type_label, NEW.class_label, '') as txt - UNION - select 2 rank, NEW.own_full_text as txt - UNION - select 3 rank, value as txt - from jsonb_each_text(NEW.related_full_texts) - ) AS all_strings - WHERE txt != '' - ) AS items - GROUP BY 1 - ) as x; - - SELECT setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(NEW.type_label, NEW.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(NEW.full_text,'')), 'C') - INTO NEW.ts_vector; - - - - RETURN NEW; - END; - $BODY$; - - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__update_dependent_related_full_texts #5 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_related_full_texts() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_related_full_texts; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $BODY$; - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__update_dependent_entity_labels #6 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_entity_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_entity_labels; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM - warehouse.entity_preview__fill_dependent_entity_labels(NEW.pk_entity, NEW.fk_project), - warehouse.entity_preview__fill_dependent_type_labels(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $BODY$; - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__update_dependent_class_labels #7 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_class_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM warehouse.entity_preview__fill_dependent_class_labels(NEW.pk_entity, NEW.fk_project); - - - RETURN NEW; - END; - $BODY$; - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__notify_upsert #8 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__notify_upsert() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - PERFORM pg_notify('entity_preview_updated'::text, json_build_object( - 'pk_entity', NEW.pk_entity, - 'fk_project', NEW.fk_project, - 'project', NEW.project, - 'fk_class', NEW.fk_class, - 'entity_type', NEW.entity_type, - 'class_label', NEW.class_label, - 'entity_label', NEW.entity_label, - 'time_span', NEW.time_span, - 'fk_type', NEW.fk_type, - 'type_label', NEW.type_label - )::text); - RETURN NEW; - END; - $BODY$; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - -- 8 - DROP FUNCTION warehouse.entity_preview__notify_upsert(); - - -- 7 - DROP FUNCTION warehouse.entity_preview__update_dependent_class_labels(); - - -- 6 - DROP FUNCTION warehouse.entity_preview__update_dependent_entity_labels(); - - -- 5 - DROP FUNCTION warehouse.entity_preview__update_dependent_related_full_texts(); - - -- 4 - DROP FUNCTION warehouse.entity_preview__concat_full_text(); - - -- 3 - DROP FUNCTION warehouse.entity_preview__get_type_label(); - - -- 2 - DROP FUNCTION warehouse.entity_preview__get_entity_label(); - - -- 1 - DROP FUNCTION warehouse.entity_preview__upsert_entity_preview(); - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190117153748-war-entity-preview-triggers.js b/server/db-migrate/migrations/_migration_archive/20190117153748-war-entity-preview-triggers.js deleted file mode 100644 index c645d21c6..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190117153748-war-entity-preview-triggers.js +++ /dev/null @@ -1,149 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_epr_upsert #1 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_epr_upsert - After INSERT OR UPDATE - ON information.entity_version_project_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__upsert_entity_preview(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_update_on_entity_preview__fk_entity_label #2 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_update_on_entity_preview__fk_entity_label - AFTER UPDATE OF fk_entity_label - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__get_entity_label(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_update_on_entity_preview__fk_type #3 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_update_on_entity_preview__fk_type - AFTER UPDATE OF fk_type - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__get_type_label(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER before_update_on_entity_preview__related_full_texts #4 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER before_update_on_entity_preview__related_full_texts - BEFORE UPDATE OF related_full_texts - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER before_update_on_entity_preview__own_full_text #5 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER before_update_on_entity_preview__own_full_text - BEFORE UPDATE OF own_full_text - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_update_on_entity_preview__own_full_text #6 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_update_on_entity_preview__own_full_text - AFTER UPDATE OF own_full_text - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_related_full_texts(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_update_on_entity_preview__entity_label #7 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_update_on_entity_preview__entity_label - AFTER UPDATE OF entity_label - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_entity_labels(); - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_update_on_class_preview__class_label #8 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_update_on_class_preview__class_label - AFTER UPDATE OF class_label - ON warehouse.class_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_class_labels(); - - - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER after_upsert_on_entity_preview #9 - ------------------------------------------------------------------------------------------------------------ - CREATE TRIGGER after_upsert_on_entity_preview - AFTER INSERT OR UPDATE OF entity_label, class_label, time_span, type_label - ON warehouse.entity_preview - FOR EACH ROW - WHEN ( - NEW.project IS NOT NULL - AND NEW.fk_class IS NOT NULL - AND NEW.entity_type IS NOT NULL - ) - EXECUTE PROCEDURE warehouse.entity_preview__notify_upsert(); - - ` - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - -- 9 - DROP TRIGGER after_upsert_on_entity_preview ON warehouse.entity_preview; - - -- 8 - DROP TRIGGER after_update_on_class_preview__class_label ON warehouse.class_preview; - - -- 7 - DROP TRIGGER after_update_on_entity_preview__entity_label ON warehouse.entity_preview; - - -- 6 - DROP TRIGGER after_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - - -- 5 - DROP TRIGGER before_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - - -- 4 - DROP TRIGGER before_update_on_entity_preview__related_full_texts ON warehouse.entity_preview; - - -- 3 - DROP TRIGGER after_update_on_entity_preview__fk_type ON warehouse.entity_preview; - - -- 2 - DROP TRIGGER after_update_on_entity_preview__fk_entity_label ON warehouse.entity_preview; - - -- 1 - DROP TRIGGER after_epr_upsert ON information.entity_version_project_rel; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190121124122-inf-remove-mv-data-units-preview.js b/server/db-migrate/migrations/_migration_archive/20190121124122-inf-remove-mv-data-units-preview.js deleted file mode 100644 index d5deb27b4..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190121124122-inf-remove-mv-data-units-preview.js +++ /dev/null @@ -1,915 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function (db, callback) { - - const sql = ` - - - DROP FUNCTION information.refresh_vm_data_unit_preview(); - - DROP TABLE commons.vm_refresh_date; - - DROP MATERIALIZED VIEW IF EXISTS information.vm_data_unit_preview CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_preview CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_preview CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_strings_per_field_and_project CASCADE; - - DROP VIEW IF EXISTS information.v_pe_it_strings_per_field_repo CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_strings_per_field_and_project CASCADE; - - DROP VIEW IF EXISTS information.v_te_en_strings_per_field_repo CASCADE; - - DROP FUNCTION information.querypeitpreview(integer, integer, integer); - DROP FUNCTION information.querypeitlabel(integer, integer, integer); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION information.queryPeItLabel( - param_pk_project integer, - param_pk_entity integer, - param_pk_ui_context integer, - OUT pk_entity integer, - OUT fk_project integer, - OUT fk_class integer, - OUT entity_label text, - OUT class_label varchar, - OUT entity_type text - ) - RETURNS SETOF record - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - WITH appe_string as ( - SELECT pk_entity, string - from information.v_appellation - ), - text_property_string as ( - SELECT txt.pk_entity, txt.fk_concerned_entity, txt.string, epr.fk_project, epr.ord_num as txt_order - from information.v_text_property as txt - INNER JOIN information.entity_version_project_rel as epr on txt.pk_entity = epr.fk_entity - WHERE is_in_project = true AND fk_project = param_pk_project - ORDER BY ord_num - ), - role as ( - SELECT r.pk_entity, r.fk_entity, r.fk_temporal_entity, r.fk_property, epr.fk_project, epr.ord_num as role_order - from information.role as r - INNER JOIN information.entity_version_project_rel as epr on r.pk_entity = epr.fk_entity - WHERE is_in_project = true AND fk_project = param_pk_project - ORDER BY ord_num - ), - persistent_item as ( - SELECT pk_entity, fk_class - from information.v_persistent_item - WHERE pk_entity = param_pk_entity - ), - ordered_fields_per_class AS ( - SELECT c.pk_entity, c.ord_num as field_order, - CASE - WHEN c.property_is_outgoing=true THEN p.dfh_has_domain - WHEN c.property_is_outgoing=false THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END as fk_class, - c.fk_property, - c.property_is_outgoing, - c.fk_class_field, - f.used_table - FROM commons.ui_context_config as c - LEFT JOIN data_for_history.property as p on p.dfh_pk_property = c.fk_property - LEFT JOIN commons.class_field as f on f.pk_entity = c.fk_class_field - WHERE fk_ui_context = param_pk_ui_context - ORDER BY fk_class, ord_num - ), - ordered_pe_it_fields AS ( - SELECT ordered_fields_per_class.* - FROM ordered_fields_per_class - INNER JOIN persistent_item as p on p.fk_class = ordered_fields_per_class.fk_class - LIMIT 1 - ), - ordered_pe_it_roles AS ( - select - pe_it.fk_class, - pe_it.pk_entity, - pi_role.fk_project, - pi_role.fk_entity, - pi_role.fk_temporal_entity, - pi_role.fk_property, - field_order, - pi_role.role_order - from persistent_item as pe_it - -- get the roles of the persistent item that are available in the ordered list of fields for the pe-it class - INNER JOIN ordered_pe_it_fields as pi_fields on pi_fields.fk_class = pe_it.fk_class - INNER JOIN role as pi_role on pi_role.fk_entity = pe_it.pk_entity AND pi_role.fk_property = pi_fields.fk_property - ORDER BY role_order - ), - ordered_pe_it_text_properties AS ( - select - pe_it.fk_class, - pe_it.pk_entity, - pi_txt.fk_project, - pi_txt.pk_entity as txt_pk, - field_order, - pi_txt.txt_order, - pi_txt.string - from persistent_item as pe_it - -- get the roles of the persistent item that are available in the ordered list of fields for the pe-it class - INNER JOIN ordered_pe_it_fields as pi_fields on pi_fields.fk_class = pe_it.fk_class - INNER JOIN text_property_string as pi_txt on pi_txt.fk_concerned_entity = pe_it.pk_entity AND pi_fields.used_table = 'information.text_property' - ORDER BY txt_order - ), - temporal_entity as ( - SELECT teen.pk_entity, teen.fk_class - from information.v_temporal_entity as teen - INNER JOIN ordered_pe_it_roles as teen_r on teen_r.fk_temporal_entity = teen.pk_entity - ), - ordered_te_en_fields AS ( - SELECT ordered_fields_per_class.* - FROM ordered_fields_per_class - INNER JOIN temporal_entity as p on p.fk_class = ordered_fields_per_class.fk_class - LIMIT 1 - ), - ordered_te_ent_roles AS ( - select - te_role.fk_project, - te_role.fk_entity, - te_role.fk_temporal_entity, - te_role.fk_property, - te_fields.field_order, - te_role.role_order, - string - from temporal_entity as te_ent - - -- The following line is for performance tuning only - INNER JOIN ordered_pe_it_roles o_peit_r on o_peit_r.fk_temporal_entity = te_ent.pk_entity - - -- get the roles of the temporal entities that are available in the ordered list of fields for the te-ent class - INNER JOIN ordered_te_en_fields as te_fields on te_fields.fk_class = te_ent.fk_class - INNER JOIN role as te_role on te_role.fk_property = te_fields.fk_property - - ----------------------------------------------------------- - -- get the strings of all related value-like tables - INNER JOIN appe_string on appe_string.pk_entity = te_role.fk_entity - - - -- add here string-selects for: - -- time_primitive - -- place - -- ... - - ----------------------------------------------------------- - - ORDER BY field_order - - ), - string AS ( - SELECT - o_peit_r.pk_entity, - o_peit_r.fk_project, - o_peit_r.fk_class, - o_peit_r.field_order, - o_peit_r.role_order as val_order, - o_teen_r.string - from ordered_pe_it_roles as o_peit_r - LEFT JOIN ordered_te_ent_roles as o_teen_r - ON o_teen_r.fk_temporal_entity = o_peit_r.fk_temporal_entity-- AND o_teen_r.string IS NOT NULL - UNION - SELECT - o_peit_txt.pk_entity, - o_peit_txt.fk_project, - o_peit_txt.fk_class, - o_peit_txt.field_order, - o_peit_txt.txt_order as val_order, - o_peit_txt.string - from ordered_pe_it_text_properties as o_peit_txt - --WHERE o_peit_txt.string IS NOT NULL - ), - class AS ( - SELECT - CASE - WHEN l.dfh_label IS NOT NULL THEN l.dfh_label - ELSE cpv.dfh_class_standard_label - END as class_label, - CASE - WHEN cpv.dfh_fk_system_type = 9 THEN 'teEn' - WHEN cpv.dfh_fk_system_type = 8 THEN 'peIt' - ELSE NULL - END as entity_type, - c.dfh_pk_class - from data_for_history.class as c - inner join string as s on s.fk_class = c.dfh_pk_class - inner join data_for_history.class_profile_view as cpv on c.dfh_pk_class = cpv.dfh_fk_class - left join data_for_history.label as l on l.dfh_fk_class = c.dfh_pk_class AND l.com_fk_system_type = 184 - LIMIT 1 - ), - final_select as ( - select DISTINCT - s.pk_entity, - s.field_order, - s.val_order, - s.fk_project, - s.fk_class, - s.string, - c.class_label, - c.entity_type - from string as s - INNER JOIN class as c on c.dfh_pk_class = s.fk_class - ORDER BY field_order, val_order - LIMIT 1 - ) - select pk_entity, fk_project, fk_class, string as entity_label, class_label, entity_type from final_select; - - - $BODY$; - - CREATE OR REPLACE FUNCTION information.queryPeItPreview( - param_pk_project integer, - param_pk_entity integer, - param_pk_ui_context integer, - OUT pk_entity integer, - OUT fk_project integer, - OUT fk_class integer, - OUT entity_label text, - OUT class_label varchar, - OUT entity_type text, - OUT type_label text - ) - RETURNS SETOF record - LANGUAGE 'sql' - - COST 100 - VOLATILE - AS $BODY$ - - WITH pe_it_label AS ( - select * - from information.queryPeItLabel(param_pk_project,param_pk_entity,param_pk_ui_context) - ), - associated_type AS ( - select ea.pk_entity, ea.fk_range_entity, ea.fk_domain_entity, ea.fk_property, - (select entity_label from information.queryPeItLabel(param_pk_project, ea.fk_range_entity, param_pk_ui_context)) - from information.entity_association as ea - inner join information.entity_version_project_rel as epr on ea.pk_entity = epr.fk_entity AND epr.is_in_project = true - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) - AND ea.fk_domain_entity = param_pk_entity - ) - select pe_it_label.*, associated_type.entity_label as type_label - from pe_it_label - left join associated_type on associated_type.fk_domain_entity = pe_it_label.pk_entity - - $BODY$; - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per teEn in the repo version #3 - -- Attention: This view gets replaced further below, for some "recursive" join ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_repo AS - SELECT - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - r.rank_for_te_ent as rank, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes) as all_strings - - -- teen - from information.v_temporal_entity as teen - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - WHERE ( r.range_max_quantifier = -1 OR r.rank_for_te_ent <= r.range_max_quantifier ) - AND r.is_in_project_count > 0 - ORDER BY field_order, rank_for_te_ent; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per teEn and project #4 - -- Attention: This view gets replaced further below, for some "recursive" join ------------------------------------------------------------------------------------------------------------- - - CREATE VIEW information.v_te_en_strings_per_field_and_project AS - SELECT - epr.fk_project, - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - epr2.ord_num, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes) as all_strings - - -- teen - from information.v_temporal_entity as teen - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = teen.pk_entity AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = epr.fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - ORDER BY field_order; - ------------------------------------------------------------------------------------------------------------- - -- VIEW that creates time span objects per TeEn, project and repo version #5 ------------------------------------------------------------------------------------------------------------- - CREATE OR REPLACE VIEW information.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive as ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.entity_version_project_rel as epr - INNER JOIN information.v_role as r on r.pk_entity = epr.fk_entity - INNER JOIN information.v_time_primitive as tp on tp.pk_entity = r.fk_entity - WHERE - epr.is_in_project = true - - UNION - - SELECT - r.fk_temporal_entity, - r.fk_property, - null::integer as fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role as r - INNER JOIN information.v_time_primitive as tp on tp.pk_entity = r.fk_entity - AND r.rank_for_te_ent = 1 - ) - select - fk_project, - fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN fk_property=71 THEN 'p81' - WHEN fk_property=72 THEN 'p82' - WHEN fk_property=150 THEN 'p81a' - WHEN fk_property=151 THEN 'p81b' - WHEN fk_property=152 THEN 'p82a' - WHEN fk_property=153 THEN 'p82b' - ELSE fk_property::text - END - - , json_build_object('julianDay', julian_day, 'duration', duration, 'calendar', calendar) ) as time_span - FROM role_with_time_primitive - GROUP BY fk_project, fk_temporal_entity; - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that unions TeEn project and repo version and adds time span objects #6 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_te_en_preview as - WITH teen_with_label as ( - select - teen_strings.fk_project, - teen_strings.pk_entity, - teen_strings.fk_class, - string_agg(string_0, ' ') as entity_label, - string_agg(string_1, ' ') as entity_label_2, - string_agg(all_strings, ', ' ORDER BY field_order) || '.' as full_text, - teen_time_span.time_span - from information.v_te_en_strings_per_field_and_project as teen_strings - LEFT JOIN information.v_te_en_time_span_per_project_and_repo as teen_time_span - ON teen_time_span.fk_project = teen_strings.fk_project AND teen_time_span.fk_temporal_entity = pk_entity - Group By teen_strings.fk_project, pk_entity, fk_class, teen_time_span.time_span - UNION - select - null as fk_project, - teen_strings.pk_entity, - teen_strings.fk_class, - string_agg(string_0, ' ') as entity_label, - string_agg(string_1, ' ') as entity_label_2, - string_agg(all_strings, ', ' ORDER BY field_order) || '.' as full_text, - teen_time_span.time_span - from information.v_te_en_strings_per_field_repo as teen_strings - LEFT JOIN information.v_te_en_time_span_per_project_and_repo as teen_time_span - ON teen_time_span.fk_project IS NULL AND teen_time_span.fk_temporal_entity = pk_entity - Group By pk_entity, fk_class, teen_time_span.time_span - ) - SELECT DISTINCT - teen_with_label.fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - time_span - FROM teen_with_label; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per peIt in the repo version #7 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_pe_it_strings_per_field_repo AS - WITH pi_role as ( - SELECT * - FROM information.v_role as r - WHERE ( r.domain_max_quantifier = -1 OR r.rank_for_pe_it <= r.domain_max_quantifier) - AND r.is_in_project_count > 0 - ) - SELECT DISTINCT - peit.pk_entity, - peit.fk_class, - peit_field.fk_property, - peit_field.field_order, - r.fk_entity, - r.fk_temporal_entity, - ROW_NUMBER () OVER ( - PARTITION BY peit.pk_entity - ORDER BY field_order, r.rank_for_pe_it - ) as rank, - r.range_max_quantifier, - CASE - WHEN field_order=0 THEN COALESCE(teen_preview.entity_label, txt_prop.string )-- add text_property here - ELSE null - END as entity_label, - COALESCE(teen_preview.full_text) as all_strings - - -- peit - from information.v_persistent_item as peit - - -- field - INNER JOIN information.v_ordered_fields_per_class peit_field on peit_field.fk_class = peit.fk_class - - -- role - LEFT JOIN pi_role as r - on peit_field.fk_property = r.fk_property - and peit.pk_entity = r.fk_entity - - ----------------------------------------------------------- - -- get the strings of the teen connected to peit via role - - -- temporal_entity - LEFT JOIN information.v_te_en_preview as teen_preview - ON r.fk_temporal_entity = teen_preview.pk_entity - AND teen_preview.fk_project IS NULL - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to peit - -- text_property - ----------------------------------------------------------- - LEFT JOIN - information.v_text_property txt_prop ON txt_prop.fk_concerned_entity = peit.pk_entity - - ORDER BY pk_entity, field_order; - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that gets all the labels/strings per PeIt and project #8 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_pe_it_strings_per_field_and_project AS - SELECT DISTINCT epr.fk_project, - peit.pk_entity, - peit.fk_class, - peit_field.fk_property, - peit_field.field_order, - r.fk_entity, - r.fk_temporal_entity, - epr2.ord_num, - ROW_NUMBER () OVER ( - PARTITION BY peit.pk_entity, epr.fk_project - ORDER BY field_order, epr2.ord_num - ) as rank, - CASE - WHEN peit_field.field_order = 0 THEN COALESCE(teen_preview.entity_label, txt_prop.string) - ELSE NULL::text - END AS entity_label, - COALESCE(teen_preview.full_text, txt_prop.string) AS all_strings - -- peit - FROM information.v_persistent_item peit - JOIN information.entity_version_project_rel epr ON epr.fk_entity = peit.pk_entity - - -- field - JOIN information.v_ordered_fields_per_class peit_field ON peit_field.fk_class = peit.fk_class - -- role - LEFT JOIN information.v_role r ON peit_field.fk_property = r.fk_property AND peit.pk_entity = r.fk_entity - LEFT JOIN information.entity_version_project_rel epr2 ON epr2.fk_entity = r.pk_entity AND epr2.fk_project = epr.fk_project - - ----------------------------------------------------------- - -- get the strings of the teen connected to peit via role - -- temporal_entity - LEFT JOIN information.v_te_en_preview teen_preview ON r.fk_temporal_entity = teen_preview.pk_entity AND teen_preview.fk_project = epr.fk_project - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to peit - -- text_property - LEFT JOIN ( - SELECT * FROM information.v_text_property as t - LEFT JOIN information.entity_version_project_rel epr3 ON epr3.fk_entity = t.pk_entity - ) as txt_prop - ON txt_prop.fk_concerned_entity = peit.pk_entity - AND txt_prop.fk_project = epr.fk_project - AND txt_prop.fk_class_field = peit_field.fk_class_field - ----------------------------------------------------------- - ORDER BY fk_project, field_order, ord_num; - - - ------------------------------------------------------------------------------------------------------------- - -- VIEW that unions PeIt project and repo version #9 ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_pe_it_preview as - WITH peit_with_label as ( - SELECT - fk_project, - pk_entity, - fk_class, - array_to_string((array_agg(entity_label order by rank))[1:1], '; ') as entity_label, - string_agg(all_strings, ' ') as full_text - from information.v_pe_it_strings_per_field_and_project as strings - WHERE (entity_label is not null OR strings.all_strings is not null) - Group By fk_project, pk_entity, fk_class - - UNION - - SELECT - null::integer as fk_project, - pk_entity, - fk_class, - array_to_string((array_agg(entity_label order by rank))[1:1], '; ') as entity_label, - string_agg(all_strings, ' ') as full_text - from information.v_pe_it_strings_per_field_repo as strings - WHERE (entity_label is not null OR strings.all_strings is not null) - Group By fk_project, pk_entity, fk_class - ) - SELECT DISTINCT - peit_with_label.fk_project, - pk_entity, - fk_class, - entity_label, - full_text - FROM peit_with_label - ORDER BY fk_project; - - - - ------------------------------------------------------------------------------------------------------------- - -- MATERIALIZED VIEW for data_unit preview #10 ------------------------------------------------------------------------------------------------------------- - - CREATE MATERIALIZED VIEW information.vm_data_unit_preview as - WITH type_info_per_project AS ( - select distinct ea.fk_domain_entity, type_preview.fk_project, type_preview.entity_label as type_label, type_preview.pk_entity as pk_type - from information.entity_association as ea - inner join information.entity_version_project_rel as epr on ea.pk_entity = epr.fk_entity AND epr.is_in_project = true - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - inner join information.v_pe_it_preview as type_preview on ea.fk_range_entity = type_preview.pk_entity and epr.fk_project = type_preview.fk_project - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) - ), - type_info_per_repo AS ( - select distinct ea.fk_domain_entity, type_preview.entity_label as type_label, ea.rank_for_domain, type_preview.pk_entity as pk_type - from information.v_entity_association as ea - inner join data_for_history.property as p on ea.fk_property = p.dfh_pk_property - inner join information.v_pe_it_preview as type_preview on ea.fk_range_entity = type_preview.pk_entity - where p.dfh_pk_property IN (1110,1190,1205,1206,1214,1204,1066) AND ea.rank_for_domain = 1 - ), - data_unit as ( - select - fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - null::jsonb as time_span - from information.v_pe_it_preview - UNION - select - fk_project, - pk_entity, - fk_class, - entity_label, - full_text, - time_span - from information.v_te_en_preview - ) - select - data_unit.fk_project, - data_unit.pk_entity, - data_unit.fk_class, - data_unit.entity_label, - class_info.class_label, - class_info.entity_type, - COALESCE(type_info_per_project.type_label, type_info_per_repo.type_label) as type_label, - COALESCE(type_info_per_project.pk_type, type_info_per_repo.pk_type) as pk_type, - data_unit.full_text as full_text, - setweight(to_tsvector(coalesce(data_unit.entity_label,'')), 'A') || - setweight(to_tsvector(coalesce(type_info_per_project.type_label, type_info_per_repo.type_label, class_info.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(data_unit.full_text,'')), 'C') - as ts_vector, - time_span - from data_unit - LEFT JOIN type_info_per_project - on type_info_per_project.fk_domain_entity = data_unit.pk_entity - and data_unit.fk_project = type_info_per_project.fk_project - LEFT JOIN type_info_per_repo - on type_info_per_repo.fk_domain_entity = data_unit.pk_entity - and data_unit.fk_project is null - - INNER JOIN information.v_class_preview as class_info on class_info.dfh_pk_class = data_unit.fk_class; - - CREATE UNIQUE INDEX vm_data_unit_preview_unique - ON information.vm_data_unit_preview (pk_entity, fk_project); - - ------------------------------------------------------------------------------------------------------------- - -- REPLACE VIEW from above, that gets all the labels/strings per teEn and project #11 - -- now with a join to the materialized view in order to add peIt labels to the teEn ------------------------------------------------------------------------------------------------------------- - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_and_project AS - SELECT - epr.fk_project, - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - epr2.ord_num, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes, peit.entity_label) as all_strings - - -- teen - from information.v_temporal_entity as teen - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = teen.pk_entity AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = epr.fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - LEFT JOIN information.vm_data_unit_preview as peit - ON r.fk_entity = peit.pk_entity AND peit.fk_project = epr.fk_project - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - ORDER BY field_order; - - - - - ------------------------------------------------------------------------------------------------------------- - -- REPLACE VIEW from above, that gets all the labels/strings of repo #12 - -- now with a join to the materialized view in order to add peIt labels to the teEn ------------------------------------------------------------------------------------------------------------- - - - CREATE OR REPLACE VIEW information.v_te_en_strings_per_field_repo AS - SELECT - teen.pk_entity, - teen.fk_class, - teen_field.fk_property, - teen_field.field_order, - r.fk_entity, - r.rank_for_te_ent as rank, - CASE - WHEN field_order=0 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_0, - CASE - WHEN field_order=1 THEN COALESCE(appe.string, lang.notes, peit.entity_label) - ELSE null - END as string_1, - COALESCE(appe.string, lang.notes, peit.entity_label) as all_strings - - -- teen - from information.v_temporal_entity as teen - - -- field - INNER JOIN information.v_ordered_fields_per_class teen_field on teen_field.fk_class = teen.fk_class - - -- role - LEFT JOIN information.v_role as r - on teen_field.fk_property = r.fk_property - and teen.pk_entity = r.fk_temporal_entity - - ----------------------------------------------------------- - -- get the strings of all tables connected to teen via role-fk_entity - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - -- persistent_item - LEFT JOIN information.vm_data_unit_preview as peit - ON r.fk_entity = peit.pk_entity AND peit.fk_project IS NULL - -- temporal_entity - ----------------------------------------------------------- - - - ----------------------------------------------------------- - -- get the tables connected directly to teen - -- text_property - ----------------------------------------------------------- - WHERE ( r.range_max_quantifier = -1 OR r.rank_for_te_ent <= r.range_max_quantifier ) - AND r.is_in_project_count > 0 - ORDER BY field_order, rank_for_te_ent; - - ------------------------------------------------------------------------------------------------------------- - -- TABLE that stores the latest refresh date of information.vm_data_unit_preview ------------------------------------------------------------------------------------------------------------- - CREATE TABLE commons.vm_refresh_date ( - information_vm_data_unit_preview timestamp with time zone - ); - ------------------------------------------------------------------------------------------------------------- - -- FUNCTION that refreshes information.vm_data_unit_preview, if the latest modification of - -- information.entity_version_project_rel is newer than the latest refresh stored in commons.vm_refresh_date ------------------------------------------------------------------------------------------------------------- - CREATE OR REPLACE FUNCTION information.refresh_vm_data_unit_preview() - RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - refresh_needed boolean; - refreshed boolean; - BEGIN - - select into refresh_needed ( - ( - select information_vm_data_unit_preview from commons.vm_refresh_date - order by information_vm_data_unit_preview desc - limit 1 - ) - < - ( - select tmsp_last_modification from information.entity_version_project_rel - order by tmsp_last_modification desc - limit 1 - ) - ); - - IF (refresh_needed = true OR refresh_needed IS NULL) THEN - REFRESH MATERIALIZED VIEW CONCURRENTLY information.vm_data_unit_preview; - - INSERT INTO commons.vm_refresh_date (information_vm_data_unit_preview) - VALUES (now()); - - refreshed = true; - ELSE - refreshed = false; - END IF; - - RETURN refreshed; - END $$; - - - - - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190123100830-war-fix-class-label-trigger.js b/server/db-migrate/migrations/_migration_archive/20190123100830-war-fix-class-label-trigger.js deleted file mode 100644 index 4c60cf6e6..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190123100830-war-fix-class-label-trigger.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__update_dependent_class_labels #7 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_class_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; dfh_pk_class: % class_label: %', NEW.dfh_pk_class, NEW.class_label; - - PERFORM warehouse.entity_preview__fill_dependent_class_labels(NEW.dfh_pk_class, NEW.class_label); - - - RETURN NEW; - END; - $BODY$; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ------------------------------------------------------------------------------------------------------------ - -- TRIGGER FUNCTION entity_preview__update_dependent_class_labels #7 - ------------------------------------------------------------------------------------------------------------ - CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_class_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM warehouse.entity_preview__fill_dependent_class_labels(NEW.pk_entity, NEW.fk_project); - - - RETURN NEW; - END; - $BODY$; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20190128175520-inf-epr-update.js b/server/db-migrate/migrations/_migration_archive/20190128175520-inf-epr-update.js deleted file mode 100644 index 4c770ad27..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190128175520-inf-epr-update.js +++ /dev/null @@ -1,209 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - ALTER TABLE information.entity_version_project_rel_vt - ADD COLUMN ord_num int; - - CREATE OR REPLACE FUNCTION information.v_entity_version_project_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_version_project_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE information.entity_version_project_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_version_project_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - ALTER TABLE information.entity_version_project_rel_vt - DROP COLUMN ord_num; - - CREATE OR REPLACE FUNCTION information.v_entity_version_project_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_version_project_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE information.entity_version_project_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_version_project_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1 - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_version_project_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20190208072531-war-update-entity-preview-create-all-fn.js b/server/db-migrate/migrations/_migration_archive/20190208072531-war-update-entity-preview-create-all-fn.js deleted file mode 100644 index c5188bd5f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190208072531-war-update-entity-preview-create-all-fn.js +++ /dev/null @@ -1,350 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all() - RETURNS BOOLEAN AS $$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS SELECT * FROM warehouse.v_entity_preview; - - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.temp - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $$ LANGUAGE plpgsql; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all() - RETURNS BOOLEAN AS $$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - CREATE TABLE warehouse.temp AS SELECT * FROM warehouse.v_entity_preview; - - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.temp - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM warehouse.previews_non_recursive t1 - LEFT JOIN warehouse.previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $$ LANGUAGE plpgsql; - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; - - diff --git a/server/db-migrate/migrations/_migration_archive/20190213090503-com-t-query.js b/server/db-migrate/migrations/_migration_archive/20190213090503-com-t-query.js deleted file mode 100644 index b0fe16075..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190213090503-com-t-query.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE TABLE commons.query ( - name VARCHAR, - description VARCHAR, - query JSONB, - fk_project INT - ) - INHERITS (commons.entity); - - SELECT commons.init_entity_child_table('commons.query'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP TABLE IF EXISTS commons.query; - DROP TABLE IF EXISTS commons.query_vt; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190215081831-com-t-class-has-type.js b/server/db-migrate/migrations/_migration_archive/20190215081831-com-t-class-has-type.js deleted file mode 100644 index cfae57e54..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190215081831-com-t-class-has-type.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE TABLE commons.class_has_type_property ( - fk_class INTEGER UNIQUE, - fk_property INTEGER, - FOREIGN KEY (fk_class) references data_for_history.class(dfh_pk_class), - FOREIGN KEY (fk_property) references data_for_history.property(dfh_pk_property) - ) - INHERITS (commons.entity); - - SELECT commons.init_entity_child_table('commons.class_has_type_property'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP TABLE IF EXISTS commons.class_has_type_property; - DROP TABLE IF EXISTS commons.class_has_type_property_vt; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190215085441-com-t-namespace-project-rel.js b/server/db-migrate/migrations/_migration_archive/20190215085441-com-t-namespace-project-rel.js deleted file mode 100644 index 8f88c4a3f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190215085441-com-t-namespace-project-rel.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE TABLE commons.namespace_project_rel ( - fk_project INTEGER, - fk_class INTEGER, - fk_namespace INTEGER, - FOREIGN KEY (fk_project) references commons.project(pk_project), - FOREIGN KEY (fk_class) references data_for_history.class(dfh_pk_class), - FOREIGN KEY (fk_namespace) references information.namespace(pk_entity), - UNIQUE (fk_project, fk_class) - ) - INHERITS (commons.entity); - - SELECT commons.init_entity_child_table('commons.namespace_project_rel'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP TABLE IF EXISTS commons.namespace_project_rel; - DROP TABLE IF EXISTS commons.namespace_project_rel_vt; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190309131628-com-t-query-add-unique-constraint.js b/server/db-migrate/migrations/_migration_archive/20190309131628-com-t-query-add-unique-constraint.js deleted file mode 100644 index 43e9f8055..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190309131628-com-t-query-add-unique-constraint.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - ALTER TABLE commons.query ADD CONSTRAINT unique_name_per_project UNIQUE (name, fk_project); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - ALTER TABLE commons.query DROP CONSTRAINT unique_name_per_project; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190409143027-com-t-visual.js b/server/db-migrate/migrations/_migration_archive/20190409143027-com-t-visual.js deleted file mode 100644 index 7b7073adf..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190409143027-com-t-visual.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE TABLE commons.visual ( - name VARCHAR, - description VARCHAR, - visual JSONB, - fk_project INT - ) - INHERITS (commons.entity); - - ALTER TABLE commons.visual ADD CONSTRAINT visual__unique_name_per_project UNIQUE (name, fk_project); - - SELECT commons.init_entity_child_table('commons.visual'); - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP TABLE IF EXISTS commons.visual; - DROP TABLE IF EXISTS commons.visual_vt; - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190430173127-com-f-characterize-quill-docs.js b/server/db-migrate/migrations/_migration_archive/20190430173127-com-f-characterize-quill-docs.js deleted file mode 100644 index 6623666da..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190430173127-com-f-characterize-quill-docs.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION commons.modernize_quill_doc(orig jsonb) RETURNS jsonb AS $f$ - DECLARE - newJ jsonb; - latestId int; - newOps jsonb; - oldOp jsonb; - char text; - BEGIN - newOps = jsonb_build_array(); - latestId = 0; - - -- LOOP over ops - FOR oldOp IN SELECT * FROM jsonb_array_elements((orig->'contents'->>'ops')::jsonb) - LOOP - - RAISE NOTICE 'Parsing Item % % %', oldOp->>'insert', oldOp->>'attributes', (SELECT char_length(oldOp->>'insert') > 1); - - - -- LOOP over insert characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(oldOp->>'insert','')) AS x(chars)) - LOOP - latestId = latestId + 1; - - IF char = E'\n' THEN - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb), '{blockid}'::text[], to_json(latestId::text)::jsonb) - ); - ELSE - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb) - 'node', '{charid}'::text[], to_json(latestId::text)::jsonb) - ); - END IF; - END LOOP; - - - END LOOP; - - RAISE NOTICE 'New Ops: %', newOps; - - - newJ = jsonb_build_object('latestId',latestId, 'ops', newOps); - - RETURN newJ; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP FUNCTION commons.modernize_quill_doc(jsonb); - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190430173513-com-f-validate-json-schema.js b/server/db-migrate/migrations/_migration_archive/20190430173513-com-f-validate-json-schema.js deleted file mode 100644 index 845145027..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190430173513-com-f-validate-json-schema.js +++ /dev/null @@ -1,300 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION commons._validate_json_schema_type(type text, data jsonb) RETURNS boolean AS $f$ - BEGIN - IF type = 'integer' THEN - IF jsonb_typeof(data) != 'number' THEN - RETURN false; - END IF; - IF trunc(data::text::numeric) != data::text::numeric THEN - RETURN false; - END IF; - ELSE - IF type != jsonb_typeof(data) THEN - RETURN false; - END IF; - END IF; - RETURN true; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - - - CREATE OR REPLACE FUNCTION commons.validate_json_schema(schema jsonb, data jsonb, root_schema jsonb DEFAULT NULL) RETURNS boolean AS $f$ - DECLARE - prop text; - item jsonb; - path text[]; - types text[]; - pattern text; - props text[]; - BEGIN - IF root_schema IS NULL THEN - root_schema = schema; - END IF; - - IF schema ? 'type' THEN - IF jsonb_typeof(schema->'type') = 'array' THEN - types = ARRAY(SELECT jsonb_array_elements_text(schema->'type')); - ELSE - types = ARRAY[schema->>'type']; - END IF; - IF (SELECT NOT bool_or(commons._validate_json_schema_type(type, data)) FROM unnest(types) type) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'properties' THEN - FOR prop IN SELECT jsonb_object_keys(schema->'properties') LOOP - IF data ? prop AND NOT commons.validate_json_schema(schema->'properties'->prop, data->prop, root_schema) THEN - RETURN false; - END IF; - END LOOP; - END IF; - - IF schema ? 'required' AND jsonb_typeof(data) = 'object' THEN - IF NOT ARRAY(SELECT jsonb_object_keys(data)) @> - ARRAY(SELECT jsonb_array_elements_text(schema->'required')) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'items' AND jsonb_typeof(data) = 'array' THEN - IF jsonb_typeof(schema->'items') = 'object' THEN - FOR item IN SELECT jsonb_array_elements(data) LOOP - IF NOT commons.validate_json_schema(schema->'items', item, root_schema) THEN - RETURN false; - END IF; - END LOOP; - ELSE - IF NOT ( - SELECT bool_and(i > jsonb_array_length(schema->'items') OR commons.validate_json_schema(schema->'items'->(i::int - 1), elem, root_schema)) - FROM jsonb_array_elements(data) WITH ORDINALITY AS t(elem, i) - ) THEN - RETURN false; - END IF; - END IF; - END IF; - - IF jsonb_typeof(schema->'additionalItems') = 'boolean' and NOT (schema->'additionalItems')::text::boolean AND jsonb_typeof(schema->'items') = 'array' THEN - IF jsonb_array_length(data) > jsonb_array_length(schema->'items') THEN - RETURN false; - END IF; - END IF; - - IF jsonb_typeof(schema->'additionalItems') = 'object' THEN - IF NOT ( - SELECT bool_and(validate_json_schema(schema->'additionalItems', elem, root_schema)) - FROM jsonb_array_elements(data) WITH ORDINALITY AS t(elem, i) - WHERE i > jsonb_array_length(schema->'items') - ) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minimum' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric < (schema->>'minimum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maximum' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric > (schema->>'maximum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'exclusiveMinimum')::text::bool, FALSE) THEN - IF data::text::numeric = (schema->>'minimum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'exclusiveMaximum')::text::bool, FALSE) THEN - IF data::text::numeric = (schema->>'maximum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'anyOf' THEN - IF NOT (SELECT bool_or(validate_json_schema(sub_schema, data, root_schema)) FROM jsonb_array_elements(schema->'anyOf') sub_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'allOf' THEN - IF NOT (SELECT bool_and(validate_json_schema(sub_schema, data, root_schema)) FROM jsonb_array_elements(schema->'allOf') sub_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'oneOf' THEN - IF 1 != (SELECT COUNT(*) FROM jsonb_array_elements(schema->'oneOf') sub_schema WHERE commons.validate_json_schema(sub_schema, data, root_schema)) THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'uniqueItems')::text::boolean, false) THEN - IF (SELECT COUNT(*) FROM jsonb_array_elements(data)) != (SELECT count(DISTINCT val) FROM jsonb_array_elements(data) val) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'additionalProperties' AND jsonb_typeof(data) = 'object' THEN - props := ARRAY( - SELECT key - FROM jsonb_object_keys(data) key - WHERE key NOT IN (SELECT jsonb_object_keys(schema->'properties')) - AND NOT EXISTS (SELECT * FROM jsonb_object_keys(schema->'patternProperties') pat WHERE key ~ pat) - ); - IF jsonb_typeof(schema->'additionalProperties') = 'boolean' THEN - IF NOT (schema->'additionalProperties')::text::boolean AND jsonb_typeof(data) = 'object' AND NOT props <@ ARRAY(SELECT jsonb_object_keys(schema->'properties')) THEN - RETURN false; - END IF; - ELSEIF NOT ( - SELECT bool_and(validate_json_schema(schema->'additionalProperties', data->key, root_schema)) - FROM unnest(props) key - ) THEN - RETURN false; - END IF; - END IF; - - IF schema ? '$ref' THEN - path := ARRAY( - SELECT regexp_replace(regexp_replace(path_part, '~1', '/'), '~0', '~') - FROM UNNEST(regexp_split_to_array(schema->>'$ref', '/')) path_part - ); - -- ASSERT path[1] = '#', 'only refs anchored at the root are supported'; - IF NOT commons.validate_json_schema(root_schema #> path[2:array_length(path, 1)], data, root_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'enum' THEN - IF NOT EXISTS (SELECT * FROM jsonb_array_elements(schema->'enum') val WHERE val = data) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minLength' AND jsonb_typeof(data) = 'string' THEN - IF char_length(data #>> '{}') < (schema->>'minLength')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxLength' AND jsonb_typeof(data) = 'string' THEN - IF char_length(data #>> '{}') > (schema->>'maxLength')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'not' THEN - IF commons.validate_json_schema(schema->'not', data, root_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxProperties' AND jsonb_typeof(data) = 'object' THEN - IF (SELECT count(*) FROM jsonb_object_keys(data)) > (schema->>'maxProperties')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minProperties' AND jsonb_typeof(data) = 'object' THEN - IF (SELECT count(*) FROM jsonb_object_keys(data)) < (schema->>'minProperties')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxItems' AND jsonb_typeof(data) = 'array' THEN - IF (SELECT count(*) FROM jsonb_array_elements(data)) > (schema->>'maxItems')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minItems' AND jsonb_typeof(data) = 'array' THEN - IF (SELECT count(*) FROM jsonb_array_elements(data)) < (schema->>'minItems')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'dependencies' THEN - FOR prop IN SELECT jsonb_object_keys(schema->'dependencies') LOOP - IF data ? prop THEN - IF jsonb_typeof(schema->'dependencies'->prop) = 'array' THEN - IF NOT (SELECT bool_and(data ? dep) FROM jsonb_array_elements_text(schema->'dependencies'->prop) dep) THEN - RETURN false; - END IF; - ELSE - IF NOT commons.validate_json_schema(schema->'dependencies'->prop, data, root_schema) THEN - RETURN false; - END IF; - END IF; - END IF; - END LOOP; - END IF; - - IF schema ? 'pattern' AND jsonb_typeof(data) = 'string' THEN - IF (data #>> '{}') !~ (schema->>'pattern') THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'patternProperties' AND jsonb_typeof(data) = 'object' THEN - FOR prop IN SELECT jsonb_object_keys(data) LOOP - FOR pattern IN SELECT jsonb_object_keys(schema->'patternProperties') LOOP - RAISE NOTICE 'prop %s, pattern %, schema %', prop, pattern, schema->'patternProperties'->pattern; - IF prop ~ pattern AND NOT commons.validate_json_schema(schema->'patternProperties'->pattern, data->prop, root_schema) THEN - RETURN false; - END IF; - END LOOP; - END LOOP; - END IF; - - IF schema ? 'multipleOf' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric % (schema->>'multipleOf')::numeric != 0 THEN - RETURN false; - END IF; - END IF; - - RETURN true; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP FUNCTION commons._validate_json_schema_type(text, jsonb); - DROP FUNCTION commons.validate_json_schema(jsonb, jsonb, jsonb); - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190430175410-com-f-validate-quill-doc.js b/server/db-migrate/migrations/_migration_archive/20190430175410-com-f-validate-quill-doc.js deleted file mode 100644 index c266d74c5..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190430175410-com-f-validate-quill-doc.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION commons.validate_quill_doc(quillDoc jsonb) RETURNS boolean AS $f$ - DECLARE - isValid boolean; - BEGIN - SELECT INTO isValid commons.validate_json_schema('{ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "QuillDoc": { - "type": "object", - "properties": { - "latestId": { - "type": "number" - }, - "ops": { - "type": "array", - "items": { - "$ref": "#/definitions/Op" - } - } - }, - "required": [ - "latestId" - ], - "additionalProperties": false - }, - "Op": { - "type": "object", - "properties": { - "insert": { - "type": "string", - "minLength": 1, - "maxLength": 1 - }, - "attributes": { - "type": "object", - "properties": { - "charid": { - "type": "string" - }, - "blockid": { - "type": "string" - } - } - } - }, - "required": [ - "insert" - ], - "additionalProperties": false - } - }, - "$ref": "#/definitions/QuillDoc" - }'::jsonb, quillDoc); - RETURN isValid; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - - - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP FUNCTION commons.validate_quill_doc(jsonb); - - - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190430182536-com-f-quill-functions.js b/server/db-migrate/migrations/_migration_archive/20190430182536-com-f-quill-functions.js deleted file mode 100644 index 1fabc248b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190430182536-com-f-quill-functions.js +++ /dev/null @@ -1,93 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - - CREATE OR REPLACE FUNCTION commons.text_to_quill_doc(text text) RETURNS jsonb AS $f$ - DECLARE - latestId int; - ops jsonb; - char text; - BEGIN - ops = jsonb_build_array(); - latestId = 1; - - -- LOOP over text characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(text,'')) AS x(chars)) - LOOP - - - IF char = E'\n' THEN - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - ELSE - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('charid', to_json(latestId::text)::jsonb) - ); - END IF; - - - latestId = latestId + 1; - END LOOP; - - ops = ops || jsonb_build_object( - 'insert', E'\n', - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - - RETURN jsonb_build_object('latestId',latestId, 'ops', ops); - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - - - CREATE OR REPLACE FUNCTION commons.quill_doc_to_text( - text_property_quill_doc jsonb, - OUT string text) - RETURNS text - LANGUAGE 'sql' - AS $BODY$ - - SELECT TRIM( TRAILING E'\n' FROM STRING_AGG(l.ops->>'insert', '')) - FROM (SELECT jsonb_array_elements(text_property_quill_doc->'ops') as ops) as l - $BODY$; - - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - - DROP FUNCTION commons.quill_doc_to_text(jsonb); - DROP FUNCTION commons.text_to_quill_doc(text); - ` - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190502152301-com-f-appellation-label-to-quill-doc.js b/server/db-migrate/migrations/_migration_archive/20190502152301-com-f-appellation-label-to-quill-doc.js deleted file mode 100644 index 3af8a071f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190502152301-com-f-appellation-label-to-quill-doc.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - - const sql = ` - CREATE OR REPLACE FUNCTION commons.appellation_label_to_quill_doc(orig jsonb) RETURNS jsonb AS $f$ - - BEGIN - RETURN commons.text_to_quill_doc(information.appellation_label_to_string(orig)); - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; - - ` - - db.runSql(sql, callback) - -}; - -exports.down = function (db, callback) { - - const sql = ` - DROP FUNCTION commons.appellation_label_to_quill_doc(jsonb) - `; - - db.runSql(sql, callback) -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506071619-redesign-schemas.js b/server/db-migrate/migrations/_migration_archive/20190506071619-redesign-schemas.js deleted file mode 100644 index 043e9d729..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506071619-redesign-schemas.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506071619-redesign-schemas-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506071619-redesign-schemas-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506075103-com-schema-setup.js b/server/db-migrate/migrations/_migration_archive/20190506075103-com-schema-setup.js deleted file mode 100644 index 0d60fb92b..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506075103-com-schema-setup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506075103-com-schema-setup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506075103-com-schema-setup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506093848-sys-schema-setup.js b/server/db-migrate/migrations/_migration_archive/20190506093848-sys-schema-setup.js deleted file mode 100644 index afb1f17df..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506093848-sys-schema-setup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506093848-sys-schema-setup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506093848-sys-schema-setup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506114340-com-f-make-child-of-text.js b/server/db-migrate/migrations/_migration_archive/20190506114340-com-f-make-child-of-text.js deleted file mode 100644 index f877cea97..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506114340-com-f-make-child-of-text.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114340-com-f-make-child-of-text-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114340-com-f-make-child-of-text-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506114345-com-f-change-fk-reference.js b/server/db-migrate/migrations/_migration_archive/20190506114345-com-f-change-fk-reference.js deleted file mode 100644 index d2864bb54..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506114345-com-f-change-fk-reference.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114345-com-f-change-fk-reference-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114345-com-f-change-fk-reference-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506114350-pro-schema-setup.js b/server/db-migrate/migrations/_migration_archive/20190506114350-pro-schema-setup.js deleted file mode 100644 index 05941317e..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506114350-pro-schema-setup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114350-pro-schema-setup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114350-pro-schema-setup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190506114351-pro-schema-setup-2.js b/server/db-migrate/migrations/_migration_archive/20190506114351-pro-schema-setup-2.js deleted file mode 100644 index 491bea4db..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190506114351-pro-schema-setup-2.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114351-pro-schema-setup-2-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190506114351-pro-schema-setup-2-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507092124-pro-change-pk-project-to-pk-entity.js b/server/db-migrate/migrations/_migration_archive/20190507092124-pro-change-pk-project-to-pk-entity.js deleted file mode 100644 index 44613f3cd..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507092124-pro-change-pk-project-to-pk-entity.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507092124-pro-change-pk-project-to-pk-entity-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507092124-pro-change-pk-project-to-pk-entity-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507105746-pro-t-drop-namespace-project-rel.js b/server/db-migrate/migrations/_migration_archive/20190507105746-pro-t-drop-namespace-project-rel.js deleted file mode 100644 index 962c6a4e0..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507105746-pro-t-drop-namespace-project-rel.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507105746-pro-t-drop-namespace-project-rel-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507105746-pro-t-drop-namespace-project-rel-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507115233-inf-schema-setup.js b/server/db-migrate/migrations/_migration_archive/20190507115233-inf-schema-setup.js deleted file mode 100644 index 9299b1566..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507115233-inf-schema-setup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507115233-inf-schema-setup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507115233-inf-schema-setup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507131338-inf-text-property-rework.js b/server/db-migrate/migrations/_migration_archive/20190507131338-inf-text-property-rework.js deleted file mode 100644 index 6044eeb0c..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507131338-inf-text-property-rework.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507131338-inf-text-property-rework-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507131338-inf-text-property-rework-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507142741-inf-appellation-rework.js b/server/db-migrate/migrations/_migration_archive/20190507142741-inf-appellation-rework.js deleted file mode 100644 index 0e21eeb80..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507142741-inf-appellation-rework.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507142741-inf-appellation-rework-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507142741-inf-appellation-rework-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507150941-com-f-characterize-quill-doc.js b/server/db-migrate/migrations/_migration_archive/20190507150941-com-f-characterize-quill-doc.js deleted file mode 100644 index 91fc82720..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507150941-com-f-characterize-quill-doc.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507150942-com-f-characterize-quill-doc-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507150942-com-f-characterize-quill-doc-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190507150942-dat-schema-setup.js b/server/db-migrate/migrations/_migration_archive/20190507150942-dat-schema-setup.js deleted file mode 100644 index 454b2ec59..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190507150942-dat-schema-setup.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507150942-dat-schema-setup-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190507150942-dat-schema-setup-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190508075346-dat-schema-tables.js b/server/db-migrate/migrations/_migration_archive/20190508075346-dat-schema-tables.js deleted file mode 100644 index 249fd4c32..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190508075346-dat-schema-tables.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508075346-dat-schema-tables-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508075346-dat-schema-tables-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190508075347-inf-rework-entity-association.js b/server/db-migrate/migrations/_migration_archive/20190508075347-inf-rework-entity-association.js deleted file mode 100644 index 7e585bc3a..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190508075347-inf-rework-entity-association.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508075347-inf-rework-entity-association-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508075347-inf-rework-entity-association-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190508085220-inf-t-property-of-property.js b/server/db-migrate/migrations/_migration_archive/20190508085220-inf-t-property-of-property.js deleted file mode 100644 index 927d77673..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190508085220-inf-t-property-of-property.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508085220-inf-t-property-of-property-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508085220-inf-t-property-of-property-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190508113041-pro-dfh-class-proj-rel-change.js b/server/db-migrate/migrations/_migration_archive/20190508113041-pro-dfh-class-proj-rel-change.js deleted file mode 100644 index 6df47c745..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190508113041-pro-dfh-class-proj-rel-change.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508113041-pro-dfh-class-proj-rel-change-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190508113041-pro-dfh-class-proj-rel-change-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190509120135-pro-class-field-config.js b/server/db-migrate/migrations/_migration_archive/20190509120135-pro-class-field-config.js deleted file mode 100644 index 6a0a747f6..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190509120135-pro-class-field-config.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190509120135-pro-class-field-config-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190509120135-pro-class-field-config-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190509144358-dat-v-digital-version.js b/server/db-migrate/migrations/_migration_archive/20190509144358-dat-v-digital-version.js deleted file mode 100644 index faeefb32d..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190509144358-dat-v-digital-version.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190509144358-dat-v-digital-version-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190509144358-dat-v-digital-version-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/20190510085733-refactorings.js b/server/db-migrate/migrations/_migration_archive/20190510085733-refactorings.js deleted file mode 100644 index 9755cb49f..000000000 --- a/server/db-migrate/migrations/_migration_archive/20190510085733-refactorings.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; -var fs = require('fs'); -var path = require('path'); -var Promise; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; - Promise = options.Promise; -}; - -exports.up = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190510085733-refactorings-up.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports.down = function(db) { - var filePath = path.join(__dirname, 'sqls', '20190510085733-refactorings-down.sql'); - return new Promise( function( resolve, reject ) { - fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ - if (err) return reject(err); - console.log('received data: ' + data); - - resolve(data); - }); - }) - .then(function(data) { - return db.runSql(data); - }); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-down.sql deleted file mode 100644 index e8dfe0849..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-down.sql +++ /dev/null @@ -1,30 +0,0 @@ - -------------------------------------------------------------------------- --- 5. drom schema che -------------------------------------------------------------------------- - -CREATE SCHEMA che; - -------------------------------------------------------------------------- --- 4. rename schema sources --> data -------------------------------------------------------------------------- - -ALTER SCHEMA data RENAME TO sources; - -------------------------------------------------------------------------- --- 3. Create empty schema system -------------------------------------------------------------------------- - -DROP SCHEMA system; - -------------------------------------------------------------------------- --- 2. Create empty schema commons -------------------------------------------------------------------------- - -DROP SCHEMA commons; - -------------------------------------------------------------------------- --- 1. RENAME SCHEMA commons --> projects -------------------------------------------------------------------------- - -ALTER SCHEMA projects RENAME TO commons; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-up.sql deleted file mode 100644 index 682e17eb0..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506071619-redesign-schemas-up.sql +++ /dev/null @@ -1,30 +0,0 @@ -------------------------------------------------------------------------- --- 1. RENAME SCHEMA commons --> projects -------------------------------------------------------------------------- - -ALTER SCHEMA commons RENAME TO projects; - - -------------------------------------------------------------------------- --- 2. Create empty schema commons -------------------------------------------------------------------------- - -CREATE SCHEMA commons; - -------------------------------------------------------------------------- --- 3. Create empty schema system -------------------------------------------------------------------------- - -CREATE SCHEMA system; - -------------------------------------------------------------------------- --- 4. rename schema sources --> data -------------------------------------------------------------------------- - -ALTER SCHEMA sources RENAME TO data; - -------------------------------------------------------------------------- --- 5. drom schema che -------------------------------------------------------------------------- - -DROP SCHEMA che; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-down.sql deleted file mode 100644 index d0ced16f8..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-down.sql +++ /dev/null @@ -1,61 +0,0 @@ --- 11 -DROP FUNCTION commons.rename_versioned_table; - --- 10. -DROP FUNCTION commons.move_entity_child_with_vt_to_schema; - --- 9. -DROP FUNCTION commons.change_parent_entity_table; - --- 8. -DROP FUNCTION commons.reinit_versioning_triggers; - --- 7. -DROP VIEW commons.v_text_version; - --- 6. -DROP TRIGGER sync_quill_doc_and_string ON commons.text; - --- 5. -DROP FUNCTION commons.text__sync_quill_doc_and_string(); - --- 4. DROP text_vt -DROP TABLE commons.text_vt; - --- 3. DROP the generic text table -DROP TABLE commons.text; - - --- 1. Move all the function from renamed commons schema to projects schema -ALTER FUNCTION commons.quill_doc_to_string RENAME TO quill_doc_to_text; - -ALTER FUNCTION commons.string_to_quill_doc RENAME TO text_to_quill_doc; - -ALTER FUNCTION commons.appellation_label_to_quill_doc SET SCHEMA projects; - -ALTER FUNCTION commons.create_entity_version_key SET SCHEMA projects; - -ALTER FUNCTION commons.evpr_fk_entity_fk_entity_version SET SCHEMA projects; - -ALTER FUNCTION commons.init_entity_child_table SET SCHEMA projects; - -ALTER FUNCTION commons.insert_schema_table_name SET SCHEMA projects; - -ALTER FUNCTION commons.modernize_quill_doc SET SCHEMA projects; - -ALTER FUNCTION commons.quill_doc_to_text SET SCHEMA projects; - -ALTER FUNCTION commons.text_to_quill_doc SET SCHEMA projects; - -ALTER FUNCTION commons.tmsp_creation SET SCHEMA projects; - -ALTER FUNCTION commons.tmsp_last_modification SET SCHEMA projects; - -ALTER FUNCTION commons.update_entity_version_key SET SCHEMA projects; - -ALTER FUNCTION commons.validate_json_schema SET SCHEMA projects; - -ALTER FUNCTION commons._validate_json_schema_type SET SCHEMA projects; - -ALTER FUNCTION commons.validate_quill_doc SET SCHEMA projects; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-up.sql deleted file mode 100644 index 8645dc85f..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506075103-com-schema-setup-up.sql +++ /dev/null @@ -1,305 +0,0 @@ --- 1. Move all the function from renamed projects schema to commons schema - -ALTER FUNCTION projects.appellation_label_to_quill_doc SET SCHEMA commons; - -ALTER FUNCTION projects.create_entity_version_key SET SCHEMA commons; - -ALTER FUNCTION projects.evpr_fk_entity_fk_entity_version SET SCHEMA commons; - -ALTER FUNCTION projects.init_entity_child_table SET SCHEMA commons; - -ALTER FUNCTION projects.insert_schema_table_name SET SCHEMA commons; - -ALTER FUNCTION projects.modernize_quill_doc SET SCHEMA commons; - -ALTER FUNCTION projects.quill_doc_to_text SET SCHEMA commons; - -ALTER FUNCTION projects.text_to_quill_doc SET SCHEMA commons; - -ALTER FUNCTION projects.tmsp_creation SET SCHEMA commons; - -ALTER FUNCTION projects.tmsp_last_modification SET SCHEMA commons; - -ALTER FUNCTION projects.update_entity_version_key SET SCHEMA commons; - -ALTER FUNCTION projects.validate_json_schema SET SCHEMA commons; - -ALTER FUNCTION projects._validate_json_schema_type SET SCHEMA commons; - -ALTER FUNCTION projects.validate_quill_doc SET SCHEMA commons; - -ALTER FUNCTION commons.quill_doc_to_text RENAME TO quill_doc_to_string; - -ALTER FUNCTION commons.text_to_quill_doc RENAME TO string_to_quill_doc; - --- 3. Create the generic text table - -CREATE TABLE commons.text ( - pk_text serial PRIMARY KEY, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - quill_doc jsonb NOT NULL CHECK (commons.validate_quill_doc(quill_doc)), - string text NOT NULL -); - --- 4. Create the text_vt - -CREATE TABLE commons.text_vt (LIKE commons.text); - --- 5. Create trigger function for syncing quill_doc and string - - -CREATE OR REPLACE FUNCTION commons.text__sync_quill_doc_and_string() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - string_is_new boolean; - quill_doc_is_new boolean; - BEGIN - - IF TG_OP = 'UPDATE' THEN - string_is_new = (NEW.string IS NOT NULL AND NEW.string != OLD.string); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL AND NEW.quill_doc != OLD.quill_doc); - ELSE - string_is_new = (NEW.string IS NOT NULL); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL); - END IF; - -- other code - - IF (string_is_new = true AND quill_doc_is_new = true) THEN - RAISE EXCEPTION 'You can not provide a string and a quill_doc at the same time when upserting a text.'; - ELSIF string_is_new = true THEN - NEW.quill_doc = commons.string_to_quill_doc(NEW.string); - ELSIF quill_doc_is_new = true THEN - NEW.string = commons.quill_doc_to_string(NEW.quill_doc); - ELSIF NEW.string IS NULL AND NEW.quill_doc IS NULL THEN - RAISE EXCEPTION 'No string or quill_doc provided on upsert of a text.'; - END IF; - - RETURN NEW; - END; - $BODY$; --- 6. Create trigger for syncing quill_doc and string -CREATE TRIGGER sync_quill_doc_and_string - BEFORE INSERT OR UPDATE - ON commons.text - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - - --- 7. Create view of text versions -CREATE VIEW commons.v_text_version AS - SELECT t.*, - concat((t.pk_text || '_'::text) || t.entity_version) AS pk_text_version - FROM commons.text t -UNION ALL - SELECT t.*, - concat((t.pk_text || '_'::text) || t.entity_version) AS pk_text_version - FROM commons.text_vt t; - - - --- 8. Create function to move tables with a version table (_vt) -CREATE FUNCTION commons.reinit_versioning_triggers( - schema_and_table_name character varying, - schema_and_table_vt_name character varying DEFAULT NULL::varchar - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - IF schema_and_table_vt_name IS NULL THEN - schema_and_table_vt_name = schema_and_table_name || '_vt'; - END IF; - - -- Do the Magic: - - EXECUTE format(' - - -- Trigger: versioning_trigger - - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s; - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%2$s'', true - ); - - -- Trigger: create_entity_version_key - - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s; - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s; - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name, - schema_and_table_vt_name - ); - - END - $BODY$; - - - - --- 9. Create function to change the parent entity table -CREATE FUNCTION commons.change_parent_entity_table( - child_schema_and_table_name character varying, - old_parent_schema_and_table_name character varying, - new_parent_schema_and_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; - ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; - UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; - ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; - - ALTER TABLE %1$s NO INHERIT %2$s; - ALTER TABLE %1$s INHERIT %3$s; - SELECT setval(''%3$s_pk_entity_seq'', (SELECT MAX(pk_entity) FROM %1$s)); - ', - child_schema_and_table_name, - old_parent_schema_and_table_name, - new_parent_schema_and_table_name - ); - - END - $BODY$; - - - - --- 10. Create function to move entity child table with versioning to another schema -CREATE FUNCTION commons.move_entity_child_with_vt_to_schema( - table_name character varying, - old_schema character varying, - new_schema character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - -- MOVE TABLES - ALTER TABLE %2$s.%1$s SET SCHEMA %3$s; - ALTER TABLE %2$s.%1$s_vt SET SCHEMA %3$s; - - -- REINIT VERSIONING TRIGGERS - SELECT commons.reinit_versioning_triggers(''%3$s.%1$s''); - - -- CHANGE PARENT ENTITY TABLE - SELECT commons.change_parent_entity_table(''%3$s.%1$s'', ''%2$s.entity'', ''%3$s.entity'') - ', - table_name, - old_schema, - new_schema - ); - - END - $BODY$; - --- 11. Rename table with version table -CREATE FUNCTION commons.rename_versioned_table( - schema character varying, - old_table_name character varying, - new_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ALTER TABLE %1$s.%2$s RENAME TO %3$s; - ALTER TABLE %1$s.%2$s_vt RENAME TO %3$s_vt; - SELECT commons.reinit_versioning_triggers(''%1$s.%3$s''); - ', - schema, - old_table_name, - new_table_name - ); - - END - $BODY$; - - --- 12. Init version table (independend of being entity child) -CREATE OR REPLACE FUNCTION commons.init_version_table( - schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' -AS $BODY$ - BEGIN - - - -- Do the Magic: - - EXECUTE format(' - - ALTER TABLE %1$s ADD COLUMN IF NOT EXISTS - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name - ); - - END - $BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-down.sql deleted file mode 100644 index dffe23a1f..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-down.sql +++ /dev/null @@ -1,31 +0,0 @@ --- 10 -DROP TABLE system.system_relevant_type; -DROP TABLE system.system_relevant_type_vt; - --- 9 -DROP TABLE system.system_relevant_class; -DROP TABLE system.system_relevant_class_vt; - --- 8 -SELECT commons.rename_versioned_table('system', 'app_context', 'ui_context'); - --- 7 -ALTER TABLE system.system_type ADD COLUMN pk_system_type serial PRIMARY KEY; - --- 6 -SELECT commons.move_entity_child_with_vt_to_schema('class_has_type_property', 'system', 'projects'); - --- 5 -SELECT commons.move_entity_child_with_vt_to_schema('class_field_property_rel', 'system', 'projects'); - --- 4 -SELECT commons.move_entity_child_with_vt_to_schema('class_field', 'system', 'projects'); - --- 3 -SELECT commons.move_entity_child_with_vt_to_schema('ui_context', 'system', 'projects'); - --- 2 -SELECT commons.move_entity_child_with_vt_to_schema('system_type', 'system', 'projects'); - --- 1. -DROP TABLE system.entity; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-up.sql deleted file mode 100644 index 50fb1de5d..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506093848-sys-schema-setup-up.sql +++ /dev/null @@ -1,79 +0,0 @@ -------------------------------------------------------------------------- --- 1. REWORK SCHEMA SYSTEM_CONFIG -------------------------------------------------------------------------- - -CREATE TABLE system.entity ( - pk_entity serial PRIMARY KEY, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp WITH time zone DEFAULT now(), - tmsp_last_modification timestamp WITH time zone, - sys_period tstzrange DEFAULT tstzrange( now(), NULL::timestamp WITH time zone) -); - -------------------------------------------------------------------------- --- 2. MOVE TABLE system_type with versioning table -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('system_type', 'projects', 'system'); - - -------------------------------------------------------------------------- --- 3. MOVE TABLE ui_context with versioning table -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('ui_context', 'projects', 'system'); - -------------------------------------------------------------------------- --- 4. MOVE TABLE class_field with versioning table -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('class_field', 'projects', 'system'); - -------------------------------------------------------------------------- --- 5. MOVE TABLE class_field_property_rel with versioning table -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('class_field_property_rel', 'projects', 'system'); - -------------------------------------------------------------------------- --- 6. MOVE TABLE class_has_type_property with versioning table -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('class_has_type_property', 'projects', 'system'); - - -------------------------------------------------------------------------- --- 7. DROP system_type.pk_system_type -------------------------------------------------------------------------- -DROP VIEW IF EXISTS projects.v_system_type_label_text_property; -DROP VIEW IF EXISTS projects.v_project_label_text_property; -ALTER TABLE system.system_type DROP COLUMN pk_system_type; - -------------------------------------------------------------------------- --- 8. RENAME ui_context --> app_context -------------------------------------------------------------------------- -SELECT commons.rename_versioned_table('system', 'ui_context', 'app_context'); - -------------------------------------------------------------------------- --- 9. CREATE TABLE system_relevant_class -------------------------------------------------------------------------- -CREATE TABLE system.system_relevant_class ( - fk_class integer NOT NULL, - required_by_entities boolean, - required_by_sources boolean, - required_by_contr_vocabs boolean, - FOREIGN KEY (fk_class) REFERENCES data_for_history.class (dfh_pk_class) -) -INHERITS (system.entity); -SELECT commons.init_entity_child_table ('system.system_relevant_class'); - - -------------------------------------------------------------------------- --- 10. CREATE TABLE system_relevant_type -------------------------------------------------------------------------- -CREATE TABLE system.system_relevant_type ( - fk_type integer NOT NULL, - FOREIGN KEY (fk_type) REFERENCES information.persistent_item (pk_entity) -) -INHERITS (system.entity); -SELECT commons.init_entity_child_table ('system.system_relevant_type'); \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-down.sql deleted file mode 100644 index 3e25f5288..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-down.sql +++ /dev/null @@ -1,11 +0,0 @@ --- 4 -DROP FUNCTION commons.unmake_versioned_table_child_of_text(character varying); - --- 3 -DROP FUNCTION commons.unmake_table_child_of_text(character varying, character varying); - --- 2 -DROP FUNCTION commons.make_versioned_table_child_of_text(character varying); - --- 1 -DROP FUNCTION commons.make_table_child_of_text(character varying, character varying); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-up.sql deleted file mode 100644 index c35657de1..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114340-com-f-make-child-of-text-up.sql +++ /dev/null @@ -1,132 +0,0 @@ - --- 1. Create a function to make versioned table child of commons.text -CREATE FUNCTION commons.make_table_child_of_text( - schema_and_table_name character varying, - parent_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ------ PREPARE THE TABLE - - UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; - - ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; - - -- SET schema_name NOT NULL - ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; - - -- SET table_name NOT NULL - ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; - - -- Add the column for the pk_text and fill the new pk_text column - ALTER TABLE %1$s - ADD COLUMN pk_text integer NOT NULL DEFAULT nextval(''commons.text_pk_text_seq''); - - -- Add the column for quill_doc and fill it with empty QuillDoc - ALTER TABLE %1$s ADD COLUMN quill_doc jsonb; - UPDATE %1$s SET quill_doc = jsonb_build_object(''latestId'', 0, ''ops'', ARRAY[]::integer[]) WHERE quill_doc IS NULL; - ALTER TABLE %1$s ALTER COLUMN quill_doc SET NOT NULL; - - -- Add the schema validation check - ALTER TABLE %1$s - ADD CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)); - - -- Add the column for string and fill with empty string - ALTER TABLE %1$s ADD COLUMN string text DEFAULT ''''; - UPDATE %1$s SET string = '''' WHERE string IS NULL; - ALTER TABLE %1$s ALTER COLUMN string SET NOT NULL; - - ---- SET THE INHERITANCE - ALTER TABLE %1$s - INHERIT commons.%2$s; - - ', - schema_and_table_name, - parent_table_name - ); - - END - $BODY$; - - --- 3. Create a function to make versioned table child of commons.text -CREATE FUNCTION commons.make_versioned_table_child_of_text( - schema_and_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ BEGIN - - PERFORM commons.make_table_child_of_text(schema_and_table_name, 'text'); - PERFORM commons.make_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); - - EXECUTE format(' - -- Create trigger for syncing quill_doc and string - CREATE TRIGGER sync_quill_doc_and_string - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - ', schema_and_table_name); - - - END $BODY$; - - - --- 3. Create a function to unmake versioned table child of commons.text -CREATE FUNCTION commons.unmake_table_child_of_text( - schema_and_table_name character varying, - parent_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ - - BEGIN - - EXECUTE format(' - ALTER TABLE %1$s NO INHERIT commons.%2$s; - - ALTER TABLE %1$s DROP COLUMN string; - - ALTER TABLE %1$s DROP CONSTRAINT text_quill_doc_check; - - ALTER TABLE %1$s DROP COLUMN quill_doc; - - ALTER TABLE %1$s DROP COLUMN pk_text; - - ', - schema_and_table_name, - parent_table_name - ); - - END - $BODY$; - - --- 4. Create a function to unmake versioned table child of commons.text -CREATE FUNCTION commons.unmake_versioned_table_child_of_text( - schema_and_table_name character varying - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ BEGIN - - PERFORM commons.unmake_table_child_of_text(schema_and_table_name, 'text'); - PERFORM commons.unmake_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); - - EXECUTE format(' - DROP TRIGGER sync_quill_doc_and_string ON %1$s; - ', schema_and_table_name); - - END $BODY$; - - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-down.sql deleted file mode 100644 index 8a7345f18..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-down.sql +++ /dev/null @@ -1,4 +0,0 @@ --- 2 -DROP FUNCTION commons.unmake_change_fk_reference_of_versioned_table; --- 1 -DROP FUNCTION commons.change_fk_reference_of_versioned_table; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-up.sql deleted file mode 100644 index 0813a677a..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114345-com-f-change-fk-reference-up.sql +++ /dev/null @@ -1,168 +0,0 @@ - --- 1. Create a function to change the reference of a FK -CREATE FUNCTION commons.change_fk_reference_of_versioned_table( - schema_name varchar, - table_name varchar, - fk_column varchar, - referenced_schema_and_table_name varchar, - old_referenced_column varchar, - new_referenced_column varchar, - fk_col_not_null boolean DEFAULT true::boolean - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ BEGIN - - EXECUTE format(' - - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; - DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; - - - -- table - ALTER TABLE %1$s.%2$s RENAME COLUMN %3$s TO _deprecated_%3$s; - ALTER TABLE %1$s.%2$s ADD COLUMN %3$s integer; - UPDATE %1$s.%2$s - SET %3$s = subq.%6$s - FROM ( - SELECT %6$s, %5$s - FROM %4$s - ) as subq - WHERE _deprecated_%3$s = subq.%5$s; - - ALTER TABLE %1$s.%2$s - DROP CONSTRAINT IF EXISTS %2$s_%3$s_fkey; - - ALTER TABLE %1$s.%2$s ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); - - -- table_vt - ALTER TABLE %1$s.%2$s_vt RENAME COLUMN %3$s TO _deprecated_%3$s; - ALTER TABLE %1$s.%2$s_vt ADD COLUMN %3$s integer; - UPDATE %1$s.%2$s_vt - SET %3$s = subq.%6$s - FROM ( - SELECT %6$s, %5$s - FROM %4$s - ) as subq - WHERE _deprecated_%3$s = subq.%5$s; - - ALTER TABLE %1$s.%2$s_vt - DROP CONSTRAINT IF EXISTS %2$s_vt_%3$s_fkey; - - ALTER TABLE %1$s.%2$s_vt ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); - - SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); - - -- Trigger: creation_tmsp - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - - - ', - schema_name, - table_name, - fk_column, - referenced_schema_and_table_name, - old_referenced_column, - new_referenced_column - ); - - - IF (fk_col_not_null = true) THEN - EXECUTE format(' - ALTER TABLE %1$s.%2$s ALTER COLUMN %3$s SET NOT NULL; - ', schema_name, - table_name, - fk_column ); - END IF; - - - END $BODY$; - - --- 2. Create unmake change fk reference -CREATE FUNCTION commons.unmake_change_fk_reference_of_versioned_table( - schema_name varchar, - table_name varchar, - fk_column varchar - ) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ BEGIN - - EXECUTE format(' - - DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; - DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; - - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; - - -- table_vt - ALTER TABLE %1$s.%2$s_vt DROP CONSTRAINT %2$s_vt_%3$s_fkey; - UPDATE %1$s.%2$s_vt - SET %3$s = _deprecated_%3$s; - ALTER TABLE %1$s.%2$s_vt DROP COLUMN %3$s; - ALTER TABLE %1$s.%2$s_vt RENAME COLUMN _deprecated_%3$s TO %3$s; - - -- table - ALTER TABLE %1$s.%2$s DROP CONSTRAINT %2$s_%3$s_fkey; - UPDATE %1$s.%2$s - SET %3$s = _deprecated_%3$s; - ALTER TABLE %1$s.%2$s DROP COLUMN %3$s; - ALTER TABLE %1$s.%2$s RENAME COLUMN _deprecated_%3$s TO %3$s; - - - SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); - - -- Trigger: creation_tmsp - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - ', - schema_name, - table_name, - fk_column - ); - - END $BODY$; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-down.sql deleted file mode 100644 index 9b719ad1b..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-down.sql +++ /dev/null @@ -1,47 +0,0 @@ - --- 9 -SELECT commons.rename_versioned_table ('projects', '_deprecated_label', 'label'); - - --- 8 -ALTER TABLE projects.project DROP CONSTRAINT project_fk_language_fkey; -ALTER TABLE projects.project DROP COLUMN fk_language; -ALTER TABLE projects.project RENAME COLUMN _deprecated_fk_language TO fk_language; -ALTER TABLE projects.project_vt RENAME COLUMN _deprecated_fk_language TO fk_language; -ALTER TABLE projects.project ADD FOREIGN KEY (fk_language) REFERENCES projects.language (pk_language); - --- 7 -ALTER TABLE projects.text_property DROP CONSTRAINT text_property_fk_system_type_fkey; -ALTER TABLE system.system_type DROP CONSTRAINT unique_note; - --- 6 -ALTER TABLE projects.text_property DROP CONSTRAINT text_property_fk_language_fkey; -ALTER TABLE projects.text_property DROP COLUMN fk_language; -ALTER TABLE projects.text_property RENAME COLUMN _deprecated_fk_language TO fk_language; -ALTER TABLE projects.text_property_vt RENAME COLUMN _deprecated_fk_language TO fk_language; -ALTER TABLE projects.text_property ADD FOREIGN KEY (fk_language) REFERENCES projects.language (pk_language); - --- 5 -ALTER TABLE projects.text_property_vt RENAME COLUMN _deprecated_text_property TO text_property; -ALTER TABLE projects.text_property RENAME COLUMN _deprecated_text_property TO text_property; -ALTER TABLE projects.text_property RENAME COLUMN _deprecated_text_property_xml TO text_property_xml; -ALTER TABLE projects.text_property_vt RENAME COLUMN _deprecated_text_property_xml TO text_property_xml; - --- 4 -SELECT commons.unmake_versioned_table_child_of_text('projects.text_property'); -ALTER TABLE projects.text_property_vt DROP COLUMN entity_version; - --- 3 -SELECT commons.reinit_versioning_triggers('projects.label', 'commons.label'); -SELECT commons.reinit_versioning_triggers('projects.language', 'commons.language'); -SELECT commons.reinit_versioning_triggers('projects.namespace_project_rel', 'commons.namespace_project_rel'); -SELECT commons.reinit_versioning_triggers('projects.query', 'commons.query'); -SELECT commons.reinit_versioning_triggers('projects.visual', 'commons.visual'); -SELECT commons.reinit_versioning_triggers('projects.text_property', 'commons.text_property'); - --- 2 -SELECT commons.rename_versioned_table('projects', 'class_field_config', 'ui_context_config'); - --- 1 -SELECT commons.rename_versioned_table('projects', 'argument', 'assertion'); -SELECT commons.change_parent_entity_table('projects.assertion', 'projects.entity', 'data.entity'); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-up.sql deleted file mode 100644 index 637ba46e4..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114350-pro-schema-setup-up.sql +++ /dev/null @@ -1,117 +0,0 @@ -------------------------------------------------------------------------- --- 1. RENAME assertion --> argument -------------------------------------------------------------------------- -SELECT commons.change_parent_entity_table('projects.assertion', 'data.entity', 'projects.entity'); - -SELECT - commons.rename_versioned_table ('projects', - 'assertion', - 'argument'); - -------------------------------------------------------------------------- --- 2. RENAME ui_context_config --> class_field_config -------------------------------------------------------------------------- - -SELECT - commons.rename_versioned_table ('projects', - 'ui_context_config', - 'class_field_config'); - -------------------------------------------------------------------------- --- 3. REINIT VERSIONING Triggers -------------------------------------------------------------------------- -SELECT - commons.reinit_versioning_triggers ('projects.project'); - -SELECT - commons.reinit_versioning_triggers ('projects.label'); - -SELECT - commons.reinit_versioning_triggers ('projects.language'); - -SELECT - commons.reinit_versioning_triggers ('projects.namespace_project_rel'); - -SELECT - commons.reinit_versioning_triggers ('projects.query'); - -SELECT - commons.reinit_versioning_triggers ('projects.visual'); - -SELECT - commons.reinit_versioning_triggers ('projects.text_property'); - -------------------------------------------------------------------------- --- 4. Make text_property child of text -------------------------------------------------------------------------- -DELETE FROM projects.text_property_vt; -- no way back -ALTER TABLE projects.text_property_vt ADD COLUMN entity_version integer; -SELECT commons.make_versioned_table_child_of_text('projects.text_property'); -UPDATE projects.text_property SET string = COALESCE(text_property, ''); - - -------------------------------------------------------------------------- --- 5. Mark unused text columns as deprecated -------------------------------------------------------------------------- -ALTER TABLE projects.text_property RENAME COLUMN text_property TO _deprecated_text_property; -ALTER TABLE projects.text_property_vt RENAME COLUMN text_property TO _deprecated_text_property; -ALTER TABLE projects.text_property RENAME COLUMN text_property_xml TO _deprecated_text_property_xml; -ALTER TABLE projects.text_property_vt RENAME COLUMN text_property_xml TO _deprecated_text_property_xml; - -------------------------------------------------------------------------- --- 6. Rework text_property.fk_language -------------------------------------------------------------------------- -ALTER TABLE projects.text_property DROP CONSTRAINT text_property_fk_language_fkey; -ALTER TABLE projects.text_property RENAME COLUMN fk_language TO _deprecated_fk_language; -ALTER TABLE projects.text_property_vt RENAME COLUMN fk_language TO _deprecated_fk_language; -ALTER TABLE projects.text_property ADD COLUMN fk_language integer; -UPDATE projects.text_property -SET fk_language = subq.pk_entity -FROM ( - SELECT pk_language, pk_entity - FROM information.language -) as subq -WHERE subq.pk_language = _deprecated_fk_language; -ALTER TABLE projects.text_property ADD FOREIGN KEY (fk_language) REFERENCES information.language (pk_entity); - -------------------------------------------------------------------------- --- 7. Rework text_property.system_type -------------------------------------------------------------------------- -ALTER TABLE system.system_type ADD CONSTRAINT unique_note UNIQUE (notes); -INSERT INTO system.system_type (notes) -VALUES ('Description of an entity.') -ON CONFLICT DO NOTHING; -UPDATE projects.text_property -SET fk_system_type = subq.pk_entity -FROM ( - SELECT notes, pk_entity - FROM system.system_type -) as subq -WHERE subq.notes = 'Description of an entity.'; -ALTER TABLE projects.text_property ADD FOREIGN KEY (fk_system_type) REFERENCES system.system_type (pk_entity); - - -------------------------------------------------------------------------- --- 8. Rework project.fk_language -------------------------------------------------------------------------- -ALTER TABLE projects.project DROP CONSTRAINT project_fk_language_fkey; -ALTER TABLE projects.project RENAME COLUMN fk_language TO _deprecated_fk_language; -ALTER TABLE projects.project_vt RENAME COLUMN fk_language TO _deprecated_fk_language; -ALTER TABLE projects.project ADD COLUMN fk_language integer; -UPDATE projects.project -SET fk_language = subq.pk_entity -FROM ( - SELECT pk_language, pk_entity - FROM information.language -) as subq -WHERE subq.pk_language = _deprecated_fk_language; -ALTER TABLE projects.project ADD FOREIGN KEY (fk_language) REFERENCES information.language (pk_entity); - -------------------------------------------------------------------------- --- 9. Mark table label as deprecated -------------------------------------------------------------------------- - -SELECT - commons.rename_versioned_table ('projects', - 'label', - '_deprecated_label'); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-down.sql deleted file mode 100644 index e1741f943..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-down.sql +++ /dev/null @@ -1,24 +0,0 @@ --- 15 -ALTER FUNCTION projects.v_info_proj_rel_update_or_creat RENAME TO v_entity_version_project_rel_update_or_create; -ALTER FUNCTION projects.v_entity_version_project_rel_update_or_create SET SCHEMA information; -ALTER VIEW projects.v_info_proj_rel RENAME TO v_entity_version_project_rel; -ALTER VIEW projects.v_entity_version_project_rel SET SCHEMA information; - --- 14 -ALTER TABLE projects.info_proj_rel RENAME COLUMN _deprecated_pk_entity_version_project_rel TO pk_entity_version_project_rel; -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN _deprecated_pk_entity_version_project_rel TO pk_entity_version_project_rel; - --- 13 -SELECT commons.rename_versioned_table('projects', 'dfh_class_proj_rel', 'proj_rel'); -SELECT commons.move_entity_child_with_vt_to_schema('proj_rel', 'projects', 'data_for_history'); - --- 12 -SELECT commons.rename_versioned_table('projects', 'info_proj_rel', 'entity_version_project_rel'); -SELECT commons.move_entity_child_with_vt_to_schema('entity_version_project_rel', 'projects', 'information'); - --- 11 -ALTER TABLE projects.text_property RENAME COLUMN _deprecated_pk_text_property TO pk_text_property; -ALTER TABLE projects.text_property_vt RENAME COLUMN _deprecated_pk_text_property TO pk_text_property; - --- 10 -DELETE FROM projects.text_property WHERE notes = 'added from _deprecated_label table'; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-up.sql deleted file mode 100644 index d7da7fd0f..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190506114351-pro-schema-setup-2-up.sql +++ /dev/null @@ -1,53 +0,0 @@ - -------------------------------------------------------------------------- --- 10. Transfer labels to table text_property -------------------------------------------------------------------------- -INSERT INTO system.system_type (notes) -VALUES ('Label of an entity.') -ON CONFLICT DO NOTHING; - -INSERT INTO projects.text_property (string, fk_system_type, notes, fk_entity) -SELECT - COALESCE(label, ''), - ( - SELECT pk_entity - from system.system_type - where notes = 'Label of an entity.' - ), - 'added from _deprecated_label table', - fk_entity -FROM projects._deprecated_label; - -------------------------------------------------------------------------- --- 11. Mark pk_text_property as deprecated on table text_property -------------------------------------------------------------------------- -ALTER TABLE projects.text_property RENAME COLUMN pk_text_property TO _deprecated_pk_text_property; -ALTER TABLE projects.text_property_vt RENAME COLUMN pk_text_property TO _deprecated_pk_text_property; - - -------------------------------------------------------------------------- --- 12. information.entity_version_project_rel --> projects.info_proj_rel -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('entity_version_project_rel', 'information', 'projects'); -SELECT commons.rename_versioned_table('projects', 'entity_version_project_rel', 'info_proj_rel'); - -------------------------------------------------------------------------- --- 13. data_for_history.proj_rel --> projects.dfh_class_proj_rel -------------------------------------------------------------------------- -SELECT commons.move_entity_child_with_vt_to_schema('proj_rel', 'data_for_history', 'projects'); -SELECT commons.rename_versioned_table('projects', 'proj_rel', 'dfh_class_proj_rel'); - -------------------------------------------------------------------------- --- 14. Mark pk_entity_version_project_rel as deprecated -------------------------------------------------------------------------- -ALTER TABLE projects.info_proj_rel RENAME COLUMN pk_entity_version_project_rel TO _deprecated_pk_entity_version_project_rel; -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN pk_entity_version_project_rel TO _deprecated_pk_entity_version_project_rel; - -------------------------------------------------------------------------- --- 15. information.v_entity_version_project_rel --> projects.v_info_proj_rel -------------------------------------------------------------------------- -ALTER VIEW information.v_entity_version_project_rel SET SCHEMA projects; -ALTER VIEW projects.v_entity_version_project_rel RENAME TO v_info_proj_rel; -ALTER FUNCTION information.v_entity_version_project_rel_update_or_create SET SCHEMA projects; -ALTER FUNCTION projects.v_entity_version_project_rel_update_or_create RENAME TO v_info_proj_rel_update_or_creat; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-down.sql deleted file mode 100644 index 874c6d05b..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-down.sql +++ /dev/null @@ -1,70 +0,0 @@ --- 22 -ALTER TABLE projects.class_field_config - ADD CONSTRAINT ui_context_config_fk_project_fkey FOREIGN KEY (_deprecated_fk_project) - REFERENCES projects.project (_deprecated_pk_project); - -SELECT commons.unmake_change_fk_reference_of_versioned_table('projects', 'class_field_config', 'fk_project'); - --- 21 -SELECT commons.unmake_change_fk_reference_of_versioned_table('public', 'account_project_rel', 'fk_project'); -DROP TABLE public.account_project_rel_vt; -DROP TRIGGER create_entity_version_key ON public.account_project_rel; -DROP TRIGGER creation_tmsp ON public.account_project_rel; -DROP TRIGGER insert_schema_table_name ON public.account_project_rel; -DROP TRIGGER last_modification_tmsp ON public.account_project_rel; -DROP TRIGGER update_entity_version_key ON public.account_project_rel; -DROP TRIGGER versioning_trigger ON public.account_project_rel; - - --- 20 -ALTER TABLE projects.dfh_class_proj_rel - ADD CONSTRAINT proj_rel_fk_project_fkey FOREIGN KEY (_deprecated_fk_project) - REFERENCES projects.project (_deprecated_pk_project); -ALTER TABLE projects.dfh_class_proj_rel DROP CONSTRAINT dfh_class_project_rel__entity_and_project_unique; -SELECT commons.unmake_change_fk_reference_of_versioned_table('projects', 'dfh_class_proj_rel', 'fk_project'); -ALTER TABLE projects.dfh_class_proj_rel - ADD CONSTRAINT proj_rel_unique UNIQUE (fk_entity, fk_project); - --- 19 -ALTER TABLE projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_project_fkey FOREIGN KEY (_deprecated_fk_project) - REFERENCES projects.project (_deprecated_pk_project); - -ALTER TABLE projects.info_proj_rel DROP CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key; -ALTER TABLE projects.info_proj_rel DROP CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key; - -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; -DROP TRIGGER on_upsert ON projects.info_proj_rel; -SELECT commons.unmake_change_fk_reference_of_versioned_table('projects', 'info_proj_rel', 'fk_project'); -CREATE TRIGGER after_epr_upsert - AFTER INSERT OR UPDATE - ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__upsert_entity_preview(); - -CREATE TRIGGER on_upsert - BEFORE INSERT OR UPDATE - ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); - -ALTER TABLE projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key UNIQUE (fk_entity, fk_project); -ALTER TABLE projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key UNIQUE (fk_entity_version_concat, fk_project); - --- 18 -ALTER TABLE projects.visual DROP CONSTRAINT visual__unique_name_per_project; -SELECT commons.unmake_change_fk_reference_of_versioned_table('projects', 'visual', 'fk_project'); -ALTER TABLE projects.visual - ADD CONSTRAINT visual__unique_name_per_project UNIQUE (name, fk_project); - --- 17 -ALTER TABLE projects.query DROP CONSTRAINT query__unique_name_per_project; -SELECT commons.unmake_change_fk_reference_of_versioned_table('projects', 'query', 'fk_project'); -ALTER TABLE projects.query - ADD CONSTRAINT unique_name_per_project UNIQUE (name, fk_project); - --- 16 -ALTER TABLE projects.project RENAME COLUMN _deprecated_pk_project TO pk_project; -ALTER TABLE projects.project_vt RENAME COLUMN _deprecated_pk_project TO pk_project; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-up.sql deleted file mode 100644 index ffd0c0781..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507092124-pro-change-pk-project-to-pk-entity-up.sql +++ /dev/null @@ -1,125 +0,0 @@ -------------------------------------------------------------------------- --- 16. Mark project (pk_project) as deprecated in favor of pk_entity -------------------------------------------------------------------------- -ALTER TABLE projects.project RENAME COLUMN pk_project TO _deprecated_pk_project; -ALTER TABLE projects.project_vt RENAME COLUMN pk_project TO _deprecated_pk_project; - -------------------------------------------------------------------------- --- 17. query: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- - -SELECT commons.change_fk_reference_of_versioned_table( - 'projects', - 'query', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity' -); -ALTER TABLE projects.query DROP CONSTRAINT unique_name_per_project; -ALTER TABLE projects.query - ADD CONSTRAINT query__unique_name_per_project UNIQUE (name, fk_project); - - - -------------------------------------------------------------------------- --- 18. visual: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- - -SELECT commons.change_fk_reference_of_versioned_table( - 'projects', - 'visual', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity' -); -ALTER TABLE projects.visual DROP CONSTRAINT visual__unique_name_per_project; -ALTER TABLE projects.visual - ADD CONSTRAINT visual__unique_name_per_project UNIQUE (name, fk_project); - - -------------------------------------------------------------------------- --- 19. info_proj_rel: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; -DROP TRIGGER on_upsert ON projects.info_proj_rel; - -SELECT commons.change_fk_reference_of_versioned_table( - 'projects', - 'info_proj_rel', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity' -); - -CREATE TRIGGER after_epr_upsert - AFTER INSERT OR UPDATE - ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__upsert_entity_preview(); - -CREATE TRIGGER on_upsert - BEFORE INSERT OR UPDATE - ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); - -ALTER TABLE projects.info_proj_rel DROP CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key; -ALTER TABLE projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key UNIQUE (fk_entity, fk_project); - -ALTER TABLE projects.info_proj_rel DROP CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key; -ALTER TABLE projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key UNIQUE (fk_entity_version_concat, fk_project); - -ALTER TABLE projects.info_proj_rel DROP CONSTRAINT entity_version_project_rel_fk_project_fkey; - - -------------------------------------------------------------------------- --- 20. dfh_class_project_rel: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- - -SELECT commons.change_fk_reference_of_versioned_table( - 'projects', - 'dfh_class_proj_rel', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity' -); -ALTER TABLE projects.dfh_class_proj_rel DROP CONSTRAINT proj_rel_unique; -ALTER TABLE projects.dfh_class_proj_rel - ADD CONSTRAINT dfh_class_project_rel__entity_and_project_unique UNIQUE (fk_entity, fk_project); -ALTER TABLE projects.dfh_class_proj_rel DROP CONSTRAINT proj_rel_fk_project_fkey; - -------------------------------------------------------------------------- --- 21. account_project_rel: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- -SELECT commons.init_version_table('public.account_project_rel'); - -SELECT commons.change_fk_reference_of_versioned_table( - 'public', - 'account_project_rel', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity' -); - -------------------------------------------------------------------------- --- 22. class_field_config: Change FK's from referencing pk_project to pk_entity -------------------------------------------------------------------------- - -SELECT commons.change_fk_reference_of_versioned_table( - 'projects', - 'class_field_config', - 'fk_project', - 'projects.project', - '_deprecated_pk_project', - 'pk_entity', - false::boolean -); - -ALTER TABLE projects.class_field_config DROP CONSTRAINT ui_context_config_fk_project_fkey; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-down.sql deleted file mode 100644 index 36c586294..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-down.sql +++ /dev/null @@ -1,103 +0,0 @@ --- 2 - -CREATE TABLE projects.namespace_project_rel_vt -( - pk_entity integer NOT NULL, - schema_name character varying COLLATE pg_catalog."default", - table_name character varying COLLATE pg_catalog."default", - entity_version integer, - notes text COLLATE pg_catalog."default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_project integer, - fk_class integer, - fk_namespace integer -); - --- 1 -CREATE TABLE projects.namespace_project_rel -( - fk_project integer, - fk_class integer, - fk_namespace integer, - CONSTRAINT commons_namespace_project_rel_pk_entity_unique UNIQUE (pk_entity) -, - CONSTRAINT namespace_project_rel_fk_project_fk_class_key UNIQUE (fk_project, fk_class) -, - CONSTRAINT namespace_project_rel_fk_class_fkey FOREIGN KEY (fk_class) - REFERENCES data_for_history.class (dfh_pk_class) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT namespace_project_rel_fk_namespace_fkey FOREIGN KEY (fk_namespace) - REFERENCES information.namespace (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT namespace_project_rel_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -) - INHERITS (projects.entity); - --- Trigger: create_entity_version_key - --- DROP TRIGGER create_entity_version_key ON projects.namespace_project_rel; - -CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - --- Trigger: creation_tmsp - --- DROP TRIGGER creation_tmsp ON projects.namespace_project_rel; - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - --- Trigger: insert_schema_table_name - --- DROP TRIGGER insert_schema_table_name ON projects.namespace_project_rel; - -CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - --- Trigger: last_modification_tmsp - --- DROP TRIGGER last_modification_tmsp ON projects.namespace_project_rel; - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - --- Trigger: update_entity_version_key - --- DROP TRIGGER update_entity_version_key ON projects.namespace_project_rel; - -CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - --- Trigger: versioning_trigger - --- DROP TRIGGER versioning_trigger ON projects.namespace_project_rel; - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON projects.namespace_project_rel - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'projects.namespace_project_rel', 'true'); \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-up.sql deleted file mode 100644 index 6ec1e1af4..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507105746-pro-t-drop-namespace-project-rel-up.sql +++ /dev/null @@ -1,5 +0,0 @@ ---1 -DROP TABLE projects.namespace_project_rel; - ---2 -DROP TABLE projects.namespace_project_rel_vt; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-down.sql deleted file mode 100644 index 8af9add10..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-down.sql +++ /dev/null @@ -1,114 +0,0 @@ --- 12 -ALTER TABLE information.entity DROP COLUMN metadata; - - --- 11 -ALTER TABLE information.appellation RENAME COLUMN _deprecated_appellation_label TO appellation_label; -ALTER TABLE information.appellation_vt RENAME COLUMN _deprecated_appellation_label TO appellation_label; -ALTER TABLE information.appellation RENAME COLUMN _deprecated_pk_appellation TO pk_appellation; -ALTER TABLE information.appellation_vt RENAME COLUMN _deprecated_pk_appellation TO pk_appellation; - --- 10 -SELECT commons.unmake_versioned_table_child_of_text('information.appellation'); -ALTER TABLE information.appellation DROP COLUMN entity_version; -ALTER TABLE information.appellation_vt DROP COLUMN entity_version; - - --- 9. ---ALTER TABLE information.text_property ALTER COLUMN _deprecated_text_property_quill_doc SET NOT NULL; - --- 8. -ALTER TABLE information.text_property RENAME COLUMN _deprecated_text_property TO text_property; -ALTER TABLE information.text_property_vt RENAME COLUMN _deprecated_text_property TO text_property; -ALTER TABLE information.text_property RENAME COLUMN _deprecated_text_property_quill_doc TO text_property_quill_doc; -ALTER TABLE information.text_property_vt RENAME COLUMN _deprecated_text_property_quill_doc TO text_property_quill_doc; - --- 7. -SELECT commons.unmake_versioned_table_child_of_text('information.text_property'); -ALTER TABLE information.text_property DROP COLUMN entity_version; -ALTER TABLE information.text_property_vt DROP COLUMN entity_version; - --- 6. -ALTER TABLE information.temporal_entity RENAME COLUMN _deprecated_pk_temporal_entity TO pk_temporal_entity; - -DROP VIEW information.v_temporal_entity; - -CREATE VIEW information.v_temporal_entity AS - SELECT temporal_entity.pk_entity, - temporal_entity.schema_name, - temporal_entity.table_name, - temporal_entity.notes, - temporal_entity.fk_creator, - temporal_entity.fk_last_modifier, - temporal_entity.tmsp_creation, - temporal_entity.tmsp_last_modification, - temporal_entity.sys_period, - temporal_entity.fk_class, - temporal_entity.pk_temporal_entity - FROM information.temporal_entity; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_find_or_create(); - --- 5. -ALTER TABLE information.role RENAME COLUMN _deprecated_pk_role TO pk_role; - --- 4. -ALTER TABLE information.persistent_item RENAME COLUMN _deprecated_pk_persistent_item TO pk_persistent_item; - -DROP VIEW information.v_persistent_item; -CREATE VIEW information.v_persistent_item AS - SELECT persistent_item.pk_entity, - persistent_item.schema_name, - persistent_item.table_name, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period, - persistent_item.fk_class, - persistent_item.pk_persistent_item - FROM information.persistent_item; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_find_or_create(); - - --- 3. -ALTER TABLE information._deprecated_namespace - ADD CONSTRAINT namespace_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project (_deprecated_pk_project); - -SELECT - commons.rename_versioned_table ('information', - '_deprecated_namespace', - 'namespace'); - --- 2. - -SELECT - commons.rename_versioned_table ('information', - '_deprecated_type_namespace_rel', - 'type_namespace_rel'); - --- 1. - -CREATE TABLE information.sourcing ( - pk_sourcing serial PRIMARY KEY, - fk_source integer, - fk_entity integer, - fk_system_type integer, - position_in_source text) -INHERITS ( - information.entity -); - -SELECT - commons.init_entity_child_table ('information.sourcing'); - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-up.sql deleted file mode 100644 index 18c87aa5e..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507115233-inf-schema-setup-up.sql +++ /dev/null @@ -1,136 +0,0 @@ -------------------------------------------------------------------------- --- 1. DROP table SOURCING -------------------------------------------------------------------------- - -DROP TABLE information.sourcing; - -DROP TABLE information.sourcing_vt; - -------------------------------------------------------------------------- --- 2. Mark table type_namespace_rel as Deprecated -------------------------------------------------------------------------- - -SELECT - commons.rename_versioned_table ('information', - 'type_namespace_rel', - '_deprecated_type_namespace_rel'); - -------------------------------------------------------------------------- --- 3. Mark table namespace as Deprecated -------------------------------------------------------------------------- - -SELECT - commons.rename_versioned_table ('information', - 'namespace', - '_deprecated_namespace'); - -ALTER TABLE information._deprecated_namespace DROP CONSTRAINT namespace_fk_project_fkey; - -------------------------------------------------------------------------- --- 4. Mark pk_persistent_item as Deprecated and remove it from v_persistent_item -------------------------------------------------------------------------- -DROP VIEW information.v_persistent_item; -CREATE VIEW information.v_persistent_item AS - SELECT persistent_item.pk_entity, - persistent_item.schema_name, - persistent_item.table_name, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period, - persistent_item.fk_class - FROM information.persistent_item; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_find_or_create(); - -ALTER TABLE information.persistent_item RENAME COLUMN pk_persistent_item TO _deprecated_pk_persistent_item; - - -------------------------------------------------------------------------- --- 5. Mark pk_role as Deprecated -------------------------------------------------------------------------- -ALTER TABLE information.role RENAME COLUMN pk_role TO _deprecated_pk_role; - -------------------------------------------------------------------------- --- 6. Mark pk_temporal_entity as Deprecated and remove it from v_temporal_entity -------------------------------------------------------------------------- -DROP VIEW information.v_temporal_entity; - -CREATE VIEW information.v_temporal_entity AS - SELECT temporal_entity.pk_entity, - temporal_entity.schema_name, - temporal_entity.table_name, - temporal_entity.notes, - temporal_entity.fk_creator, - temporal_entity.fk_last_modifier, - temporal_entity.tmsp_creation, - temporal_entity.tmsp_last_modification, - temporal_entity.sys_period, - temporal_entity.fk_class - FROM information.temporal_entity; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_temporal_entity - FOR EACH ROW - EXECUTE PROCEDURE information.v_temporal_entity_find_or_create(); - -ALTER TABLE information.temporal_entity RENAME COLUMN pk_temporal_entity TO _deprecated_pk_temporal_entity; - -------------------------------------------------------------------------- --- 7. Make text_property a child of text -------------------------------------------------------------------------- -DELETE FROM information.text_property_vt; -ALTER TABLE information.text_property ADD COLUMN entity_version integer; -ALTER TABLE information.text_property_vt ADD COLUMN entity_version integer; -SELECT commons.reinit_versioning_triggers('information.text_property'); -SELECT commons.make_versioned_table_child_of_text('information.text_property'); -UPDATE information.text_property SET string = information.text_property_to_string(text_property_quill_doc); -DELETE FROM information.text_property_vt; -- no way back: Loss of history - - -------------------------------------------------------------------------- --- 8. Mark unused text_property columns as deprecated -------------------------------------------------------------------------- -ALTER TABLE information.text_property RENAME COLUMN text_property TO _deprecated_text_property; -ALTER TABLE information.text_property_vt RENAME COLUMN text_property TO _deprecated_text_property; -ALTER TABLE information.text_property RENAME COLUMN text_property_quill_doc TO _deprecated_text_property_quill_doc; -ALTER TABLE information.text_property_vt RENAME COLUMN text_property_quill_doc TO _deprecated_text_property_quill_doc; - -------------------------------------------------------------------------- --- 9. Remove NOT NULL from _deprecated_text_property_quill_doc -------------------------------------------------------------------------- -ALTER TABLE information.text_property ALTER COLUMN _deprecated_text_property_quill_doc DROP NOT NULL; - - -------------------------------------------------------------------------- --- 10. Make appellation a child of text -------------------------------------------------------------------------- -DELETE FROM information.appellation_vt; -ALTER TABLE information.appellation ADD COLUMN entity_version integer; -ALTER TABLE information.appellation_vt ADD COLUMN entity_version integer; -SELECT commons.reinit_versioning_triggers('information.appellation'); -SELECT commons.make_versioned_table_child_of_text('information.appellation'); -UPDATE information.appellation SET string = information.appellation_label_to_string(appellation_label); -DELETE FROM information.appellation_vt; -- no way back: Loss of history - -------------------------------------------------------------------------- --- 11. Mark unused appellation columns as deprecated -------------------------------------------------------------------------- -ALTER TABLE information.appellation RENAME COLUMN appellation_label TO _deprecated_appellation_label; -ALTER TABLE information.appellation_vt RENAME COLUMN appellation_label TO _deprecated_appellation_label; -ALTER TABLE information.appellation RENAME COLUMN pk_appellation TO _deprecated_pk_appellation; -ALTER TABLE information.appellation_vt RENAME COLUMN pk_appellation TO _deprecated_pk_appellation; - - -------------------------------------------------------------------------- --- 12. Add column metadata -------------------------------------------------------------------------- -ALTER TABLE information.entity ADD COLUMN metadata jsonb; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-down.sql deleted file mode 100644 index da5b4ea9f..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-down.sql +++ /dev/null @@ -1,602 +0,0 @@ --- 4. -DROP view warehouse.v_entity_preview; -DROP view warehouse.v_entity_preview_non_recursive; -DROP view warehouse.v_own_entity_label; -DROP view warehouse.v_own_full_text; -DROP view warehouse.v_text_properties_per_project_and_repo; - --- -- 3. -DROP TRIGGER _02_find_or_create ON information.v_text_property; -DROP TRIGGER _01_sync_quill_doc_and_string ON information.v_text_property; - -CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - text_property_quill_doc::jsonb = NEW.text_property_quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - text_property_quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.text_property_quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - -ALTER FUNCTION information.v_text_property_find_or_create() - OWNER TO postgres; - --- 2. -DROP VIEW information.v_text_property; - --- 1 - -CREATE OR REPLACE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property._deprecated_text_property AS text_property, - text_property.fk_concerned_entity, - text_property._deprecated_text_property_quill_doc AS text_property_quill_doc, - text_property.fk_language, - text_property.fk_class_field, - information.text_property_to_string(text_property._deprecated_text_property_quill_doc) AS string, - count(epr.fk_project) AS is_in_project_count - FROM information.text_property - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = text_property.pk_entity AND epr.is_in_project = true - GROUP BY text_property.pk_entity, text_property.schema_name, text_property.table_name, text_property.notes, text_property.fk_creator, text_property.fk_last_modifier, text_property.tmsp_creation, text_property.tmsp_last_modification, text_property.sys_period, text_property._deprecated_text_property, text_property.fk_concerned_entity, text_property._deprecated_text_property_quill_doc, text_property.fk_language, text_property.fk_class_field; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.text_property, - t.fk_concerned_entity, - t.text_property_quill_doc, - t.fk_language, - t.fk_class_field, - t.string, - t.is_in_project_count, - epr._deprecated_fk_project AS fk_project, - COALESCE(epr._deprecated_fk_project, 0) AS "coalesce" - FROM information.v_text_property t - JOIN projects.info_proj_rel epr ON epr.fk_entity = t.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.text_property, - t.fk_concerned_entity, - t.text_property_quill_doc, - t.fk_language, - t.fk_class_field, - t.string, - t.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" - FROM information.v_text_property t - WHERE t.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order IS NOT NULL - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; - - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order = 0 - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE all_roles.role_number = 1 - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE all_txtp.txtp_number = 1 - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-up.sql deleted file mode 100644 index c2b39adef..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507131338-inf-text-property-rework-up.sql +++ /dev/null @@ -1,612 +0,0 @@ -------------------------------------------------------------------------- --- 1. DROP v_text_property and dependent views -------------------------------------------------------------------------- -DROP view warehouse.v_entity_preview; -DROP view warehouse.v_entity_preview_non_recursive; -DROP view warehouse.v_own_entity_label; -DROP view warehouse.v_own_full_text; -DROP view warehouse.v_text_properties_per_project_and_repo; -DROP VIEW information.v_text_property; - -------------------------------------------------------------------------- --- 2. Replace v_text_property and make use of the new string column -------------------------------------------------------------------------- - -CREATE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.fk_concerned_entity, - text_property.fk_language, - text_property.fk_class_field, - text_property.quill_doc, - text_property.string, - count(epr._deprecated_fk_project) AS is_in_project_count - FROM information.text_property - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = text_property.pk_entity AND epr.is_in_project = true - GROUP BY text_property.pk_entity, text_property.schema_name, text_property.table_name, text_property.notes, text_property.fk_creator, text_property.fk_last_modifier, text_property.tmsp_creation, text_property.tmsp_last_modification, text_property.sys_period, text_property._deprecated_text_property, text_property.fk_concerned_entity, text_property.quill_doc, text_property.fk_language, text_property.fk_class_field, text_property.string; - -------------------------------------------------------------------------- --- 3. Replace v_text_property_find_or_create -------------------------------------------------------------------------- - - -CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - -CREATE TRIGGER _01_sync_quill_doc_and_string - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - -CREATE TRIGGER _02_find_or_create - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - - - -------------------------------------------------------------------------- --- 4. ADD VIEWS dropped above -------------------------------------------------------------------------- - - -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - epr._deprecated_fk_project AS fk_project, - COALESCE(epr._deprecated_fk_project, 0) AS "coalesce" - FROM information.v_text_property t - JOIN projects.info_proj_rel epr ON epr.fk_entity = t.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" - FROM information.v_text_property t - WHERE t.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order IS NOT NULL - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; - - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order = 0 - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE all_roles.role_number = 1 - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE all_txtp.txtp_number = 1 - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-down.sql deleted file mode 100644 index 76f548a90..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-down.sql +++ /dev/null @@ -1,535 +0,0 @@ --- 4. -DROP view warehouse.v_entity_preview; -DROP view warehouse.v_entity_preview_non_recursive; -DROP view warehouse.v_own_entity_label; -DROP view warehouse.v_own_full_text; - --- 3 -DROP TRIGGER _02_find_or_create ON information.v_appellation; -DROP TRIGGER _01_sync_quill_doc_and_string ON information.v_appellation; - -CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.v_appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - information.appe_tokens_for_comparision(appellation_label) = - information.appe_tokens_for_comparision(NEW.appellation_label) - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - appellation_label, - fk_class - ) - VALUES ( - NEW.appellation_label, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - --- 2 -DROP VIEW information.v_appellation; - --- 1. -CREATE OR REPLACE VIEW information.v_appellation AS - SELECT appellation.pk_entity, - appellation.schema_name, - appellation.table_name, - appellation.notes, - appellation.fk_creator, - appellation.fk_last_modifier, - appellation.tmsp_creation, - appellation.tmsp_last_modification, - appellation.sys_period, - appellation._deprecated_pk_appellation AS pk_appellation, - appellation._deprecated_appellation_label AS appellation_label, - appellation.fk_class, - information.appellation_label_to_string(appellation._deprecated_appellation_label) AS string - FROM information.appellation; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order IS NOT NULL - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; - - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order = 0 - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE all_roles.role_number = 1 - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE all_txtp.txtp_number = 1 - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-up.sql deleted file mode 100644 index b110e7b59..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507142741-inf-appellation-rework-up.sql +++ /dev/null @@ -1,549 +0,0 @@ -------------------------------------------------------------------------- --- 1. DROP v_appellation and dependent views -------------------------------------------------------------------------- -DROP view warehouse.v_entity_preview; -DROP view warehouse.v_entity_preview_non_recursive; -DROP view warehouse.v_own_entity_label; -DROP view warehouse.v_own_full_text; -DROP VIEW information.v_appellation; - -------------------------------------------------------------------------- --- 2. Replace v_appellation and make use of the new string column -------------------------------------------------------------------------- -CREATE VIEW information.v_appellation AS - SELECT appellation.pk_entity, - appellation.schema_name, - appellation.table_name, - appellation.notes, - appellation.fk_creator, - appellation.fk_last_modifier, - appellation.tmsp_creation, - appellation.tmsp_last_modification, - appellation.sys_period, - appellation.fk_class, - appellation.quill_doc, - appellation.string - FROM information.appellation; - -------------------------------------------------------------------------- --- 3. Replace v_appellation_find_or_create -------------------------------------------------------------------------- - -CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.v_appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - quill_doc, - fk_class - ) - VALUES ( - NEW.quill_doc, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - -CREATE TRIGGER _01_sync_quill_doc_and_string - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - -CREATE TRIGGER _02_find_or_create - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - -------------------------------------------------------------------------- --- 4. ADD VIEWS dropped above -------------------------------------------------------------------------- - - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order IS NOT NULL - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; - - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order = 0 - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE all_roles.role_number = 1 - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE all_txtp.txtp_number = 1 - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-down.sql deleted file mode 100644 index 31555c76a..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-down.sql +++ /dev/null @@ -1,60 +0,0 @@ - CREATE OR REPLACE FUNCTION commons.modernize_quill_doc(orig jsonb) RETURNS jsonb AS $f$ - DECLARE - newJ jsonb; - latestId int; - newOps jsonb; - oldOp jsonb; - char text; - BEGIN - newOps = jsonb_build_array(); - latestId = (orig->>'latestId')::int; - - -- LOOP over ops - FOR oldOp IN SELECT * FROM jsonb_array_elements((orig->'contents'->>'ops')::jsonb) - LOOP - - -- IF insert length > 1 - IF((SELECT char_length(oldOp->>'insert') > 1)) THEN - RAISE NOTICE 'Parsing Item % % %', oldOp->>'insert', oldOp->>'attributes', (SELECT char_length(oldOp->>'insert') > 1); - - - -- LOOP over insert characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(oldOp->>'insert','')) AS x(chars)) - LOOP - latestId = latestId + 1; - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(oldOp->'attributes', '{node}'::text[], latestId::text::jsonb) - ); - - END LOOP; - - ELSE - -- - IF(oldOp->'attributes' ? 'node') THEN - newOps = newOps || jsonb_build_object( - 'insert', oldOp->'insert', - 'attributes', jsonb_set(oldOp->'attributes', '{node}'::text[], (oldOp->'attributes'->>'node')::int::text::jsonb) - ); - ELSIF (oldOp ? 'attributes') THEN - newOps = newOps || jsonb_build_object( - 'insert', oldOp->'insert', - 'attributes', oldOp->'attributes' - ); - ELSE - newOps = newOps || jsonb_build_object( - 'insert', oldOp->'insert' - ); - END IF; - - END IF; - - END LOOP; - - RAISE NOTICE 'New Ops: %', newOps; - - newJ = jsonb_build_object('latestId',latestId, 'ops', newOps); - - RETURN newJ; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-up.sql deleted file mode 100644 index c2d0c4c3b..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-com-f-characterize-quill-doc-up.sql +++ /dev/null @@ -1,47 +0,0 @@ - CREATE OR REPLACE FUNCTION commons.modernize_quill_doc(orig jsonb) RETURNS jsonb AS $f$ - DECLARE - newJ jsonb; - latestId int; - newOps jsonb; - oldOp jsonb; - char text; - BEGIN - newOps = jsonb_build_array(); - latestId = 0; - - -- LOOP over ops - FOR oldOp IN SELECT * FROM jsonb_array_elements((orig->'contents'->>'ops')::jsonb) - LOOP - - RAISE NOTICE 'Parsing Item % % %', oldOp->>'insert', oldOp->>'attributes', (SELECT char_length(oldOp->>'insert') > 1); - - - -- LOOP over insert characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(oldOp->>'insert','')) AS x(chars)) - LOOP - latestId = latestId + 1; - - IF char = E'\n' THEN - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb), '{blockid}'::text[], to_json(latestId::text)::jsonb) - ); - ELSE - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb) - 'node', '{charid}'::text[], to_json(latestId::text)::jsonb) - ); - END IF; - END LOOP; - - - END LOOP; - - RAISE NOTICE 'New Ops: %', newOps; - - - newJ = jsonb_build_object('latestId',latestId, 'ops', newOps); - - RETURN newJ; - END; - $f$ LANGUAGE 'plpgsql' IMMUTABLE; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-down.sql deleted file mode 100644 index fd0436ab8..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-down.sql +++ /dev/null @@ -1,119 +0,0 @@ - --- 10 -CREATE TABLE information.chunk -( - pk_chunk serial PRIMARY KEY, - js_quill_data jsonb, - fk_digital_object integer -) - INHERITS (information.entity); - -SELECT commons.init_entity_child_table('information.chunk'); - -CREATE OR REPLACE VIEW information.v_chunk AS - SELECT chunk.pk_entity, - chunk.schema_name, - chunk.table_name, - chunk.notes, - chunk.fk_creator, - chunk.fk_last_modifier, - chunk.tmsp_creation, - chunk.tmsp_last_modification, - chunk.sys_period, - chunk.pk_chunk, - chunk.js_quill_data, - chunk.fk_digital_object - FROM information.chunk; - - --- 9 -CREATE FUNCTION information.v_chunk_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_chunk; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.chunk - WHERE - js_quill_data::jsonb = NEW.js_quill_data::jsonb - AND fk_digital_object = NEW.fk_digital_object; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.chunk ( - js_quill_data, - fk_digital_object - ) - VALUES ( - NEW.js_quill_data::jsonb, - NEW.fk_digital_object - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_chunk - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_chunk - FOR EACH ROW - EXECUTE PROCEDURE information.v_chunk_find_or_create(); - - --- 8 --- no way back, data loss - - --- 7. -ALTER TABLE data.digital DROP COLUMN fk_system_type; - --- 6. -ALTER TABLE data.digital RENAME COLUMN _deprecated_pk_digital_object TO pk_digital_object; -ALTER TABLE data.digital_vt RENAME COLUMN _deprecated_pk_digital_object TO pk_digital_object; -ALTER TABLE data.digital RENAME COLUMN _deprecated_js_quill_data TO js_quill_data; -ALTER TABLE data.digital_vt RENAME COLUMN _deprecated_js_quill_data TO js_quill_data; - --- 5. -SELECT commons.unmake_versioned_table_child_of_text('data.digital'); - --- 4. -SELECT commons.rename_versioned_table('data', 'digital', 'digital_object'); - --- 3. -SELECT commons.move_entity_child_with_vt_to_schema('digital_object', 'data', 'information'); - -ALTER TABLE information.digital_object DROP COLUMN fk_namespace; -ALTER TABLE information.digital_object_vt DROP COLUMN fk_namespace; - --- 2. -DROP TABLE data.entity; - --- 1. -DROP SCHEMA data CASCADE; -CREATE SCHEMA data; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-up.sql deleted file mode 100644 index cf5699bab..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190507150942-dat-schema-setup-up.sql +++ /dev/null @@ -1,98 +0,0 @@ ------------------------------------------------------------------------------------------------------------- --- 1. TABULA RASA for SCHEMA data ------------------------------------------------------------------------------------------------------------- -ALTER TABLE projects.argument DROP CONSTRAINT IF EXISTS assertion_fk_is_based_on_factoid_role_fkey; -ALTER TABLE projects.argument DROP CONSTRAINT IF EXISTS assertion_fk_is_based_on_cell_fkey; -ALTER TABLE projects.argument ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); - -DROP SCHEMA data CASCADE; -- no way back, but no ploblem since never used. -CREATE SCHEMA data; - ------------------------------------------------------------------------------------------------------------- --- 2. TABLE entity ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.entity - ( - pk_entity serial PRIMARY KEY, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb - ); - - ------------------------------------------------------------------------------------------------------------- --- 3. Move digital_object here ------------------------------------------------------------------------------------------------------------- -ALTER TABLE information.digital_object ADD COLUMN fk_namespace integer; -ALTER TABLE information.digital_object_vt ADD COLUMN fk_namespace integer; -SELECT commons.move_entity_child_with_vt_to_schema('digital_object', 'information', 'data'); - - ------------------------------------------------------------------------------------------------------------- --- 4. Rename digital_object --> digital ------------------------------------------------------------------------------------------------------------- -SELECT commons.rename_versioned_table('data', 'digital_object', 'digital'); - - ------------------------------------------------------------------------------------------------------------- --- 5. Make digital a child of text -------------------------------------------------------------------------- - -DELETE FROM data.digital WHERE js_quill_data::jsonb = '{}'::jsonb; -- no way back: Loss of history -DELETE FROM data.digital_vt; -SELECT commons.reinit_versioning_triggers('data.digital'); -SELECT commons.make_versioned_table_child_of_text('data.digital'); -UPDATE data.digital SET quill_doc = commons.modernize_quill_doc(js_quill_data::jsonb); -UPDATE data.digital SET entity_version = 1; -DELETE FROM data.digital_vt; -- no way back: Loss of history - -------------------------------------------------------------------------- --- 6. Mark unused digital columns as deprecated -------------------------------------------------------------------------- -ALTER TABLE data.digital RENAME COLUMN pk_digital_object TO _deprecated_pk_digital_object; -ALTER TABLE data.digital_vt RENAME COLUMN pk_digital_object TO _deprecated_pk_digital_object; -ALTER TABLE data.digital RENAME COLUMN js_quill_data TO _deprecated_js_quill_data; -ALTER TABLE data.digital_vt RENAME COLUMN js_quill_data TO _deprecated_js_quill_data; - -------------------------------------------------------------------------- --- 7. Table digital, add column fk_system_type -------------------------------------------------------------------------- -ALTER TABLE data.digital ADD COLUMN fk_system_type INT REFERENCES system.system_type (pk_entity); - -------------------------------------------------------------------------- --- 8. Delete all mentionings and chunks --- No way back, loss of data -------------------------------------------------------------------------- -DELETE FROM information.entity_association ea -WHERE ea.fk_property IN ( - SELECT dfh_pk_property - FROM data_for_history.property_profile_view - WHERE dfh_fk_property_of_origin = 1218); - -DELETE FROM information.chunk; -DELETE FROM information.chunk_vt; - --- Cleanup info_proj_rel -DELETE FROM projects.info_proj_rel -WHERE fk_entity NOT IN ( SELECT pk_entity FROM information.entity); - -------------------------------------------------------------------------- --- 9. Drop function v_chunk_find_or_create -------------------------------------------------------------------------- -DROP TRIGGER on_insert ON information.v_chunk; -DROP FUNCTION information.v_chunk_find_or_create(); - -------------------------------------------------------------------------- --- 10. DROP View and Table Chunk -------------------------------------------------------------------------- -DROP VIEW information.v_chunk; -DROP TABLE information.chunk_vt; -DROP TABLE information.chunk; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-down.sql deleted file mode 100644 index 4446b9bd1..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-down.sql +++ /dev/null @@ -1,62 +0,0 @@ --- 15 -ALTER TABLE data.entity DROP CONSTRAINT entity_fk_namespace_fkey; -DROP TABLE IF EXISTS data.namespace; -DROP TABLE IF EXISTS data.namespace_vt; - --- 14 -DROP TABLE IF EXISTS data.text_property; -DROP TABLE IF EXISTS data.text_property_vt; - --- 13 -DROP TABLE IF EXISTS data.avatar; -DROP TABLE IF EXISTS data.avatar_vt; - --- 12 -DROP TABLE IF EXISTS data.data_association; -DROP TABLE IF EXISTS data.data_association_vt; - --- 11 -DROP TABLE IF EXISTS data.values_association; -DROP TABLE IF EXISTS data.values_association_vt; - --- 10 -DROP TABLE IF EXISTS data.factoid_role; -DROP TABLE IF EXISTS data.factoid_role_vt; - --- 9 -DROP TABLE IF EXISTS data.factoid; -DROP TABLE IF EXISTS data.factoid_vt; - --- 8 -DROP TABLE IF EXISTS data.factoid_property_column_rel; -DROP TABLE IF EXISTS data.factoid_property_column_rel_vt; - --- 7 -DROP TABLE IF EXISTS data.class_column_rel; -DROP TABLE IF EXISTS data.class_column_rel_vt; - --- 6 -DROP TABLE IF EXISTS data.value_association_columns_rel; -DROP TABLE IF EXISTS data.value_association_columns_rel_vt; - --- 5 -DROP TABLE IF EXISTS data.factoid_class_digital_rel; -DROP TABLE IF EXISTS data.factoid_class_digital_rel_vt; - --- 4 -DROP TABLE IF EXISTS data.cell; -DROP TABLE IF EXISTS data.cell_vt; - --- 3 -DROP TABLE IF EXISTS data.column; -DROP TABLE IF EXISTS data.column_vt; - --- 2 -DROP TABLE IF EXISTS data.row; -DROP TABLE IF EXISTS data.row_vt; - --- 1. -DROP TABLE data.chunk_vt; -DROP TABLE data.chunk; -ALTER TABLE commons.text DROP CONSTRAINT text_version_unique; - diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-up.sql deleted file mode 100644 index 01fcb567c..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508075346-dat-schema-tables-up.sql +++ /dev/null @@ -1,222 +0,0 @@ ------------------------------------------------------------------------------------------------------------- --- 1. CREATE Table Chunk ------------------------------------------------------------------------------------------------------------- -ALTER TABLE commons.text ADD CONSTRAINT text_version_unique UNIQUE (pk_text, entity_version); - -CREATE TABLE data.chunk -( - fk_text INT, - fk_entity_version INT, - CONSTRAINT text_fkey FOREIGN KEY (fk_text, fk_entity_version) REFERENCES commons.text (pk_text, entity_version) -) -INHERITS (data.entity); - -SELECT commons.init_entity_child_table('data.chunk'); -SELECT commons.make_versioned_table_child_of_text('data.chunk'); - ------------------------------------------------------------------------------------------------------------- --- 2. CREATE Table Row ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.row - ( - fk_digital INTEGER NOT NULL REFERENCES data.digital (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.row'); - - ------------------------------------------------------------------------------------------------------------- --- 3. TABLE data.column (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.column - ( - fk_digital INTEGER NOT NULL REFERENCES data.digital (pk_entity), - fk_data_type INTEGER NOT NULL REFERENCES system.system_type (pk_entity), - fk_meta_data INTEGER NOT NULL REFERENCES system.system_type (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.column'); - - ------------------------------------------------------------------------------------------------------------- --- 4. TABLE data.cell (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.cell - ( - fk_column INTEGER NOT NULL REFERENCES data.column (pk_entity), - fk_row INTEGER NOT NULL REFERENCES data.row (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.cell'); - SELECT commons.make_versioned_table_child_of_text('data.cell'); - ------------------------------------------------------------------------------------------------------------- --- 5. TABLE data.factoid_class_digital_rel (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.factoid_class_digital_rel - ( - fk_digital INTEGER NOT NULL REFERENCES data.digital (pk_entity), - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.factoid_class_digital_rel'); - - ------------------------------------------------------------------------------------------------------------- --- 6. TABLE data.value_association_columns_rel (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.value_association_columns_rel - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_column INTEGER NOT NULL REFERENCES data.column (pk_entity), - fk_range_column INTEGER NOT NULL REFERENCES data.column (pk_entity), - fk_factoid_class_digital_rel INTEGER NOT NULL REFERENCES data.factoid_class_digital_rel (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.value_association_columns_rel'); - - - ------------------------------------------------------------------------------------------------------------- --- 7. TABLE data.class_column_rel (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.class_column_rel - ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class), - fk_column INTEGER NOT NULL REFERENCES data.column (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.class_column_rel'); - - ------------------------------------------------------------------------------------------------------------- --- 8. TABLE data.factoid_property_column_rel (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.factoid_property_column_rel - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_column INTEGER NOT NULL REFERENCES data.column (pk_entity), - fk_factoid_class_digital_rel INTEGER NOT NULL REFERENCES data.factoid_class_digital_rel (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.factoid_property_column_rel'); - - ------------------------------------------------------------------------------------------------------------- --- 9. TABLE data.factoid (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.factoid - ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.factoid'); - - ------------------------------------------------------------------------------------------------------------- --- 10. TABLE data.factoid_role (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.factoid_role - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_factoid INTEGER NOT NULL REFERENCES data.factoid (pk_entity), - fk_range_cell INTEGER REFERENCES data.cell (pk_entity), - fk_range_chunk INTEGER REFERENCES data.chunk (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.factoid_role'); - - ------------------------------------------------------------------------------------------------------------- --- 11. TABLE data.values_association (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.values_association - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_domain_cell INTEGER REFERENCES data.cell (pk_entity), - fk_range_cell INTEGER REFERENCES data.cell (pk_entity), - fk_domain_chunk INTEGER REFERENCES data.chunk (pk_entity), - fk_range_chunk INTEGER REFERENCES data.chunk (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.values_association'); - ------------------------------------------------------------------------------------------------------------- --- 12. TABLE data.data_association (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.data_association - ( - fk_property INTEGER NOT NULL REFERENCES data_for_history.property (dfh_pk_property), - fk_data_domain INTEGER, -- REFERENCES data.entity (pk_entity), -- Not possible to reference parent - fk_data_range INTEGER, -- REFERENCES data.entity (pk_entity), - fk_info_domain INTEGER, -- REFERENCES information.entity (pk_entity) - fk_info_range INTEGER -- REFERENCES information.entity (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.data_association'); - ------------------------------------------------------------------------------------------------------------- --- 13. TABLE data.avatar (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.avatar - ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.avatar'); - - ------------------------------------------------------------------------------------------------------------- --- 14. TABLE data.text_property (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.text_property - ( - fk_system_type INTEGER NOT NULL REFERENCES system.system_type (pk_entity), - fk_language INTEGER NOT NULL REFERENCES information.language (pk_entity) - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.text_property'); - SELECT commons.make_versioned_table_child_of_text('data.text_property'); - ------------------------------------------------------------------------------------------------------------- --- 15. TABLE data.namespace (including *_vt) ------------------------------------------------------------------------------------------------------------- - - CREATE TABLE data.namespace - ( - fk_root_namespace INTEGER, - fk_project INTEGER REFERENCES projects.project (pk_entity), - standard_label TEXT - ) - INHERITS (data.entity); - - SELECT commons.init_entity_child_table('data.namespace'); - -ALTER TABLE data.namespace ADD FOREIGN KEY (fk_root_namespace) REFERENCES data.namespace (pk_entity); -ALTER TABLE data.entity ADD FOREIGN KEY (fk_namespace) REFERENCES data.namespace (pk_entity); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-down.sql deleted file mode 100644 index 526490619..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-down.sql +++ /dev/null @@ -1,395 +0,0 @@ --- 8 -CREATE OR REPLACE FUNCTION information.v_entity_association_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.entity_association - WHERE - fk_domain_entity = NEW.fk_domain_entity - AND fk_range_entity = NEW.fk_range_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_domain_entity, - fk_range_entity, - fk_property - ) - VALUES ( - NEW.fk_domain_entity, - NEW.fk_range_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_association - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - --- 7 -DROP VIEW warehouse.v_entity_preview; - --- 6 -DROP VIEW warehouse.v_entity_preview_non_recursive; - --- 5 -DROP VIEW warehouse.v_fk_type; - --- 4 -DROP VIEW warehouse.v_entity_association_per_project_and_repo; - --- 3 -DROP VIEW information.v_entity_association; - --- 2 -CREATE OR REPLACE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain AS fk_domain_entity, - ea_1.fk_info_range AS fk_range_entity, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_domain_entity, - ea.fk_range_entity, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY ea.fk_domain_entity, ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY ea.fk_range_entity, ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS - SELECT DISTINCT ea.pk_entity, - ea.fk_range_entity, - ea.fk_domain_entity, - ea.fk_property, - epr._deprecated_fk_project AS fk_project, - epr.ord_num AS rank_for_domain, - epr.ord_num AS rank_for_range, - COALESCE(epr._deprecated_fk_project, 0) AS project - FROM information.v_entity_association ea - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_range_entity, - ea.fk_domain_entity, - ea.fk_property, - NULL::integer AS fk_project, - ea.rank_for_domain, - ea.rank_for_range, - 0 AS project - FROM information.v_entity_association ea - WHERE ea.is_in_project_count > 0; - - -CREATE OR REPLACE VIEW warehouse.v_fk_type AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT DISTINCT ea.fk_domain_entity AS pk_entity, - ea.fk_project, - ea.project, - ea.fk_range_entity AS fk_type - FROM warehouse.v_entity_association_per_project_and_repo ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE (p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066])) AND ea.rank_for_domain = 1; - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - --- 1 -ALTER TABLE information.entity_association RENAME COLUMN fk_info_range TO fk_range_entity; -ALTER TABLE information.entity_association RENAME COLUMN fk_info_domain TO fk_domain_entity; -ALTER TABLE information.entity_association DROP COLUMN fk_data_domain; -ALTER TABLE information.entity_association DROP COLUMN fk_data_range; diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-up.sql deleted file mode 100644 index a1354d659..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508075347-inf-rework-entity-association-up.sql +++ /dev/null @@ -1,431 +0,0 @@ - ------------------------------------------------------------------------------------------------------------- --- 1. REWORK TABLE information.entity_association (including *_vt) ------------------------------------------------------------------------------------------------------------- - - ALTER TABLE information.entity_association RENAME COLUMN fk_range_entity TO fk_info_range; - ALTER TABLE information.entity_association RENAME COLUMN fk_domain_entity TO fk_info_domain; - ALTER TABLE information.entity_association ADD COLUMN fk_data_domain integer; - -- REFERENCES data.entity (pk_entity), -- Not possible to reference parent - ALTER TABLE information.entity_association ADD COLUMN fk_data_range integer; - -- REFERENCES data.entity (pk_entity), -- Not possible to reference parent - ------------------------------------------------------------------------------------------------------------- --- 2. DROP VIEWS depending on v_entity_association ------------------------------------------------------------------------------------------------------------- -DROP VIEW warehouse.v_entity_preview; -DROP VIEW warehouse.v_entity_preview_non_recursive; -DROP VIEW warehouse.v_fk_type; -DROP view warehouse.v_entity_association_per_project_and_repo; -DROP view information.v_entity_association; - - ------------------------------------------------------------------------------------------------------------- --- 3. RECREATE VIEW v_entity_association ------------------------------------------------------------------------------------------------------------- -CREATE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY COALESCE(ea.fk_info_domain, ea.fk_data_domain), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY COALESCE(ea.fk_info_range, ea.fk_data_range), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - - ------------------------------------------------------------------------------------------------------------- --- 4. RECREATE VIEW v_entity_association_per_project_and_repo ------------------------------------------------------------------------------------------------------------- - -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - epr.ord_num AS rank_for_domain, - epr.ord_num AS rank_for_range, - COALESCE(epr.fk_project, 0) AS project - FROM information.v_entity_association ea - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - ea.rank_for_domain, - ea.rank_for_range, - 0 AS project - FROM information.v_entity_association ea - WHERE ea.is_in_project_count > 0; - - ------------------------------------------------------------------------------------------------------------- --- 5. RECREATE VIEW v_fk_type ------------------------------------------------------------------------------------------------------------- - -CREATE OR REPLACE VIEW warehouse.v_fk_type AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT DISTINCT ea.fk_info_domain AS pk_entity, - ea.fk_project, - ea.project, - ea.fk_info_range AS fk_type - FROM warehouse.v_entity_association_per_project_and_repo ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - JOIN system.class_has_type_property hasProp ON hasProp.fk_property = p.dfh_pk_property - WHERE ea.rank_for_domain = 1; - - ------------------------------------------------------------------------------------------------------------- --- 6. RECREATE VIEW v_entity_preview_non_recursive ------------------------------------------------------------------------------------------------------------- -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN information.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - ------------------------------------------------------------------------------------------------------------- --- 7. RECREATE VIEW v_entity_preview ------------------------------------------------------------------------------------------------------------- - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - ------------------------------------------------------------------------------------------------------------- --- 8. RECREATE VIEW v_entity_association ------------------------------------------------------------------------------------------------------------- -CREATE OR REPLACE FUNCTION information.v_entity_association_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity - FROM INTO resulting_pk information.entity_association - WHERE fk_property = NEW.fk_property - AND fk_info_domain IS NOT DISTINCT FROM NEW.fk_info_domain - AND fk_info_range IS NOT DISTINCT FROM NEW.fk_info_range - AND fk_data_domain IS NOT DISTINCT FROM NEW.fk_data_domain - AND fk_data_range IS NOT DISTINCT FROM NEW.fk_data_range; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_property, - fk_info_domain, - fk_info_range, - fk_data_domain, - fk_data_range - ) - VALUES ( - NEW.fk_property, - NEW.fk_info_domain, - NEW.fk_info_range, - NEW.fk_data_domain, - NEW.fk_data_range - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_association - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-down.sql deleted file mode 100644 index b8d8bea0a..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-down.sql +++ /dev/null @@ -1,12 +0,0 @@ --- 4 -DROP TRIGGER on_insert ON information.v_property_of_property; - --- 3 -DROP FUNCTION information.v_property_of_property_find_or_create(); - --- 2 -DROP VIEW information.v_property_of_property; - --- 1 -DROP TABLE IF EXISTS information.property_of_property; -DROP TABLE IF EXISTS information.property_of_property_vt; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-up.sql deleted file mode 100644 index 1b3a25dc4..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508085220-inf-t-property-of-property-up.sql +++ /dev/null @@ -1,105 +0,0 @@ ------------------------------------------------------------------------------------------------------------- --- 1. TABLE information.property_of_property (including *_vt) ------------------------------------------------------------------------------------------------------------- - CREATE TABLE information.property_of_property - ( - fk_property INTEGER REFERENCES data_for_history.property (dfh_pk_property), - provisional_property varchar, - fk_role INTEGER REFERENCES information.role (pk_entity), - fk_entity_association INTEGER REFERENCES information.entity_association (pk_entity), - fk_range_entity INTEGER NOT NULL, - entity_version INTEGER - ) - INHERITS (information.entity); - - SELECT commons.init_entity_child_table('information.property_of_property'); - - ------------------------------------------------------------------------------------------------------------- --- 2. VIEW information.v_property_of_property ------------------------------------------------------------------------------------------------------------- -CREATE VIEW information.v_property_of_property AS - SELECT * FROM information.property_of_property; - - ------------------------------------------------------------------------------------------------------------- --- 3. FUNCTION information.v_property_of_property_find_or_create ------------------------------------------------------------------------------------------------------------- -CREATE FUNCTION information.v_property_of_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_property_of_property; - BEGIN - - RAISE INFO ' input values - NEW.fk_property: %, - NEW.provisional_property: % - NEW.fk_role: % - NEW.fk_entity_association: % - NEW.fk_range_entity: % - ', - NEW.fk_property, - NEW.provisional_property, - NEW.fk_role, - NEW.fk_entity_association, - NEW.fk_range_entity; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.property_of_property - WHERE fk_property IS NOT DISTINCT FROM NEW.fk_property - AND provisional_property IS NOT DISTINCT FROM NEW.provisional_property - AND fk_role IS NOT DISTINCT FROM NEW.fk_role - AND fk_entity_association IS NOT DISTINCT FROM NEW.fk_entity_association - AND fk_range_entity IS NOT DISTINCT FROM NEW.fk_range_entity; - - RAISE INFO 'resulting_pk: %', resulting_pk; - - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.property_of_property ( - fk_property, - provisional_property, - fk_role, - fk_entity_association, - fk_range_entity - ) - VALUES ( - NEW.fk_property, - NEW.provisional_property, - NEW.fk_role, - NEW.fk_entity_association, - NEW.fk_range_entity - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_property_of_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - ------------------------------------------------------------------------------------------------------------- --- 4. TRIGGER v_property_of_property on_insert ------------------------------------------------------------------------------------------------------------- -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_property_of_property - FOR EACH ROW - EXECUTE PROCEDURE information.v_property_of_property_find_or_create(); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-down.sql deleted file mode 100644 index 586015f20..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE projects.dfh_class_proj_rel RENAME COLUMN enabled_in_entities TO is_in_project; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-up.sql deleted file mode 100644 index b4a5b7666..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190508113041-pro-dfh-class-proj-rel-change-up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE projects.dfh_class_proj_rel RENAME COLUMN is_in_project TO enabled_in_entities; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-down.sql deleted file mode 100644 index 13e5da508..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE projects.class_field_config_vt RENAME COLUMN fk_app_context TO fk_ui_context; -ALTER TABLE projects.class_field_config RENAME COLUMN fk_app_context TO fk_ui_context; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-up.sql deleted file mode 100644 index 4f008452a..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190509120135-pro-class-field-config-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE projects.class_field_config_vt RENAME COLUMN fk_ui_context TO fk_app_context; -ALTER TABLE projects.class_field_config RENAME COLUMN fk_ui_context TO fk_app_context; \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-down.sql deleted file mode 100644 index cbd0d3adb..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-down.sql +++ /dev/null @@ -1,85 +0,0 @@ --- 4 -DROP TRIGGER on_insert ON data.v_digital_version; - --- 3 -DROP FUNCTION data.v_digital_version_insert(); - --- 2 -DROP VIEW data.v_digital_version ; - --- 1 - -CREATE OR REPLACE VIEW information.v_digital_object_version AS - SELECT v.pk_entity, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v._deprecated_pk_digital_object AS pk_digital_object, - v._deprecated_js_quill_data AS js_quill_data, - v.entity_version, - concat((v.pk_entity || '_'::text) || v.entity_version) AS pk_entity_version_concat - FROM data.digital v -UNION ALL - SELECT v.pk_entity, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v._deprecated_pk_digital_object AS pk_digital_object, - v._deprecated_js_quill_data AS js_quill_data, - v.entity_version, - concat((v.pk_entity || '_'::text) || v.entity_version) AS pk_entity_version_concat - FROM data.digital_vt v; - - -CREATE FUNCTION information.v_digital_object_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_concat_pk text; - resulting_row information.v_digital_object_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE information.digital_object SET - notes = NEW.notes, - js_quill_data = NEW.js_quill_data - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO information.digital_object (notes, js_quill_data) - VALUES(NEW.notes, NEW.js_quill_data) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row information.v_digital_object_version where pk_entity_version_concat = resulting_concat_pk; - - RETURN resulting_row; - END; - - $BODY$; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_digital_object_version - FOR EACH ROW - EXECUTE PROCEDURE information.v_digital_object_version_insert(); \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-up.sql deleted file mode 100644 index 2f7144cfd..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190509144358-dat-v-digital-version-up.sql +++ /dev/null @@ -1,85 +0,0 @@ --- 1 -DROP VIEW information.v_digital_object_version; -DROP FUNCTION information.v_digital_object_version_insert(); - --- 2 -CREATE OR REPLACE VIEW data.v_digital_version AS - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital v -UNION ALL - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital_vt v; - - --- 3 - -CREATE FUNCTION data.v_digital_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_concat_pk text; - resulting_row data.v_digital_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE data.digital SET - notes = NEW.notes, - quill_doc = NEW.quill_doc - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO data.digital (notes, quill_doc) - VALUES(NEW.notes, NEW.quill_doc) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row data.v_digital_version where pk_entity_version_concat = resulting_concat_pk; - - RETURN resulting_row; - END; - - $BODY$; - - --- 4 - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON data.v_digital_version - FOR EACH ROW - EXECUTE PROCEDURE data.v_digital_version_insert(); \ No newline at end of file diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-down.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-down.sql deleted file mode 100644 index 8bcc4b382..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-down.sql +++ /dev/null @@ -1,1138 +0,0 @@ - --- 16 - -CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.time_primitive; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.time_primitive ( - julian_day, - duration, - fk_class - ) - VALUES ( - NEW.julian_day, - NEW.duration, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - --- 15 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - has_type_properties INT[] = ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_range_entity INTO new_fk_type - FROM information.v_entity_association ea - JOIN information.entity_version_project_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.fk_domain_entity = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_range_entity INTO new_fk_type - FROM information.entity_association ea - JOIN information.entity_version_project_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (has_type_properties) - AND ea.fk_domain_entity = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; - - --- 14 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; - BEGIN - - - - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT ( - SELECT fk_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1 - ) IS NULL - ) THEN - - IF param_fk_project IS NULL THEN - - ---------------------- REPO VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - and r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN information.entity_version_project_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - LEFT JOIN information.entity_version_project_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = param_fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - ORDER BY epr2.ord_num - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - - - END IF; - - - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - - ----- Insert or update column own_entity_label of table entity_preview - - SELECT entity_label INTO old_own_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - - ELSIF (SELECT (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET entity_label = new_own_entity_label - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; - - END IF; - RETURN true; - END; - $BODY$; - --- 13 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity AND r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY r.rank_for_te_ent - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - -- TODO: Check if we need to exclude textproperties that are in 0 projects$ - -- TODO: Check if we need to order textproperties - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - LEFT JOIN information.entity_version_project_rel as epr ON epr.fk_entity = r.pk_entity - AND epr.fk_project = param_fk_project AND epr.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY epr.ord_num - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - INNER JOIN information.entity_version_project_rel as epr ON epr.fk_entity = txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - END IF; - - RETURN true; - END; - $BODY$; - --- 12 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_time_span jsonb; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_time_span - SELECT time_span INTO new_time_span - FROM information.v_te_en_time_span_per_project_and_repo - WHERE fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_time_span: %', new_time_span; - - -- update this entity_preview with new_time_span - UPDATE warehouse.entity_preview - SET time_span = new_time_span - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $BODY$; - --- 11 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, r.rank_for_pe_it as rank - FROM information.v_role r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - UNION - ( - SELECT r.fk_entity as pk, r.rank_for_te_ent as rank - FROM information.v_role r - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - ) AS a - ORDER BY rank - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_object: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, epr.ord_num - FROM information.role r - JOIN information.entity_version_project_rel epr ON epr.fk_entity = r.pk_entity - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - - UNION - - ( - SELECT r.fk_entity as pk, epr.ord_num - FROM information.role r - JOIN information.entity_version_project_rel epr ON epr.fk_entity = r.pk_entity - JOIN commons.ui_context_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_ui_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - ) AS a - ORDER BY ord_num - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', old_fk_entity_label, - 'new_val', new_fk_entity_label) - INTO result_info; - - RETURN result_info; - END; - $BODY$; - - --- 10 -DROP VIEW information.v_persistent_item; -CREATE VIEW information.v_persistent_item AS - SELECT persistent_item.pk_entity, - persistent_item.schema_name, - persistent_item.table_name, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period, - persistent_item.fk_class - FROM information.persistent_item; - --- 9 --- no way back - --- 8 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_domain_entity INT; - _fk_range_entity INT; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - PERFORM - - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_domain_entity into _fk_domain_entity - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_range_entity into _fk_range_entity - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_domain_entity: %, fk_range_entity: %, fk_project: %', _fk_domain_entity, _fk_range_entity, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_domain_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_domain_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_range_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_range_entity::text, NULL::text]); - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $BODY$; - --- 7 -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - epr._deprecated_fk_project AS fk_project, - COALESCE(epr._deprecated_fk_project, 0) AS "coalesce" - FROM information.v_text_property t - JOIN projects.info_proj_rel epr ON epr.fk_entity = t.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" - FROM information.v_text_property t - WHERE t.is_in_project_count > 0; - - -- 6 -CREATE OR REPLACE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.fk_concerned_entity, - text_property.fk_language, - text_property.fk_class_field, - text_property.quill_doc, - text_property.string, - count(epr._deprecated_fk_project) AS is_in_project_count - FROM information.text_property - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = text_property.pk_entity AND epr.is_in_project = true - GROUP BY text_property.pk_entity, text_property.schema_name, text_property.table_name, text_property.notes, text_property.fk_creator, text_property.fk_last_modifier, text_property.tmsp_creation, text_property.tmsp_last_modification, text_property.sys_period, text_property._deprecated_text_property, text_property.fk_concerned_entity, text_property.quill_doc, text_property.fk_language, text_property.fk_class_field, text_property.string; - - --- 5 -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr._deprecated_fk_project AS fk_project, - epr.ord_num AS rank_for_pe_it, - epr.ord_num AS rank_for_te_ent, - COALESCE(epr._deprecated_fk_project, 0) AS project - FROM information.v_role r - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.rank_for_pe_it, - r.rank_for_te_ent, - 0 AS project - FROM information.v_role r - WHERE r.is_in_project_count > 0; - --- 4 -ALTER VIEW warehouse.v_te_en_time_span_per_project_and_repo SET SCHEMA information; - -CREATE OR REPLACE VIEW information.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr._deprecated_fk_project AS fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM projects.info_proj_rel epr - JOIN information.v_role r ON r.pk_entity = epr.fk_entity - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE epr.is_in_project = true - UNION - SELECT r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity AND r.rank_for_te_ent = 1 - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN role_with_time_primitive.fk_property = 71 THEN 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN 'p82b'::text - ELSE role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - - --- 3 -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel._deprecated_pk_entity_version_project_rel AS pk_entity_version_project_rel, - info_proj_rel._deprecated_fk_project AS fk_project, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num, - info_proj_rel.entity_version - FROM projects.info_proj_rel; - --- 2 - -CREATE OR REPLACE VIEW warehouse.v_entities AS - SELECT DISTINCT e.pk_entity, - epr._deprecated_fk_project AS fk_project, - epr._deprecated_fk_project AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM projects.info_proj_rel epr - JOIN information.entity e ON e.pk_entity = epr.fk_entity - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE epr.is_in_project = true AND (e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text])) -UNION - SELECT DISTINCT e.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM information.entity e - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text]) - ORDER BY 1; - - --- 1 -ALTER TABLE public.account_project_rel DROP COLUMN entity_version; -ALTER TABLE public.account_project_rel_vt DROP COLUMN entity_version; - --- ALTER TABLE public.account_project_rel ALTER COLUMN _deprecated_fk_project SET NOT NULL ; --- ALTER TABLE public.account_project_rel_vt ALTER COLUMN _deprecated_fk_project SET NOT NULL; - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON public.account_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - -CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON public.account_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON public.account_project_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); diff --git a/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-up.sql b/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-up.sql deleted file mode 100644 index 5c49b359c..000000000 --- a/server/db-migrate/migrations/_migration_archive/sqls/20190510085733-refactorings-up.sql +++ /dev/null @@ -1,1208 +0,0 @@ --- 1 -ALTER TABLE public.account_project_rel ADD COLUMN entity_version int ; -ALTER TABLE public.account_project_rel_vt ADD COLUMN entity_version int; - -ALTER TABLE public.account_project_rel ALTER COLUMN _deprecated_fk_project DROP NOT NULL; -ALTER TABLE public.account_project_rel_vt ALTER COLUMN _deprecated_fk_project DROP NOT NULL; - -DROP TRIGGER insert_schema_table_name ON public.account_project_rel; -DROP TRIGGER last_modification_tmsp ON public.account_project_rel; -DROP TRIGGER creation_tmsp ON public.account_project_rel; - - --- 2 -CREATE OR REPLACE VIEW warehouse.v_entities AS - SELECT DISTINCT e.pk_entity, - epr.fk_project, - epr.fk_project AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM projects.info_proj_rel epr - JOIN information.entity e ON e.pk_entity = epr.fk_entity - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE epr.is_in_project = true AND (e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text])) -UNION - SELECT DISTINCT e.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM information.entity e - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text]) - ORDER BY 1; - - --- 3 -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel._deprecated_pk_entity_version_project_rel AS pk_entity_version_project_rel, - info_proj_rel.fk_project, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num, - info_proj_rel.entity_version - FROM projects.info_proj_rel; - --- 4 - -CREATE OR REPLACE VIEW information.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM projects.info_proj_rel epr - JOIN information.v_role r ON r.pk_entity = epr.fk_entity - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE epr.is_in_project = true - UNION - SELECT r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity AND r.rank_for_te_ent = 1 - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN role_with_time_primitive.fk_property = 71 THEN 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN 'p82b'::text - ELSE role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - - -ALTER VIEW information.v_te_en_time_span_per_project_and_repo SET SCHEMA warehouse; - --- 5 -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.ord_num AS rank_for_pe_it, - epr.ord_num AS rank_for_te_ent, - COALESCE(epr.fk_project, 0) AS project - FROM information.v_role r - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.rank_for_pe_it, - r.rank_for_te_ent, - 0 AS project - FROM information.v_role r - WHERE r.is_in_project_count > 0; - --- 6 - -CREATE OR REPLACE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.fk_concerned_entity, - text_property.fk_language, - text_property.fk_class_field, - text_property.quill_doc, - text_property.string, - count(epr.fk_project) AS is_in_project_count - FROM information.text_property - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = text_property.pk_entity AND epr.is_in_project = true - GROUP BY text_property.pk_entity, text_property.schema_name, text_property.table_name, text_property.notes, text_property.fk_creator, text_property.fk_last_modifier, text_property.tmsp_creation, text_property.tmsp_last_modification, text_property.sys_period, text_property._deprecated_text_property, text_property.fk_concerned_entity, text_property.quill_doc, text_property.fk_language, text_property.fk_class_field, text_property.string; - --- 7 -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - epr.fk_project AS fk_project, - COALESCE(epr.fk_project, 0) AS "coalesce" - FROM information.v_text_property t - JOIN projects.info_proj_rel epr ON epr.fk_entity = t.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" - FROM information.v_text_property t - WHERE t.is_in_project_count > 0; - - --- 8 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - PERFORM - - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_info_domain into _fk_info_domain - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_info_range into _fk_info_range - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, NULL::text]); - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $BODY$; - - --- 9 - -CREATE OR REPLACE FUNCTION projects.v_info_proj_rel_update_or_creat() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - - --- 10 - -DROP VIEW information.v_persistent_item; -CREATE OR REPLACE VIEW information.v_persistent_item AS -SELECT * FROM information.persistent_item; - --- 11 - - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, r.rank_for_pe_it as rank - FROM information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - UNION - ( - SELECT r.fk_entity as pk, r.rank_for_te_ent as rank - FROM information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - ) AS a - ORDER BY rank - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_object: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, epr.ord_num - FROM information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - - UNION - - ( - SELECT r.fk_entity as pk, epr.ord_num - FROM information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - ) AS a - ORDER BY ord_num - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', old_fk_entity_label, - 'new_val', new_fk_entity_label) - INTO result_info; - - RETURN result_info; - END; - $BODY$; - --- 12 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_time_span jsonb; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_time_span - SELECT time_span INTO new_time_span - FROM warehouse.v_te_en_time_span_per_project_and_repo - WHERE fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_time_span: %', new_time_span; - - -- update this entity_preview with new_time_span - UPDATE warehouse.entity_preview - SET time_span = new_time_span - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $BODY$; - - - -- 13 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity AND r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY r.rank_for_te_ent - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - -- TODO: Check if we need to exclude textproperties that are in 0 projects$ - -- TODO: Check if we need to order textproperties - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - LEFT JOIN projects.info_proj_rel as epr ON epr.fk_entity = r.pk_entity - AND epr.fk_project = param_fk_project AND epr.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY epr.ord_num - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity = txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - END IF; - - RETURN true; - END; - $BODY$; - - -- 14 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; - BEGIN - - - - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT ( - SELECT fk_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1 - ) IS NULL - ) THEN - - IF param_fk_project IS NULL THEN - - ---------------------- REPO VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN projects.info_proj_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - and r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN projects.info_proj_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - LEFT JOIN projects.info_proj_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = param_fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - ORDER BY epr2.ord_num - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - - - END IF; - - - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - - ----- Insert or update column own_entity_label of table entity_preview - - SELECT entity_label INTO old_own_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - - ELSIF (SELECT (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET entity_label = new_own_entity_label - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; - - END IF; - RETURN true; - END; - $BODY$; - - - -- 15 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - has_type_properties INT[] = ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.v_entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.fk_info_domain = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (has_type_properties) - AND ea.fk_info_domain = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; - --- 16 - -CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_time_primitive; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.time_primitive ( - julian_day, - duration, - fk_class - ) - VALUES ( - NEW.julian_day, - NEW.duration, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_time_primitive - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; diff --git a/server/db-migrate/migrations/_seeds_archive/20171022163320-com-system-type.js b/server/db-migrate/migrations/_seeds_archive/20171022163320-com-system-type.js deleted file mode 100644 index 32e8e1d00..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20171022163320-com-system-type.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - INSERT INTO commons.system_type (notes) - VALUES - ('label of entity') - `; - - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - TRUNCATE commons.system_type CASCADE; - `; - - db.runSql(sql, callback); -}; - - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20171028092820-dfh-class.js b/server/db-migrate/migrations/_seeds_archive/20171028092820-dfh-class.js deleted file mode 100644 index cd644d4da..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20171028092820-dfh-class.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - const sql = ` - INSERT INTO data_for_history.class (dfh_pk_class, dfh_identifier_in_namespace, dfh_standard_label) - VALUES - (1, 'E21', 'Person'), - (2, 'E82', 'Actor Appellation'), - (3, 'F52', 'Name Use Activity'), - (4, 'E56', 'Language'), - (5, 'E67', 'Birth'), - (335, 'E61', 'Time Primitive'), - (22, 'E2', 'Temporal Entity'), - (363, 'histC8', 'Geographical Place'), - (84, 'E93', 'Presence'), - (51, 'E53', 'Place') - - `; - - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - TRUNCATE data_for_history.class CASCADE; - `; - - db.runSql(sql, callback); -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20171029135904-dfh-property.js b/server/db-migrate/migrations/_seeds_archive/20171029135904-dfh-property.js deleted file mode 100644 index 6bfc8d270..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20171029135904-dfh-property.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - const sql = ` - INSERT INTO data_for_history.property ( - dfh_pk_property, - dfh_identifier_in_namespace, - dfh_has_domain, - dfh_has_range, - dfh_standard_label, - dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier - ) - VALUES - (1, 'R63', 3, 1, 'Named', 0, -1, 0, -1), - (2, 'R64', 3, 2, 'Used Name', 0, -1, 1, 1), - (3, 'R61', 3, 4, 'Occured in kind of context', 0, -1, 1, 1), - (4, 'P96', 5, 1, 'By Mother', 1, -1, 1, 1), - (5, 'P97', 5, 1, 'From Father', 1, -1, 1, 1), - (6, 'P98', 5, 1, 'Brought into life', 1, 1, 1, 9), - - -- histC8 is identfied by E82 appellation - (7, 'R63', 3, 363, 'Named', 0, -1, 0, -1), - - -- properties to time_primitives - (71, 'P81', 22, 335, 'Ongoing throughout', 0, 1, 0, 1), - (150, 'P81a', 22, 335, 'End of begin', 0, 1, 0, 1), - (151, 'P81b', 22, 335, 'Begin of end', 0, 1, 0, 1), - (72, 'P82', 22, 335, 'At some time within', 0, 1, 0, 1), - (152, 'P82a', 22, 335, 'Begin of begin', 0, 1, 0, 1), - (153, 'P82b', 22, 335, 'End of end', 0, 1, 0, 1), - - - -- properties of E93 Precence - (147, 'P166', 84, 363, 'Was a precence of', 1, 1, 1, 1), - (148, 'P167', 84, 51, 'Was at', 1, 1, 1, 1) - - `; - - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - TRUNCATE data_for_history.property CASCADE; - `; - - db.runSql(sql, callback); -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20171029143103-inf-persistent-item.js b/server/db-migrate/migrations/_seeds_archive/20171029143103-inf-persistent-item.js deleted file mode 100644 index 98269b624..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20171029143103-inf-persistent-item.js +++ /dev/null @@ -1,366 +0,0 @@ -'use strict'; -var faker = require('faker'); - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - let sqlArray = []; - - const getInsertStatement = function (firstname, lastname, seedProject){ - return ` - -- insert a new person - - WITH insert_persistent_item AS ( - INSERT INTO information.persistent_item (fk_class, notes) - VALUES - ( - 1, -- Person - '` + firstname + ' ' + lastname + `' - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Appellation Usage - insert_appe_usage AS ( - INSERT INTO information.temporal_entity (fk_class, notes) - SELECT dfh_pk_class, notes - FROM data_for_history.class AS c - WHERE c.dfh_pk_class = 3 -- Name Use Activity - ON CONFLICT DO NOTHING - RETURNING pk_temporal_entity, pk_entity, entity_version - ), - - -- relate Person with Appellation Usage - insert_role_1 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 1, -- Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 1 -- Named - ), - ( - SELECT pk_entity - FROM insert_persistent_item - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Appellation - insert_appe AS ( - INSERT INTO information.appellation (fk_class, appellation_label) - VALUES - ( - 2, -- Actor Appellation - ( - SELECT '{"latestTokenId":4,"tokens":[{"id":0,"string":"` + firstname + `","typeId":1,"isSeparator":false},{"id":1,"string":" ","isSeparator":true},{"id":2,"string":"` + lastname + `","typeId":3,"isSeparator":false}]}'::jsonb - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- relate Appellation with Appellation Usage - insert_role_2 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 2, -- Used Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 2 -- Used Named - ), - ( - SELECT pk_entity - FROM insert_appe - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- relate Appellation Usage with Language - insert_role_3 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 3, -- Occured in Kind of context - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 3 - ), - ( - SELECT pk_entity - FROM information.language - WHERE pk_language = 'deu' -- German - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Appellation Usage 2 - insert_appe_usage_2 AS ( - INSERT INTO information.temporal_entity (fk_class, notes) - SELECT dfh_pk_class, notes - FROM data_for_history.class AS c - WHERE c.dfh_pk_class = 3 -- Name Use Activity - ON CONFLICT DO NOTHING - RETURNING pk_temporal_entity, pk_entity, entity_version - ), - - -- relate Person with Appellation Usage - insert_role_4 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 1, -- Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 1 -- Named - ), - ( - SELECT pk_entity - FROM insert_persistent_item - ), - ( - SELECT pk_entity - FROM insert_appe_usage_2 - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Appellation - insert_appe_2 AS ( - INSERT INTO information.appellation (fk_class, appellation_label) - VALUES - ( - 2, -- Actor Appellation - ( - SELECT '{"latestTokenId":4,"tokens":[{"id":0,"string":"` + firstname + `s","typeId":1,"isSeparator":false},{"id":1,"string":" ","isSeparator":true},{"id":2,"string":"` + lastname + `s","typeId":3,"isSeparator":false}]}'::jsonb - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- relate Appellation with Appellation Usage - insert_role_5 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 2, -- Used Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 2 -- Used Named - ), - ( - SELECT pk_entity - FROM insert_appe_2 - ), - ( - SELECT pk_entity - FROM insert_appe_usage_2 - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add all the entities to the seed project - add_entities_to_seed_project AS ( - INSERT INTO information.entity_version_project_rel (fk_project, fk_entity_version_concat, is_in_project, is_standard_in_project) - VALUES - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_persistent_item), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe_usage), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_1), - true, - true - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_2), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_3), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe_usage_2), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_4), - true, - false - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe_2), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_5), - true, - null - ), - -- Also add the language to the project - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - ( - SELECT pk_entity_version_concat - FROM information.v_language_version - WHERE pk_language = 'deu' -- German - ), - true, - null - ) - - - - ON CONFLICT DO NOTHING - ) - - Select true as success; - ` - } - - for (var i = 0; i < 4; i++) { - faker.locale = "fr"; - - sqlArray.push(getInsertStatement( - faker.name.firstName(), - faker.name.lastName(), - 'Francesco Seed Project' - )); - } - - for (var i = 0; i < 25; i++) { - faker.locale = "de_CH"; - - sqlArray.push(getInsertStatement( - faker.name.firstName(), - faker.name.lastName(), - 'Jonas Seed Project' - )); - } - - for (var i = 0; i < 25; i++) { - faker.locale = "de_CH"; - - sqlArray.push(getInsertStatement( - faker.name.firstName(), - faker.name.lastName(), - 'Jonas Seed Project2' - )); - } - - for (var i = 0; i < 2; i++) { - faker.locale = "de_CH"; - - sqlArray.push(getInsertStatement( - faker.name.firstName(), - faker.name.lastName(), - 'David Seed Project' - )); - } - - - const sql = sqlArray.join('') - console.log(`Sample insert statement - ` + getInsertStatement( - faker.name.firstName(), - faker.name.lastName(), - 'David Seed Project') - ) - console.log('Try to insert persistent items: ' + sqlArray.length); - - db.runSql(sql, callback); - - }; - - exports.down = function(db, callback) { - const sql = ` - TRUNCATE information.persistent_item CASCADE; - TRUNCATE information.role CASCADE; - TRUNCATE information.appellation CASCADE; - TRUNCATE information.temporal_entity CASCADE; - TRUNCATE information.entity_version_project_rel CASCADE; - - - TRUNCATE information.persistent_item_vt CASCADE; - TRUNCATE information.role_vt CASCADE; - TRUNCATE information.appellation_vt CASCADE; - TRUNCATE information.temporal_entity_vt CASCADE; - TRUNCATE information.entity_version_project_rel CASCADE; - `; - - db.runSql(sql, callback); - }; - - exports._meta = { - "version": 1 - }; diff --git a/server/db-migrate/migrations/_seeds_archive/20171120072621-inf-modify-persistent-item.js b/server/db-migrate/migrations/_seeds_archive/20171120072621-inf-modify-persistent-item.js deleted file mode 100644 index 057c2011d..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20171120072621-inf-modify-persistent-item.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - const sql = ` - -- Add a Persistent Item to another Project - WITH insert_epr_1 AS ( - INSERT INTO information.entity_version_project_rel (fk_project, fk_entity_version_concat, is_in_project) - VALUES - ( - ( - SELECT pk_project - FROM commons.project AS p - WHERE p.notes = 'Jonas Seed Project' - ), - ( - SELECT pk_entity_version_concat - FROM information.v_persistent_item_version pv - INNER JOIN information.entity_version_project_rel AS epr ON - epr.fk_entity_version_concat = concat(pv.pk_entity || '_' || pv.entity_version) - WHERE epr.fk_project <> ( - SELECT pk_project - FROM commons.project AS p - WHERE p.notes = 'Jonas Seed Project' - ) - AND pv.is_community_favorite = true - LIMIT 1 - ), - true - ) - RETURNING fk_project, fk_entity_version_concat, pk_entity_version_project_rel - ), - - -- Update the Persistent Item - update_pi_1 AS ( - UPDATE information.persistent_item - SET notes = 'updated' WHERE concat(pk_entity || '_' || entity_version) = ( - SELECT fk_entity_version_concat - FROM insert_epr_1 - ) - RETURNING pk_entity, entity_version - ), - - -- Update the new Entity Version Project Relation to have the new value - add_new_version_to_project AS ( - UPDATE information.entity_version_project_rel - SET fk_entity_version_concat = ( - SELECT concat(pk_entity || '_' || entity_version) - FROM update_pi_1 - ) - WHERE pk_entity_version_project_rel = ( - SELECT pk_entity_version_project_rel - FROM insert_epr_1 - ) - ) - select pk_entity - FROM update_pi_1 - - `; - - - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - TRUNCATE information.persistent_item CASCADE; - TRUNCATE information.entity_version_project_rel CASCADE; - - TRUNCATE information.persistent_item_vt CASCADE; - TRUNCATE information.entity_version_project_rel_vt CASCADE; - `; - - db.runSql(sql, callback); -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20180222162455-dfh-labels-for-properties.js b/server/db-migrate/migrations/_seeds_archive/20180222162455-dfh-labels-for-properties.js deleted file mode 100644 index d77ccd980..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20180222162455-dfh-labels-for-properties.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** -* We receive the dbmigrate dependency from dbmigrate initially. -* This enables us to not have to rely on NODE_PATH. -*/ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function (db, callback) { - const sql = ` - INSERT INTO data_for_history.label (dfh_fk_property, dfh_label, notes) - VALUES - (1, 'Entity with this Name', 'label.sg'), - (1, 'Entities with this Name', 'label.pl'), - (1, 'Name', 'label_inversed.sg'), - (1, 'Names', 'label_inversed.pl'), - - (2, 'Detailed Name', 'label.sg'), - (2, 'Detailed Names', 'label.pl'), - (2, 'Names with this details', 'label_inversed.sg'), - (2, 'Name with this details', 'label_inversed.pl'), - - (3, 'Language', 'label.sg'), - (3, 'Languages', 'label.pl'), - (3, 'Name with this language', 'label_inversed.sg'), - (3, 'Names with this language', 'label_inversed.pl'), - - (4, 'Mother', 'label.sg'), - (4, 'Mothers', 'label.pl'), - (4, 'Bith given as Mother', 'label_inversed.sg'), - (4, 'Births given as Mother', 'label_inversed.pl'), - - (5, 'Father', 'label.sg'), - (5, 'Fathers', 'label.pl'), - (5, 'Birth initiated as biological Father', 'label_inversed.sg'), - (5, 'Births initiated as biological Father', 'label_inversed.pl'), - - (6, 'Born child', 'label.sg'), - (6, 'Born children', 'label.pl'), - (6, 'Birth', 'label_inversed.sg'), - (6, 'Births', 'label_inversed.pl'), - - (71, 'Ongoing throughout' , 'label_inversed.sg'), - (150,'End of begin' , 'label_inversed.sg'), - (151,'Begin of end' , 'label_inversed.sg'), - (72, 'At some time within', 'label_inversed.sg'), - (152,'Begin of begin' , 'label_inversed.sg'), - (153,'End of end' , 'label_inversed.sg') - - - ; `; - - - db.runSql(sql, callback); - -}; - -exports.down = function (db, callback) { - const sql = ` - TRUNCATE data_for_history.label CASCADE; - `; - - db.runSql(sql, callback); -}; - - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20180305090856-inf-add-a-birth.js b/server/db-migrate/migrations/_seeds_archive/20180305090856-inf-add-a-birth.js deleted file mode 100644 index fca7d323f..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20180305090856-inf-add-a-birth.js +++ /dev/null @@ -1,298 +0,0 @@ -'use strict'; -var faker = require('faker'); - -var dbm; -var type; -var seed; - - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - - -exports.up = function(db, callback) { - var faker = require('faker'); - - const firstname = faker.name.firstName(); - const lastname = 'Tobler'; - const seedProject = 'Jonas Seed Project'; - - const sql = ` - -- insert a new person - - WITH insert_persistent_item AS ( - INSERT INTO information.persistent_item (fk_class, notes) - VALUES - ( - 1, -- Person - '` + firstname + ' ' + lastname + `' - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Birth - insert_birth AS ( - INSERT INTO information.temporal_entity (fk_class, notes) - VALUES ( - ( - - SELECT dfh_pk_class - FROM data_for_history.class AS c - WHERE c.dfh_pk_class = 5 -- Birth - ), - 'TestBirth' - ) - ON CONFLICT DO NOTHING - RETURNING pk_temporal_entity, pk_entity, entity_version - ), - - -- relate Person with Birth - insert_role_4 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 6, -- Brought into life - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 6 -- Brought into life - ), - ( - SELECT pk_entity - FROM insert_persistent_item - ), - ( - SELECT pk_entity - FROM insert_birth - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - -- select an random Person - select_person AS ( - SELECT pk_entity, entity_version - FROM information.v_persistent_item_version - WHERE fk_class = 1 -- Person - AND pk_entity = 50450 - LIMIT 1 - ), - -- relate Random Person in the role of the Mother with Birth - insert_role_5 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 4, -- By Mother - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 4 -- By Mother - ), - ( - SELECT pk_entity - FROM select_person - ), - ( - SELECT pk_entity - FROM insert_birth - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - -- add an Appellation Usage - insert_appe_usage AS ( - INSERT INTO information.temporal_entity (fk_class, notes) - SELECT dfh_pk_class, notes - FROM data_for_history.class AS c - WHERE c.dfh_pk_class = 3 -- Name Use Activity - ON CONFLICT DO NOTHING - RETURNING pk_temporal_entity, pk_entity, entity_version - ), - - -- relate Person with Appellation Usage - insert_role_1 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 1, -- Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 1 -- Named - ), - ( - SELECT pk_entity - FROM insert_persistent_item - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add an Appellation - insert_appe AS ( - INSERT INTO information.appellation (fk_class, appellation_label) - VALUES - ( - 2, -- Actor Appellation - ( - SELECT '{"latestTokenId":4,"tokens":[{"id":0,"string":"` + firstname + `","typeId":1,"isSeparator":false},{"id":1,"string":" ","isSeparator":true},{"id":2,"string":"` + lastname + `","typeId":3,"isSeparator":false}]}'::jsonb - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- relate Appellation with Appellation Usage - insert_role_2 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 2, -- Used Named - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 2 -- Used Named - ), - ( - SELECT pk_entity - FROM insert_appe - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- relate Appellation Usage with Language - insert_role_3 AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 3, -- Occured in Kind of context - ( - SELECT notes - FROM data_for_history.property - WHERE dfh_pk_property = 3 - ), - ( - SELECT pk_entity - FROM information.language - WHERE pk_language = 'deu' -- German - ), - ( - SELECT pk_entity - FROM insert_appe_usage - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - - -- add all the entities to the seed project - add_entities_to_seed_project AS ( - INSERT INTO information.entity_version_project_rel (fk_project, fk_entity_version_concat, is_in_project, is_standard_in_project) - VALUES - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_persistent_item), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe_usage), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_1), - true, - true - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_appe), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_2), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_3), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_4), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role_5), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_birth), - true, - null - ), - -- Also add the language to the project - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - ( - SELECT pk_entity_version_concat - FROM information.v_language_version - WHERE pk_language = 'deu' -- German - ), - true, - null - ) - ON CONFLICT DO NOTHING - ) - - Select true as success; - ` - - db.runSql(sql, callback) - -}; - -exports.down = function(db, callback) { - - const sql = ` - - ` - - db.runSql(sql, callback) - -}; -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/_seeds_archive/20180322153550-inf-add-time-primitives.js b/server/db-migrate/migrations/_seeds_archive/20180322153550-inf-add-time-primitives.js deleted file mode 100644 index 2cd2fa5ae..000000000 --- a/server/db-migrate/migrations/_seeds_archive/20180322153550-inf-add-time-primitives.js +++ /dev/null @@ -1,85 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function(options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -exports.up = function(db, callback) { - - const seedProject = 'Jonas Seed Project'; - - const sql = ` - WITH insert_time_primitive AS ( - INSERT INTO information.time_primitive (begin, duration, fk_class) - VALUES - ('J1971231'::timestamp, '1 day', 335) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - -- relate with a birth (temporal entity) - insert_role AS ( - INSERT INTO information."role" (fk_property, notes, fk_entity, fk_temporal_entity) - VALUES - ( - 72, -- At some time within - 'At some time within', - ( - SELECT pk_entity - FROM insert_time_primitive - ), - ( - SELECT pk_entity - FROM information.temporal_entity - WHERE notes = 'TestBirth' - ) - ) - ON CONFLICT DO NOTHING - RETURNING pk_entity, entity_version - ), - -- add the role and the time primitive to the seed project - add_entities_to_seed_project AS ( - INSERT INTO information.entity_version_project_rel (fk_project, fk_entity_version_concat, is_in_project, is_standard_in_project) - VALUES - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_role), - true, - null - ), - ( - (SELECT pk_project FROM commons.project AS p WHERE p.notes = '` + seedProject + `'), - (SELECT concat(pk_entity || '_' || entity_version) FROM insert_time_primitive), - true, - null - ) - ON CONFLICT DO NOTHING - ) - Select true as success; - `; - - - db.runSql(sql, callback); - -}; - -exports.down = function(db, callback) { - const sql = ` - TRUNCATE information.time_primitive CASCADE; - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/property-labels/20180613172800-property-labels.js b/server/db-migrate/migrations/property-labels/20180613172800-property-labels.js deleted file mode 100644 index 9c9f2d187..000000000 --- a/server/db-migrate/migrations/property-labels/20180613172800-property-labels.js +++ /dev/null @@ -1,235 +0,0 @@ -'use strict'; - -var dbm; -var type; -var seed; - -/** - * We receive the dbmigrate dependency from dbmigrate initially. - * This enables us to not have to rely on NODE_PATH. - */ -exports.setup = function (options, seedLink) { - dbm = options.dbmigrate; - type = dbm.dataType; - seed = seedLink; -}; - -// (1, 'Entity with this Name', 'label.sg'), -// (1, 'Entities with this Name', 'label.pl'), -// (1, 'Name', 'label_inversed.sg'), -// (1, 'Names', 'label_inversed.pl'), - -// (2, 'Detailed Name', 'label.sg'), -// (2, 'Detailed Names', 'label.pl'), -// (2, 'Names with this details', 'label_inversed.sg'), -// (2, 'Name with this details', 'label_inversed.pl'), - -// (3, 'Language', 'label.sg'), -// (3, 'Languages', 'label.pl'), -// (3, 'Name with this language', 'label_inversed.sg'), -// (3, 'Names with this language', 'label_inversed.pl'), -exports.up = function (db, callback) { - const sql = ` - - INSERT INTO data_for_history.label (dfh_fk_property, dfh_label, notes) - VALUES - - ------------------- Person --------------------- - - (84, 'Mother', 'label.sg'), - (84, 'Mothers', 'label.pl'), - (84, 'Bith given as Mother', 'label_inversed.sg'), - (84, 'Births given as Mother', 'label_inversed.pl'), - - (85, 'Father', 'label.sg'), - (85, 'Fathers', 'label.pl'), - (85, 'Birth initiated as biological Father', 'label_inversed.sg'), - (85, 'Births initiated as biological Father', 'label_inversed.pl'), - - (86, 'Born child', 'label.sg'), - (86, 'Born children', 'label.pl'), - (86, 'Birth', 'label_inversed.sg'), - (86, 'Births', 'label_inversed.pl'), - - (88, 'Person that died', 'label.sg'), - (88, 'Persons that died', 'label.pl'), - (88, 'Death', 'label_inversed.sg'), - (88, 'Deaths', 'label_inversed.pl'), - - (1180, 'Person located relative to place', 'label.sg'), - (1180, 'Person located relative to place', 'label.pl'), - (1180, 'Found himself / herself at place', 'label_inversed.sg'), - (1180, 'Found himself / herself at place', 'label_inversed.pl'), - - (1188, 'Member (Person)', 'label.sg'), - (1188, 'Members (Persons)', 'label.pl'), - (1188, 'Is member of', 'label_inversed.sg'), - (1188, 'Is member of', 'label_inversed.pl'), - - (1192, 'Entity with this Name', 'label.sg'), - (1192, 'Entities with this Name', 'label.pl'), - (1192, 'Name', 'label_inversed.sg'), - (1192, 'Names', 'label_inversed.pl'), - - - ------------------ Group --------------------- - - (83, 'Formed Group (Organization)', 'label.sg'), - (83, 'Formed Groups (Organizations)', 'label.pl'), - (83, 'Start (Formation / Foundation)', 'label_inversed.sg'), - (83, 'Start (Formations / Foundations)', 'label_inversed.pl'), - - (87, 'Dissolved Group (Organization)', 'label.sg'), - (87, 'Dissolved Groups (Organizations)', 'label.pl'), - (87, 'End (Dissolution)', 'label_inversed.sg'), - (87, 'End (Dissolution)', 'label_inversed.pl'), - - -- todo: 132, 134, 139, 1013, 1035 - - (132, 'Was joined', 'label.sg'), - (132, 'Was joined', 'label.pl'), - (132, 'Joining', 'label_inversed.sg'), - (132, 'Joining', 'label_inversed.pl'), - - (134, 'Was left', 'label.sg'), - (134, 'Was left', 'label.pl'), - (134, 'Left', 'label_inversed.sg'), - (134, 'Left', 'label_inversed.pl'), - - (139, 'Formed from Group (Organization)', 'label.sg'), - (139, 'Formed from Groups (Organization)', 'label.pl'), - (139, 'Participated in Formation', 'label_inversed.sg'), - (139, 'Participated in Formation', 'label_inversed.pl'), - - (1182, 'Is location of', 'label.sg'), - (1182, 'Is location of', 'label.pl'), - (1182, 'Localization (time related)', 'label_inversed.sg'), - (1182, 'Localization (time related)', 'label_inversed.pl'), - - (1189, 'Group (Organization)', 'label.sg'), - (1189, 'Group (Organization)', 'label.pl'), - (1189, 'Member', 'label_inversed.sg'), - (1189, 'Members', 'label_inversed.pl'), - - (1193, 'Entity with this Name', 'label.sg'), - (1193, 'Entities with this Name', 'label.pl'), - (1193, 'Name', 'label_inversed.sg'), - (1193, 'Names', 'label_inversed.pl'), - - - ------------- Geographical Place ----------------- - - (1178, 'Was located relative to place', 'label.sg'), - (1178, 'Was located relative to places', 'label.pl'), - (1178, 'Was place of', 'label_inversed.sg'), - (1178, 'Was place of', 'label_inversed.pl'), - - (1194, 'Entity with this Name', 'label.sg'), - (1194, 'Entities with this Name', 'label.pl'), - (1194, 'Name', 'label_inversed.sg'), - (1194, 'Names', 'label_inversed.pl'), - - (1113, 'Detailed Name', 'label.sg'), - (1113, 'Detailed Names', 'label.pl'), - (1113, 'Names with this details', 'label_inversed.sg'), - (1113, 'Name with this details', 'label_inversed.pl'), - - (1181, 'Place', 'label.sg'), - (1181, 'Places', 'label.pl'), - (1181, 'Geolocalization (time related)', 'label_inversed.sg'), - (1181, 'Geolocalizations (time related)', 'label_inversed.pl'), - - - ------------- Built Work ------------ - (1195, 'Entity with this Name', 'label.sg'), - (1195, 'Entities with this Name', 'label.pl'), - (1195, 'Name', 'label_inversed.sg'), - (1195, 'Names', 'label_inversed.pl'), - - (1184, 'Place', 'label.sg'), - (1184, 'Places', 'label.pl'), - (1184, 'Geolocalization (time related)', 'label_inversed.sg'), - (1184, 'Geolocalizations (time related)', 'label_inversed.pl'), - - - - ------------- Place ----------------- - - (148, 'Geocoordinates', 'label.sg'), - (148, 'Geocoordinates', 'label.pl'), - (148, 'Are coordinates of precence', 'label_inversed.sg'), - (148, 'Are coordinates of precences', 'label_inversed.pl'), - - - ------------- BIRTH ----------------- - - (1186, 'Born at this place', 'label.sg'), - (1186, 'Born at this places', 'label.pl'), - (1186, 'Is place of birth', 'label_inversed.sg'), - (1186, 'Is place of births', 'label_inversed.pl'), - - (1187, 'Born in this building', 'label.sg'), - (1187, 'Born in this building', 'label.pl'), - (1187, 'Is place of birth', 'label_inversed.sg'), - (1187, 'Is place of births', 'label_inversed.pl'), - - ------------- DEATH ----------------- - - (1191, 'Died at this place', 'label.sg'), - (1191, 'Died at this places', 'label.pl'), - (1191, 'Is place of death', 'label_inversed.sg'), - (1191, 'Is place of death', 'label_inversed.pl'), - - - ------------- TIME RELATED LOCALIZATION ----------------- - - (1185, 'Built work located relative to place', 'label.sg'), - (1185, 'Built work located relative to places', 'label.pl'), - (1185, 'Was built at place', 'label_inversed.sg'), - (1185, 'Was built at places', 'label_inversed.pl'), - - - - ------------------ Time Span --------------------- - - (71, 'Ongoing throughout' , 'label_inversed.sg'), - (150,'End of begin' , 'label_inversed.sg'), - (151,'Begin of end' , 'label_inversed.sg'), - (72, 'At some time within', 'label_inversed.sg'), - (152,'Begin of begin' , 'label_inversed.sg'), - (153,'End of end' , 'label_inversed.sg'), - (71, 'Ongoing throughout' , 'label.pl'), - (150,'End of begin' , 'label.pl'), - (151,'Begin of end' , 'label.pl'), - (72, 'At some time within', 'label.pl'), - (152,'Begin of begin' , 'label.pl'), - (153,'End of end' , 'label.pl'), - - - ------------------ Appellation for language --------------------- - - (1112, 'Language', 'label.sg'), - (1112, 'Languages', 'label.pl'), - (1112, 'Name with this language', 'label_inversed.sg'), - (1112, 'Names with this language', 'label_inversed.pl') - - ;`; - - - db.runSql(sql, callback); - -}; - -exports.down = function (db, callback) { - const sql = ` - DELETE FROM data_for_history.label - WHERE - notes IN ('label.sg','label.pl','label_inversed.sg','label_inversed.pl'); - `; - - db.runSql(sql, callback); -}; - -exports._meta = { - "version": 1 -}; diff --git a/server/db-migrate/migrations/sqls/20190515131648-initialize-beta-schema-up.sql b/server/db-migrate/migrations/sqls/20190515131648-initialize-beta-schema-up.sql deleted file mode 100644 index 766a74fa5..000000000 --- a/server/db-migrate/migrations/sqls/20190515131648-initialize-beta-schema-up.sql +++ /dev/null @@ -1,14081 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 10.6 (Debian 10.6-1.pgdg90+1) --- Dumped by pg_dump version 11.2 - --- Started on 2019-05-15 15:21:04 CEST - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET client_min_messages = warning; -SET row_security = off; - --- --- TOC entry 14 (class 2615 OID 244677) --- Name: commons; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA commons; - - --- --- TOC entry 16 (class 2615 OID 245291) --- Name: data; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA data; - - --- --- TOC entry 10 (class 2615 OID 240162) --- Name: data_for_history; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA data_for_history; - - --- --- TOC entry 9 (class 2615 OID 240161) --- Name: information; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA information; - - --- --- TOC entry 13 (class 2615 OID 240160) --- Name: projects; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA projects; - - --- --- TOC entry 15 (class 2615 OID 244678) --- Name: system; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA system; - - --- --- TOC entry 11 (class 2615 OID 242796) --- Name: topology; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA IF NOT EXISTS topology; - - --- --- TOC entry 6156 (class 0 OID 0) --- Dependencies: 11 --- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON SCHEMA topology IS 'PostGIS Topology schema'; - - --- --- TOC entry 12 (class 2615 OID 243970) --- Name: warehouse; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA warehouse; - - --- --- TOC entry 2 (class 3079 OID 241297) --- Name: postgis; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; - - --- --- TOC entry 6157 (class 0 OID 0) --- Dependencies: 2 --- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: - --- - --- COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions'; - - --- --- TOC entry 3 (class 3079 OID 242797) --- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS postgis_topology; -- WITH SCHEMA topology; - - --- --- TOC entry 6158 (class 0 OID 0) --- Dependencies: 3 --- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: - --- - --- COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions'; - - --- --- TOC entry 2522 (class 1247 OID 241176) --- Name: calendar_granularities; Type: TYPE; Schema: public; Owner: - --- - -CREATE TYPE public.calendar_granularities AS ENUM ( - '1 year', - '1 month', - '1 day', - '1 hour', - '1 minute', - '1 second' -); - - --- --- TOC entry 2532 (class 1247 OID 241228) --- Name: calendar_type; Type: TYPE; Schema: public; Owner: - --- - -CREATE TYPE public.calendar_type AS ENUM ( - 'gregorian', - 'julian' -); - - --- --- TOC entry 1725 (class 1255 OID 244670) --- Name: _validate_json_schema_type(text, jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons._validate_json_schema_type(type text, data jsonb) RETURNS boolean - LANGUAGE plpgsql IMMUTABLE - AS $$ - BEGIN - IF type = 'integer' THEN - IF jsonb_typeof(data) != 'number' THEN - RETURN false; - END IF; - IF trunc(data::text::numeric) != data::text::numeric THEN - RETURN false; - END IF; - ELSE - IF type != jsonb_typeof(data) THEN - RETURN false; - END IF; - END IF; - RETURN true; - END; - $$; - - --- --- TOC entry 1724 (class 1255 OID 244676) --- Name: appellation_label_to_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.appellation_label_to_quill_doc(orig jsonb) RETURNS jsonb - LANGUAGE plpgsql IMMUTABLE - AS $$ - - BEGIN - RETURN commons.text_to_quill_doc(information.appellation_label_to_string(orig)); - END; - $$; - - --- --- TOC entry 1739 (class 1255 OID 244800) --- Name: change_fk_reference_of_versioned_table(character varying, character varying, character varying, character varying, character varying, character varying, boolean); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.change_fk_reference_of_versioned_table(schema_name character varying, table_name character varying, fk_column character varying, referenced_schema_and_table_name character varying, old_referenced_column character varying, new_referenced_column character varying, fk_col_not_null boolean DEFAULT true) RETURNS void - LANGUAGE plpgsql - AS $_$ BEGIN - - EXECUTE format(' - - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; - DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; - - - -- table - ALTER TABLE %1$s.%2$s RENAME COLUMN %3$s TO _deprecated_%3$s; - ALTER TABLE %1$s.%2$s ADD COLUMN %3$s integer; - UPDATE %1$s.%2$s - SET %3$s = subq.%6$s - FROM ( - SELECT %6$s, %5$s - FROM %4$s - ) as subq - WHERE _deprecated_%3$s = subq.%5$s; - - ALTER TABLE %1$s.%2$s - DROP CONSTRAINT IF EXISTS %2$s_%3$s_fkey; - - ALTER TABLE %1$s.%2$s ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); - - -- table_vt - ALTER TABLE %1$s.%2$s_vt RENAME COLUMN %3$s TO _deprecated_%3$s; - ALTER TABLE %1$s.%2$s_vt ADD COLUMN %3$s integer; - UPDATE %1$s.%2$s_vt - SET %3$s = subq.%6$s - FROM ( - SELECT %6$s, %5$s - FROM %4$s - ) as subq - WHERE _deprecated_%3$s = subq.%5$s; - - ALTER TABLE %1$s.%2$s_vt - DROP CONSTRAINT IF EXISTS %2$s_vt_%3$s_fkey; - - ALTER TABLE %1$s.%2$s_vt ADD FOREIGN KEY (%3$s) REFERENCES %4$s (%6$s); - - SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); - - -- Trigger: creation_tmsp - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - - - ', - schema_name, - table_name, - fk_column, - referenced_schema_and_table_name, - old_referenced_column, - new_referenced_column - ); - - - IF (fk_col_not_null = true) THEN - EXECUTE format(' - ALTER TABLE %1$s.%2$s ALTER COLUMN %3$s SET NOT NULL; - ', schema_name, - table_name, - fk_column ); - END IF; - - - END $_$; - - --- --- TOC entry 1731 (class 1255 OID 244705) --- Name: change_parent_entity_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.change_parent_entity_table(child_schema_and_table_name character varying, old_parent_schema_and_table_name character varying, new_parent_schema_and_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; - ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; - UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; - ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; - - ALTER TABLE %1$s NO INHERIT %2$s; - ALTER TABLE %1$s INHERIT %3$s; - SELECT setval(''%3$s_pk_entity_seq'', (SELECT MAX(pk_entity) FROM %1$s)); - ', - child_schema_and_table_name, - old_parent_schema_and_table_name, - new_parent_schema_and_table_name - ); - - END - $_$; - - --- --- TOC entry 470 (class 1255 OID 240169) --- Name: create_entity_version_key(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.create_entity_version_key() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - NEW.entity_version = 1; - RETURN NEW; - END; - $$; - - --- --- TOC entry 475 (class 1255 OID 241295) --- Name: evpr_fk_entity_fk_entity_version(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.evpr_fk_entity_fk_entity_version() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - result text; - - BEGIN - - -- Added if condition: - -- only if there is a fk_entity_version_concat, generate fk_entity and fk_entity_version - - IF (NEW.fk_entity_version_concat IS NOT NULL) THEN - NEW.fk_entity = split_part(NEW.fk_entity_version_concat, '_', 1)::integer; - NEW.fk_entity_version = split_part(NEW.fk_entity_version_concat, '_', 2)::integer; - END IF; - - RETURN NEW; - END; - - $$; - - --- --- TOC entry 468 (class 1255 OID 243541) --- Name: init_entity_child_table(character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.init_entity_child_table(schema_and_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - DECLARE - unique_constraint_name varchar; - BEGIN - - -- Create the name of the unique constraint that will be applied to the new table's pk_entity - - SELECT INTO unique_constraint_name replace( schema_and_table_name , '.' , '_' )_pk_entity_unique; - - -- Do the Magic: - - EXECUTE format(' - - -- Add unique constraint to pk_entity of the new table, so that it can be referenced by foreign keys - - ALTER TABLE %1$s ADD CONSTRAINT %2$s_pk_entity_unique UNIQUE (pk_entity); - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name, - unique_constraint_name - - ); - - END - $_$; - - --- --- TOC entry 1734 (class 1255 OID 244708) --- Name: init_version_table(character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.init_version_table(schema_and_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - BEGIN - - - -- Do the Magic: - - EXECUTE format(' - - ALTER TABLE %1$s ADD COLUMN IF NOT EXISTS - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name - ); - - END - $_$; - - --- --- TOC entry 471 (class 1255 OID 240168) --- Name: insert_schema_table_name(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.insert_schema_table_name() RETURNS trigger - LANGUAGE plpgsql - AS $$ - -- source https://www.postgresql.org/docs/current/static/plpgsql-trigger.html - BEGIN - NEW.schema_name = TG_TABLE_SCHEMA; - NEW.table_name = TG_TABLE_NAME; - RETURN NEW; - END; - $$; - - --- --- TOC entry 1735 (class 1255 OID 244796) --- Name: make_table_child_of_text(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.make_table_child_of_text(schema_and_table_name character varying, parent_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ------ PREPARE THE TABLE - - UPDATE %1$s SET entity_version = 1 WHERE entity_version IS NULL; - - ALTER TABLE %1$s ALTER COLUMN entity_version SET NOT NULL; - - -- SET schema_name NOT NULL - ALTER TABLE %1$s ALTER COLUMN schema_name SET NOT NULL; - - -- SET table_name NOT NULL - ALTER TABLE %1$s ALTER COLUMN table_name SET NOT NULL; - - -- Add the column for the pk_text and fill the new pk_text column - ALTER TABLE %1$s - ADD COLUMN pk_text integer NOT NULL DEFAULT nextval(''commons.text_pk_text_seq''); - - -- Add the column for quill_doc and fill it with empty QuillDoc - ALTER TABLE %1$s ADD COLUMN quill_doc jsonb; - UPDATE %1$s SET quill_doc = jsonb_build_object(''latestId'', 0, ''ops'', ARRAY[]::integer[]) WHERE quill_doc IS NULL; - ALTER TABLE %1$s ALTER COLUMN quill_doc SET NOT NULL; - - -- Add the schema validation check - ALTER TABLE %1$s - ADD CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)); - - -- Add the column for string and fill with empty string - ALTER TABLE %1$s ADD COLUMN string text DEFAULT ''''; - UPDATE %1$s SET string = '''' WHERE string IS NULL; - ALTER TABLE %1$s ALTER COLUMN string SET NOT NULL; - - ---- SET THE INHERITANCE - ALTER TABLE %1$s - INHERIT commons.%2$s; - - ', - schema_and_table_name, - parent_table_name - ); - - END - $_$; - - --- --- TOC entry 1736 (class 1255 OID 244797) --- Name: make_versioned_table_child_of_text(character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.make_versioned_table_child_of_text(schema_and_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ BEGIN - - PERFORM commons.make_table_child_of_text(schema_and_table_name, 'text'); - PERFORM commons.make_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); - - EXECUTE format(' - -- Create trigger for syncing quill_doc and string - CREATE TRIGGER sync_quill_doc_and_string - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - ', schema_and_table_name); - - - END $_$; - - --- --- TOC entry 1723 (class 1255 OID 244669) --- Name: modernize_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.modernize_quill_doc(orig jsonb) RETURNS jsonb - LANGUAGE plpgsql IMMUTABLE - AS $$ - DECLARE - newJ jsonb; - latestId int; - newOps jsonb; - oldOp jsonb; - char text; - BEGIN - newOps = jsonb_build_array(); - latestId = 0; - - -- LOOP over ops - FOR oldOp IN SELECT * FROM jsonb_array_elements((orig->'contents'->>'ops')::jsonb) - LOOP - - RAISE NOTICE 'Parsing Item % % %', oldOp->>'insert', oldOp->>'attributes', (SELECT char_length(oldOp->>'insert') > 1); - - - -- LOOP over insert characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(oldOp->>'insert','')) AS x(chars)) - LOOP - latestId = latestId + 1; - - IF char = E'\n' THEN - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb), '{blockid}'::text[], to_json(latestId::text)::jsonb) - ); - ELSE - newOps = newOps || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_set(COALESCE(oldOp->'attributes', '{}'::jsonb) - 'node', '{charid}'::text[], to_json(latestId::text)::jsonb) - ); - END IF; - END LOOP; - - - END LOOP; - - RAISE NOTICE 'New Ops: %', newOps; - - - newJ = jsonb_build_object('latestId',latestId, 'ops', newOps); - - RETURN newJ; - END; - $$; - - --- --- TOC entry 1732 (class 1255 OID 244706) --- Name: move_entity_child_with_vt_to_schema(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.move_entity_child_with_vt_to_schema(table_name character varying, old_schema character varying, new_schema character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - -- MOVE TABLES - ALTER TABLE %2$s.%1$s SET SCHEMA %3$s; - ALTER TABLE %2$s.%1$s_vt SET SCHEMA %3$s; - - -- REINIT VERSIONING TRIGGERS - SELECT commons.reinit_versioning_triggers(''%3$s.%1$s''); - - -- CHANGE PARENT ENTITY TABLE - SELECT commons.change_parent_entity_table(''%3$s.%1$s'', ''%2$s.entity'', ''%3$s.entity'') - ', - table_name, - old_schema, - new_schema - ); - - END - $_$; - - --- --- TOC entry 1726 (class 1255 OID 244675) --- Name: quill_doc_to_string(jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.quill_doc_to_string(text_property_quill_doc jsonb, OUT string text) RETURNS text - LANGUAGE sql - AS $$ - - SELECT TRIM( TRAILING E' -' FROM STRING_AGG(l.ops->>'insert', '')) - FROM (SELECT jsonb_array_elements(text_property_quill_doc->'ops') as ops) as l - $$; - - --- --- TOC entry 1730 (class 1255 OID 244704) --- Name: reinit_versioning_triggers(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.reinit_versioning_triggers(schema_and_table_name character varying, schema_and_table_vt_name character varying DEFAULT NULL::character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - IF schema_and_table_vt_name IS NULL THEN - schema_and_table_vt_name = schema_and_table_name || '_vt'; - END IF; - - -- Do the Magic: - - EXECUTE format(' - - -- Trigger: versioning_trigger - - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s; - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%2$s'', true - ); - - -- Trigger: create_entity_version_key - - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s; - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s; - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', - schema_and_table_name, - schema_and_table_vt_name - ); - - END - $_$; - - --- --- TOC entry 1733 (class 1255 OID 244707) --- Name: rename_versioned_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.rename_versioned_table(schema character varying, old_table_name character varying, new_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - -- Do the Magic: - - EXECUTE format(' - ALTER TABLE %1$s.%2$s RENAME TO %3$s; - ALTER TABLE %1$s.%2$s_vt RENAME TO %3$s_vt; - SELECT commons.reinit_versioning_triggers(''%1$s.%3$s''); - ', - schema, - old_table_name, - new_table_name - ); - - END - $_$; - - --- --- TOC entry 1728 (class 1255 OID 244674) --- Name: string_to_quill_doc(text); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.string_to_quill_doc(text text) RETURNS jsonb - LANGUAGE plpgsql IMMUTABLE - AS $$ - DECLARE - latestId int; - ops jsonb; - char text; - BEGIN - ops = jsonb_build_array(); - latestId = 1; - - -- LOOP over text characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(text,'')) AS x(chars)) - LOOP - - - IF char = E' -' THEN - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - ELSE - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('charid', to_json(latestId::text)::jsonb) - ); - END IF; - - - latestId = latestId + 1; - END LOOP; - - ops = ops || jsonb_build_object( - 'insert', E' -', - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - - RETURN jsonb_build_object('latestId',latestId, 'ops', ops); - END; - $$; - - --- --- TOC entry 1729 (class 1255 OID 244698) --- Name: text__sync_quill_doc_and_string(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.text__sync_quill_doc_and_string() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - string_is_new boolean; - quill_doc_is_new boolean; - BEGIN - - IF TG_OP = 'UPDATE' THEN - string_is_new = (NEW.string IS NOT NULL AND NEW.string != OLD.string); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL AND NEW.quill_doc != OLD.quill_doc); - ELSE - string_is_new = (NEW.string IS NOT NULL); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL); - END IF; - -- other code - - IF (string_is_new = true AND quill_doc_is_new = true) THEN - RAISE EXCEPTION 'You can not provide a string and a quill_doc at the same time when upserting a text.'; - ELSIF string_is_new = true THEN - NEW.quill_doc = commons.string_to_quill_doc(NEW.string); - ELSIF quill_doc_is_new = true THEN - NEW.string = commons.quill_doc_to_string(NEW.quill_doc); - ELSIF NEW.string IS NULL AND NEW.quill_doc IS NULL THEN - RAISE EXCEPTION 'No string or quill_doc provided on upsert of a text.'; - END IF; - - RETURN NEW; - END; - $$; - - --- --- TOC entry 472 (class 1255 OID 240166) --- Name: tmsp_creation(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.tmsp_creation() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - NEW.tmsp_creation = NOW(); - RETURN NEW; - END; - $$; - - --- --- TOC entry 473 (class 1255 OID 240167) --- Name: tmsp_last_modification(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.tmsp_last_modification() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN NEW.tmsp_last_modification = NOW(); - RETURN NEW; - END; - $$; - - --- --- TOC entry 1740 (class 1255 OID 244801) --- Name: unmake_change_fk_reference_of_versioned_table(character varying, character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.unmake_change_fk_reference_of_versioned_table(schema_name character varying, table_name character varying, fk_column character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ BEGIN - - EXECUTE format(' - - DROP TRIGGER IF EXISTS creation_tmsp ON %1$s.%2$s; - DROP TRIGGER IF EXISTS insert_schema_table_name ON %1$s.%2$s; - DROP TRIGGER IF EXISTS last_modification_tmsp ON %1$s.%2$s; - - DROP TRIGGER IF EXISTS versioning_trigger ON %1$s.%2$s; - DROP TRIGGER IF EXISTS create_entity_version_key ON %1$s.%2$s; - DROP TRIGGER IF EXISTS update_entity_version_key ON %1$s.%2$s; - - -- table_vt - ALTER TABLE %1$s.%2$s_vt DROP CONSTRAINT %2$s_vt_%3$s_fkey; - UPDATE %1$s.%2$s_vt - SET %3$s = _deprecated_%3$s; - ALTER TABLE %1$s.%2$s_vt DROP COLUMN %3$s; - ALTER TABLE %1$s.%2$s_vt RENAME COLUMN _deprecated_%3$s TO %3$s; - - -- table - ALTER TABLE %1$s.%2$s DROP CONSTRAINT %2$s_%3$s_fkey; - UPDATE %1$s.%2$s - SET %3$s = _deprecated_%3$s; - ALTER TABLE %1$s.%2$s DROP COLUMN %3$s; - ALTER TABLE %1$s.%2$s RENAME COLUMN _deprecated_%3$s TO %3$s; - - - SELECT commons.reinit_versioning_triggers(''%1$s.%2$s''); - - -- Trigger: creation_tmsp - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s.%2$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - ', - schema_name, - table_name, - fk_column - ); - - END $_$; - - --- --- TOC entry 1737 (class 1255 OID 244798) --- Name: unmake_table_child_of_text(character varying, character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.unmake_table_child_of_text(schema_and_table_name character varying, parent_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ - - BEGIN - - EXECUTE format(' - ALTER TABLE %1$s NO INHERIT commons.%2$s; - - ALTER TABLE %1$s DROP COLUMN string; - - ALTER TABLE %1$s DROP CONSTRAINT text_quill_doc_check; - - ALTER TABLE %1$s DROP COLUMN quill_doc; - - ALTER TABLE %1$s DROP COLUMN pk_text; - - ', - schema_and_table_name, - parent_table_name - ); - - END - $_$; - - --- --- TOC entry 1738 (class 1255 OID 244799) --- Name: unmake_versioned_table_child_of_text(character varying); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.unmake_versioned_table_child_of_text(schema_and_table_name character varying) RETURNS void - LANGUAGE plpgsql - AS $_$ BEGIN - - PERFORM commons.unmake_table_child_of_text(schema_and_table_name, 'text'); - PERFORM commons.unmake_table_child_of_text(schema_and_table_name || '_vt', 'text_vt'); - - EXECUTE format(' - DROP TRIGGER sync_quill_doc_and_string ON %1$s; - ', schema_and_table_name); - - END $_$; - - --- --- TOC entry 474 (class 1255 OID 240170) --- Name: update_entity_version_key(); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.update_entity_version_key() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - NEW.entity_version := NEW.entity_version + 1; - RETURN NEW; - END; - $$; - - --- --- TOC entry 1722 (class 1255 OID 244671) --- Name: validate_json_schema(jsonb, jsonb, jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.validate_json_schema(schema jsonb, data jsonb, root_schema jsonb DEFAULT NULL::jsonb) RETURNS boolean - LANGUAGE plpgsql IMMUTABLE - AS $_$ - DECLARE - prop text; - item jsonb; - path text[]; - types text[]; - pattern text; - props text[]; - BEGIN - IF root_schema IS NULL THEN - root_schema = schema; - END IF; - - IF schema ? 'type' THEN - IF jsonb_typeof(schema->'type') = 'array' THEN - types = ARRAY(SELECT jsonb_array_elements_text(schema->'type')); - ELSE - types = ARRAY[schema->>'type']; - END IF; - IF (SELECT NOT bool_or(commons._validate_json_schema_type(type, data)) FROM unnest(types) type) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'properties' THEN - FOR prop IN SELECT jsonb_object_keys(schema->'properties') LOOP - IF data ? prop AND NOT commons.validate_json_schema(schema->'properties'->prop, data->prop, root_schema) THEN - RETURN false; - END IF; - END LOOP; - END IF; - - IF schema ? 'required' AND jsonb_typeof(data) = 'object' THEN - IF NOT ARRAY(SELECT jsonb_object_keys(data)) @> - ARRAY(SELECT jsonb_array_elements_text(schema->'required')) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'items' AND jsonb_typeof(data) = 'array' THEN - IF jsonb_typeof(schema->'items') = 'object' THEN - FOR item IN SELECT jsonb_array_elements(data) LOOP - IF NOT commons.validate_json_schema(schema->'items', item, root_schema) THEN - RETURN false; - END IF; - END LOOP; - ELSE - IF NOT ( - SELECT bool_and(i > jsonb_array_length(schema->'items') OR commons.validate_json_schema(schema->'items'->(i::int - 1), elem, root_schema)) - FROM jsonb_array_elements(data) WITH ORDINALITY AS t(elem, i) - ) THEN - RETURN false; - END IF; - END IF; - END IF; - - IF jsonb_typeof(schema->'additionalItems') = 'boolean' and NOT (schema->'additionalItems')::text::boolean AND jsonb_typeof(schema->'items') = 'array' THEN - IF jsonb_array_length(data) > jsonb_array_length(schema->'items') THEN - RETURN false; - END IF; - END IF; - - IF jsonb_typeof(schema->'additionalItems') = 'object' THEN - IF NOT ( - SELECT bool_and(validate_json_schema(schema->'additionalItems', elem, root_schema)) - FROM jsonb_array_elements(data) WITH ORDINALITY AS t(elem, i) - WHERE i > jsonb_array_length(schema->'items') - ) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minimum' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric < (schema->>'minimum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maximum' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric > (schema->>'maximum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'exclusiveMinimum')::text::bool, FALSE) THEN - IF data::text::numeric = (schema->>'minimum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'exclusiveMaximum')::text::bool, FALSE) THEN - IF data::text::numeric = (schema->>'maximum')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'anyOf' THEN - IF NOT (SELECT bool_or(validate_json_schema(sub_schema, data, root_schema)) FROM jsonb_array_elements(schema->'anyOf') sub_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'allOf' THEN - IF NOT (SELECT bool_and(validate_json_schema(sub_schema, data, root_schema)) FROM jsonb_array_elements(schema->'allOf') sub_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'oneOf' THEN - IF 1 != (SELECT COUNT(*) FROM jsonb_array_elements(schema->'oneOf') sub_schema WHERE commons.validate_json_schema(sub_schema, data, root_schema)) THEN - RETURN false; - END IF; - END IF; - - IF COALESCE((schema->'uniqueItems')::text::boolean, false) THEN - IF (SELECT COUNT(*) FROM jsonb_array_elements(data)) != (SELECT count(DISTINCT val) FROM jsonb_array_elements(data) val) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'additionalProperties' AND jsonb_typeof(data) = 'object' THEN - props := ARRAY( - SELECT key - FROM jsonb_object_keys(data) key - WHERE key NOT IN (SELECT jsonb_object_keys(schema->'properties')) - AND NOT EXISTS (SELECT * FROM jsonb_object_keys(schema->'patternProperties') pat WHERE key ~ pat) - ); - IF jsonb_typeof(schema->'additionalProperties') = 'boolean' THEN - IF NOT (schema->'additionalProperties')::text::boolean AND jsonb_typeof(data) = 'object' AND NOT props <@ ARRAY(SELECT jsonb_object_keys(schema->'properties')) THEN - RETURN false; - END IF; - ELSEIF NOT ( - SELECT bool_and(validate_json_schema(schema->'additionalProperties', data->key, root_schema)) - FROM unnest(props) key - ) THEN - RETURN false; - END IF; - END IF; - - IF schema ? '$ref' THEN - path := ARRAY( - SELECT regexp_replace(regexp_replace(path_part, '~1', '/'), '~0', '~') - FROM UNNEST(regexp_split_to_array(schema->>'$ref', '/')) path_part - ); - -- ASSERT path[1] = '#', 'only refs anchored at the root are supported'; - IF NOT commons.validate_json_schema(root_schema #> path[2:array_length(path, 1)], data, root_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'enum' THEN - IF NOT EXISTS (SELECT * FROM jsonb_array_elements(schema->'enum') val WHERE val = data) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minLength' AND jsonb_typeof(data) = 'string' THEN - IF char_length(data #>> '{}') < (schema->>'minLength')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxLength' AND jsonb_typeof(data) = 'string' THEN - IF char_length(data #>> '{}') > (schema->>'maxLength')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'not' THEN - IF commons.validate_json_schema(schema->'not', data, root_schema) THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxProperties' AND jsonb_typeof(data) = 'object' THEN - IF (SELECT count(*) FROM jsonb_object_keys(data)) > (schema->>'maxProperties')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minProperties' AND jsonb_typeof(data) = 'object' THEN - IF (SELECT count(*) FROM jsonb_object_keys(data)) < (schema->>'minProperties')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'maxItems' AND jsonb_typeof(data) = 'array' THEN - IF (SELECT count(*) FROM jsonb_array_elements(data)) > (schema->>'maxItems')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'minItems' AND jsonb_typeof(data) = 'array' THEN - IF (SELECT count(*) FROM jsonb_array_elements(data)) < (schema->>'minItems')::numeric THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'dependencies' THEN - FOR prop IN SELECT jsonb_object_keys(schema->'dependencies') LOOP - IF data ? prop THEN - IF jsonb_typeof(schema->'dependencies'->prop) = 'array' THEN - IF NOT (SELECT bool_and(data ? dep) FROM jsonb_array_elements_text(schema->'dependencies'->prop) dep) THEN - RETURN false; - END IF; - ELSE - IF NOT commons.validate_json_schema(schema->'dependencies'->prop, data, root_schema) THEN - RETURN false; - END IF; - END IF; - END IF; - END LOOP; - END IF; - - IF schema ? 'pattern' AND jsonb_typeof(data) = 'string' THEN - IF (data #>> '{}') !~ (schema->>'pattern') THEN - RETURN false; - END IF; - END IF; - - IF schema ? 'patternProperties' AND jsonb_typeof(data) = 'object' THEN - FOR prop IN SELECT jsonb_object_keys(data) LOOP - FOR pattern IN SELECT jsonb_object_keys(schema->'patternProperties') LOOP - RAISE NOTICE 'prop %s, pattern %, schema %', prop, pattern, schema->'patternProperties'->pattern; - IF prop ~ pattern AND NOT commons.validate_json_schema(schema->'patternProperties'->pattern, data->prop, root_schema) THEN - RETURN false; - END IF; - END LOOP; - END LOOP; - END IF; - - IF schema ? 'multipleOf' AND jsonb_typeof(data) = 'number' THEN - IF data::text::numeric % (schema->>'multipleOf')::numeric != 0 THEN - RETURN false; - END IF; - END IF; - - RETURN true; - END; - $_$; - - --- --- TOC entry 1727 (class 1255 OID 244673) --- Name: validate_quill_doc(jsonb); Type: FUNCTION; Schema: commons; Owner: - --- - -CREATE FUNCTION commons.validate_quill_doc(quilldoc jsonb) RETURNS boolean - LANGUAGE plpgsql IMMUTABLE - AS $_$ - DECLARE - isValid boolean; - BEGIN - SELECT INTO isValid commons.validate_json_schema('{ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "QuillDoc": { - "type": "object", - "properties": { - "latestId": { - "type": "number" - }, - "ops": { - "type": "array", - "items": { - "$ref": "#/definitions/Op" - } - } - }, - "required": [ - "latestId" - ], - "additionalProperties": false - }, - "Op": { - "type": "object", - "properties": { - "insert": { - "type": "string", - "minLength": 1, - "maxLength": 1 - }, - "attributes": { - "type": "object", - "properties": { - "charid": { - "type": "string" - }, - "blockid": { - "type": "string" - } - } - } - }, - "required": [ - "insert" - ], - "additionalProperties": false - } - }, - "$ref": "#/definitions/QuillDoc" - }'::jsonb, quillDoc); - RETURN isValid; - END; - $_$; - - --- --- TOC entry 415 (class 1255 OID 246087) --- Name: v_digital_version_insert(); Type: FUNCTION; Schema: data; Owner: - --- - -CREATE FUNCTION data.v_digital_version_insert() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_concat_pk text; - resulting_row data.v_digital_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE data.digital SET - notes = NEW.notes, - quill_doc = NEW.quill_doc - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO data.digital (notes, quill_doc) - VALUES(NEW.notes, NEW.quill_doc) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row data.v_digital_version where pk_entity_version_concat = resulting_concat_pk; - - RETURN resulting_row; - END; - - $$; - - --- --- TOC entry 458 (class 1255 OID 243085) --- Name: appe_tokens_for_comparision(jsonb); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.appe_tokens_for_comparision(appe_label jsonb, OUT tokens_for_comparision jsonb) RETURNS jsonb - LANGUAGE sql - AS $$ - Select array_to_json(array_agg(json_build_object('string',tokens_without_ids.string, 'typeId', tokens_without_ids.typeId)))::jsonb as tokens_for_comparision from - ( - SELECT appe.tokens->>'string' as string, appe.tokens->>'typeId' as typeId - FROM ( - SELECT jsonb_array_elements(appe_label->'tokens') as tokens - ) as appe - ) as tokens_without_ids - $$; - - --- --- TOC entry 467 (class 1255 OID 243461) --- Name: appellation_label_to_string(jsonb); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.appellation_label_to_string(appellation_label jsonb, OUT string text) RETURNS text - LANGUAGE sql - AS $$ - - SELECT STRING_AGG(l.tokens->>'string', '') - FROM (SELECT jsonb_array_elements(appellation_label->'tokens') as tokens) as l - - $$; - - -SET default_tablespace = ''; - -SET default_with_oids = false; - --- --- TOC entry 240 (class 1259 OID 240502) --- Name: entity; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.entity ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb -); - - --- --- TOC entry 254 (class 1259 OID 240691) --- Name: temporal_entity; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.temporal_entity ( - _deprecated_pk_temporal_entity integer NOT NULL, - fk_class integer -) -INHERITS (information.entity); - - --- --- TOC entry 686 (class 1255 OID 243969) --- Name: temporal_entity_find_or_create(integer, jsonb); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.temporal_entity_find_or_create(param_fk_class integer, param_roles jsonb) RETURNS information.temporal_entity - LANGUAGE plpgsql - AS $$ - - DECLARE - resulting_row information.temporal_entity; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - WITH existing_te_ens as ( - select fk_temporal_entity, array_agg(jsonb_build_object('fk_property',fk_property, 'fk_entity', fk_entity)) identity_defining_roles - from information.role as r - join data_for_history.property as p on p.dfh_pk_property = r.fk_property AND p.identity_defining = true - group by fk_temporal_entity - ), - new_te_en as ( - SELECT array_agg(a.elements::jsonb) roles - FROM - (select 1 x, jsonb_array_elements_text(param_roles) elements) as a - Group by a.x - ) - select teEn.* - from INTO resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - join new_te_en on new_te_en.roles @> existing_te_ens.identity_defining_roles - join information.temporal_entity as teEn on teEn.pk_entity = existing_te_ens.fk_temporal_entity - where teEn.fk_class = param_fk_class; - - - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.temporal_entity ( - fk_class - ) - VALUES ( - param_fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row -- ; - END IF; - - - RETURN resulting_row; - END; - - $$; - - --- --- TOC entry 466 (class 1255 OID 243460) --- Name: text_property_to_string(jsonb); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.text_property_to_string(text_property_quill_doc jsonb, OUT string text) RETURNS text - LANGUAGE sql - AS $$ - - SELECT STRING_AGG(l.ops->>'insert', '') - FROM (SELECT jsonb_array_elements(text_property_quill_doc->'contents'->'ops') as ops) as l - - $$; - - --- --- TOC entry 465 (class 1255 OID 243090) --- Name: v_appellation_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_appellation_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_row information.v_appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - quill_doc, - fk_class - ) - VALUES ( - NEW.quill_doc, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 464 (class 1255 OID 243120) --- Name: v_entity_association_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_entity_association_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_pk integer; - resulting_row information.v_entity_association; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity - FROM INTO resulting_pk information.entity_association - WHERE fk_property = NEW.fk_property - AND fk_info_domain IS NOT DISTINCT FROM NEW.fk_info_domain - AND fk_info_range IS NOT DISTINCT FROM NEW.fk_info_range - AND fk_data_domain IS NOT DISTINCT FROM NEW.fk_data_domain - AND fk_data_range IS NOT DISTINCT FROM NEW.fk_data_range; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.entity_association ( - fk_property, - fk_info_domain, - fk_info_range, - fk_data_domain, - fk_data_range - ) - VALUES ( - NEW.fk_property, - NEW.fk_info_domain, - NEW.fk_info_range, - NEW.fk_data_domain, - NEW.fk_data_range - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_entity_association - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 459 (class 1255 OID 243096) --- Name: v_language_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_language_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_row information.language; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.language - WHERE - fk_class = NEW.fk_class - AND lang_type = NEW.lang_type - AND scope = NEW.scope - AND iso6392b = NEW.iso6392b - AND iso6392t = NEW.iso6392t - AND iso6391 = NEW.iso6391; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.language ( - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES ( - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 460 (class 1255 OID 243102) --- Name: v_persistent_item_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_persistent_item_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_row information.persistent_item; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.persistent_item - WHERE pk_entity = NEW.pk_entity; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.persistent_item ( - fk_class - ) - VALUES ( - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 462 (class 1255 OID 243114) --- Name: v_place_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_place_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_row information.v_place; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT - *, - NEW.long, - NEW.lat - FROM INTO resulting_row information.place - WHERE geo_point = ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.place ( - geo_point, - fk_class - ) - VALUES ( - ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT - *, - ST_X(geo_point::geometry) as long, - ST_Y(geo_point::geometry) as lat - FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 402 (class 1255 OID 246080) --- Name: v_property_of_property_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_property_of_property_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_pk integer; - resulting_row information.v_property_of_property; - BEGIN - - RAISE INFO ' input values - NEW.fk_property: %, - NEW.provisional_property: % - NEW.fk_role: % - NEW.fk_entity_association: % - NEW.fk_range_entity: % - ', - NEW.fk_property, - NEW.provisional_property, - NEW.fk_role, - NEW.fk_entity_association, - NEW.fk_range_entity; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.property_of_property - WHERE fk_property IS NOT DISTINCT FROM NEW.fk_property - AND provisional_property IS NOT DISTINCT FROM NEW.provisional_property - AND fk_role IS NOT DISTINCT FROM NEW.fk_role - AND fk_entity_association IS NOT DISTINCT FROM NEW.fk_entity_association - AND fk_range_entity IS NOT DISTINCT FROM NEW.fk_range_entity; - - RAISE INFO 'resulting_pk: %', resulting_pk; - - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.property_of_property ( - fk_property, - provisional_property, - fk_role, - fk_entity_association, - fk_range_entity - ) - VALUES ( - NEW.fk_property, - NEW.provisional_property, - NEW.fk_role, - NEW.fk_entity_association, - NEW.fk_range_entity - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_property_of_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 457 (class 1255 OID 243083) --- Name: v_role_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_role_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_pk integer; - resulting_row information.v_role; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.role - WHERE - fk_entity = NEW.fk_entity - AND fk_temporal_entity = NEW.fk_temporal_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.role ( - fk_entity, - fk_temporal_entity, - fk_property - ) - VALUES ( - NEW.fk_entity, - NEW.fk_temporal_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_role - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 461 (class 1255 OID 243108) --- Name: v_temporal_entity_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_temporal_entity_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_row information.temporal_entity; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.temporal_entity - WHERE pk_entity = NEW.pk_entity; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.temporal_entity ( - fk_class - ) - VALUES ( - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 463 (class 1255 OID 243453) --- Name: v_text_property_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_text_property_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $$; - - --- --- TOC entry 456 (class 1255 OID 242978) --- Name: v_time_primitive_find_or_create(); Type: FUNCTION; Schema: information; Owner: - --- - -CREATE FUNCTION information.v_time_primitive_find_or_create() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_pk integer; - resulting_row information.v_time_primitive; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.time_primitive ( - julian_day, - duration, - fk_class - ) - VALUES ( - NEW.julian_day, - NEW.duration, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_time_primitive - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 1741 (class 1255 OID 243429) --- Name: v_info_proj_rel_update_or_creat(); Type: FUNCTION; Schema: projects; Owner: - --- - -CREATE FUNCTION projects.v_info_proj_rel_update_or_creat() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $$; - - --- --- TOC entry 469 (class 1255 OID 240164) --- Name: versioning(); Type: FUNCTION; Schema: public; Owner: - --- - -CREATE FUNCTION public.versioning() RETURNS trigger - LANGUAGE plpgsql - AS $_$ - DECLARE - sys_period text; - history_table text; - manipulate jsonb; - commonColumns text[]; - time_stamp_to_use timestamptz := current_timestamp; - range_lower timestamptz; - transaction_info txid_snapshot; - existing_range tstzrange; - holder record; - holder2 record; - pg_version integer; - BEGIN - -- version 0.2.0 - - IF TG_WHEN != 'BEFORE' OR TG_LEVEL != 'ROW' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired BEFORE ROW'; - END IF; - - IF TG_OP != 'INSERT' AND TG_OP != 'UPDATE' AND TG_OP != 'DELETE' THEN - RAISE TRIGGER_PROTOCOL_VIOLATED USING - MESSAGE = 'function "versioning" must be fired for INSERT or UPDATE or DELETE'; - END IF; - - IF TG_NARGS != 3 THEN - RAISE INVALID_PARAMETER_VALUE USING - MESSAGE = 'wrong number of parameters for function "versioning"', - HINT = 'expected 3 parameters but got ' || TG_NARGS; - END IF; - - sys_period := TG_ARGV[0]; - history_table := TG_ARGV[1]; - - -- check if sys_period exists on original table - SELECT atttypid, attndims INTO holder FROM pg_attribute WHERE attrelid = TG_RELID AND attname = sys_period AND NOT attisdropped; - IF NOT FOUND THEN - RAISE 'column "%" of relation "%" does not exist', sys_period, TG_TABLE_NAME USING - ERRCODE = 'undefined_column'; - END IF; - IF holder.atttypid != to_regtype('tstzrange') THEN - IF holder.attndims > 0 THEN - RAISE 'system period column "%" of relation "%" is not a range but an array', sys_period, TG_TABLE_NAME USING - ERRCODE = 'datatype_mismatch'; - END IF; - - SELECT rngsubtype INTO holder2 FROM pg_range WHERE rngtypid = holder.atttypid; - IF FOUND THEN - RAISE 'system period column "%" of relation "%" is not a range of timestamp with timezone but of type %', sys_period, TG_TABLE_NAME, format_type(holder2.rngsubtype, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - RAISE 'system period column "%" of relation "%" is not a range but type %', sys_period, TG_TABLE_NAME, format_type(holder.atttypid, null) USING - ERRCODE = 'datatype_mismatch'; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN - -- Ignore rows already modified in this transaction - transaction_info := txid_current_snapshot(); - IF OLD.xmin::text >= (txid_snapshot_xmin(transaction_info) % (2^32)::bigint)::text - AND OLD.xmin::text <= (txid_snapshot_xmax(transaction_info) % (2^32)::bigint)::text THEN - IF TG_OP = 'DELETE' THEN - RETURN OLD; - END IF; - - RETURN NEW; - END IF; - - SELECT current_setting('server_version_num')::integer - INTO pg_version; - - -- to support postgres < 9.6 - IF pg_version < 90600 THEN - -- check if history table exits - IF to_regclass(history_table::cstring) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - ELSE - IF to_regclass(history_table) IS NULL THEN - RAISE 'relation "%" does not exist', history_table; - END IF; - END IF; - - -- check if history table has sys_period - IF NOT EXISTS(SELECT * FROM pg_attribute WHERE attrelid = history_table::regclass AND attname = sys_period AND NOT attisdropped) THEN - RAISE 'history relation "%" does not contain system period column "%"', history_table, sys_period USING - HINT = 'history relation must contain system period column with the same name and data type as the versioned one'; - END IF; - - EXECUTE format('SELECT $1.%I', sys_period) USING OLD INTO existing_range; - - IF existing_range IS NULL THEN - RAISE 'system period column "%" of relation "%" must not be null', sys_period, TG_TABLE_NAME USING - ERRCODE = 'null_value_not_allowed'; - END IF; - - IF isempty(existing_range) OR NOT upper_inf(existing_range) THEN - RAISE 'system period column "%" of relation "%" contains invalid value', sys_period, TG_TABLE_NAME USING - ERRCODE = 'data_exception', - DETAIL = 'valid ranges must be non-empty and unbounded on the high side'; - END IF; - - IF TG_ARGV[2] = 'true' THEN - -- mitigate update conflicts - range_lower := lower(existing_range); - IF range_lower >= time_stamp_to_use THEN - time_stamp_to_use := range_lower + interval '1 microseconds'; - END IF; - END IF; - - WITH history AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname, atttypid - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT - history.attname AS history_name, - main.attname AS main_name, - history.atttypid AS history_type, - main.atttypid AS main_type - INTO holder - FROM history - INNER JOIN main - ON history.attname = main.attname - WHERE - history.atttypid != main.atttypid; - - IF FOUND THEN - RAISE 'column "%" of relation "%" is of type % but column "%" of history relation "%" is of type %', - holder.main_name, TG_TABLE_NAME, format_type(holder.main_type, null), holder.history_name, history_table, format_type(holder.history_type, null) - USING ERRCODE = 'datatype_mismatch'; - END IF; - - WITH history AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = history_table::regclass - AND attnum > 0 - AND NOT attisdropped), - main AS - (SELECT attname - FROM pg_attribute - WHERE attrelid = TG_RELID - AND attnum > 0 - AND NOT attisdropped) - SELECT array_agg(quote_ident(history.attname)) INTO commonColumns - FROM history - INNER JOIN main - ON history.attname = main.attname - AND history.attname != sys_period; - - EXECUTE ('INSERT INTO ' || - CASE split_part(history_table, '.', 2) - WHEN '' THEN - quote_ident(history_table) - ELSE - quote_ident(split_part(history_table, '.', 1)) || '.' || quote_ident(split_part(history_table, '.', 2)) - END || - '(' || - array_to_string(commonColumns , ',') || - ',' || - quote_ident(sys_period) || - ') VALUES ($1.' || - array_to_string(commonColumns, ',$1.') || - ',tstzrange($2, $3, ''[)''))') - USING OLD, range_lower, time_stamp_to_use; - END IF; - - IF TG_OP = 'UPDATE' OR TG_OP = 'INSERT' THEN - manipulate := jsonb_set('{}'::jsonb, ('{' || sys_period || '}')::text[], to_jsonb(tstzrange(time_stamp_to_use, null, '[)'))); - - RETURN jsonb_populate_record(NEW, manipulate); - END IF; - - RETURN OLD; - END; - $_$; - - --- --- TOC entry 1716 (class 1255 OID 244066) --- Name: entity_preview__concat_full_text(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__concat_full_text() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__concat_full_text; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - - SELECT string_agg into NEW.full_text from ( - SELECT 1, string_agg(txt, ', ' ORDER BY rank) from ( - SELECT rank, txt - FROM ( - select 1 rank, coalesce(NEW.type_label, NEW.class_label, '') as txt - UNION - select 2 rank, NEW.own_full_text as txt - UNION - select 3 rank, value as txt - from jsonb_each_text(NEW.related_full_texts) - ) AS all_strings - WHERE txt != '' - ) AS items - GROUP BY 1 - ) as x; - - SELECT setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(NEW.type_label, NEW.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(NEW.full_text,'')), 'C') - INTO NEW.ts_vector; - - - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1711 (class 1255 OID 244059) --- Name: entity_preview__create(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - e warehouse.v_entities; - c warehouse.class_preview; - p INT; - BEGIN - - ---------- upsert the unchagable rows ---------- - - p = coalesce(param_fk_project, 0); - - SELECT * INTO e - FROM warehouse.v_entities - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - SELECT * INTO c - FROM warehouse.class_preview as cpre - WHERE cpre.dfh_pk_class = e.fk_class; - - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label) - VALUES ( - param_pk_entity, - param_fk_project, - p, -- project - e.fk_class, - e.entity_type, - c.class_label - ) - ON CONFLICT (pk_entity, project) - DO - UPDATE - SET fk_class = e.fk_class, entity_type = e.entity_type, class_label = c.class_label - WHERE entity_preview.pk_entity = param_pk_entity AND entity_preview.project = p; - - - ---------- first create the dependency indexes ---------- - - PERFORM warehouse.entity_preview__create_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_type(param_pk_entity, param_fk_project); - - ---------- second fill the own entity_label and own_full_text ---------- - - PERFORM warehouse.entity_preview__fill_own_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_own_full_text(param_pk_entity, param_fk_project); - - - ---------- third fill the dependencies ---------- - - PERFORM warehouse.entity_preview__fill_dependent_entity_labels(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_type_labels(param_pk_entity, param_fk_project); - - RETURN true; - END; - $$; - - --- --- TOC entry 1721 (class 1255 OID 244060) --- Name: entity_preview__create_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS SELECT * FROM warehouse.v_entity_preview; - - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.temp - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $$; - - --- --- TOC entry 416 (class 1255 OID 244050) --- Name: entity_preview__create_fk_entity_label(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create_fk_entity_label(param_pk_entity integer, param_fk_project integer) RETURNS jsonb - LANGUAGE plpgsql - AS $$ - DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, r.rank_for_pe_it as rank - FROM information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - UNION - ( - SELECT r.fk_entity as pk, r.rank_for_te_ent as rank - FROM information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0 - ) - ) AS a - ORDER BY rank - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_object: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the fk_entity_label - - SELECT pk INTO new_fk_entity_label - FROM - ( - ( - SELECT fk_temporal_entity as pk, epr.ord_num - FROM information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = false - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_temporal_entity = e.pk_entity AND e.table_name = 'temporal_entity' - WHERE r.fk_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - - UNION - - ( - SELECT r.fk_entity as pk, epr.ord_num - FROM information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = true - AND ucc.fk_app_context = 45 - JOIN information.entity e on r.fk_entity = e.pk_entity AND e.table_name = 'persistent_item' - WHERE r.fk_temporal_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = true - ) - ) AS a - ORDER BY ord_num - LIMIT 1; - - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - - ----- Insert or update column fk_entity_label of table entity_preview - - SELECT fk_entity_label INTO old_fk_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - - ELSIF (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET fk_entity_label = new_fk_entity_label - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', old_fk_entity_label, - 'new_val', new_fk_entity_label) - INTO result_info; - - RETURN result_info; - END; - $$; - - --- --- TOC entry 420 (class 1255 OID 244051) --- Name: entity_preview__create_fk_type(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create_fk_type(param_pk_entity integer, param_fk_project integer) RETURNS jsonb - LANGUAGE plpgsql - AS $$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - has_type_properties INT[] = ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.v_entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.fk_info_domain = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (has_type_properties) - AND ea.fk_info_domain = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $$; - - --- --- TOC entry 1242 (class 1255 OID 244049) --- Name: entity_preview__create_related_full_texts(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create_related_full_texts(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_related_full_texts jsonb; - param_project INT; - BEGIN - RAISE INFO 'entity_preview__create_related_full_texts pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - param_project = coalesce(param_fk_project, 0); - - ---------------------- REPO AND PROJECT VERSIONS ---------------------- - WITH full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_temporal_entity = param_pk_entity - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_entity = param_pk_entity - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ) - select related_full_texts INTO new_related_full_texts - FROM aggregated_related_full_texts; - - RAISE INFO 'new_related_full_texts: %', new_related_full_texts; - - ----- Insert or update the entity_preview - - PERFORM pk_entity - FROM warehouse.entity_preview pre - WHERE pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project; - - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, related_full_texts) - VALUES (param_pk_entity, param_fk_project, param_project, new_related_full_texts); - - RAISE INFO 'inserted new_related_full_texts: %', new_related_full_texts; - - ELSE - - UPDATE warehouse.entity_preview pre - SET related_full_texts = new_related_full_texts - where pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project - AND ( - pre.related_full_texts @> new_related_full_texts - AND - pre.related_full_texts <@ new_related_full_texts - ) IS DISTINCT FROM true; - - END IF; - - - RETURN true; - END; - $$; - - --- --- TOC entry 1709 (class 1255 OID 244056) --- Name: entity_preview__fill_dependent_class_labels(integer, text); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_dependent_class_labels(pk_class integer, param_class_label text DEFAULT NULL::text) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_class_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_class_labels of pk_entity: %', pk_class; - - -- get new_class_label - IF (param_class_label IS NULL) THEN - SELECT class_label INTO new_class_label - FROM warehouse.class_preview - WHERE dfh_pk_class = pk_class; - ELSE - new_class_label = param_class_label; - END IF; - - RAISE INFO 'new_class_label: %', new_class_label; - - -- update all dependent entity_previews with new_class_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET class_label = new_class_label - WHERE fk_class = pk_class - AND class_label IS DISTINCT FROM new_class_label; - - RETURN true; - END; - $$; - - --- --- TOC entry 1707 (class 1255 OID 244054) --- Name: entity_preview__fill_dependent_entity_labels(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_dependent_entity_labels(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_entity_label TEXT; - dependent_entity_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_entity_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_entity_label - SELECT entity_label INTO new_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_entity_label: %', new_entity_label; - - -- update all dependent entity_previews with new_entity_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET entity_label = new_entity_label - WHERE fk_entity_label = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND entity_label IS DISTINCT FROM new_entity_label; - - - RETURN true; - END; - $$; - - --- --- TOC entry 1708 (class 1255 OID 244055) --- Name: entity_preview__fill_dependent_related_full_texts(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_dependent_related_full_texts(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_related_full_texts of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_own_full_text - SELECT own_full_text INTO new_own_full_text - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - - -- update all related_full_texts with new_own_full_text (if DISTINCT) - UPDATE warehouse.entity_preview - SET related_full_texts = ( - SELECT jsonb_set( - related_full_texts, - array_agg(param_pk_entity::text), - to_jsonb(new_own_full_text) - ) - ) - WHERE related_full_texts ? param_pk_entity::text - AND related_full_texts->>param_pk_entity::text IS DISTINCT FROM new_own_full_text - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $$; - - --- --- TOC entry 1710 (class 1255 OID 244057) --- Name: entity_preview__fill_dependent_type_labels(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_dependent_type_labels(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_type_label TEXT; - dependent_type_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_type_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_type_label - SELECT entity_label INTO new_type_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_type_label: %', new_type_label; - - -- update all dependent entity_previews with new_type_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET type_label = new_type_label - WHERE fk_type = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND type_label IS DISTINCT FROM new_type_label; - - RETURN true; - END; - $$; - - --- --- TOC entry 419 (class 1255 OID 244052) --- Name: entity_preview__fill_own_entity_label(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_own_entity_label(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; - BEGIN - - - - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT ( - SELECT fk_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1 - ) IS NULL - ) THEN - - IF param_fk_project IS NULL THEN - - ---------------------- REPO VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN projects.info_proj_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - and r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - - WITH first_field AS ( - SELECT entity_field.fk_property, entity_field.fk_class_field, entity.pk_entity - -- teen or peit - from ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ) as entity - INNER JOIN projects.info_proj_rel as epr on epr.fk_entity = entity.pk_entity - AND epr.is_in_project = true - - -- field - INNER JOIN information.v_ordered_fields_per_class entity_field on entity_field.fk_class = entity.fk_class - AND field_order = 0 - ), - string_from_first_role AS ( - - SELECT COALESCE(appe.string, lang.notes) as string - FROM - first_field - LEFT JOIN information.v_role as r - on first_field.fk_property = r.fk_property - and first_field.pk_entity = r.fk_temporal_entity - LEFT JOIN projects.info_proj_rel as epr2 - on epr2.fk_entity = r.pk_entity - and epr2.fk_project = param_fk_project - and epr2.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - - ORDER BY epr2.ord_num - LIMIT 1 - ), - string_from_first_text_prop AS ( - - SELECT txtp.string - FROM information.v_text_property as txtp - INNER JOIN first_field on first_field.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = first_field.pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity=txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - LIMIT 1 - - ), - string AS ( - SELECT string - FROM string_from_first_role - UNION - SELECT string - FROM string_from_first_text_prop - ) - SELECT string INTO new_own_entity_label FROM string; - - - - END IF; - - - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - - ----- Insert or update column own_entity_label of table entity_preview - - SELECT entity_label INTO old_own_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - - ELSIF (SELECT (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET entity_label = new_own_entity_label - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; - - END IF; - RETURN true; - END; - $$; - - --- --- TOC entry 418 (class 1255 OID 244053) --- Name: entity_preview__fill_own_full_text(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_own_full_text(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $_$ - DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO VERSIONS ---------------------- - - IF param_fk_project IS NULL THEN - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity AND r.is_in_project_count > 0 - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY r.rank_for_te_ent - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - -- TODO: Check if we need to exclude textproperties that are in 0 projects$ - -- TODO: Check if we need to order textproperties - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project IS NULL; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - - ---------------------- PROJECTS VERSIONS ---------------------- - - ELSE - - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_full_text - - WITH entity AS ( - SELECT t.pk_entity, t.fk_class - FROM information.temporal_entity as t - WHERE t.pk_entity = param_pk_entity - UNION - SELECT p.pk_entity, p.fk_class - FROM information.persistent_item as p - WHERE p.pk_entity = param_pk_entity - ), - fields AS ( - -- fields - SELECT fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL - ), - strings_from_roles AS ( - - SELECT COALESCE(appe.string, lang.notes) as string, field_order - FROM fields - JOIN information.v_role as r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - LEFT JOIN projects.info_proj_rel as epr ON epr.fk_entity = r.pk_entity - AND epr.fk_project = param_fk_project AND epr.is_in_project = true - - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - - -- appellation - LEFT JOIN information.v_appellation as appe - ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language as lang - ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- - ORDER BY epr.ord_num - ), - strings_from_text_props AS ( - - SELECT regexp_replace(txtp.string, E'[\n\r]+', '', 'g' ) as string, field_order - FROM information.v_text_property as txtp - INNER JOIN fields on fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - INNER JOIN projects.info_proj_rel as epr ON epr.fk_entity = txtp.pk_entity - AND epr.is_in_project = true AND epr.fk_project = param_fk_project - ORDER BY epr.ord_num - ), - all_stings AS ( - SELECT string, field_order - FROM strings_from_roles - UNION - SELECT string, field_order - FROM strings_from_text_props - ), - aggregated AS ( - SELECT 1, string_agg(string, ', ' ORDER BY field_order) as full_text - FROM all_stings - GROUP BY 1 - ) - SELECT full_text INTO new_own_full_text - FROM aggregated; - - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - ----- Insert or update column own_full_text of table entity_preview - - SELECT own_full_text INTO old_own_full_text FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project = param_fk_project; - - RAISE INFO 'old_own_full_text: %', old_own_full_text; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - - ELSIF (SELECT (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - - UPDATE warehouse.entity_preview - SET own_full_text = new_own_full_text - where pk_entity=param_pk_entity AND fk_project=param_fk_project; - - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - - END IF; - - RETURN true; - END; - $_$; - - --- --- TOC entry 417 (class 1255 OID 244058) --- Name: entity_preview__fill_time_span(integer, integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__fill_time_span(param_pk_entity integer, param_fk_project integer) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_time_span jsonb; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_time_span - SELECT time_span INTO new_time_span - FROM warehouse.v_te_en_time_span_per_project_and_repo - WHERE fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_time_span: %', new_time_span; - - -- update this entity_preview with new_time_span - UPDATE warehouse.entity_preview - SET time_span = new_time_span - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $$; - - --- --- TOC entry 1715 (class 1255 OID 244064) --- Name: entity_preview__get_entity_label(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__get_entity_label() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_entity_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_entity_label IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET entity_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_entity_label - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1527 (class 1255 OID 244065) --- Name: entity_preview__get_type_label(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__get_type_label() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_type_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_type IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET type_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_type - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1719 (class 1255 OID 244070) --- Name: entity_preview__notify_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__notify_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - PERFORM pg_notify('entity_preview_updated'::text, json_build_object( - 'pk_entity', NEW.pk_entity, - 'fk_project', NEW.fk_project, - 'project', NEW.project, - 'fk_class', NEW.fk_class, - 'entity_type', NEW.entity_type, - 'class_label', NEW.class_label, - 'entity_label', NEW.entity_label, - 'time_span', NEW.time_span, - 'fk_type', NEW.fk_type, - 'type_label', NEW.type_label - )::text); - RETURN NEW; - END; - $$; - - --- --- TOC entry 1720 (class 1255 OID 244069) --- Name: entity_preview__update_dependent_class_labels(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_dependent_class_labels() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; dfh_pk_class: % class_label: %', NEW.dfh_pk_class, NEW.class_label; - - PERFORM warehouse.entity_preview__fill_dependent_class_labels(NEW.dfh_pk_class, NEW.class_label); - - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1718 (class 1255 OID 244068) --- Name: entity_preview__update_dependent_entity_labels(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_dependent_entity_labels() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_entity_labels; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM - warehouse.entity_preview__fill_dependent_entity_labels(NEW.pk_entity, NEW.fk_project), - warehouse.entity_preview__fill_dependent_type_labels(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1717 (class 1255 OID 244067) --- Name: entity_preview__update_dependent_related_full_texts(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_dependent_related_full_texts() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_related_full_texts; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1712 (class 1255 OID 244063) --- Name: entity_preview__upsert_entity_preview(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__upsert_entity_preview() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - PERFORM - - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_info_domain into _fk_info_domain - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_info_range into _fk_info_range - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, NULL::text]); - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $$; - - --- --- TOC entry 1714 (class 1255 OID 244062) --- Name: needs_update(text, text[]); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.needs_update(fn_name text, fn_params text[]) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - fn_name_concat TEXT; - BEGIN - - fn_name_concat = array_to_string(ARRAY['warehouse.', fn_name],''); - - PERFORM warehouse.notify_fn_call('warehouse_update_request'::text, fn_name_concat, fn_params); - - RETURN TRUE; - - END; - $$; - - --- --- TOC entry 1713 (class 1255 OID 244061) --- Name: notify_fn_call(text, text, text[]); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.notify_fn_call(channel text, fn_name text, fn_params text[]) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - fn_concat TEXT; - BEGIN - - fn_concat = fn_name || '(' || array_to_string(fn_params, ',', 'NULL'::text) || ')'; - - PERFORM pg_notify( - channel, - json_build_object('fn', fn_concat)::text - ); - - RETURN TRUE; - - END; - $$; - - --- --- TOC entry 1035 (class 1255 OID 243983) --- Name: update_class_preview__on_class_profile_view_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - label text; - entity_type text; - BEGIN - - INSERT INTO warehouse.class_preview (dfh_pk_class, class_label, entity_type) - SELECT v.dfh_pk_class, v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ON CONFLICT (dfh_pk_class) - DO - UPDATE - SET (class_label, entity_type) = ( - SELECT v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ); - - RETURN NEW; - - END; - $$; - - --- --- TOC entry 801 (class 1255 OID 243980) --- Name: update_class_preview__on_label_delete(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_label_delete() RETURNS trigger - LANGUAGE plpgsql - AS $$ BEGIN - - -- If it is a geovistory class label - IF (OLD.dfh_fk_class IS NOT NULL AND OLD.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = ( - SELECT dfh_standard_label - FROM data_for_history.class - WHERE dfh_pk_class = OLD.dfh_fk_class - ) - WHERE dfh_pk_class = OLD.dfh_fk_class; - - END IF; - - RETURN OLD; - - END; - $$; - - --- --- TOC entry 698 (class 1255 OID 243979) --- Name: update_class_preview__on_label_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_label_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ BEGIN - - - -- If it is a geovistory class label - IF ( NEW.dfh_fk_class IS NOT NULL AND NEW.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = NEW.dfh_label - WHERE dfh_pk_class = NEW.dfh_fk_class; - - END IF; - - RETURN NEW; - - END; - $$; - - --- --- TOC entry 343 (class 1259 OID 244682) --- Name: text; Type: TABLE; Schema: commons; Owner: - --- - -CREATE TABLE commons.text ( - pk_text integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - quill_doc jsonb NOT NULL, - string text NOT NULL, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -); - - --- --- TOC entry 342 (class 1259 OID 244680) --- Name: text_pk_text_seq; Type: SEQUENCE; Schema: commons; Owner: - --- - -CREATE SEQUENCE commons.text_pk_text_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6159 (class 0 OID 0) --- Dependencies: 342 --- Name: text_pk_text_seq; Type: SEQUENCE OWNED BY; Schema: commons; Owner: - --- - -ALTER SEQUENCE commons.text_pk_text_seq OWNED BY commons.text.pk_text; - - --- --- TOC entry 344 (class 1259 OID 244692) --- Name: text_vt; Type: TABLE; Schema: commons; Owner: - --- - -CREATE TABLE commons.text_vt ( - pk_text integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - quill_doc jsonb NOT NULL, - string text NOT NULL -); - - --- --- TOC entry 345 (class 1259 OID 244700) --- Name: v_text_version; Type: VIEW; Schema: commons; Owner: - --- - -CREATE VIEW commons.v_text_version AS - SELECT t.pk_text, - t.schema_name, - t.table_name, - t.entity_version, - t.quill_doc, - t.string, - concat(((t.pk_text || '_'::text) || t.entity_version)) AS pk_text_version - FROM commons.text t -UNION ALL - SELECT t.pk_text, - t.schema_name, - t.table_name, - t.entity_version, - t.quill_doc, - t.string, - concat(((t.pk_text || '_'::text) || t.entity_version)) AS pk_text_version - FROM commons.text_vt t; - - --- --- TOC entry 360 (class 1259 OID 245294) --- Name: entity; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.entity ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb -); - - --- --- TOC entry 385 (class 1259 OID 245880) --- Name: avatar; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.avatar ( - fk_class integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 386 (class 1259 OID 245899) --- Name: avatar_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.avatar_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_class integer NOT NULL -); - - --- --- TOC entry 367 (class 1259 OID 245520) --- Name: cell; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.cell ( - fk_column integer NOT NULL, - fk_row integer NOT NULL, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (data.entity, commons.text); - - --- --- TOC entry 368 (class 1259 OID 245544) --- Name: cell_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.cell_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_column integer NOT NULL, - fk_row integer NOT NULL, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 361 (class 1259 OID 245393) --- Name: chunk; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.chunk ( - fk_text integer, - fk_entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (data.entity, commons.text); - - --- --- TOC entry 362 (class 1259 OID 245412) --- Name: chunk_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.chunk_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_text integer, - fk_entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 373 (class 1259 OID 245662) --- Name: class_column_rel; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.class_column_rel ( - fk_class integer NOT NULL, - fk_column integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 374 (class 1259 OID 245686) --- Name: class_column_rel_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.class_column_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_class integer NOT NULL, - fk_column integer NOT NULL -); - - --- --- TOC entry 365 (class 1259 OID 245482) --- Name: column; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data."column" ( - fk_digital integer NOT NULL, - fk_data_type integer NOT NULL, - fk_meta_data integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 366 (class 1259 OID 245511) --- Name: column_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.column_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_digital integer NOT NULL, - fk_data_type integer NOT NULL, - fk_meta_data integer NOT NULL -); - - --- --- TOC entry 383 (class 1259 OID 245852) --- Name: data_association; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.data_association ( - fk_property integer NOT NULL, - fk_data_domain integer, - fk_data_range integer, - fk_info_domain integer, - fk_info_range integer -) -INHERITS (data.entity); - - --- --- TOC entry 384 (class 1259 OID 245871) --- Name: data_association_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.data_association_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer NOT NULL, - fk_data_domain integer, - fk_data_range integer, - fk_info_domain integer, - fk_info_range integer -); - - --- --- TOC entry 239 (class 1259 OID 240500) --- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.entity_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6160 (class 0 OID 0) --- Dependencies: 239 --- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.entity_pk_entity_seq OWNED BY information.entity.pk_entity; - - --- --- TOC entry 280 (class 1259 OID 241256) --- Name: digital; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.digital ( - pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - _deprecated_pk_digital_object integer NOT NULL, - _deprecated_js_quill_data json, - entity_version integer DEFAULT 1, - metadata jsonb, - fk_namespace integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - fk_system_type integer, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (data.entity, commons.text); - - --- --- TOC entry 279 (class 1259 OID 241254) --- Name: digital_object_pk_digital_object_seq; Type: SEQUENCE; Schema: data; Owner: - --- - -CREATE SEQUENCE data.digital_object_pk_digital_object_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6161 (class 0 OID 0) --- Dependencies: 279 --- Name: digital_object_pk_digital_object_seq; Type: SEQUENCE OWNED BY; Schema: data; Owner: - --- - -ALTER SEQUENCE data.digital_object_pk_digital_object_seq OWNED BY data.digital._deprecated_pk_digital_object; - - --- --- TOC entry 313 (class 1259 OID 243129) --- Name: digital_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.digital_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - _deprecated_pk_digital_object integer NOT NULL, - _deprecated_js_quill_data json, - entity_version integer, - fk_namespace integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 359 (class 1259 OID 245292) --- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: data; Owner: - --- - -CREATE SEQUENCE data.entity_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6162 (class 0 OID 0) --- Dependencies: 359 --- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: data; Owner: - --- - -ALTER SEQUENCE data.entity_pk_entity_seq OWNED BY data.entity.pk_entity; - - --- --- TOC entry 377 (class 1259 OID 245733) --- Name: factoid; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid ( - fk_class integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 369 (class 1259 OID 245586) --- Name: factoid_class_digital_rel; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_class_digital_rel ( - fk_digital integer NOT NULL, - fk_class integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 370 (class 1259 OID 245610) --- Name: factoid_class_digital_rel_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_class_digital_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_digital integer NOT NULL, - fk_class integer NOT NULL -); - - --- --- TOC entry 375 (class 1259 OID 245695) --- Name: factoid_property_column_rel; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_property_column_rel ( - fk_property integer NOT NULL, - fk_column integer NOT NULL, - fk_factoid_class_digital_rel integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 376 (class 1259 OID 245724) --- Name: factoid_property_column_rel_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_property_column_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer NOT NULL, - fk_column integer NOT NULL, - fk_factoid_class_digital_rel integer NOT NULL -); - - --- --- TOC entry 379 (class 1259 OID 245761) --- Name: factoid_role; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_role ( - fk_property integer NOT NULL, - fk_domain_factoid integer NOT NULL, - fk_range_cell integer, - fk_range_chunk integer -) -INHERITS (data.entity); - - --- --- TOC entry 380 (class 1259 OID 245795) --- Name: factoid_role_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_role_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer NOT NULL, - fk_domain_factoid integer NOT NULL, - fk_range_cell integer, - fk_range_chunk integer -); - - --- --- TOC entry 378 (class 1259 OID 245752) --- Name: factoid_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.factoid_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_class integer NOT NULL -); - - --- --- TOC entry 389 (class 1259 OID 245974) --- Name: namespace; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.namespace ( - fk_root_namespace integer, - fk_project integer, - standard_label text -) -INHERITS (data.entity); - - --- --- TOC entry 390 (class 1259 OID 245993) --- Name: namespace_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.namespace_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_root_namespace integer, - fk_project integer, - standard_label text -); - - --- --- TOC entry 363 (class 1259 OID 245454) --- Name: row; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data."row" ( - fk_digital integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 364 (class 1259 OID 245473) --- Name: row_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.row_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_digital integer NOT NULL -); - - --- --- TOC entry 387 (class 1259 OID 245908) --- Name: text_property; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.text_property ( - fk_system_type integer NOT NULL, - fk_language integer NOT NULL, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (data.entity, commons.text); - - --- --- TOC entry 388 (class 1259 OID 245932) --- Name: text_property_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.text_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_system_type integer NOT NULL, - fk_language integer NOT NULL, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 399 (class 1259 OID 246082) --- Name: v_digital_version; Type: VIEW; Schema: data; Owner: - --- - -CREATE VIEW data.v_digital_version AS - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat(((v.pk_text || '_'::text) || v.entity_version)) AS pk_text_version_concat - FROM data.digital v -UNION ALL - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat(((v.pk_text || '_'::text) || v.entity_version)) AS pk_text_version_concat - FROM data.digital_vt v; - - --- --- TOC entry 371 (class 1259 OID 245619) --- Name: value_association_columns_rel; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.value_association_columns_rel ( - fk_property integer NOT NULL, - fk_domain_column integer NOT NULL, - fk_range_column integer NOT NULL, - fk_factoid_class_digital_rel integer NOT NULL -) -INHERITS (data.entity); - - --- --- TOC entry 372 (class 1259 OID 245653) --- Name: value_association_columns_rel_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.value_association_columns_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer NOT NULL, - fk_domain_column integer NOT NULL, - fk_range_column integer NOT NULL, - fk_factoid_class_digital_rel integer NOT NULL -); - - --- --- TOC entry 381 (class 1259 OID 245804) --- Name: values_association; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.values_association ( - fk_property integer NOT NULL, - fk_domain_cell integer, - fk_range_cell integer, - fk_domain_chunk integer, - fk_range_chunk integer -) -INHERITS (data.entity); - - --- --- TOC entry 382 (class 1259 OID 245843) --- Name: values_association_vt; Type: TABLE; Schema: data; Owner: - --- - -CREATE TABLE data.values_association_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer NOT NULL, - fk_domain_cell integer, - fk_range_cell integer, - fk_domain_chunk integer, - fk_range_chunk integer -); - - --- --- TOC entry 210 (class 1259 OID 240193) --- Name: entity; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.entity ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - tmsp_last_dfh_update timestamp with time zone, - is_enabled_in_profile boolean, - removed_from_api boolean DEFAULT false -); - - --- --- TOC entry 273 (class 1259 OID 241085) --- Name: associates_system_type; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.associates_system_type ( - dfh_pk_associates_system_type integer, - dfh_fk_system_type integer, - dfh_fk_class integer, - dfh_fk_class_type integer, - dfh_fk_property integer, - dfh_fk_property_type integer, - dfh_fk_namespace integer, - dfh_fk_label integer, - dfh_fk_text_property integer, - dfh_fk_project integer, - dfh_fk_profile integer, - dfh_fk_entity_association integer, - is_enabled_in_profile boolean, - removed_from_api boolean DEFAULT false -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 274 (class 1259 OID 241100) --- Name: associates_system_type_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.associates_system_type_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_associates_system_type integer, - dfh_fk_system_type integer, - dfh_fk_class integer, - dfh_fk_class_type integer, - dfh_fk_property integer, - dfh_fk_property_type integer, - dfh_fk_namespace integer, - dfh_fk_label integer, - dfh_fk_text_property integer, - dfh_fk_project integer, - dfh_fk_profile integer, - dfh_fk_entity_association integer, - is_inabled_in_profile boolean, - removed_from_api boolean -); - - --- --- TOC entry 213 (class 1259 OID 240223) --- Name: class; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.class ( - dfh_pk_class integer, - dfh_identifier_in_namespace text, - dfh_standard_label character varying(500), - tmsp_last_dfh_update timestamp with time zone, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 211 (class 1259 OID 240204) --- Name: class_profile_view; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.class_profile_view ( - dfh_fk_class integer, - dfh_identifier_in_namespace text, - dfh_class_standard_label character varying, - dfh_fk_system_type integer, - dfh_type_label character varying, - dfh_root_namespace text, - dfh_profile_association_type character varying, - dfh_fk_profile integer, - dfh_profile_label character varying, - tmsp_last_dfh_update timestamp with time zone, - removed_from_api boolean DEFAULT NULL -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 212 (class 1259 OID 240216) --- Name: class_profile_view_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.class_profile_view_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - dfh_fk_class integer, - dfh_identifier_in_namespace text, - dfh_class_standard_label character varying, - dfh_fk_system_type integer, - dfh_type_label character varying, - dfh_root_namespace text, - dfh_profile_association_type character varying, - dfh_fk_profile integer, - dfh_profile_label character varying, - is_enabled_in_profile boolean, - tmsp_last_dfh_update timestamp with time zone, - removed_from_api boolean -); - - --- --- TOC entry 214 (class 1259 OID 240237) --- Name: class_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.class_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - dfh_pk_class integer, - dfh_identifier_in_namespace text, - dfh_standard_label character varying(500), - tmsp_last_dfh_update timestamp with time zone -); - - --- --- TOC entry 209 (class 1259 OID 240191) --- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: data_for_history; Owner: - --- - -CREATE SEQUENCE data_for_history.entity_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6163 (class 0 OID 0) --- Dependencies: 209 --- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: data_for_history; Owner: - --- - -ALTER SEQUENCE data_for_history.entity_pk_entity_seq OWNED BY data_for_history.entity.pk_entity; - - --- --- TOC entry 263 (class 1259 OID 240845) --- Name: label; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.label ( - dfh_pk_label integer, - dfh_label text, - dfh_language_iso_code character varying, - dfh_is_standard_label_for_language boolean, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_profile integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_fk_system_type integer, - com_fk_system_type integer, - inf_fk_language integer -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 264 (class 1259 OID 240857) --- Name: label_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.label_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_label integer, - dfh_label text, - dfh_language_iso_code character varying, - dfh_is_standard_label_for_language boolean, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_profile integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -); - - --- --- TOC entry 269 (class 1259 OID 241041) --- Name: profile; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.profile ( - dfh_pk_profile integer, - dfh_fk_is_subprofile_of integer, - dfh_standard_label character varying(500), - dfh_fk_project_of_belonging integer, - dfh_start_date date, - dfh_end_date date, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 270 (class 1259 OID 241057) --- Name: profile_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.profile_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_profile integer, - dfh_fk_is_subprofile_of integer, - dfh_standard_label character varying(500), - dfh_fk_project_of_belonging integer, - dfh_start_date date, - dfh_end_date date, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -); - - --- --- TOC entry 267 (class 1259 OID 240883) --- Name: property; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.property ( - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_standard_label character varying(500), - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint, - dfh_fk_property_of_origin integer, - identity_defining boolean DEFAULT false -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 6164 (class 0 OID 0) --- Dependencies: 267 --- Name: COLUMN property.identity_defining; Type: COMMENT; Schema: data_for_history; Owner: - --- - -COMMENT ON COLUMN data_for_history.property.identity_defining IS 'If the value is set to true, this means that this property is relevant for the TeEn identity.'; - - --- --- TOC entry 271 (class 1259 OID 241064) --- Name: property_profile_view; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.property_profile_view ( - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_fk_property_of_origin integer, - dfh_standard_label character varying, - dfh_root_namespace text, - dfh_pk_profile integer, - dfh_profile_label character varying, - is_enabled_in_profile boolean, - removed_from_api boolean DEFAULT NULL -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 272 (class 1259 OID 241078) --- Name: property_profile_view_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.property_profile_view_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_fk_property_of_origin integer, - dfh_standard_label character varying, - dfh_root_namespace text, - dfh_pk_profile integer, - dfh_profile_label character varying, - is_inabled_in_profile boolean, - removed_from_api boolean -); - - --- --- TOC entry 268 (class 1259 OID 240895) --- Name: property_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_property integer, - dfh_identifier_in_namespace text, - dfh_has_domain integer, - dfh_has_range integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_domain_instances_cardinality smallint, - dfh_range_instances_cardinality smallint, - dfh_standard_label character varying(500), - dfh_fk_property_of_origin integer, - identity_defining boolean -); - - --- --- TOC entry 275 (class 1259 OID 241153) --- Name: system_type; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.system_type ( - dfh_pk_system_type integer, - dfh_used_in_table character varying(250), - dfh_standard_label character varying(500), - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 276 (class 1259 OID 241167) --- Name: system_type_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.system_type_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - is_inabled_in_profile boolean, - removed_from_api boolean, - dfh_pk_system_type integer, - dfh_used_in_table character varying(250), - dfh_standard_label character varying(500), - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone -); - - --- --- TOC entry 265 (class 1259 OID 240864) --- Name: text_property; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.text_property ( - dfh_pk_text_property integer, - dfh_text_property text, - dfh_language_iso_code character varying, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_system_type integer, - dfh_fk_entity_association integer, - dfh_fk_profile integer, - dfh_fk_is_subclass_of integer -) -INHERITS (data_for_history.entity); - - --- --- TOC entry 266 (class 1259 OID 240876) --- Name: text_property_vt; Type: TABLE; Schema: data_for_history; Owner: - --- - -CREATE TABLE data_for_history.text_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - dfh_pk_text_property integer, - dfh_text_property text, - dfh_language_iso_code character varying, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_fk_property integer, - dfh_fk_namespace integer, - dfh_fk_class integer, - dfh_fk_project integer, - dfh_fk_class_type integer, - dfh_fk_property_type integer, - dfh_fk_system_type integer, - dfh_fk_entity_association integer, - dfh_fk_profile integer, - dfh_fk_is_subclass_of integer -); - - --- --- TOC entry 318 (class 1259 OID 243295) --- Name: _deprecated_namespace; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information._deprecated_namespace ( - pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - fk_root_namespace integer, - fk_project integer, - standard_label character varying(500) -) -INHERITS (information.entity); - - --- --- TOC entry 6165 (class 0 OID 0) --- Dependencies: 318 --- Name: TABLE _deprecated_namespace; Type: COMMENT; Schema: information; Owner: - --- - -COMMENT ON TABLE information._deprecated_namespace IS 'This table stores namespaces of controlled vocabularies.'; - - --- --- TOC entry 6166 (class 0 OID 0) --- Dependencies: 318 --- Name: COLUMN _deprecated_namespace.fk_root_namespace; Type: COMMENT; Schema: information; Owner: - --- - -COMMENT ON COLUMN information._deprecated_namespace.fk_root_namespace IS 'References the root namespace. If null, the namespace is a root namespace'; - - --- --- TOC entry 319 (class 1259 OID 243319) --- Name: _deprecated_namespace_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information._deprecated_namespace_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_root_namespace integer, - fk_project integer, - standard_label character varying(500) -); - - --- --- TOC entry 320 (class 1259 OID 243326) --- Name: _deprecated_type_namespace_rel; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information._deprecated_type_namespace_rel ( - pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - fk_persistent_item integer, - fk_namespace integer -) -INHERITS (information.entity); - - --- --- TOC entry 6167 (class 0 OID 0) --- Dependencies: 320 --- Name: TABLE _deprecated_type_namespace_rel; Type: COMMENT; Schema: information; Owner: - --- - -COMMENT ON TABLE information._deprecated_type_namespace_rel IS 'This table stores relation between instances of E55 Type and Namespaces.'; - - --- --- TOC entry 6168 (class 0 OID 0) --- Dependencies: 320 --- Name: COLUMN _deprecated_type_namespace_rel.fk_persistent_item; Type: COMMENT; Schema: information; Owner: - --- - -COMMENT ON COLUMN information._deprecated_type_namespace_rel.fk_persistent_item IS 'References the pk_entity of the persistent_item table.'; - - --- --- TOC entry 321 (class 1259 OID 243350) --- Name: _deprecated_type_namespace_rel_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information._deprecated_type_namespace_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_persistent_item integer, - fk_namespace integer -); - - --- --- TOC entry 242 (class 1259 OID 240515) --- Name: appellation; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.appellation ( - _deprecated_pk_appellation integer NOT NULL, - _deprecated_appellation_label jsonb, - fk_class integer NOT NULL, - entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text, information.entity); - - --- --- TOC entry 241 (class 1259 OID 240513) --- Name: appellation_pk_appellation_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.appellation_pk_appellation_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6169 (class 0 OID 0) --- Dependencies: 241 --- Name: appellation_pk_appellation_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.appellation_pk_appellation_seq OWNED BY information.appellation._deprecated_pk_appellation; - - --- --- TOC entry 243 (class 1259 OID 240535) --- Name: appellation_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.appellation_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - _deprecated_pk_appellation integer NOT NULL, - _deprecated_appellation_label jsonb, - fk_class integer NOT NULL, - entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 245 (class 1259 OID 240572) --- Name: entity_association; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.entity_association ( - pk_entity_association integer NOT NULL, - fk_info_domain integer, - fk_info_range integer, - fk_property integer, - fk_data_domain integer, - fk_data_range integer -) -INHERITS (information.entity); - - --- --- TOC entry 244 (class 1259 OID 240570) --- Name: entity_association_pk_entity_association_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.entity_association_pk_entity_association_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6170 (class 0 OID 0) --- Dependencies: 244 --- Name: entity_association_pk_entity_association_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.entity_association_pk_entity_association_seq OWNED BY information.entity_association.pk_entity_association; - - --- --- TOC entry 246 (class 1259 OID 240592) --- Name: entity_association_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.entity_association_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_entity_association integer NOT NULL, - fk_domain_entity integer, - fk_range_entity integer, - fk_property integer -); - - --- --- TOC entry 258 (class 1259 OID 240746) --- Name: language; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.language ( - pk_language character(3) NOT NULL, - fk_class integer, - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3) -) -INHERITS (information.entity); - - --- --- TOC entry 259 (class 1259 OID 240765) --- Name: language_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.language_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_language character(3) NOT NULL, - fk_class integer, - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3) -); - - --- --- TOC entry 248 (class 1259 OID 240603) --- Name: persistent_item; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.persistent_item ( - _deprecated_pk_persistent_item integer NOT NULL, - fk_class integer -) -INHERITS (information.entity); - - --- --- TOC entry 247 (class 1259 OID 240601) --- Name: persistent_item_pk_persistent_item_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.persistent_item_pk_persistent_item_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6171 (class 0 OID 0) --- Dependencies: 247 --- Name: persistent_item_pk_persistent_item_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.persistent_item_pk_persistent_item_seq OWNED BY information.persistent_item._deprecated_pk_persistent_item; - - --- --- TOC entry 249 (class 1259 OID 240623) --- Name: persistent_item_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.persistent_item_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_persistent_item integer NOT NULL, - fk_class integer -); - - --- --- TOC entry 302 (class 1259 OID 242949) --- Name: place; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.place ( - geo_point public.geography(Point,4326), - fk_class integer -) -INHERITS (information.entity); - - --- --- TOC entry 314 (class 1259 OID 243136) --- Name: place_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.place_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - geo_point public.geography(Point,4326), - fk_class integer -); - - --- --- TOC entry 396 (class 1259 OID 246038) --- Name: property_of_property; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.property_of_property ( - fk_property integer, - provisional_property character varying, - fk_role integer, - fk_entity_association integer, - fk_range_entity integer NOT NULL, - entity_version integer -) -INHERITS (information.entity); - - --- --- TOC entry 397 (class 1259 OID 246067) --- Name: property_of_property_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.property_of_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer, - provisional_property character varying, - fk_role integer, - fk_entity_association integer, - fk_range_entity integer NOT NULL, - entity_version integer -); - - --- --- TOC entry 251 (class 1259 OID 240634) --- Name: role; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.role ( - _deprecated_pk_role integer NOT NULL, - fk_entity integer, - fk_temporal_entity integer, - fk_property integer -) -INHERITS (information.entity); - - --- --- TOC entry 250 (class 1259 OID 240632) --- Name: role_pk_role_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.role_pk_role_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6172 (class 0 OID 0) --- Dependencies: 250 --- Name: role_pk_role_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.role_pk_role_seq OWNED BY information.role._deprecated_pk_role; - - --- --- TOC entry 252 (class 1259 OID 240654) --- Name: role_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.role_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_role integer NOT NULL, - fk_entity integer, - fk_temporal_entity integer, - fk_property integer -); - - --- --- TOC entry 253 (class 1259 OID 240689) --- Name: temporal_entity_pk_temporal_entity_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.temporal_entity_pk_temporal_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6173 (class 0 OID 0) --- Dependencies: 253 --- Name: temporal_entity_pk_temporal_entity_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.temporal_entity_pk_temporal_entity_seq OWNED BY information.temporal_entity._deprecated_pk_temporal_entity; - - --- --- TOC entry 255 (class 1259 OID 240711) --- Name: temporal_entity_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.temporal_entity_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_temporal_entity integer NOT NULL, - fk_class integer -); - - --- --- TOC entry 256 (class 1259 OID 240722) --- Name: text_property; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.text_property ( - _deprecated_text_property text, - fk_concerned_entity integer NOT NULL, - _deprecated_text_property_quill_doc jsonb, - fk_language integer NOT NULL, - fk_class_field integer, - entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text, information.entity); - - --- --- TOC entry 257 (class 1259 OID 240737) --- Name: text_property_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.text_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - _deprecated_text_property text, - fk_concerned_entity integer, - _deprecated_text_property_quill_doc jsonb, - fk_language integer, - fk_class_field integer, - entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 278 (class 1259 OID 241191) --- Name: time_primitive; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.time_primitive ( - pk_time_primitive integer NOT NULL, - duration public.calendar_granularities, - fk_class integer, - julian_day integer -) -INHERITS (information.entity); - - --- --- TOC entry 277 (class 1259 OID 241189) --- Name: time_primitive_pk_time_primitive_seq; Type: SEQUENCE; Schema: information; Owner: - --- - -CREATE SEQUENCE information.time_primitive_pk_time_primitive_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6174 (class 0 OID 0) --- Dependencies: 277 --- Name: time_primitive_pk_time_primitive_seq; Type: SEQUENCE OWNED BY; Schema: information; Owner: - --- - -ALTER SEQUENCE information.time_primitive_pk_time_primitive_seq OWNED BY information.time_primitive.pk_time_primitive; - - --- --- TOC entry 315 (class 1259 OID 243143) --- Name: time_primitive_vt; Type: TABLE; Schema: information; Owner: - --- - -CREATE TABLE information.time_primitive_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - pk_time_primitive integer NOT NULL, - duration public.calendar_granularities, - fk_class integer, - julian_day integer -); - - --- --- TOC entry 356 (class 1259 OID 245264) --- Name: v_appellation; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_appellation AS - SELECT appellation.pk_entity, - appellation.schema_name, - appellation.table_name, - appellation.notes, - appellation.fk_creator, - appellation.fk_last_modifier, - appellation.tmsp_creation, - appellation.tmsp_last_modification, - appellation.sys_period, - appellation.fk_class, - appellation.quill_doc, - appellation.string - FROM information.appellation; - - --- --- TOC entry 325 (class 1259 OID 243481) --- Name: v_class_preview; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_class_preview AS - SELECT DISTINCT ON (c.dfh_pk_class) - CASE - WHEN (l.dfh_label IS NOT NULL) THEN (l.dfh_label)::character varying - ELSE cpv.dfh_class_standard_label - END AS class_label, - CASE - WHEN (cpv.dfh_fk_system_type = 9) THEN 'teEn'::text - WHEN (cpv.dfh_fk_system_type = 8) THEN 'peIt'::text - ELSE NULL::text - END AS entity_type, - c.dfh_pk_class - FROM ((data_for_history.class c - JOIN data_for_history.class_profile_view cpv ON ((c.dfh_pk_class = cpv.dfh_fk_class))) - LEFT JOIN data_for_history.label l ON (((l.dfh_fk_class = c.dfh_pk_class) AND (l.com_fk_system_type = 184)))) - ORDER BY c.dfh_pk_class, l.dfh_label; - - --- --- TOC entry 225 (class 1259 OID 240339) --- Name: entity; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.entity ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) -); - - --- --- TOC entry 261 (class 1259 OID 240776) --- Name: info_proj_rel; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.info_proj_rel ( - pk_entity integer DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - _deprecated_pk_entity_version_project_rel integer NOT NULL, - _deprecated_fk_project integer, - fk_entity integer, - fk_entity_version integer, - fk_entity_version_concat text, - is_in_project boolean, - is_standard_in_project boolean, - calendar public.calendar_type, - ord_num integer, - entity_version integer NOT NULL, - fk_project integer NOT NULL -) -INHERITS (projects.entity); - - --- --- TOC entry 391 (class 1259 OID 246012) --- Name: v_entity_association; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE (epr.is_in_project = true)), (0)::bigint) AS is_in_project_count - FROM (information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON ((epr.fk_entity = ea_1.pk_entity))) - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY COALESCE(ea.fk_info_domain, ea.fk_data_domain), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY COALESCE(ea.fk_info_range, ea.fk_data_range), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM (ea_project_count ea - JOIN data_for_history.property p ON ((ea.fk_property = p.dfh_pk_property))); - - --- --- TOC entry 311 (class 1259 OID 243092) --- Name: v_language; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_language AS - SELECT language.pk_entity, - language.schema_name, - language.table_name, - language.notes, - language.fk_creator, - language.fk_last_modifier, - language.tmsp_creation, - language.tmsp_last_modification, - language.sys_period, - language.pk_language, - language.fk_class, - language.lang_type, - language.scope, - language.iso6392b, - language.iso6392t, - language.iso6391 - FROM information.language; - - --- --- TOC entry 305 (class 1259 OID 243017) --- Name: class_field_config; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.class_field_config ( - fk_app_context integer NOT NULL, - _deprecated_fk_project integer, - fk_property integer, - property_is_outgoing boolean, - fk_class_field integer, - fk_class_for_class_field integer, - ord_num integer, - fk_project integer -) -INHERITS (projects.entity); - - --- --- TOC entry 224 (class 1259 OID 240337) --- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: projects; Owner: - --- - -CREATE SEQUENCE projects.entity_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6175 (class 0 OID 0) --- Dependencies: 224 --- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - --- - -ALTER SEQUENCE projects.entity_pk_entity_seq OWNED BY projects.entity.pk_entity; - - --- --- TOC entry 347 (class 1259 OID 244711) --- Name: entity; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.entity ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) -); - - --- --- TOC entry 307 (class 1259 OID 243052) --- Name: class_field; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_field ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - label character varying NOT NULL, - description text, - used_table text, - fk_system_type_ng_component integer -) -INHERITS (system.entity); - - --- --- TOC entry 326 (class 1259 OID 243486) --- Name: v_ordered_fields_per_class; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_ordered_fields_per_class AS - SELECT c.pk_entity, - c.ord_num AS field_order, - CASE - WHEN (c.property_is_outgoing = true) THEN p.dfh_has_domain - WHEN (c.property_is_outgoing = false) THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END AS fk_class, - c.fk_property, - c.property_is_outgoing, - c.fk_class_field, - f.used_table - FROM ((projects.class_field_config c - LEFT JOIN data_for_history.property p ON ((p.dfh_pk_property = c.fk_property))) - LEFT JOIN system.class_field f ON ((f.pk_entity = c.fk_class_field))) - WHERE (c.fk_app_context = 45) - ORDER BY - CASE - WHEN (c.property_is_outgoing = true) THEN p.dfh_has_domain - WHEN (c.property_is_outgoing = false) THEN p.dfh_has_range - ELSE c.fk_class_for_class_field - END, c.ord_num; - - --- --- TOC entry 400 (class 1259 OID 246094) --- Name: v_persistent_item; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_persistent_item AS - SELECT persistent_item.pk_entity, - persistent_item.schema_name, - persistent_item.table_name, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period, - persistent_item._deprecated_pk_persistent_item, - persistent_item.fk_class, - persistent_item.metadata - FROM information.persistent_item; - - --- --- TOC entry 312 (class 1259 OID 243110) --- Name: v_place; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_place AS - SELECT place.pk_entity, - place.schema_name, - place.table_name, - place.notes, - place.fk_creator, - place.fk_last_modifier, - place.tmsp_creation, - place.tmsp_last_modification, - place.sys_period, - place.geo_point, - place.fk_class, - public.st_x((place.geo_point)::public.geometry) AS long, - public.st_y((place.geo_point)::public.geometry) AS lat - FROM information.place; - - --- --- TOC entry 398 (class 1259 OID 246076) --- Name: v_property_of_property; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_property_of_property AS - SELECT property_of_property.pk_entity, - property_of_property.schema_name, - property_of_property.table_name, - property_of_property.notes, - property_of_property.fk_creator, - property_of_property.fk_last_modifier, - property_of_property.tmsp_creation, - property_of_property.tmsp_last_modification, - property_of_property.sys_period, - property_of_property.metadata, - property_of_property.fk_property, - property_of_property.provisional_property, - property_of_property.fk_role, - property_of_property.fk_entity_association, - property_of_property.fk_range_entity, - property_of_property.entity_version - FROM information.property_of_property; - - --- --- TOC entry 310 (class 1259 OID 243078) --- Name: v_role; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_role AS - WITH role_project_count AS ( - SELECT r_1.pk_entity, - r_1.fk_property, - r_1.fk_entity, - r_1.fk_temporal_entity, - COALESCE(count(*) FILTER (WHERE (epr.is_in_project = true)), (0)::bigint) AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE (epr.ord_num = 0)), (0)::bigint) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar, - r_1.notes, - r_1.tmsp_creation, - r_1.tmsp_last_modification, - r_1.sys_period - FROM (information.role r_1 - LEFT JOIN projects.info_proj_rel epr ON ((epr.fk_entity = r_1.pk_entity))) - GROUP BY r_1.pk_entity, r_1.fk_property, r_1.fk_entity, r_1.fk_temporal_entity, r_1.notes, r_1.tmsp_creation, r_1.tmsp_last_modification, r_1.sys_period - ) - SELECT r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - r.is_in_project_count, - r.is_standard_in_project_count, - r.community_favorite_calendar, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period, - row_number() OVER (PARTITION BY r.fk_temporal_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_te_ent, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY r.fk_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_pe_it, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM (role_project_count r - JOIN data_for_history.property p ON ((r.fk_property = p.dfh_pk_property))); - - --- --- TOC entry 6176 (class 0 OID 0) --- Dependencies: 310 --- Name: VIEW v_role; Type: COMMENT; Schema: information; Owner: - --- - -COMMENT ON VIEW information.v_role IS 'If rank_for_te_ent is bigger than range_max_quantifier, the role can be considered a repo-wide alternative from the perspective of the temporal entits. - - If rank_for_pe_it is bigger than domain_max_quantifier, the role can be considered a repo-wide alternative from the perspective of the persistent item.'; - - --- --- TOC entry 353 (class 1259 OID 245148) --- Name: v_temporal_entity; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_temporal_entity AS - SELECT temporal_entity.pk_entity, - temporal_entity.schema_name, - temporal_entity.table_name, - temporal_entity.notes, - temporal_entity.fk_creator, - temporal_entity.fk_last_modifier, - temporal_entity.tmsp_creation, - temporal_entity.tmsp_last_modification, - temporal_entity.sys_period, - temporal_entity.fk_class - FROM information.temporal_entity; - - --- --- TOC entry 354 (class 1259 OID 245232) --- Name: v_text_property; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_text_property AS - SELECT text_property.pk_entity, - text_property.schema_name, - text_property.table_name, - text_property.notes, - text_property.fk_creator, - text_property.fk_last_modifier, - text_property.tmsp_creation, - text_property.tmsp_last_modification, - text_property.sys_period, - text_property.fk_concerned_entity, - text_property.fk_language, - text_property.fk_class_field, - text_property.quill_doc, - text_property.string, - count(epr.fk_project) AS is_in_project_count - FROM (information.text_property - LEFT JOIN projects.info_proj_rel epr ON (((epr.fk_entity = text_property.pk_entity) AND (epr.is_in_project = true)))) - GROUP BY text_property.pk_entity, text_property.schema_name, text_property.table_name, text_property.notes, text_property.fk_creator, text_property.fk_last_modifier, text_property.tmsp_creation, text_property.tmsp_last_modification, text_property.sys_period, text_property._deprecated_text_property, text_property.fk_concerned_entity, text_property.quill_doc, text_property.fk_language, text_property.fk_class_field, text_property.string; - - --- --- TOC entry 309 (class 1259 OID 243073) --- Name: v_time_primitive; Type: VIEW; Schema: information; Owner: - --- - -CREATE VIEW information.v_time_primitive AS - SELECT time_primitive.pk_entity, - time_primitive.schema_name, - time_primitive.table_name, - time_primitive.notes, - time_primitive.fk_creator, - time_primitive.fk_last_modifier, - time_primitive.tmsp_creation, - time_primitive.tmsp_last_modification, - time_primitive.sys_period, - time_primitive.pk_time_primitive, - time_primitive.duration, - time_primitive.fk_class, - time_primitive.julian_day - FROM information.time_primitive; - - --- --- TOC entry 227 (class 1259 OID 240350) --- Name: _deprecated_label; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects._deprecated_label ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - pk_label integer NOT NULL, - label text, - fk_system_type integer, - fk_language character(3), - fk_entity integer, - notes text, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) -) -INHERITS (projects.entity); - - --- --- TOC entry 228 (class 1259 OID 240370) --- Name: _deprecated_label_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects._deprecated_label_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - pk_label integer NOT NULL, - label text, - fk_system_type integer, - fk_language character(3), - fk_entity integer, - notes text, - sys_period tstzrange -); - - --- --- TOC entry 328 (class 1259 OID 243906) --- Name: argument; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.argument ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - fk_is_about_role integer NOT NULL, - fk_is_about_entity_association integer NOT NULL, - fk_is_based_on_role integer NOT NULL, - fk_is_based_on_entity_association integer NOT NULL, - fk_is_based_on_persistent_item integer NOT NULL, - fk_is_based_on_factoid_role integer NOT NULL, - fk_is_based_on_cell integer NOT NULL, - fk_assertion_method_type integer NOT NULL, - source_reliability integer, - value integer -) -INHERITS (projects.entity); - - --- --- TOC entry 329 (class 1259 OID 243960) --- Name: argument_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.argument_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_is_about_role integer NOT NULL, - fk_is_about_entity_association integer NOT NULL, - fk_is_based_on_role integer NOT NULL, - fk_is_based_on_entity_association integer NOT NULL, - fk_is_based_on_persistent_item integer NOT NULL, - fk_is_based_on_factoid_role integer NOT NULL, - fk_is_based_on_cell integer NOT NULL, - fk_assertion_method_type integer NOT NULL, - source_reliability integer, - value integer -); - - --- --- TOC entry 306 (class 1259 OID 243045) --- Name: class_field_config_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.class_field_config_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_app_context integer NOT NULL, - _deprecated_fk_project integer, - fk_property integer, - property_is_outgoing boolean, - fk_class_field integer, - fk_class_for_class_field integer, - ord_num integer, - fk_project integer -); - - --- --- TOC entry 316 (class 1259 OID 243261) --- Name: dfh_class_proj_rel; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.dfh_class_proj_rel ( - pk_entity integer DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass), - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - tmsp_last_dfh_update timestamp with time zone, - is_enabled_in_profile boolean, - removed_from_api boolean DEFAULT false, - _deprecated_fk_project integer, - fk_entity integer, - enabled_in_entities boolean, - fk_project integer NOT NULL -) -INHERITS (projects.entity); - - --- --- TOC entry 6177 (class 0 OID 0) --- Dependencies: 316 --- Name: TABLE dfh_class_proj_rel; Type: COMMENT; Schema: projects; Owner: - --- - -COMMENT ON TABLE projects.dfh_class_proj_rel IS 'This table relates any child table of the data_for_history.entity to a project.'; - - --- --- TOC entry 6178 (class 0 OID 0) --- Dependencies: 316 --- Name: COLUMN dfh_class_proj_rel.enabled_in_entities; Type: COMMENT; Schema: projects; Owner: - --- - -COMMENT ON COLUMN projects.dfh_class_proj_rel.enabled_in_entities IS 'If true, the entity is (added / activated / visible) in the project, if false it is not in the project'; - - --- --- TOC entry 317 (class 1259 OID 243288) --- Name: dfh_class_proj_rel_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.dfh_class_proj_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - is_enabled_in_profile boolean, - removed_from_api boolean, - _deprecated_fk_project integer, - fk_entity integer, - is_in_project boolean, - fk_project integer -); - - --- --- TOC entry 260 (class 1259 OID 240774) --- Name: entity_version_project_rel_pk_entity_version_project_rel_seq; Type: SEQUENCE; Schema: projects; Owner: - --- - -CREATE SEQUENCE projects.entity_version_project_rel_pk_entity_version_project_rel_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6179 (class 0 OID 0) --- Dependencies: 260 --- Name: entity_version_project_rel_pk_entity_version_project_rel_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - --- - -ALTER SEQUENCE projects.entity_version_project_rel_pk_entity_version_project_rel_seq OWNED BY projects.info_proj_rel._deprecated_pk_entity_version_project_rel; - - --- --- TOC entry 262 (class 1259 OID 240800) --- Name: info_proj_rel_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.info_proj_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - _deprecated_pk_entity_version_project_rel integer NOT NULL, - _deprecated_fk_project integer, - fk_entity integer, - fk_entity_version integer, - fk_entity_version_concat text, - is_in_project boolean, - is_standard_in_project boolean, - calendar public.calendar_type, - ord_num integer, - fk_project integer -); - - --- --- TOC entry 226 (class 1259 OID 240348) --- Name: label_pk_label_seq; Type: SEQUENCE; Schema: projects; Owner: - --- - -CREATE SEQUENCE projects.label_pk_label_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6180 (class 0 OID 0) --- Dependencies: 226 --- Name: label_pk_label_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - --- - -ALTER SEQUENCE projects.label_pk_label_seq OWNED BY projects._deprecated_label.pk_label; - - --- --- TOC entry 207 (class 1259 OID 240172) --- Name: language; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.language ( - pk_language character(3) NOT NULL, - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3), - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone) -); - - --- --- TOC entry 208 (class 1259 OID 240184) --- Name: language_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.language_vt ( - pk_language character(3) NOT NULL, - lang_type character varying, - scope character varying, - iso6392b character(3), - iso6392t character(3), - iso6391 character(3), - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange -); - - --- --- TOC entry 230 (class 1259 OID 240379) --- Name: project; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.project ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - _deprecated_pk_project integer NOT NULL, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - _deprecated_fk_language character(3), - notes text, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - fk_language integer -) -INHERITS (projects.entity); - - --- --- TOC entry 229 (class 1259 OID 240377) --- Name: project_pk_project_seq; Type: SEQUENCE; Schema: projects; Owner: - --- - -CREATE SEQUENCE projects.project_pk_project_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6181 (class 0 OID 0) --- Dependencies: 229 --- Name: project_pk_project_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - --- - -ALTER SEQUENCE projects.project_pk_project_seq OWNED BY projects.project._deprecated_pk_project; - - --- --- TOC entry 231 (class 1259 OID 240409) --- Name: project_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.project_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - _deprecated_pk_project integer NOT NULL, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - _deprecated_fk_language character(3), - notes text, - sys_period tstzrange -); - - --- --- TOC entry 336 (class 1259 OID 244080) --- Name: query; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.query ( - name character varying, - description character varying, - query jsonb, - _deprecated_fk_project integer, - fk_project integer NOT NULL -) -INHERITS (projects.entity); - - --- --- TOC entry 337 (class 1259 OID 244094) --- Name: query_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.query_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - name character varying, - description character varying, - query jsonb, - _deprecated_fk_project integer, - fk_project integer -); - - --- --- TOC entry 235 (class 1259 OID 240442) --- Name: text_property; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.text_property ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - _deprecated_pk_text_property integer NOT NULL, - _deprecated_text_property text, - _deprecated_text_property_xml xml, - fk_system_type integer, - _deprecated_fk_language character(3), - fk_entity integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - fk_language integer, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (projects.entity, commons.text); - - --- --- TOC entry 234 (class 1259 OID 240440) --- Name: text_property_pk_text_property_seq; Type: SEQUENCE; Schema: projects; Owner: - --- - -CREATE SEQUENCE projects.text_property_pk_text_property_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6182 (class 0 OID 0) --- Dependencies: 234 --- Name: text_property_pk_text_property_seq; Type: SEQUENCE OWNED BY; Schema: projects; Owner: - --- - -ALTER SEQUENCE projects.text_property_pk_text_property_seq OWNED BY projects.text_property._deprecated_pk_text_property; - - --- --- TOC entry 236 (class 1259 OID 240462) --- Name: text_property_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.text_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - _deprecated_pk_text_property integer NOT NULL, - _deprecated_text_property text, - _deprecated_text_property_xml xml, - fk_system_type integer, - _deprecated_fk_language character(3), - fk_entity integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - entity_version integer, - pk_text integer DEFAULT nextval('commons.text_pk_text_seq'::regclass), - quill_doc jsonb, - string text DEFAULT ''::text, - CONSTRAINT text_quill_doc_check CHECK (commons.validate_quill_doc(quill_doc)) -) -INHERITS (commons.text_vt); - - --- --- TOC entry 324 (class 1259 OID 243425) --- Name: v_info_proj_rel; Type: VIEW; Schema: projects; Owner: - --- - -CREATE VIEW projects.v_info_proj_rel AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel._deprecated_pk_entity_version_project_rel AS pk_entity_version_project_rel, - info_proj_rel.fk_project, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num, - info_proj_rel.entity_version - FROM projects.info_proj_rel; - - --- --- TOC entry 340 (class 1259 OID 244180) --- Name: visual; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.visual ( - name character varying, - description character varying, - visual jsonb, - _deprecated_fk_project integer, - fk_project integer NOT NULL -) -INHERITS (projects.entity); - - --- --- TOC entry 341 (class 1259 OID 244196) --- Name: visual_vt; Type: TABLE; Schema: projects; Owner: - --- - -CREATE TABLE projects.visual_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - name character varying, - description character varying, - visual jsonb, - _deprecated_fk_project integer, - fk_project integer -); - - --- --- TOC entry 217 (class 1259 OID 240285) --- Name: accesstoken; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.accesstoken ( - id text NOT NULL, - ttl integer DEFAULT 1209600, - scopes text, - created timestamp with time zone, - userid integer -); - - --- --- TOC entry 216 (class 1259 OID 240272) --- Name: account; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.account ( - realm text, - username text, - password text NOT NULL, - email text NOT NULL, - emailverified boolean, - verificationtoken text, - id integer NOT NULL -); - - --- --- TOC entry 215 (class 1259 OID 240270) --- Name: account_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.account_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6183 (class 0 OID 0) --- Dependencies: 215 --- Name: account_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.account_id_seq OWNED BY public.account.id; - - --- --- TOC entry 238 (class 1259 OID 240481) --- Name: account_project_rel; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.account_project_rel ( - account_id integer NOT NULL, - _deprecated_fk_project integer, - role text NOT NULL, - id integer NOT NULL, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - fk_project integer NOT NULL, - entity_version integer -); - - --- --- TOC entry 237 (class 1259 OID 240479) --- Name: account_project_rel_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.account_project_rel_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6184 (class 0 OID 0) --- Dependencies: 237 --- Name: account_project_rel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.account_project_rel_id_seq OWNED BY public.account_project_rel.id; - - --- --- TOC entry 352 (class 1259 OID 244981) --- Name: account_project_rel_vt; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.account_project_rel_vt ( - account_id integer NOT NULL, - _deprecated_fk_project integer, - role text NOT NULL, - id integer NOT NULL, - sys_period tstzrange, - fk_project integer, - entity_version integer -); - - --- --- TOC entry 223 (class 1259 OID 240328) --- Name: acl; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.acl ( - model text, - property text, - accesstype text, - permission text, - principaltype text, - principalid text, - id integer NOT NULL -); - - --- --- TOC entry 222 (class 1259 OID 240326) --- Name: acl_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.acl_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6185 (class 0 OID 0) --- Dependencies: 222 --- Name: acl_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.acl_id_seq OWNED BY public.acl.id; - - --- -- --- -- TOC entry 206 (class 1259 OID 240154) --- -- Name: migrations; Type: TABLE; Schema: public; Owner: - --- -- - --- CREATE TABLE IF NOT EXISTS public.migrations ( --- id integer NOT NULL, --- name character varying(255) NOT NULL, --- run_on timestamp without time zone NOT NULL --- ); - - --- -- --- -- TOC entry 205 (class 1259 OID 240152) --- -- Name: migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- -- - --- CREATE SEQUENCE IF NOT EXISTS public.migrations_id_seq --- AS integer --- START WITH 1 --- INCREMENT BY 1 --- NO MINVALUE --- NO MAXVALUE --- CACHE 1; - - --- -- --- -- TOC entry 6186 (class 0 OID 0) --- -- Dependencies: 205 --- -- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- -- - --- ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; - - --- --- TOC entry 219 (class 1259 OID 240301) --- Name: role; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.role ( - id integer NOT NULL, - name text NOT NULL, - description text, - created timestamp with time zone, - modified timestamp with time zone -); - - --- --- TOC entry 218 (class 1259 OID 240299) --- Name: role_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.role_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6187 (class 0 OID 0) --- Dependencies: 218 --- Name: role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.role_id_seq OWNED BY public.role.id; - - --- --- TOC entry 221 (class 1259 OID 240312) --- Name: rolemapping; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.rolemapping ( - id integer NOT NULL, - principaltype text, - principalid text, - roleid integer -); - - --- --- TOC entry 220 (class 1259 OID 240310) --- Name: rolemapping_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.rolemapping_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6188 (class 0 OID 0) --- Dependencies: 220 --- Name: rolemapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.rolemapping_id_seq OWNED BY public.rolemapping.id; - - --- --- TOC entry 303 (class 1259 OID 242996) --- Name: app_context; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.app_context ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - label character varying NOT NULL, - description text -) -INHERITS (system.entity); - - --- --- TOC entry 304 (class 1259 OID 243010) --- Name: app_context_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.app_context_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - label character varying NOT NULL, - description text -); - - --- --- TOC entry 322 (class 1259 OID 243385) --- Name: class_field_property_rel; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_field_property_rel ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - fk_class_field integer, - fk_property integer, - property_is_outgoing boolean, - ord_num integer -) -INHERITS (system.entity); - - --- --- TOC entry 6189 (class 0 OID 0) --- Dependencies: 322 --- Name: TABLE class_field_property_rel; Type: COMMENT; Schema: system; Owner: - --- - -COMMENT ON TABLE system.class_field_property_rel IS 'This table stores, what properties are bundled in the property set'; - - --- --- TOC entry 6190 (class 0 OID 0) --- Dependencies: 322 --- Name: COLUMN class_field_property_rel.fk_class_field; Type: COMMENT; Schema: system; Owner: - --- - -COMMENT ON COLUMN system.class_field_property_rel.fk_class_field IS 'The property set'; - - --- --- TOC entry 6191 (class 0 OID 0) --- Dependencies: 322 --- Name: COLUMN class_field_property_rel.fk_property; Type: COMMENT; Schema: system; Owner: - --- - -COMMENT ON COLUMN system.class_field_property_rel.fk_property IS 'The property belonging to the property set'; - - --- --- TOC entry 6192 (class 0 OID 0) --- Dependencies: 322 --- Name: COLUMN class_field_property_rel.property_is_outgoing; Type: COMMENT; Schema: system; Owner: - --- - -COMMENT ON COLUMN system.class_field_property_rel.property_is_outgoing IS 'Wether the property is outgoing, seen from the class that will use it'; - - --- --- TOC entry 6193 (class 0 OID 0) --- Dependencies: 322 --- Name: COLUMN class_field_property_rel.ord_num; Type: COMMENT; Schema: system; Owner: - --- - -COMMENT ON COLUMN system.class_field_property_rel.ord_num IS 'The order number of the property within the property set.'; - - --- --- TOC entry 323 (class 1259 OID 243411) --- Name: class_field_property_rel_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_field_property_rel_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_class_field integer, - fk_property integer, - property_is_outgoing boolean, - ord_num integer -); - - --- --- TOC entry 308 (class 1259 OID 243066) --- Name: class_field_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_field_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - label character varying NOT NULL, - description text, - used_table text, - fk_system_type_ng_component integer -); - - --- --- TOC entry 338 (class 1259 OID 244103) --- Name: class_has_type_property; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_has_type_property ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - fk_class integer, - fk_property integer -) -INHERITS (system.entity); - - --- --- TOC entry 339 (class 1259 OID 244129) --- Name: class_has_type_property_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.class_has_type_property_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - entity_version integer, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_class integer, - fk_property integer -); - - --- --- TOC entry 346 (class 1259 OID 244709) --- Name: entity_pk_entity_seq; Type: SEQUENCE; Schema: system; Owner: - --- - -CREATE SEQUENCE system.entity_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- TOC entry 6194 (class 0 OID 0) --- Dependencies: 346 --- Name: entity_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: system; Owner: - --- - -ALTER SEQUENCE system.entity_pk_entity_seq OWNED BY system.entity.pk_entity; - - --- --- TOC entry 348 (class 1259 OID 244740) --- Name: system_relevant_class; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_relevant_class ( - fk_class integer NOT NULL, - required_by_entities boolean, - required_by_sources boolean, - required_by_contr_vocabs boolean -) -INHERITS (system.entity); - - --- --- TOC entry 349 (class 1259 OID 244759) --- Name: system_relevant_class_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_relevant_class_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_class integer NOT NULL, - required_by_entities boolean, - required_by_sources boolean, - required_by_contr_vocabs boolean -); - - --- --- TOC entry 350 (class 1259 OID 244768) --- Name: system_relevant_type; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_relevant_type ( - fk_type integer NOT NULL -) -INHERITS (system.entity); - - --- --- TOC entry 351 (class 1259 OID 244787) --- Name: system_relevant_type_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_relevant_type_vt ( - pk_entity integer NOT NULL, - schema_name character varying NOT NULL, - table_name character varying NOT NULL, - entity_version integer NOT NULL, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - fk_type integer NOT NULL -); - - --- --- TOC entry 232 (class 1259 OID 240418) --- Name: system_type; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_type ( - pk_entity integer DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - schema_name character varying, - table_name character varying, - st_schema_name character varying, - st_table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - entity_version integer -) -INHERITS (system.entity); - - --- --- TOC entry 233 (class 1259 OID 240433) --- Name: system_type_vt; Type: TABLE; Schema: system; Owner: - --- - -CREATE TABLE system.system_type_vt ( - pk_entity integer NOT NULL, - schema_name character varying, - table_name character varying, - pk_system_type integer NOT NULL, - st_schema_name character varying, - st_table_name character varying, - notes text, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange -); - - --- --- TOC entry 330 (class 1259 OID 243971) --- Name: class_preview; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.class_preview ( - class_label character varying, - entity_type text, - dfh_pk_class integer -); - - --- --- TOC entry 335 (class 1259 OID 244041) --- Name: entity_preview; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.entity_preview ( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - entity_type text, - class_label character varying, - entity_label text, - time_span jsonb, - own_full_text text, - fk_entity_label integer, - fk_type integer, - type_label text, - related_full_texts jsonb, - full_text text, - ts_vector tsvector -); - - --- --- TOC entry 332 (class 1259 OID 243996) --- Name: v_entities; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_entities AS - SELECT DISTINCT e.pk_entity, - epr.fk_project, - epr.fk_project AS project, - CASE - WHEN (pi.pk_entity IS NOT NULL) THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN ((e.table_name)::text = 'persistent_item'::text) THEN 'peIt'::text - WHEN ((e.table_name)::text = 'temporal_entity'::text) THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM (((projects.info_proj_rel epr - JOIN information.entity e ON ((e.pk_entity = epr.fk_entity))) - LEFT JOIN information.persistent_item pi ON ((e.pk_entity = pi.pk_entity))) - LEFT JOIN information.temporal_entity te ON ((e.pk_entity = te.pk_entity))) - WHERE ((epr.is_in_project = true) AND ((e.table_name)::text = ANY (ARRAY[('temporal_entity'::character varying)::text, ('persistent_item'::character varying)::text]))) -UNION - SELECT DISTINCT e.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - CASE - WHEN (pi.pk_entity IS NOT NULL) THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN ((e.table_name)::text = 'persistent_item'::text) THEN 'peIt'::text - WHEN ((e.table_name)::text = 'temporal_entity'::text) THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM ((information.entity e - LEFT JOIN information.persistent_item pi ON ((e.pk_entity = pi.pk_entity))) - LEFT JOIN information.temporal_entity te ON ((e.pk_entity = te.pk_entity))) - WHERE ((e.table_name)::text = ANY (ARRAY[('temporal_entity'::character varying)::text, ('persistent_item'::character varying)::text])) - ORDER BY 1; - - --- --- TOC entry 392 (class 1259 OID 246017) --- Name: v_entity_association_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_entity_association_per_project_and_repo AS - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - epr.ord_num AS rank_for_domain, - epr.ord_num AS rank_for_range, - COALESCE(epr.fk_project, 0) AS project - FROM (information.v_entity_association ea - LEFT JOIN projects.info_proj_rel epr ON (((epr.fk_entity = ea.pk_entity) AND (epr.is_in_project = true)))) -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - ea.rank_for_domain, - ea.rank_for_range, - 0 AS project - FROM information.v_entity_association ea - WHERE (ea.is_in_project_count > 0); - - --- --- TOC entry 331 (class 1259 OID 243991) --- Name: v_roles_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_roles_per_project_and_repo AS - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.ord_num AS rank_for_pe_it, - epr.ord_num AS rank_for_te_ent, - COALESCE(epr.fk_project, 0) AS project - FROM (information.v_role r - LEFT JOIN projects.info_proj_rel epr ON (((epr.fk_entity = r.pk_entity) AND (epr.is_in_project = true)))) -UNION - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.rank_for_pe_it, - r.rank_for_te_ent, - 0 AS project - FROM information.v_role r - WHERE (r.is_in_project_count > 0); - - --- --- TOC entry 333 (class 1259 OID 244011) --- Name: v_fk_entity_label; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_fk_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - a.fk_entity_label - FROM (entities - LEFT JOIN ( SELECT r.fk_entity AS pk_entity, - r.fk_temporal_entity AS fk_entity_label, - r.fk_project, - row_number() OVER (PARTITION BY r.fk_entity, COALESCE(r.fk_project, 0) ORDER BY r.rank_for_pe_it) AS rank - FROM ((warehouse.v_roles_per_project_and_repo r - JOIN projects.class_field_config ucc ON (((ucc.fk_property = r.fk_property) AND (ucc.ord_num = 0) AND (ucc.property_is_outgoing = false) AND (ucc.fk_app_context = 45)))) - JOIN information.entity e ON (((r.fk_temporal_entity = e.pk_entity) AND ((e.table_name)::text = 'temporal_entity'::text)))) - UNION - SELECT r.fk_temporal_entity AS pk_entity, - r.fk_entity AS fk_entity_label, - r.fk_project, - row_number() OVER (PARTITION BY r.fk_temporal_entity, COALESCE(r.fk_project, 0) ORDER BY r.rank_for_te_ent) AS rank - FROM ((warehouse.v_roles_per_project_and_repo r - JOIN projects.class_field_config ucc ON (((ucc.fk_property = r.fk_property) AND (ucc.ord_num = 0) AND (ucc.property_is_outgoing = true) AND (ucc.fk_app_context = 45)))) - JOIN information.entity e ON (((r.fk_entity = e.pk_entity) AND ((e.table_name)::text = 'persistent_item'::text))))) a ON (((a.pk_entity = entities.pk_entity) AND (NOT (a.fk_project IS DISTINCT FROM entities.fk_project))))) - WHERE (a.rank = 1); - - --- --- TOC entry 393 (class 1259 OID 246022) --- Name: v_fk_type; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_fk_type AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT DISTINCT ea.fk_info_domain AS pk_entity, - ea.fk_project, - ea.project, - ea.fk_info_range AS fk_type - FROM (((warehouse.v_entity_association_per_project_and_repo ea - JOIN projects.info_proj_rel epr ON ((ea.pk_entity = epr.fk_entity))) - JOIN data_for_history.property p ON ((ea.fk_property = p.dfh_pk_property))) - JOIN system.class_has_type_property hasprop ON ((hasprop.fk_property = p.dfh_pk_property))) - WHERE (ea.rank_for_domain = 1); - - --- --- TOC entry 355 (class 1259 OID 245239) --- Name: v_text_properties_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS "coalesce" - FROM (information.v_text_property t - JOIN projects.info_proj_rel epr ON (((epr.fk_entity = t.pk_entity) AND (epr.is_in_project = true)))) -UNION - SELECT DISTINCT t.pk_entity, - t.schema_name, - t.table_name, - t.notes, - t.fk_creator, - t.fk_last_modifier, - t.tmsp_creation, - t.tmsp_last_modification, - t.sys_period, - t.fk_concerned_entity, - t.fk_language, - t.fk_class_field, - t.quill_doc, - t.string, - t.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" - FROM information.v_text_property t - WHERE (t.is_in_project_count > 0); - - --- --- TOC entry 358 (class 1259 OID 245275) --- Name: v_own_entity_label; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM (information.v_ordered_fields_per_class f - JOIN entities e ON ((f.fk_class = e.fk_class))) - WHERE (f.field_order = 0) - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM (((first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON (((first_field.fk_property = r.fk_property) AND (first_field.pk_entity = r.fk_temporal_entity) AND (NOT (r.fk_project IS DISTINCT FROM first_field.fk_project))))) - LEFT JOIN information.v_appellation appe ON ((r.fk_entity = appe.pk_entity))) - LEFT JOIN information.v_language lang ON ((r.fk_entity = lang.pk_entity)))) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE (all_roles.role_number = 1) - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM (string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON (((NOT (string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field)) AND (txtp.fk_concerned_entity = string_from_first_role.pk_entity) AND (NOT (txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project)))))) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE (all_txtp.txtp_number = 1) - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - --- --- TOC entry 357 (class 1259 OID 245270) --- Name: v_own_full_text; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM (information.v_ordered_fields_per_class f - JOIN entities e ON ((f.fk_class = e.fk_class))) - WHERE (f.field_order IS NOT NULL) - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM (((field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON (((field.fk_property = r.fk_property) AND (field.pk_entity = r.fk_temporal_entity) AND (NOT (r.fk_project IS DISTINCT FROM field.fk_project))))) - LEFT JOIN information.v_appellation appe ON ((r.fk_entity = appe.pk_entity))) - LEFT JOIN information.v_language lang ON ((r.fk_entity = lang.pk_entity)))) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM (field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON (((NOT (field.fk_class_field IS DISTINCT FROM txtp.fk_class_field)) AND (txtp.fk_concerned_entity = field.pk_entity) AND (NOT (txtp.fk_project IS DISTINCT FROM field.fk_project)))))) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; - - --- --- TOC entry 327 (class 1259 OID 243501) --- Name: v_te_en_time_span_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM ((projects.info_proj_rel epr - JOIN information.v_role r ON ((r.pk_entity = epr.fk_entity))) - JOIN information.v_time_primitive tp ON ((tp.pk_entity = r.fk_entity))) - WHERE (epr.is_in_project = true) - UNION - SELECT r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM (information.v_role r - JOIN information.v_time_primitive tp ON (((tp.pk_entity = r.fk_entity) AND (r.rank_for_te_ent = 1)))) - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN (role_with_time_primitive.fk_property = 71) THEN 'p81'::text - WHEN (role_with_time_primitive.fk_property = 72) THEN 'p82'::text - WHEN (role_with_time_primitive.fk_property = 150) THEN 'p81a'::text - WHEN (role_with_time_primitive.fk_property = 151) THEN 'p81b'::text - WHEN (role_with_time_primitive.fk_property = 152) THEN 'p82a'::text - WHEN (role_with_time_primitive.fk_property = 153) THEN 'p82b'::text - ELSE (role_with_time_primitive.fk_property)::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - - --- --- TOC entry 394 (class 1259 OID 246027) --- Name: v_entity_preview_non_recursive; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM (entities - JOIN warehouse.class_preview c ON ((c.dfh_pk_class = entities.fk_class))) - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM (add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON (((a.pk_entity = l.pk_entity) AND (a.project = l.project)))) - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM (add_own_entity_label a - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t ON (((a.pk_entity = t.fk_temporal_entity) AND (NOT (a.fk_project IS DISTINCT FROM t.fk_project))))) - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM (add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON (((a.pk_entity = t.pk_entity) AND (a.project = t.project)))) - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM (add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON (((a.pk_entity = t.pk_entity) AND (NOT (a.fk_project IS DISTINCT FROM t.fk_project))))) - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM (add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON (((a.pk_entity = t.pk_entity) AND (a.project = t.project)))) - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - --- --- TOC entry 395 (class 1259 OID 246032) --- Name: v_entity_preview; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM (previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON (((t1.fk_entity_label = t2.pk_entity) AND (t1.project = t2.project)))) - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM (fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON (((t1.fk_type = t2.pk_entity) AND (t1.project = t2.project)))) - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM ((warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON (((e.pk_entity = r.fk_entity) AND ((e.table_name)::text = 'persistent_item'::text)))) - LEFT JOIN previews_non_recursive pre ON (((pre.pk_entity = e.pk_entity) AND (pre.project = r.project)))) - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM ((warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON (((e.pk_entity = r.fk_temporal_entity) AND ((e.table_name)::text = 'temporal_entity'::text)))) - LEFT JOIN previews_non_recursive pre ON (((pre.pk_entity = e.pk_entity) AND (pre.project = r.project)))) - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg((full_text_dependencies.pk_related_full_text)::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM (fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON (((t1.pk_entity = t2.pk_entity) AND (t1.project = t2.project)))) - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - ((setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, (t.class_label)::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char")) AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - - --- --- TOC entry 334 (class 1259 OID 244026) --- Name: v_related_full_texts; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_related_full_texts AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), all_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text - FROM (warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON (((e.pk_entity = r.fk_entity) AND ((e.table_name)::text = 'persistent_item'::text)))) - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text - FROM (warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON (((e.pk_entity = r.fk_temporal_entity) AND ((e.table_name)::text = 'temporal_entity'::text)))) - ), agg AS ( - SELECT all_dependencies.pk_entity, - all_dependencies.project, - all_dependencies.fk_project, - jsonb_object_agg((all_dependencies.pk_related_full_text)::text, '') AS related_full_texts - FROM all_dependencies - GROUP BY all_dependencies.pk_entity, all_dependencies.project, all_dependencies.fk_project - ) - SELECT agg.pk_entity, - agg.project, - agg.fk_project, - agg.related_full_texts - FROM agg; - - --- --- TOC entry 5273 (class 2604 OID 244685) --- Name: text pk_text; Type: DEFAULT; Schema: commons; Owner: - --- - -ALTER TABLE ONLY commons.text ALTER COLUMN pk_text SET DEFAULT nextval('commons.text_pk_text_seq'::regclass); - - --- --- TOC entry 5335 (class 2604 OID 245883) --- Name: avatar pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.avatar ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5336 (class 2604 OID 245884) --- Name: avatar tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.avatar ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5337 (class 2604 OID 245885) --- Name: avatar sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.avatar ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5302 (class 2604 OID 245523) --- Name: cell pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5303 (class 2604 OID 245524) --- Name: cell tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5304 (class 2604 OID 245525) --- Name: cell sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5287 (class 2604 OID 245396) --- Name: chunk pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.chunk ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5288 (class 2604 OID 245397) --- Name: chunk tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.chunk ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5289 (class 2604 OID 245398) --- Name: chunk sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.chunk ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5317 (class 2604 OID 245665) --- Name: class_column_rel pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5318 (class 2604 OID 245666) --- Name: class_column_rel tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5319 (class 2604 OID 245667) --- Name: class_column_rel sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5299 (class 2604 OID 245485) --- Name: column pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5300 (class 2604 OID 245486) --- Name: column tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5301 (class 2604 OID 245487) --- Name: column sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5332 (class 2604 OID 245855) --- Name: data_association pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.data_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5333 (class 2604 OID 245856) --- Name: data_association tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.data_association ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5334 (class 2604 OID 245857) --- Name: data_association sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.data_association ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5226 (class 2604 OID 241262) --- Name: digital _deprecated_pk_digital_object; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.digital ALTER COLUMN _deprecated_pk_digital_object SET DEFAULT nextval('data.digital_object_pk_digital_object_seq'::regclass); - - --- --- TOC entry 5284 (class 2604 OID 245297) --- Name: entity pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5323 (class 2604 OID 245736) --- Name: factoid pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5324 (class 2604 OID 245737) --- Name: factoid tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5325 (class 2604 OID 245738) --- Name: factoid sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5311 (class 2604 OID 245589) --- Name: factoid_class_digital_rel pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5312 (class 2604 OID 245590) --- Name: factoid_class_digital_rel tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5313 (class 2604 OID 245591) --- Name: factoid_class_digital_rel sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5320 (class 2604 OID 245698) --- Name: factoid_property_column_rel pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5321 (class 2604 OID 245699) --- Name: factoid_property_column_rel tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5322 (class 2604 OID 245700) --- Name: factoid_property_column_rel sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5326 (class 2604 OID 245764) --- Name: factoid_role pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5327 (class 2604 OID 245765) --- Name: factoid_role tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5328 (class 2604 OID 245766) --- Name: factoid_role sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5347 (class 2604 OID 245977) --- Name: namespace pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5348 (class 2604 OID 245978) --- Name: namespace tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5349 (class 2604 OID 245979) --- Name: namespace sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5296 (class 2604 OID 245457) --- Name: row pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."row" ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5297 (class 2604 OID 245458) --- Name: row tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."row" ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5298 (class 2604 OID 245459) --- Name: row sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."row" ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5338 (class 2604 OID 245911) --- Name: text_property pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5339 (class 2604 OID 245912) --- Name: text_property tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5340 (class 2604 OID 245913) --- Name: text_property sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5314 (class 2604 OID 245622) --- Name: value_association_columns_rel pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5315 (class 2604 OID 245623) --- Name: value_association_columns_rel tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5316 (class 2604 OID 245624) --- Name: value_association_columns_rel sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5329 (class 2604 OID 245807) --- Name: values_association pk_entity; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5330 (class 2604 OID 245808) --- Name: values_association tmsp_creation; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5331 (class 2604 OID 245809) --- Name: values_association sys_period; Type: DEFAULT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5209 (class 2604 OID 241088) --- Name: associates_system_type pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.associates_system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5210 (class 2604 OID 241089) --- Name: associates_system_type tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.associates_system_type ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5211 (class 2604 OID 241090) --- Name: associates_system_type sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.associates_system_type ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5109 (class 2604 OID 240226) --- Name: class pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5110 (class 2604 OID 240227) --- Name: class tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5112 (class 2604 OID 240228) --- Name: class sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5111 (class 2604 OID 241108) --- Name: class removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5106 (class 2604 OID 240207) --- Name: class_profile_view pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5107 (class 2604 OID 240208) --- Name: class_profile_view tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class_profile_view ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5108 (class 2604 OID 240209) --- Name: class_profile_view sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class_profile_view ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5102 (class 2604 OID 240196) --- Name: entity pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5190 (class 2604 OID 240848) --- Name: label pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5191 (class 2604 OID 240849) --- Name: label tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5192 (class 2604 OID 240850) --- Name: label sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5189 (class 2604 OID 241109) --- Name: label removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5203 (class 2604 OID 241044) --- Name: profile pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5204 (class 2604 OID 241045) --- Name: profile tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5205 (class 2604 OID 241046) --- Name: profile sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5202 (class 2604 OID 241112) --- Name: profile removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5198 (class 2604 OID 240886) --- Name: property pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5199 (class 2604 OID 240887) --- Name: property tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5200 (class 2604 OID 240888) --- Name: property sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5197 (class 2604 OID 241111) --- Name: property removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5206 (class 2604 OID 241067) --- Name: property_profile_view pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5207 (class 2604 OID 241068) --- Name: property_profile_view tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property_profile_view ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5208 (class 2604 OID 241069) --- Name: property_profile_view sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property_profile_view ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5213 (class 2604 OID 241156) --- Name: system_type pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5214 (class 2604 OID 241157) --- Name: system_type tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.system_type ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5215 (class 2604 OID 241158) --- Name: system_type sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.system_type ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5216 (class 2604 OID 241159) --- Name: system_type removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.system_type ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5194 (class 2604 OID 240867) --- Name: text_property pk_entity; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5195 (class 2604 OID 240868) --- Name: text_property tmsp_creation; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.text_property ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5196 (class 2604 OID 240869) --- Name: text_property sys_period; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.text_property ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5193 (class 2604 OID 241110) --- Name: text_property removed_from_api; Type: DEFAULT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.text_property ALTER COLUMN removed_from_api SET DEFAULT false; - - --- --- TOC entry 5253 (class 2604 OID 243299) --- Name: _deprecated_namespace tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_namespace ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5254 (class 2604 OID 243300) --- Name: _deprecated_namespace sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_namespace ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5256 (class 2604 OID 243330) --- Name: _deprecated_type_namespace_rel tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_type_namespace_rel ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5257 (class 2604 OID 243331) --- Name: _deprecated_type_namespace_rel sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_type_namespace_rel ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5149 (class 2604 OID 240518) --- Name: appellation pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5150 (class 2604 OID 240519) --- Name: appellation tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5151 (class 2604 OID 240520) --- Name: appellation sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5152 (class 2604 OID 240521) --- Name: appellation _deprecated_pk_appellation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation ALTER COLUMN _deprecated_pk_appellation SET DEFAULT nextval('information.appellation_pk_appellation_seq'::regclass); - - --- --- TOC entry 5144 (class 2604 OID 240505) --- Name: entity pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5157 (class 2604 OID 240575) --- Name: entity_association pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5158 (class 2604 OID 240576) --- Name: entity_association tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5159 (class 2604 OID 240577) --- Name: entity_association sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5160 (class 2604 OID 240578) --- Name: entity_association pk_entity_association; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association ALTER COLUMN pk_entity_association SET DEFAULT nextval('information.entity_association_pk_entity_association_seq'::regclass); - - --- --- TOC entry 5182 (class 2604 OID 240749) --- Name: language pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5183 (class 2604 OID 240750) --- Name: language tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5184 (class 2604 OID 240751) --- Name: language sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5161 (class 2604 OID 240606) --- Name: persistent_item pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5162 (class 2604 OID 240607) --- Name: persistent_item tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5163 (class 2604 OID 240608) --- Name: persistent_item sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5164 (class 2604 OID 240609) --- Name: persistent_item _deprecated_pk_persistent_item; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item ALTER COLUMN _deprecated_pk_persistent_item SET DEFAULT nextval('information.persistent_item_pk_persistent_item_seq'::regclass); - - --- --- TOC entry 5233 (class 2604 OID 242952) --- Name: place pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.place ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5234 (class 2604 OID 242953) --- Name: place tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.place ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5235 (class 2604 OID 242954) --- Name: place sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.place ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5350 (class 2604 OID 246041) --- Name: property_of_property pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5351 (class 2604 OID 246042) --- Name: property_of_property tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5352 (class 2604 OID 246043) --- Name: property_of_property sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5165 (class 2604 OID 240637) --- Name: role pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5166 (class 2604 OID 240638) --- Name: role tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5167 (class 2604 OID 240639) --- Name: role sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5168 (class 2604 OID 240640) --- Name: role _deprecated_pk_role; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role ALTER COLUMN _deprecated_pk_role SET DEFAULT nextval('information.role_pk_role_seq'::regclass); - - --- --- TOC entry 5169 (class 2604 OID 240694) --- Name: temporal_entity pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5170 (class 2604 OID 240695) --- Name: temporal_entity tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5171 (class 2604 OID 240696) --- Name: temporal_entity sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5172 (class 2604 OID 240697) --- Name: temporal_entity _deprecated_pk_temporal_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity ALTER COLUMN _deprecated_pk_temporal_entity SET DEFAULT nextval('information.temporal_entity_pk_temporal_entity_seq'::regclass); - - --- --- TOC entry 5175 (class 2604 OID 240725) --- Name: text_property pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5176 (class 2604 OID 240726) --- Name: text_property tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5177 (class 2604 OID 240727) --- Name: text_property sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5217 (class 2604 OID 241194) --- Name: time_primitive pk_entity; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5218 (class 2604 OID 241195) --- Name: time_primitive tmsp_creation; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5219 (class 2604 OID 241196) --- Name: time_primitive sys_period; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5220 (class 2604 OID 241197) --- Name: time_primitive pk_time_primitive; Type: DEFAULT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive ALTER COLUMN pk_time_primitive SET DEFAULT nextval('information.time_primitive_pk_time_primitive_seq'::regclass); - - --- --- TOC entry 5123 (class 2604 OID 240355) --- Name: _deprecated_label pk_label; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects._deprecated_label ALTER COLUMN pk_label SET DEFAULT nextval('projects.label_pk_label_seq'::regclass); - - --- --- TOC entry 5239 (class 2604 OID 243020) --- Name: class_field_config pk_entity; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5240 (class 2604 OID 243021) --- Name: class_field_config tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5241 (class 2604 OID 243022) --- Name: class_field_config sys_period; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5118 (class 2604 OID 240342) --- Name: entity pk_entity; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.entity ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5188 (class 2604 OID 240782) --- Name: info_proj_rel _deprecated_pk_entity_version_project_rel; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel ALTER COLUMN _deprecated_pk_entity_version_project_rel SET DEFAULT nextval('projects.entity_version_project_rel_pk_entity_version_project_rel_seq'::regclass); - - --- --- TOC entry 5127 (class 2604 OID 240383) --- Name: project _deprecated_pk_project; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project ALTER COLUMN _deprecated_pk_project SET DEFAULT nextval('projects.project_pk_project_seq'::regclass); - - --- --- TOC entry 5264 (class 2604 OID 244083) --- Name: query pk_entity; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5265 (class 2604 OID 244084) --- Name: query tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5266 (class 2604 OID 244085) --- Name: query sys_period; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5133 (class 2604 OID 240446) --- Name: text_property _deprecated_pk_text_property; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.text_property ALTER COLUMN _deprecated_pk_text_property SET DEFAULT nextval('projects.text_property_pk_text_property_seq'::regclass); - - --- --- TOC entry 5270 (class 2604 OID 244183) --- Name: visual pk_entity; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5271 (class 2604 OID 244184) --- Name: visual tmsp_creation; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5272 (class 2604 OID 244185) --- Name: visual sys_period; Type: DEFAULT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5113 (class 2604 OID 240275) --- Name: account id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account ALTER COLUMN id SET DEFAULT nextval('public.account_id_seq'::regclass); - - --- --- TOC entry 5142 (class 2604 OID 240484) --- Name: account_project_rel id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account_project_rel ALTER COLUMN id SET DEFAULT nextval('public.account_project_rel_id_seq'::regclass); - - --- --- TOC entry 5117 (class 2604 OID 240331) --- Name: acl id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.acl ALTER COLUMN id SET DEFAULT nextval('public.acl_id_seq'::regclass); - - --- --- TOC entry 5099 (class 2604 OID 240157) --- Name: migrations id; Type: DEFAULT; Schema: public; Owner: - --- - --- ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); - - --- --- TOC entry 5115 (class 2604 OID 240304) --- Name: role id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.role ALTER COLUMN id SET DEFAULT nextval('public.role_id_seq'::regclass); - - --- --- TOC entry 5116 (class 2604 OID 240315) --- Name: rolemapping id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.rolemapping ALTER COLUMN id SET DEFAULT nextval('public.rolemapping_id_seq'::regclass); - - --- --- TOC entry 5275 (class 2604 OID 244714) --- Name: entity pk_entity; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.entity ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5278 (class 2604 OID 244743) --- Name: system_relevant_class pk_entity; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_class ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5279 (class 2604 OID 244744) --- Name: system_relevant_class tmsp_creation; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_class ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5280 (class 2604 OID 244745) --- Name: system_relevant_class sys_period; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_class ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5281 (class 2604 OID 244771) --- Name: system_relevant_type pk_entity; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_type ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); - - --- --- TOC entry 5282 (class 2604 OID 244772) --- Name: system_relevant_type tmsp_creation; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_type ALTER COLUMN tmsp_creation SET DEFAULT now(); - - --- --- TOC entry 5283 (class 2604 OID 244773) --- Name: system_relevant_type sys_period; Type: DEFAULT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_type ALTER COLUMN sys_period SET DEFAULT tstzrange(now(), NULL::timestamp with time zone); - - --- --- TOC entry 5518 (class 2606 OID 244691) --- Name: text text_pkey; Type: CONSTRAINT; Schema: commons; Owner: - --- - -ALTER TABLE ONLY commons.text - ADD CONSTRAINT text_pkey PRIMARY KEY (pk_text); - - --- --- TOC entry 5520 (class 2606 OID 245392) --- Name: text text_version_unique; Type: CONSTRAINT; Schema: commons; Owner: - --- - -ALTER TABLE ONLY commons.text - ADD CONSTRAINT text_version_unique UNIQUE (pk_text, entity_version); - - --- --- TOC entry 5554 (class 2606 OID 245895) --- Name: avatar data_avatar_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.avatar - ADD CONSTRAINT data_avatar_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5536 (class 2606 OID 245540) --- Name: cell data_cell_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell - ADD CONSTRAINT data_cell_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5530 (class 2606 OID 245408) --- Name: chunk data_chunk_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.chunk - ADD CONSTRAINT data_chunk_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5542 (class 2606 OID 245682) --- Name: class_column_rel data_class_column_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel - ADD CONSTRAINT data_class_column_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5534 (class 2606 OID 245507) --- Name: column data_column_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" - ADD CONSTRAINT data_column_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5552 (class 2606 OID 245867) --- Name: data_association data_data_association_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.data_association - ADD CONSTRAINT data_data_association_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5538 (class 2606 OID 245606) --- Name: factoid_class_digital_rel data_factoid_class_digital_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel - ADD CONSTRAINT data_factoid_class_digital_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5546 (class 2606 OID 245748) --- Name: factoid data_factoid_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid - ADD CONSTRAINT data_factoid_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5544 (class 2606 OID 245720) --- Name: factoid_property_column_rel data_factoid_property_column_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel - ADD CONSTRAINT data_factoid_property_column_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5548 (class 2606 OID 245791) --- Name: factoid_role data_factoid_role_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role - ADD CONSTRAINT data_factoid_role_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5558 (class 2606 OID 245989) --- Name: namespace data_namespace_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace - ADD CONSTRAINT data_namespace_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5532 (class 2606 OID 245469) --- Name: row data_row_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."row" - ADD CONSTRAINT data_row_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5556 (class 2606 OID 245928) --- Name: text_property data_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property - ADD CONSTRAINT data_text_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5540 (class 2606 OID 245649) --- Name: value_association_columns_rel data_value_association_columns_rel_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel - ADD CONSTRAINT data_value_association_columns_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5550 (class 2606 OID 245839) --- Name: values_association data_values_association_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT data_values_association_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5464 (class 2606 OID 241267) --- Name: digital digital_object_pkey; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.digital - ADD CONSTRAINT digital_object_pkey PRIMARY KEY (_deprecated_pk_digital_object); - - --- --- TOC entry 5528 (class 2606 OID 245304) --- Name: entity entity_pkey; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.entity - ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); - - --- --- TOC entry 5466 (class 2606 OID 243240) --- Name: digital information_digital_object_pk_entity_unique; Type: CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.digital - ADD CONSTRAINT information_digital_object_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5454 (class 2606 OID 243218) --- Name: associates_system_type data_for_history_associates_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.associates_system_type - ADD CONSTRAINT data_for_history_associates_system_type_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5364 (class 2606 OID 243220) --- Name: class data_for_history_class_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class - ADD CONSTRAINT data_for_history_class_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5362 (class 2606 OID 243222) --- Name: class_profile_view data_for_history_class_profile_view_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class_profile_view - ADD CONSTRAINT data_for_history_class_profile_view_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5440 (class 2606 OID 243224) --- Name: label data_for_history_label_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label - ADD CONSTRAINT data_for_history_label_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5448 (class 2606 OID 243226) --- Name: profile data_for_history_profile_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile - ADD CONSTRAINT data_for_history_profile_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5444 (class 2606 OID 243228) --- Name: property data_for_history_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property - ADD CONSTRAINT data_for_history_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5452 (class 2606 OID 243230) --- Name: property_profile_view data_for_history_property_profile_view_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property_profile_view - ADD CONSTRAINT data_for_history_property_profile_view_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5456 (class 2606 OID 243232) --- Name: system_type data_for_history_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.system_type - ADD CONSTRAINT data_for_history_system_type_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5442 (class 2606 OID 243234) --- Name: text_property data_for_history_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.text_property - ADD CONSTRAINT data_for_history_text_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5360 (class 2606 OID 240203) --- Name: entity entity_pkey; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.entity - ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); - - --- --- TOC entry 5366 (class 2606 OID 240903) --- Name: class unique_dfh_pk_class; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.class - ADD CONSTRAINT unique_dfh_pk_class UNIQUE (dfh_pk_class); - - --- --- TOC entry 5450 (class 2606 OID 241051) --- Name: profile unique_dfh_pk_profile; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.profile - ADD CONSTRAINT unique_dfh_pk_profile UNIQUE (dfh_pk_profile); - - --- --- TOC entry 5446 (class 2606 OID 241005) --- Name: property unique_dfh_pk_property; Type: CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.property - ADD CONSTRAINT unique_dfh_pk_property UNIQUE (dfh_pk_property); - - --- --- TOC entry 5404 (class 2606 OID 240526) --- Name: appellation appellation_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation - ADD CONSTRAINT appellation_pkey PRIMARY KEY (_deprecated_pk_appellation); - - --- --- TOC entry 5408 (class 2606 OID 240583) --- Name: entity_association entity_association_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association - ADD CONSTRAINT entity_association_pkey PRIMARY KEY (pk_entity_association); - - --- --- TOC entry 5402 (class 2606 OID 240512) --- Name: entity entity_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity - ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); - - --- --- TOC entry 5406 (class 2606 OID 243236) --- Name: appellation information_appellation_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation - ADD CONSTRAINT information_appellation_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5410 (class 2606 OID 243242) --- Name: entity_association information_entity_association_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.entity_association - ADD CONSTRAINT information_entity_association_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5428 (class 2606 OID 243246) --- Name: language information_language_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language - ADD CONSTRAINT information_language_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5494 (class 2606 OID 243305) --- Name: _deprecated_namespace information_namespace_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_namespace - ADD CONSTRAINT information_namespace_pk_entity_unique PRIMARY KEY (pk_entity); - - --- --- TOC entry 5412 (class 2606 OID 243248) --- Name: persistent_item information_persistent_item_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item - ADD CONSTRAINT information_persistent_item_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5478 (class 2606 OID 243250) --- Name: place information_place_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.place - ADD CONSTRAINT information_place_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5560 (class 2606 OID 246063) --- Name: property_of_property information_property_of_property_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property - ADD CONSTRAINT information_property_of_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5416 (class 2606 OID 243252) --- Name: role information_role_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role - ADD CONSTRAINT information_role_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5420 (class 2606 OID 243256) --- Name: temporal_entity information_temporal_entity_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity - ADD CONSTRAINT information_temporal_entity_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5424 (class 2606 OID 243258) --- Name: text_property information_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property - ADD CONSTRAINT information_text_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5458 (class 2606 OID 243260) --- Name: time_primitive information_time_primitive_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive - ADD CONSTRAINT information_time_primitive_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5496 (class 2606 OID 243336) --- Name: _deprecated_type_namespace_rel information_type_namespace_rel_pk_entity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_type_namespace_rel - ADD CONSTRAINT information_type_namespace_rel_pk_entity_unique PRIMARY KEY (pk_entity); - - --- --- TOC entry 5430 (class 2606 OID 240756) --- Name: language language_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language - ADD CONSTRAINT language_pkey PRIMARY KEY (pk_language); - - --- --- TOC entry 5414 (class 2606 OID 240614) --- Name: persistent_item persistent_item_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item - ADD CONSTRAINT persistent_item_pkey PRIMARY KEY (_deprecated_pk_persistent_item); - - --- --- TOC entry 5418 (class 2606 OID 240645) --- Name: role role_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role - ADD CONSTRAINT role_pkey PRIMARY KEY (_deprecated_pk_role); - - --- --- TOC entry 5422 (class 2606 OID 240702) --- Name: temporal_entity temporal_entity_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity - ADD CONSTRAINT temporal_entity_pkey PRIMARY KEY (_deprecated_pk_temporal_entity); - - --- --- TOC entry 5426 (class 2606 OID 243448) --- Name: text_property text_property_identity_unique; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property - ADD CONSTRAINT text_property_identity_unique UNIQUE (fk_class_field, fk_language, fk_concerned_entity, _deprecated_text_property_quill_doc); - - --- --- TOC entry 5460 (class 2606 OID 241202) --- Name: time_primitive time_primitive_pkey; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive - ADD CONSTRAINT time_primitive_pkey PRIMARY KEY (pk_time_primitive); - - --- --- TOC entry 5462 (class 2606 OID 242973) --- Name: time_primitive time_primitive_unique_constraint; Type: CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive - ADD CONSTRAINT time_primitive_unique_constraint UNIQUE (julian_day, duration, fk_class); - - --- --- TOC entry 5500 (class 2606 OID 243956) --- Name: argument commons_assertion_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT commons_assertion_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5384 (class 2606 OID 243204) --- Name: _deprecated_label commons_label_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects._deprecated_label - ADD CONSTRAINT commons_label_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5388 (class 2606 OID 243206) --- Name: project commons_project_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project - ADD CONSTRAINT commons_project_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5506 (class 2606 OID 244090) --- Name: query commons_query_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query - ADD CONSTRAINT commons_query_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5396 (class 2606 OID 243212) --- Name: text_property commons_text_property_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.text_property - ADD CONSTRAINT commons_text_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5482 (class 2606 OID 243216) --- Name: class_field_config commons_ui_context_config_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config - ADD CONSTRAINT commons_ui_context_config_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5514 (class 2606 OID 244192) --- Name: visual commons_visual_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual - ADD CONSTRAINT commons_visual_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5490 (class 2606 OID 243272) --- Name: dfh_class_proj_rel data_for_history_proj_rel_pk_entity; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.dfh_class_proj_rel - ADD CONSTRAINT data_for_history_proj_rel_pk_entity PRIMARY KEY (pk_entity); - - --- --- TOC entry 5492 (class 2606 OID 244972) --- Name: dfh_class_proj_rel dfh_class_project_rel__entity_and_project_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.dfh_class_proj_rel - ADD CONSTRAINT dfh_class_project_rel__entity_and_project_unique UNIQUE (fk_entity, fk_project); - - --- --- TOC entry 5382 (class 2606 OID 240347) --- Name: entity entity_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.entity - ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); - - --- --- TOC entry 5432 (class 2606 OID 244952) --- Name: info_proj_rel entity_version_project_rel_fk_entity_fk_project_key; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key UNIQUE (fk_entity, fk_project); - - --- --- TOC entry 5434 (class 2606 OID 244954) --- Name: info_proj_rel entity_version_project_rel_fk_entity_version_concat_fk_proj_key; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_fk_entity_version_concat_fk_proj_key UNIQUE (fk_entity_version_concat, fk_project); - - --- --- TOC entry 5436 (class 2606 OID 240787) --- Name: info_proj_rel entity_version_project_rel_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel - ADD CONSTRAINT entity_version_project_rel_pkey PRIMARY KEY (_deprecated_pk_entity_version_project_rel); - - --- --- TOC entry 5438 (class 2606 OID 243244) --- Name: info_proj_rel information_entity_version_project_rel_pk_entity_unique; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel - ADD CONSTRAINT information_entity_version_project_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5386 (class 2606 OID 240361) --- Name: _deprecated_label label_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects._deprecated_label - ADD CONSTRAINT label_pkey PRIMARY KEY (pk_label); - - --- --- TOC entry 5358 (class 2606 OID 240181) --- Name: language language_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.language - ADD CONSTRAINT language_pkey PRIMARY KEY (pk_language); - - --- --- TOC entry 5390 (class 2606 OID 240390) --- Name: project project_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project - ADD CONSTRAINT project_pkey PRIMARY KEY (_deprecated_pk_project); - - --- --- TOC entry 5508 (class 2606 OID 244914) --- Name: query query__unique_name_per_project; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query - ADD CONSTRAINT query__unique_name_per_project UNIQUE (name, fk_project); - - --- --- TOC entry 5398 (class 2606 OID 240453) --- Name: text_property text_property_pkey; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.text_property - ADD CONSTRAINT text_property_pkey PRIMARY KEY (_deprecated_pk_text_property); - - --- --- TOC entry 5516 (class 2606 OID 244932) --- Name: visual visual__unique_name_per_project; Type: CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual - ADD CONSTRAINT visual__unique_name_per_project UNIQUE (name, fk_project); - - --- --- TOC entry 5374 (class 2606 OID 240293) --- Name: accesstoken accesstoken_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.accesstoken - ADD CONSTRAINT accesstoken_pkey PRIMARY KEY (id); - - --- --- TOC entry 5368 (class 2606 OID 240284) --- Name: account account_email_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account - ADD CONSTRAINT account_email_key UNIQUE (email); - - --- --- TOC entry 5370 (class 2606 OID 240280) --- Name: account account_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account - ADD CONSTRAINT account_pkey PRIMARY KEY (id); - - --- --- TOC entry 5400 (class 2606 OID 240489) --- Name: account_project_rel account_project_rel_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account_project_rel - ADD CONSTRAINT account_project_rel_pkey PRIMARY KEY (id); - - --- --- TOC entry 5372 (class 2606 OID 240282) --- Name: account account_username_key; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account - ADD CONSTRAINT account_username_key UNIQUE (username); - - --- --- TOC entry 5380 (class 2606 OID 240336) --- Name: acl acl_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.acl - ADD CONSTRAINT acl_pkey PRIMARY KEY (id); - - --- --- TOC entry 5356 (class 2606 OID 240159) --- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - --- ALTER TABLE ONLY public.migrations --- ADD CONSTRAINT migrations_pkey PRIMARY KEY (id); - - --- --- TOC entry 5376 (class 2606 OID 240309) --- Name: role role_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.role - ADD CONSTRAINT role_pkey PRIMARY KEY (id); - - --- --- TOC entry 5378 (class 2606 OID 240320) --- Name: rolemapping rolemapping_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.rolemapping - ADD CONSTRAINT rolemapping_pkey PRIMARY KEY (id); - - --- --- TOC entry 5510 (class 2606 OID 244113) --- Name: class_has_type_property class_has_type_property_fk_class_key; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_has_type_property - ADD CONSTRAINT class_has_type_property_fk_class_key UNIQUE (fk_class); - - --- --- TOC entry 5512 (class 2606 OID 244125) --- Name: class_has_type_property commons_class_has_type_property_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_has_type_property - ADD CONSTRAINT commons_class_has_type_property_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5488 (class 2606 OID 243208) --- Name: class_field commons_property_set_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_field - ADD CONSTRAINT commons_property_set_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5498 (class 2606 OID 243405) --- Name: class_field_property_rel commons_property_set_property_rel_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_field_property_rel - ADD CONSTRAINT commons_property_set_property_rel_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5392 (class 2606 OID 243210) --- Name: system_type commons_system_type_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_type - ADD CONSTRAINT commons_system_type_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5480 (class 2606 OID 243214) --- Name: app_context commons_ui_context_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.app_context - ADD CONSTRAINT commons_ui_context_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5522 (class 2606 OID 244721) --- Name: entity entity_pkey; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.entity - ADD CONSTRAINT entity_pkey PRIMARY KEY (pk_entity); - - --- --- TOC entry 5524 (class 2606 OID 244755) --- Name: system_relevant_class system_system_relevant_class_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_class - ADD CONSTRAINT system_system_relevant_class_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5526 (class 2606 OID 244783) --- Name: system_relevant_type system_system_relevant_type_pk_entity_unique; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_type - ADD CONSTRAINT system_system_relevant_type_pk_entity_unique UNIQUE (pk_entity); - - --- --- TOC entry 5394 (class 2606 OID 244871) --- Name: system_type unique_note; Type: CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_type - ADD CONSTRAINT unique_note UNIQUE (notes); - - --- --- TOC entry 5502 (class 2606 OID 243978) --- Name: class_preview dfh_pk_class_unique; Type: CONSTRAINT; Schema: warehouse; Owner: - --- - -ALTER TABLE ONLY warehouse.class_preview - ADD CONSTRAINT dfh_pk_class_unique UNIQUE (dfh_pk_class); - - --- --- TOC entry 5504 (class 2606 OID 244048) --- Name: entity_preview entity_preview_unique; Type: CONSTRAINT; Schema: warehouse; Owner: - --- - -ALTER TABLE ONLY warehouse.entity_preview - ADD CONSTRAINT entity_preview_unique UNIQUE (pk_entity, project); - - --- --- TOC entry 5483 (class 1259 OID 243036) --- Name: ui_context_config_for_prop_and_proj_uni_idx; Type: INDEX; Schema: projects; Owner: - --- - -CREATE UNIQUE INDEX ui_context_config_for_prop_and_proj_uni_idx ON projects.class_field_config USING btree (fk_app_context, _deprecated_fk_project, fk_property, property_is_outgoing) WHERE (_deprecated_fk_project IS NOT NULL); - - --- --- TOC entry 5484 (class 1259 OID 243037) --- Name: ui_context_config_for_prop_no_proj_uni_idx; Type: INDEX; Schema: projects; Owner: - --- - -CREATE UNIQUE INDEX ui_context_config_for_prop_no_proj_uni_idx ON projects.class_field_config USING btree (fk_app_context, fk_property, property_is_outgoing) WHERE (_deprecated_fk_project IS NULL); - - --- --- TOC entry 5485 (class 1259 OID 243038) --- Name: ui_context_config_for_prop_set_and_proj_uni_idx; Type: INDEX; Schema: projects; Owner: - --- - -CREATE UNIQUE INDEX ui_context_config_for_prop_set_and_proj_uni_idx ON projects.class_field_config USING btree (fk_app_context, _deprecated_fk_project, fk_class_field, fk_class_for_class_field) WHERE (_deprecated_fk_project IS NOT NULL); - - --- --- TOC entry 5486 (class 1259 OID 243039) --- Name: ui_context_config_for_prop_set_no_proj_uni_idx; Type: INDEX; Schema: projects; Owner: - --- - -CREATE UNIQUE INDEX ui_context_config_for_prop_set_no_proj_uni_idx ON projects.class_field_config USING btree (fk_app_context, fk_class_field, fk_class_for_class_field) WHERE (_deprecated_fk_project IS NULL); - - --- --- TOC entry 5876 (class 2620 OID 244699) --- Name: text sync_quill_doc_and_string; Type: TRIGGER; Schema: commons; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON commons.text FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5787 (class 2620 OID 245312) --- Name: digital create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5898 (class 2620 OID 245419) --- Name: chunk create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5905 (class 2620 OID 245480) --- Name: row create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data."row" FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5911 (class 2620 OID 245518) --- Name: column create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data."column" FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5917 (class 2620 OID 245551) --- Name: cell create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5924 (class 2620 OID 245617) --- Name: factoid_class_digital_rel create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5930 (class 2620 OID 245660) --- Name: value_association_columns_rel create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5936 (class 2620 OID 245693) --- Name: class_column_rel create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5942 (class 2620 OID 245731) --- Name: factoid_property_column_rel create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5948 (class 2620 OID 245759) --- Name: factoid create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.factoid FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5954 (class 2620 OID 245802) --- Name: factoid_role create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5960 (class 2620 OID 245850) --- Name: values_association create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.values_association FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5966 (class 2620 OID 245878) --- Name: data_association create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.data_association FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5972 (class 2620 OID 245906) --- Name: avatar create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.avatar FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5978 (class 2620 OID 245939) --- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5985 (class 2620 OID 246000) --- Name: namespace create_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data.namespace FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5790 (class 2620 OID 241268) --- Name: digital creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5894 (class 2620 OID 245409) --- Name: chunk creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5901 (class 2620 OID 245470) --- Name: row creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data."row" FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5907 (class 2620 OID 245508) --- Name: column creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data."column" FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5913 (class 2620 OID 245541) --- Name: cell creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5920 (class 2620 OID 245607) --- Name: factoid_class_digital_rel creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5926 (class 2620 OID 245650) --- Name: value_association_columns_rel creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5932 (class 2620 OID 245683) --- Name: class_column_rel creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5938 (class 2620 OID 245721) --- Name: factoid_property_column_rel creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5944 (class 2620 OID 245749) --- Name: factoid creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.factoid FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5950 (class 2620 OID 245792) --- Name: factoid_role creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5956 (class 2620 OID 245840) --- Name: values_association creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.values_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5962 (class 2620 OID 245868) --- Name: data_association creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.data_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5968 (class 2620 OID 245896) --- Name: avatar creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.avatar FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5974 (class 2620 OID 245929) --- Name: text_property creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5981 (class 2620 OID 245990) --- Name: namespace creation_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data.namespace FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5791 (class 2620 OID 241269) --- Name: digital insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5895 (class 2620 OID 245410) --- Name: chunk insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5902 (class 2620 OID 245471) --- Name: row insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data."row" FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5908 (class 2620 OID 245509) --- Name: column insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data."column" FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5914 (class 2620 OID 245542) --- Name: cell insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5921 (class 2620 OID 245608) --- Name: factoid_class_digital_rel insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5927 (class 2620 OID 245651) --- Name: value_association_columns_rel insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5933 (class 2620 OID 245684) --- Name: class_column_rel insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5939 (class 2620 OID 245722) --- Name: factoid_property_column_rel insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5945 (class 2620 OID 245750) --- Name: factoid insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.factoid FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5951 (class 2620 OID 245793) --- Name: factoid_role insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5957 (class 2620 OID 245841) --- Name: values_association insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.values_association FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5963 (class 2620 OID 245869) --- Name: data_association insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.data_association FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5969 (class 2620 OID 245897) --- Name: avatar insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.avatar FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5975 (class 2620 OID 245930) --- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5982 (class 2620 OID 245991) --- Name: namespace insert_schema_table_name; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data.namespace FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5792 (class 2620 OID 241270) --- Name: digital last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5896 (class 2620 OID 245411) --- Name: chunk last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5903 (class 2620 OID 245472) --- Name: row last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data."row" FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5909 (class 2620 OID 245510) --- Name: column last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data."column" FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5915 (class 2620 OID 245543) --- Name: cell last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5922 (class 2620 OID 245609) --- Name: factoid_class_digital_rel last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5928 (class 2620 OID 245652) --- Name: value_association_columns_rel last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5934 (class 2620 OID 245685) --- Name: class_column_rel last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5940 (class 2620 OID 245723) --- Name: factoid_property_column_rel last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5946 (class 2620 OID 245751) --- Name: factoid last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.factoid FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5952 (class 2620 OID 245794) --- Name: factoid_role last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5958 (class 2620 OID 245842) --- Name: values_association last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.values_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5964 (class 2620 OID 245870) --- Name: data_association last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.data_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5970 (class 2620 OID 245898) --- Name: avatar last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.avatar FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5976 (class 2620 OID 245931) --- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5983 (class 2620 OID 245992) --- Name: namespace last_modification_tmsp; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data.namespace FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5995 (class 2620 OID 246088) --- Name: v_digital_version on_insert; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON data.v_digital_version FOR EACH ROW EXECUTE PROCEDURE data.v_digital_version_insert(); - - --- --- TOC entry 5789 (class 2620 OID 245366) --- Name: digital sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5900 (class 2620 OID 245453) --- Name: chunk sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5919 (class 2620 OID 245585) --- Name: cell sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5980 (class 2620 OID 245973) --- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5788 (class 2620 OID 245313) --- Name: digital update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.digital FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5899 (class 2620 OID 245420) --- Name: chunk update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.chunk FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5906 (class 2620 OID 245481) --- Name: row update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data."row" FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5912 (class 2620 OID 245519) --- Name: column update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data."column" FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5918 (class 2620 OID 245552) --- Name: cell update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.cell FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5925 (class 2620 OID 245618) --- Name: factoid_class_digital_rel update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5931 (class 2620 OID 245661) --- Name: value_association_columns_rel update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5937 (class 2620 OID 245694) --- Name: class_column_rel update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5943 (class 2620 OID 245732) --- Name: factoid_property_column_rel update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5949 (class 2620 OID 245760) --- Name: factoid update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.factoid FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5955 (class 2620 OID 245803) --- Name: factoid_role update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5961 (class 2620 OID 245851) --- Name: values_association update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.values_association FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5967 (class 2620 OID 245879) --- Name: data_association update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.data_association FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5973 (class 2620 OID 245907) --- Name: avatar update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.avatar FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5979 (class 2620 OID 245940) --- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.text_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5986 (class 2620 OID 246001) --- Name: namespace update_entity_version_key; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data.namespace FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5786 (class 2620 OID 245311) --- Name: digital versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.digital FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.digital_vt', 'true'); - - --- --- TOC entry 5897 (class 2620 OID 245418) --- Name: chunk versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.chunk FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.chunk_vt', 'true'); - - --- --- TOC entry 5904 (class 2620 OID 245479) --- Name: row versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data."row" FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.row_vt', 'true'); - - --- --- TOC entry 5910 (class 2620 OID 245517) --- Name: column versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data."column" FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.column_vt', 'true'); - - --- --- TOC entry 5916 (class 2620 OID 245550) --- Name: cell versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.cell FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.cell_vt', 'true'); - - --- --- TOC entry 5923 (class 2620 OID 245616) --- Name: factoid_class_digital_rel versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_class_digital_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.factoid_class_digital_rel_vt', 'true'); - - --- --- TOC entry 5929 (class 2620 OID 245659) --- Name: value_association_columns_rel versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.value_association_columns_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.value_association_columns_rel_vt', 'true'); - - --- --- TOC entry 5935 (class 2620 OID 245692) --- Name: class_column_rel versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.class_column_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.class_column_rel_vt', 'true'); - - --- --- TOC entry 5941 (class 2620 OID 245730) --- Name: factoid_property_column_rel versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_property_column_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.factoid_property_column_rel_vt', 'true'); - - --- --- TOC entry 5947 (class 2620 OID 245758) --- Name: factoid versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.factoid FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.factoid_vt', 'true'); - - --- --- TOC entry 5953 (class 2620 OID 245801) --- Name: factoid_role versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.factoid_role FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.factoid_role_vt', 'true'); - - --- --- TOC entry 5959 (class 2620 OID 245849) --- Name: values_association versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.values_association FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.values_association_vt', 'true'); - - --- --- TOC entry 5965 (class 2620 OID 245877) --- Name: data_association versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.data_association FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.data_association_vt', 'true'); - - --- --- TOC entry 5971 (class 2620 OID 245905) --- Name: avatar versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.avatar FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.avatar_vt', 'true'); - - --- --- TOC entry 5977 (class 2620 OID 245938) --- Name: text_property versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.text_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.text_property_vt', 'true'); - - --- --- TOC entry 5984 (class 2620 OID 245999) --- Name: namespace versioning_trigger; Type: TRIGGER; Schema: data; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data.namespace FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data.namespace_vt', 'true'); - - --- --- TOC entry 5746 (class 2620 OID 243982) --- Name: label after_delete; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER after_delete AFTER DELETE ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE warehouse.update_class_preview__on_label_delete(); - - --- --- TOC entry 5745 (class 2620 OID 243981) --- Name: label after_insert_or_update; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER after_insert_or_update AFTER INSERT OR UPDATE ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE warehouse.update_class_preview__on_label_upsert(); - - --- --- TOC entry 5662 (class 2620 OID 243984) --- Name: class_profile_view after_insert_or_update; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER after_insert_or_update AFTER INSERT OR UPDATE ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE warehouse.update_class_preview__on_class_profile_view_upsert(); - - --- --- TOC entry 5666 (class 2620 OID 241031) --- Name: class create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5659 (class 2620 OID 241033) --- Name: class_profile_view create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5742 (class 2620 OID 241035) --- Name: label create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5756 (class 2620 OID 241037) --- Name: property create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5750 (class 2620 OID 241039) --- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5762 (class 2620 OID 241055) --- Name: profile create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5768 (class 2620 OID 241076) --- Name: property_profile_view create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5774 (class 2620 OID 241098) --- Name: associates_system_type create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5780 (class 2620 OID 241166) --- Name: system_type create_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON data_for_history.system_type FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5656 (class 2620 OID 240213) --- Name: class_profile_view creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5663 (class 2620 OID 240234) --- Name: class creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5739 (class 2620 OID 240854) --- Name: label creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5747 (class 2620 OID 240873) --- Name: text_property creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5753 (class 2620 OID 240892) --- Name: property creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5759 (class 2620 OID 241052) --- Name: profile creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5765 (class 2620 OID 241073) --- Name: property_profile_view creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5771 (class 2620 OID 241095) --- Name: associates_system_type creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5777 (class 2620 OID 241163) --- Name: system_type creation_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON data_for_history.system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5658 (class 2620 OID 240215) --- Name: class_profile_view insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5665 (class 2620 OID 240236) --- Name: class insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5741 (class 2620 OID 240856) --- Name: label insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5749 (class 2620 OID 240875) --- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5755 (class 2620 OID 240894) --- Name: property insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5761 (class 2620 OID 241054) --- Name: profile insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5767 (class 2620 OID 241075) --- Name: property_profile_view insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5773 (class 2620 OID 241097) --- Name: associates_system_type insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5779 (class 2620 OID 241165) --- Name: system_type insert_schema_table_name; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON data_for_history.system_type FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5657 (class 2620 OID 240214) --- Name: class_profile_view last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5664 (class 2620 OID 240235) --- Name: class last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5740 (class 2620 OID 240855) --- Name: label last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5748 (class 2620 OID 240874) --- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5754 (class 2620 OID 240893) --- Name: property last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5760 (class 2620 OID 241053) --- Name: profile last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5766 (class 2620 OID 241074) --- Name: property_profile_view last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5772 (class 2620 OID 241096) --- Name: associates_system_type last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5778 (class 2620 OID 241164) --- Name: system_type last_modification_tmsp; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON data_for_history.system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5667 (class 2620 OID 241032) --- Name: class update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5660 (class 2620 OID 241034) --- Name: class_profile_view update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5743 (class 2620 OID 241036) --- Name: label update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5757 (class 2620 OID 241038) --- Name: property update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5751 (class 2620 OID 241040) --- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5763 (class 2620 OID 241056) --- Name: profile update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5769 (class 2620 OID 241077) --- Name: property_profile_view update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5775 (class 2620 OID 241099) --- Name: associates_system_type update_entity_version_key; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5661 (class 2620 OID 243181) --- Name: class_profile_view versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.class_profile_view FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.class_profile_view_vt', 'true'); - - --- --- TOC entry 5668 (class 2620 OID 243182) --- Name: class versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.class FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.class_vt', 'true'); - - --- --- TOC entry 5744 (class 2620 OID 243183) --- Name: label versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.label FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.label_vt', 'true'); - - --- --- TOC entry 5752 (class 2620 OID 243184) --- Name: text_property versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.text_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.text_property_vt', 'true'); - - --- --- TOC entry 5758 (class 2620 OID 243185) --- Name: property versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.property_vt', 'true'); - - --- --- TOC entry 5764 (class 2620 OID 243186) --- Name: profile versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.profile FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.profile_vt', 'true'); - - --- --- TOC entry 5770 (class 2620 OID 243187) --- Name: property_profile_view versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.property_profile_view FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.property_profile_view_vt', 'true'); - - --- --- TOC entry 5776 (class 2620 OID 243188) --- Name: associates_system_type versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.associates_system_type FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.associates_system_type_vt', 'true'); - - --- --- TOC entry 5781 (class 2620 OID 243189) --- Name: system_type versioning_trigger; Type: TRIGGER; Schema: data_for_history; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON data_for_history.system_type FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'data_for_history.system_type_vt', 'true'); - - --- --- TOC entry 5890 (class 2620 OID 245237) --- Name: v_text_property _01_sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER _01_sync_quill_doc_and_string INSTEAD OF INSERT ON information.v_text_property FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5892 (class 2620 OID 245268) --- Name: v_appellation _01_sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER _01_sync_quill_doc_and_string INSTEAD OF INSERT ON information.v_appellation FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5891 (class 2620 OID 245238) --- Name: v_text_property _02_find_or_create; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER _02_find_or_create INSTEAD OF INSERT ON information.v_text_property FOR EACH ROW EXECUTE PROCEDURE information.v_text_property_find_or_create(); - - --- --- TOC entry 5893 (class 2620 OID 245269) --- Name: v_appellation _02_find_or_create; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER _02_find_or_create INSTEAD OF INSERT ON information.v_appellation FOR EACH ROW EXECUTE PROCEDURE information.v_appellation_find_or_create(); - - --- --- TOC entry 5832 (class 2620 OID 245138) --- Name: _deprecated_type_namespace_rel create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5826 (class 2620 OID 245141) --- Name: _deprecated_namespace create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5721 (class 2620 OID 245154) --- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5698 (class 2620 OID 245195) --- Name: appellation create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5992 (class 2620 OID 246074) --- Name: property_of_property create_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5701 (class 2620 OID 240532) --- Name: appellation creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5704 (class 2620 OID 240589) --- Name: entity_association creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.entity_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5708 (class 2620 OID 240620) --- Name: persistent_item creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.persistent_item FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5712 (class 2620 OID 240651) --- Name: role creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.role FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5716 (class 2620 OID 240708) --- Name: temporal_entity creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.temporal_entity FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5724 (class 2620 OID 240734) --- Name: text_property creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5727 (class 2620 OID 240762) --- Name: language creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.language FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5782 (class 2620 OID 241208) --- Name: time_primitive creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.time_primitive FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5793 (class 2620 OID 242963) --- Name: place creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.place FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5828 (class 2620 OID 243316) --- Name: _deprecated_namespace creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5834 (class 2620 OID 243347) --- Name: _deprecated_type_namespace_rel creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5988 (class 2620 OID 246064) --- Name: property_of_property creation_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5702 (class 2620 OID 240533) --- Name: appellation insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5705 (class 2620 OID 240590) --- Name: entity_association insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.entity_association FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5709 (class 2620 OID 240621) --- Name: persistent_item insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.persistent_item FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5713 (class 2620 OID 240652) --- Name: role insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.role FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5717 (class 2620 OID 240709) --- Name: temporal_entity insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.temporal_entity FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5725 (class 2620 OID 240735) --- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5729 (class 2620 OID 240764) --- Name: language insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.language FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5783 (class 2620 OID 241209) --- Name: time_primitive insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.time_primitive FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5794 (class 2620 OID 242964) --- Name: place insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.place FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5830 (class 2620 OID 243318) --- Name: _deprecated_namespace insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5836 (class 2620 OID 243349) --- Name: _deprecated_type_namespace_rel insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5989 (class 2620 OID 246065) --- Name: property_of_property insert_schema_table_name; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5703 (class 2620 OID 240534) --- Name: appellation last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5706 (class 2620 OID 240591) --- Name: entity_association last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.entity_association FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5710 (class 2620 OID 240622) --- Name: persistent_item last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.persistent_item FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5714 (class 2620 OID 240653) --- Name: role last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.role FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5718 (class 2620 OID 240710) --- Name: temporal_entity last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.temporal_entity FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5726 (class 2620 OID 240736) --- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5728 (class 2620 OID 240763) --- Name: language last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.language FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5784 (class 2620 OID 241210) --- Name: time_primitive last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.time_primitive FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5795 (class 2620 OID 242965) --- Name: place last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.place FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5829 (class 2620 OID 243317) --- Name: _deprecated_namespace last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5835 (class 2620 OID 243348) --- Name: _deprecated_type_namespace_rel last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5990 (class 2620 OID 246066) --- Name: property_of_property last_modification_tmsp; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5815 (class 2620 OID 243077) --- Name: v_time_primitive on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_time_primitive FOR EACH ROW EXECUTE PROCEDURE information.v_time_primitive_find_or_create(); - - --- --- TOC entry 5816 (class 2620 OID 243084) --- Name: v_role on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_role FOR EACH ROW EXECUTE PROCEDURE information.v_role_find_or_create(); - - --- --- TOC entry 5817 (class 2620 OID 243097) --- Name: v_language on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_language FOR EACH ROW EXECUTE PROCEDURE information.v_language_find_or_create(); - - --- --- TOC entry 5818 (class 2620 OID 243115) --- Name: v_place on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_place FOR EACH ROW EXECUTE PROCEDURE information.v_place_find_or_create(); - - --- --- TOC entry 5889 (class 2620 OID 245152) --- Name: v_temporal_entity on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_temporal_entity FOR EACH ROW EXECUTE PROCEDURE information.v_temporal_entity_find_or_create(); - - --- --- TOC entry 5987 (class 2620 OID 246037) --- Name: v_entity_association on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_entity_association FOR EACH ROW EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - - --- --- TOC entry 5994 (class 2620 OID 246081) --- Name: v_property_of_property on_insert; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_property_of_property FOR EACH ROW EXECUTE PROCEDURE information.v_property_of_property_find_or_create(); - - --- --- TOC entry 5723 (class 2620 OID 245190) --- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5700 (class 2620 OID 245231) --- Name: appellation sync_quill_doc_and_string; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5833 (class 2620 OID 245139) --- Name: _deprecated_type_namespace_rel update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5827 (class 2620 OID 245142) --- Name: _deprecated_namespace update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5722 (class 2620 OID 245155) --- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON information.text_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5699 (class 2620 OID 245196) --- Name: appellation update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON information.appellation FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5993 (class 2620 OID 246075) --- Name: property_of_property update_entity_version_key; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5707 (class 2620 OID 243192) --- Name: entity_association versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.entity_association FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.entity_association_vt', 'true'); - - --- --- TOC entry 5730 (class 2620 OID 243193) --- Name: language versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.language FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.language_vt', 'true'); - - --- --- TOC entry 5711 (class 2620 OID 243194) --- Name: persistent_item versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.persistent_item FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.persistent_item_vt', 'true'); - - --- --- TOC entry 5715 (class 2620 OID 243195) --- Name: role versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.role FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.role_vt', 'true'); - - --- --- TOC entry 5719 (class 2620 OID 243197) --- Name: temporal_entity versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.temporal_entity FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.temporal_entity_vt', 'true'); - - --- --- TOC entry 5796 (class 2620 OID 243201) --- Name: place versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.place FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.place_vt', 'true'); - - --- --- TOC entry 5785 (class 2620 OID 243202) --- Name: time_primitive versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.time_primitive FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.time_primitive_vt', 'true'); - - --- --- TOC entry 5831 (class 2620 OID 245137) --- Name: _deprecated_type_namespace_rel versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information._deprecated_type_namespace_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information._deprecated_type_namespace_rel_vt', 'true'); - - --- --- TOC entry 5825 (class 2620 OID 245140) --- Name: _deprecated_namespace versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information._deprecated_namespace FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information._deprecated_namespace_vt', 'true'); - - --- --- TOC entry 5720 (class 2620 OID 245153) --- Name: text_property versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.text_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.text_property_vt', 'true'); - - --- --- TOC entry 5697 (class 2620 OID 245194) --- Name: appellation versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.appellation FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.appellation_vt', 'true'); - - --- --- TOC entry 5991 (class 2620 OID 246073) --- Name: property_of_property versioning_trigger; Type: TRIGGER; Schema: information; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON information.property_of_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'information.property_of_property_vt', 'true'); - - --- --- TOC entry 5737 (class 2620 OID 244949) --- Name: info_proj_rel after_epr_upsert; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER after_epr_upsert AFTER INSERT OR UPDATE ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__upsert_entity_preview(); - - --- --- TOC entry 5848 (class 2620 OID 244803) --- Name: argument create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.argument FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5679 (class 2620 OID 244809) --- Name: project create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.project FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5654 (class 2620 OID 244815) --- Name: language create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.language FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5691 (class 2620 OID 244827) --- Name: text_property create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5673 (class 2620 OID 244883) --- Name: _deprecated_label create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5859 (class 2620 OID 244908) --- Name: query create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.query FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5871 (class 2620 OID 244926) --- Name: visual create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.visual FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5732 (class 2620 OID 244944) --- Name: info_proj_rel create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5820 (class 2620 OID 244966) --- Name: dfh_class_proj_rel create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5804 (class 2620 OID 245017) --- Name: class_field_config create_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5651 (class 2620 OID 240182) --- Name: language creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.language FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5669 (class 2620 OID 240367) --- Name: _deprecated_label creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5675 (class 2620 OID 240406) --- Name: project creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.project FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5687 (class 2620 OID 240459) --- Name: text_property creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5844 (class 2620 OID 243957) --- Name: argument creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.argument FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5861 (class 2620 OID 244910) --- Name: query creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.query FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5873 (class 2620 OID 244928) --- Name: visual creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.visual FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5734 (class 2620 OID 244946) --- Name: info_proj_rel creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5822 (class 2620 OID 244968) --- Name: dfh_class_proj_rel creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5806 (class 2620 OID 245019) --- Name: class_field_config creation_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5670 (class 2620 OID 240368) --- Name: _deprecated_label insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5676 (class 2620 OID 240407) --- Name: project insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.project FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5688 (class 2620 OID 240460) --- Name: text_property insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5845 (class 2620 OID 243958) --- Name: argument insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.argument FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5862 (class 2620 OID 244911) --- Name: query insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.query FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5874 (class 2620 OID 244929) --- Name: visual insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.visual FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5735 (class 2620 OID 244947) --- Name: info_proj_rel insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5823 (class 2620 OID 244969) --- Name: dfh_class_proj_rel insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5807 (class 2620 OID 245020) --- Name: class_field_config insert_schema_table_name; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5652 (class 2620 OID 240183) --- Name: language last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.language FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5671 (class 2620 OID 240369) --- Name: _deprecated_label last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5677 (class 2620 OID 240408) --- Name: project last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.project FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5689 (class 2620 OID 240461) --- Name: text_property last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5846 (class 2620 OID 243959) --- Name: argument last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.argument FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5863 (class 2620 OID 244912) --- Name: query last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.query FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5875 (class 2620 OID 244930) --- Name: visual last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.visual FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5736 (class 2620 OID 244948) --- Name: info_proj_rel last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5824 (class 2620 OID 244970) --- Name: dfh_class_proj_rel last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5808 (class 2620 OID 245021) --- Name: class_field_config last_modification_tmsp; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5843 (class 2620 OID 243430) --- Name: v_info_proj_rel on_insert; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON projects.v_info_proj_rel FOR EACH ROW EXECUTE PROCEDURE projects.v_info_proj_rel_update_or_creat(); - - --- --- TOC entry 5738 (class 2620 OID 244950) --- Name: info_proj_rel on_upsert; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER on_upsert BEFORE INSERT OR UPDATE ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.evpr_fk_entity_fk_entity_version(); - - --- --- TOC entry 5693 (class 2620 OID 244863) --- Name: text_property sync_quill_doc_and_string; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER sync_quill_doc_and_string BEFORE INSERT OR UPDATE ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - - --- --- TOC entry 5849 (class 2620 OID 244804) --- Name: argument update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.argument FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5680 (class 2620 OID 244810) --- Name: project update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.project FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5655 (class 2620 OID 244816) --- Name: language update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.language FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5692 (class 2620 OID 244828) --- Name: text_property update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5674 (class 2620 OID 244884) --- Name: _deprecated_label update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5860 (class 2620 OID 244909) --- Name: query update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.query FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5872 (class 2620 OID 244927) --- Name: visual update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.visual FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5733 (class 2620 OID 244945) --- Name: info_proj_rel update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5821 (class 2620 OID 244967) --- Name: dfh_class_proj_rel update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5805 (class 2620 OID 245018) --- Name: class_field_config update_entity_version_key; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5847 (class 2620 OID 244802) --- Name: argument versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.argument FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.argument_vt', 'true'); - - --- --- TOC entry 5678 (class 2620 OID 244808) --- Name: project versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.project FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.project_vt', 'true'); - - --- --- TOC entry 5653 (class 2620 OID 244814) --- Name: language versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.language FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.language_vt', 'true'); - - --- --- TOC entry 5690 (class 2620 OID 244826) --- Name: text_property versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.text_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.text_property_vt', 'true'); - - --- --- TOC entry 5672 (class 2620 OID 244882) --- Name: _deprecated_label versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects._deprecated_label FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects._deprecated_label_vt', 'true'); - - --- --- TOC entry 5858 (class 2620 OID 244907) --- Name: query versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.query FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.query_vt', 'true'); - - --- --- TOC entry 5870 (class 2620 OID 244925) --- Name: visual versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.visual FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.visual_vt', 'true'); - - --- --- TOC entry 5731 (class 2620 OID 244943) --- Name: info_proj_rel versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.info_proj_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.info_proj_rel_vt', 'true'); - - --- --- TOC entry 5819 (class 2620 OID 244965) --- Name: dfh_class_proj_rel versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.dfh_class_proj_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.dfh_class_proj_rel_vt', 'true'); - - --- --- TOC entry 5803 (class 2620 OID 245016) --- Name: class_field_config versioning_trigger; Type: TRIGGER; Schema: projects; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON projects.class_field_config FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'projects.class_field_config_vt', 'true'); - - --- --- TOC entry 5695 (class 2620 OID 245001) --- Name: account_project_rel create_entity_version_key; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON public.account_project_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5696 (class 2620 OID 245002) --- Name: account_project_rel update_entity_version_key; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON public.account_project_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5694 (class 2620 OID 245000) --- Name: account_project_rel versioning_trigger; Type: TRIGGER; Schema: public; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON public.account_project_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'public.account_project_rel_vt', 'true'); - - --- --- TOC entry 5685 (class 2620 OID 244723) --- Name: system_type create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.system_type FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5813 (class 2620 OID 244729) --- Name: class_field create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.class_field FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5841 (class 2620 OID 244732) --- Name: class_field_property_rel create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5868 (class 2620 OID 244735) --- Name: class_has_type_property create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5801 (class 2620 OID 244738) --- Name: app_context create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.app_context FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5881 (class 2620 OID 244766) --- Name: system_relevant_class create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5887 (class 2620 OID 244794) --- Name: system_relevant_type create_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER create_entity_version_key BEFORE INSERT ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- --- TOC entry 5681 (class 2620 OID 240430) --- Name: system_type creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5797 (class 2620 OID 243005) --- Name: app_context creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.app_context FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5809 (class 2620 OID 243061) --- Name: class_field creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.class_field FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5837 (class 2620 OID 243406) --- Name: class_field_property_rel creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5864 (class 2620 OID 244126) --- Name: class_has_type_property creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5877 (class 2620 OID 244756) --- Name: system_relevant_class creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5883 (class 2620 OID 244784) --- Name: system_relevant_type creation_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER creation_tmsp BEFORE INSERT ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_creation(); - - --- --- TOC entry 5682 (class 2620 OID 240431) --- Name: system_type insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.system_type FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5799 (class 2620 OID 243007) --- Name: app_context insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.app_context FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5811 (class 2620 OID 243063) --- Name: class_field insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.class_field FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5838 (class 2620 OID 243408) --- Name: class_field_property_rel insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5865 (class 2620 OID 244127) --- Name: class_has_type_property insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5878 (class 2620 OID 244757) --- Name: system_relevant_class insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5884 (class 2620 OID 244785) --- Name: system_relevant_type insert_schema_table_name; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER insert_schema_table_name BEFORE INSERT ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- --- TOC entry 5683 (class 2620 OID 240432) --- Name: system_type last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.system_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5798 (class 2620 OID 243006) --- Name: app_context last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.app_context FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5810 (class 2620 OID 243062) --- Name: class_field last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.class_field FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5839 (class 2620 OID 243407) --- Name: class_field_property_rel last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5866 (class 2620 OID 244128) --- Name: class_has_type_property last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5879 (class 2620 OID 244758) --- Name: system_relevant_class last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5885 (class 2620 OID 244786) --- Name: system_relevant_type last_modification_tmsp; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - - --- --- TOC entry 5686 (class 2620 OID 244724) --- Name: system_type update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.system_type FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5814 (class 2620 OID 244730) --- Name: class_field update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.class_field FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5842 (class 2620 OID 244733) --- Name: class_field_property_rel update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5869 (class 2620 OID 244736) --- Name: class_has_type_property update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5802 (class 2620 OID 244739) --- Name: app_context update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.app_context FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5882 (class 2620 OID 244767) --- Name: system_relevant_class update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5888 (class 2620 OID 244795) --- Name: system_relevant_type update_entity_version_key; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- --- TOC entry 5684 (class 2620 OID 244722) --- Name: system_type versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.system_type FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.system_type_vt', 'true'); - - --- --- TOC entry 5812 (class 2620 OID 244728) --- Name: class_field versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.class_field FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.class_field_vt', 'true'); - - --- --- TOC entry 5840 (class 2620 OID 244731) --- Name: class_field_property_rel versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.class_field_property_rel FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.class_field_property_rel_vt', 'true'); - - --- --- TOC entry 5867 (class 2620 OID 244734) --- Name: class_has_type_property versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.class_has_type_property FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.class_has_type_property_vt', 'true'); - - --- --- TOC entry 5800 (class 2620 OID 244737) --- Name: app_context versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.app_context FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.app_context_vt', 'true'); - - --- --- TOC entry 5880 (class 2620 OID 244765) --- Name: system_relevant_class versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.system_relevant_class FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.system_relevant_class_vt', 'true'); - - --- --- TOC entry 5886 (class 2620 OID 244793) --- Name: system_relevant_type versioning_trigger; Type: TRIGGER; Schema: system; Owner: - --- - -CREATE TRIGGER versioning_trigger BEFORE INSERT OR DELETE OR UPDATE ON system.system_relevant_type FOR EACH ROW EXECUTE PROCEDURE public.versioning('sys_period', 'system.system_relevant_type_vt', 'true'); - - --- --- TOC entry 5850 (class 2620 OID 244078) --- Name: class_preview after_update_on_class_preview__class_label; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_class_preview__class_label AFTER UPDATE OF class_label ON warehouse.class_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_class_labels(); - - --- --- TOC entry 5856 (class 2620 OID 244077) --- Name: entity_preview after_update_on_entity_preview__entity_label; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_entity_preview__entity_label AFTER UPDATE OF entity_label ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_entity_labels(); - - --- --- TOC entry 5857 (class 2620 OID 244072) --- Name: entity_preview after_update_on_entity_preview__fk_entity_label; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_entity_preview__fk_entity_label AFTER UPDATE OF fk_entity_label ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__get_entity_label(); - - --- --- TOC entry 5851 (class 2620 OID 244073) --- Name: entity_preview after_update_on_entity_preview__fk_type; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_entity_preview__fk_type AFTER UPDATE OF fk_type ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__get_type_label(); - - --- --- TOC entry 5852 (class 2620 OID 244076) --- Name: entity_preview after_update_on_entity_preview__own_full_text; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_entity_preview__own_full_text AFTER UPDATE OF own_full_text ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_related_full_texts(); - - --- --- TOC entry 5853 (class 2620 OID 244079) --- Name: entity_preview after_upsert_on_entity_preview; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_upsert_on_entity_preview AFTER INSERT OR UPDATE OF entity_label, class_label, time_span, type_label ON warehouse.entity_preview FOR EACH ROW WHEN (((new.project IS NOT NULL) AND (new.fk_class IS NOT NULL) AND (new.entity_type IS NOT NULL))) EXECUTE PROCEDURE warehouse.entity_preview__notify_upsert(); - - --- --- TOC entry 5854 (class 2620 OID 244075) --- Name: entity_preview before_update_on_entity_preview__own_full_text; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER before_update_on_entity_preview__own_full_text BEFORE UPDATE OF own_full_text ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - - --- --- TOC entry 5855 (class 2620 OID 244074) --- Name: entity_preview before_update_on_entity_preview__related_full_texts; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER before_update_on_entity_preview__related_full_texts BEFORE UPDATE OF related_full_texts ON warehouse.entity_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - - --- --- TOC entry 5643 (class 2606 OID 245889) --- Name: avatar avatar_fk_class_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.avatar - ADD CONSTRAINT avatar_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5619 (class 2606 OID 245529) --- Name: cell cell_fk_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell - ADD CONSTRAINT cell_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); - - --- --- TOC entry 5620 (class 2606 OID 245534) --- Name: cell cell_fk_row_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.cell - ADD CONSTRAINT cell_fk_row_fkey FOREIGN KEY (fk_row) REFERENCES data."row"(pk_entity); - - --- --- TOC entry 5627 (class 2606 OID 245671) --- Name: class_column_rel class_column_rel_fk_class_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel - ADD CONSTRAINT class_column_rel_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5628 (class 2606 OID 245676) --- Name: class_column_rel class_column_rel_fk_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.class_column_rel - ADD CONSTRAINT class_column_rel_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); - - --- --- TOC entry 5617 (class 2606 OID 245496) --- Name: column column_fk_data_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" - ADD CONSTRAINT column_fk_data_type_fkey FOREIGN KEY (fk_data_type) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5616 (class 2606 OID 245491) --- Name: column column_fk_digital_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" - ADD CONSTRAINT column_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); - - --- --- TOC entry 5618 (class 2606 OID 245501) --- Name: column column_fk_meta_data_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."column" - ADD CONSTRAINT column_fk_meta_data_fkey FOREIGN KEY (fk_meta_data) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5642 (class 2606 OID 245861) --- Name: data_association data_association_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.data_association - ADD CONSTRAINT data_association_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5583 (class 2606 OID 245386) --- Name: digital digital_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.digital - ADD CONSTRAINT digital_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5613 (class 2606 OID 246007) --- Name: entity entity_fk_namespace_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.entity - ADD CONSTRAINT entity_fk_namespace_fkey FOREIGN KEY (fk_namespace) REFERENCES data.namespace(pk_entity); - - --- --- TOC entry 5622 (class 2606 OID 245600) --- Name: factoid_class_digital_rel factoid_class_digital_rel_fk_class_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel - ADD CONSTRAINT factoid_class_digital_rel_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5621 (class 2606 OID 245595) --- Name: factoid_class_digital_rel factoid_class_digital_rel_fk_digital_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_class_digital_rel - ADD CONSTRAINT factoid_class_digital_rel_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); - - --- --- TOC entry 5632 (class 2606 OID 245742) --- Name: factoid factoid_fk_class_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid - ADD CONSTRAINT factoid_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5630 (class 2606 OID 245709) --- Name: factoid_property_column_rel factoid_property_column_rel_fk_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel - ADD CONSTRAINT factoid_property_column_rel_fk_column_fkey FOREIGN KEY (fk_column) REFERENCES data."column"(pk_entity); - - --- --- TOC entry 5631 (class 2606 OID 245714) --- Name: factoid_property_column_rel factoid_property_column_rel_fk_factoid_class_digital_rel_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel - ADD CONSTRAINT factoid_property_column_rel_fk_factoid_class_digital_rel_fkey FOREIGN KEY (fk_factoid_class_digital_rel) REFERENCES data.factoid_class_digital_rel(pk_entity); - - --- --- TOC entry 5629 (class 2606 OID 245704) --- Name: factoid_property_column_rel factoid_property_column_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_property_column_rel - ADD CONSTRAINT factoid_property_column_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5634 (class 2606 OID 245775) --- Name: factoid_role factoid_role_fk_domain_factoid_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role - ADD CONSTRAINT factoid_role_fk_domain_factoid_fkey FOREIGN KEY (fk_domain_factoid) REFERENCES data.factoid(pk_entity); - - --- --- TOC entry 5633 (class 2606 OID 245770) --- Name: factoid_role factoid_role_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role - ADD CONSTRAINT factoid_role_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5635 (class 2606 OID 245780) --- Name: factoid_role factoid_role_fk_range_cell_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role - ADD CONSTRAINT factoid_role_fk_range_cell_fkey FOREIGN KEY (fk_range_cell) REFERENCES data.cell(pk_entity); - - --- --- TOC entry 5636 (class 2606 OID 245785) --- Name: factoid_role factoid_role_fk_range_chunk_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.factoid_role - ADD CONSTRAINT factoid_role_fk_range_chunk_fkey FOREIGN KEY (fk_range_chunk) REFERENCES data.chunk(pk_entity); - - --- --- TOC entry 5646 (class 2606 OID 245983) --- Name: namespace namespace_fk_project_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace - ADD CONSTRAINT namespace_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5647 (class 2606 OID 246002) --- Name: namespace namespace_fk_root_namespace_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.namespace - ADD CONSTRAINT namespace_fk_root_namespace_fkey FOREIGN KEY (fk_root_namespace) REFERENCES data.namespace(pk_entity); - - --- --- TOC entry 5615 (class 2606 OID 245463) --- Name: row row_fk_digital_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data."row" - ADD CONSTRAINT row_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital(pk_entity); - - --- --- TOC entry 5614 (class 2606 OID 245402) --- Name: chunk text_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.chunk - ADD CONSTRAINT text_fkey FOREIGN KEY (fk_text, fk_entity_version) REFERENCES commons.text(pk_text, entity_version); - - --- --- TOC entry 5645 (class 2606 OID 245922) --- Name: text_property text_property_fk_language_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property - ADD CONSTRAINT text_property_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); - - --- --- TOC entry 5644 (class 2606 OID 245917) --- Name: text_property text_property_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.text_property - ADD CONSTRAINT text_property_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5624 (class 2606 OID 245633) --- Name: value_association_columns_rel value_association_columns_rel_fk_domain_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel - ADD CONSTRAINT value_association_columns_rel_fk_domain_column_fkey FOREIGN KEY (fk_domain_column) REFERENCES data."column"(pk_entity); - - --- --- TOC entry 5626 (class 2606 OID 245643) --- Name: value_association_columns_rel value_association_columns_rel_fk_factoid_class_digital_rel_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel - ADD CONSTRAINT value_association_columns_rel_fk_factoid_class_digital_rel_fkey FOREIGN KEY (fk_factoid_class_digital_rel) REFERENCES data.factoid_class_digital_rel(pk_entity); - - --- --- TOC entry 5623 (class 2606 OID 245628) --- Name: value_association_columns_rel value_association_columns_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel - ADD CONSTRAINT value_association_columns_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5625 (class 2606 OID 245638) --- Name: value_association_columns_rel value_association_columns_rel_fk_range_column_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.value_association_columns_rel - ADD CONSTRAINT value_association_columns_rel_fk_range_column_fkey FOREIGN KEY (fk_range_column) REFERENCES data."column"(pk_entity); - - --- --- TOC entry 5638 (class 2606 OID 245818) --- Name: values_association values_association_fk_domain_cell_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT values_association_fk_domain_cell_fkey FOREIGN KEY (fk_domain_cell) REFERENCES data.cell(pk_entity); - - --- --- TOC entry 5640 (class 2606 OID 245828) --- Name: values_association values_association_fk_domain_chunk_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT values_association_fk_domain_chunk_fkey FOREIGN KEY (fk_domain_chunk) REFERENCES data.chunk(pk_entity); - - --- --- TOC entry 5637 (class 2606 OID 245813) --- Name: values_association values_association_fk_property_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT values_association_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5639 (class 2606 OID 245823) --- Name: values_association values_association_fk_range_cell_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT values_association_fk_range_cell_fkey FOREIGN KEY (fk_range_cell) REFERENCES data.cell(pk_entity); - - --- --- TOC entry 5641 (class 2606 OID 245833) --- Name: values_association values_association_fk_range_chunk_fkey; Type: FK CONSTRAINT; Schema: data; Owner: - --- - -ALTER TABLE ONLY data.values_association - ADD CONSTRAINT values_association_fk_range_chunk_fkey FOREIGN KEY (fk_range_chunk) REFERENCES data.chunk(pk_entity); - - --- --- TOC entry 5580 (class 2606 OID 243375) --- Name: label label_com_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label - ADD CONSTRAINT label_com_fk_system_type_fkey FOREIGN KEY (com_fk_system_type) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5581 (class 2606 OID 243380) --- Name: label label_inf_fk_language_fkey; Type: FK CONSTRAINT; Schema: data_for_history; Owner: - --- - -ALTER TABLE ONLY data_for_history.label - ADD CONSTRAINT label_inf_fk_language_fkey FOREIGN KEY (inf_fk_language) REFERENCES information.language(pk_entity); - - --- --- TOC entry 5571 (class 2606 OID 240961) --- Name: appellation appellation_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.appellation - ADD CONSTRAINT appellation_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5577 (class 2606 OID 240986) --- Name: language language_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.language - ADD CONSTRAINT language_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5593 (class 2606 OID 243306) --- Name: _deprecated_namespace namespace_fk_root_namespace_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_namespace - ADD CONSTRAINT namespace_fk_root_namespace_fkey FOREIGN KEY (fk_root_namespace) REFERENCES information._deprecated_namespace(pk_entity); - - --- --- TOC entry 5572 (class 2606 OID 240911) --- Name: persistent_item persistent_item_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.persistent_item - ADD CONSTRAINT persistent_item_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5584 (class 2606 OID 242958) --- Name: place place_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.place - ADD CONSTRAINT place_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5650 (class 2606 OID 246057) --- Name: property_of_property property_of_property_fk_entity_association_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property - ADD CONSTRAINT property_of_property_fk_entity_association_fkey FOREIGN KEY (fk_entity_association) REFERENCES information.entity_association(pk_entity); - - --- --- TOC entry 5648 (class 2606 OID 246047) --- Name: property_of_property property_of_property_fk_property_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property - ADD CONSTRAINT property_of_property_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5649 (class 2606 OID 246052) --- Name: property_of_property property_of_property_fk_role_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.property_of_property - ADD CONSTRAINT property_of_property_fk_role_fkey FOREIGN KEY (fk_role) REFERENCES information.role(pk_entity); - - --- --- TOC entry 5573 (class 2606 OID 241013) --- Name: role role_fk_property_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.role - ADD CONSTRAINT role_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5574 (class 2606 OID 240936) --- Name: temporal_entity temporal_entity_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.temporal_entity - ADD CONSTRAINT temporal_entity_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5576 (class 2606 OID 243442) --- Name: text_property text_property_fk_class_field_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property - ADD CONSTRAINT text_property_fk_class_field_fkey FOREIGN KEY (fk_class_field) REFERENCES system.class_field(pk_entity); - - --- --- TOC entry 5575 (class 2606 OID 243362) --- Name: text_property text_property_fk_language_constraint; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.text_property - ADD CONSTRAINT text_property_fk_language_constraint FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); - - --- --- TOC entry 5582 (class 2606 OID 241203) --- Name: time_primitive time_primitive_fk_class_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information.time_primitive - ADD CONSTRAINT time_primitive_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5595 (class 2606 OID 243342) --- Name: _deprecated_type_namespace_rel type_namespace_rel_fk_namespace_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_type_namespace_rel - ADD CONSTRAINT type_namespace_rel_fk_namespace_fkey FOREIGN KEY (fk_namespace) REFERENCES information._deprecated_namespace(pk_entity); - - --- --- TOC entry 5594 (class 2606 OID 243337) --- Name: _deprecated_type_namespace_rel type_namespace_rel_fk_persistent_item_fkey; Type: FK CONSTRAINT; Schema: information; Owner: - --- - -ALTER TABLE ONLY information._deprecated_type_namespace_rel - ADD CONSTRAINT type_namespace_rel_fk_persistent_item_fkey FOREIGN KEY (fk_persistent_item) REFERENCES information.persistent_item(pk_entity); - - --- --- TOC entry 5603 (class 2606 OID 243950) --- Name: argument assertion_fk_assertion_method_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_assertion_method_type_fkey FOREIGN KEY (fk_assertion_method_type) REFERENCES information.persistent_item(pk_entity); - - --- --- TOC entry 5599 (class 2606 OID 243920) --- Name: argument assertion_fk_is_about_entity_association_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_is_about_entity_association_fkey FOREIGN KEY (fk_is_about_entity_association) REFERENCES information.entity_association(pk_entity); - - --- --- TOC entry 5598 (class 2606 OID 243915) --- Name: argument assertion_fk_is_about_role_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_is_about_role_fkey FOREIGN KEY (fk_is_about_role) REFERENCES information.role(pk_entity); - - --- --- TOC entry 5601 (class 2606 OID 243930) --- Name: argument assertion_fk_is_based_on_entity_association_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_is_based_on_entity_association_fkey FOREIGN KEY (fk_is_based_on_entity_association) REFERENCES information.entity_association(pk_entity); - - --- --- TOC entry 5602 (class 2606 OID 243935) --- Name: argument assertion_fk_is_based_on_persistent_item_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_is_based_on_persistent_item_fkey FOREIGN KEY (fk_is_based_on_persistent_item) REFERENCES information.persistent_item(pk_entity); - - --- --- TOC entry 5600 (class 2606 OID 243925) --- Name: argument assertion_fk_is_based_on_role_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.argument - ADD CONSTRAINT assertion_fk_is_based_on_role_fkey FOREIGN KEY (fk_is_based_on_role) REFERENCES information.role(pk_entity); - - --- --- TOC entry 5587 (class 2606 OID 245006) --- Name: class_field_config class_field_config_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config - ADD CONSTRAINT class_field_config_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5588 (class 2606 OID 245011) --- Name: class_field_config_vt class_field_config_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config_vt - ADD CONSTRAINT class_field_config_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5591 (class 2606 OID 244955) --- Name: dfh_class_proj_rel dfh_class_proj_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.dfh_class_proj_rel - ADD CONSTRAINT dfh_class_proj_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5592 (class 2606 OID 244960) --- Name: dfh_class_proj_rel_vt dfh_class_proj_rel_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.dfh_class_proj_rel_vt - ADD CONSTRAINT dfh_class_proj_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5578 (class 2606 OID 244933) --- Name: info_proj_rel info_proj_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel - ADD CONSTRAINT info_proj_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5579 (class 2606 OID 244938) --- Name: info_proj_rel_vt info_proj_rel_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.info_proj_rel_vt - ADD CONSTRAINT info_proj_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5563 (class 2606 OID 240362) --- Name: _deprecated_label label_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects._deprecated_label - ADD CONSTRAINT label_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES projects.language(pk_language); - - --- --- TOC entry 5590 (class 2606 OID 243280) --- Name: dfh_class_proj_rel proj_rel_fk_entity_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.dfh_class_proj_rel - ADD CONSTRAINT proj_rel_fk_entity_fkey FOREIGN KEY (fk_entity) REFERENCES data_for_history.class(pk_entity); - - --- --- TOC entry 5564 (class 2606 OID 240391) --- Name: project project_fk_creator_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project - ADD CONSTRAINT project_fk_creator_fkey FOREIGN KEY (fk_creator) REFERENCES public.account(id); - - --- --- TOC entry 5566 (class 2606 OID 244877) --- Name: project project_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project - ADD CONSTRAINT project_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); - - --- --- TOC entry 5565 (class 2606 OID 240396) --- Name: project project_fk_last_modifier_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.project - ADD CONSTRAINT project_fk_last_modifier_fkey FOREIGN KEY (fk_last_modifier) REFERENCES public.account(id); - - --- --- TOC entry 5604 (class 2606 OID 244897) --- Name: query query_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query - ADD CONSTRAINT query_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5605 (class 2606 OID 244902) --- Name: query_vt query_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.query_vt - ADD CONSTRAINT query_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5567 (class 2606 OID 244865) --- Name: text_property text_property_fk_language_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.text_property - ADD CONSTRAINT text_property_fk_language_fkey FOREIGN KEY (fk_language) REFERENCES information.language(pk_entity); - - --- --- TOC entry 5568 (class 2606 OID 244872) --- Name: text_property text_property_fk_system_type_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.text_property - ADD CONSTRAINT text_property_fk_system_type_fkey FOREIGN KEY (fk_system_type) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5585 (class 2606 OID 243031) --- Name: class_field_config ui_context_config_fk_property_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config - ADD CONSTRAINT ui_context_config_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5586 (class 2606 OID 243455) --- Name: class_field_config ui_context_config_fk_ui_context_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.class_field_config - ADD CONSTRAINT ui_context_config_fk_ui_context_fkey FOREIGN KEY (fk_app_context) REFERENCES system.app_context(pk_entity); - - --- --- TOC entry 5608 (class 2606 OID 244915) --- Name: visual visual_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual - ADD CONSTRAINT visual_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5609 (class 2606 OID 244920) --- Name: visual_vt visual_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: projects; Owner: - --- - -ALTER TABLE ONLY projects.visual_vt - ADD CONSTRAINT visual_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5561 (class 2606 OID 240294) --- Name: accesstoken accesstoken_userid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.accesstoken - ADD CONSTRAINT accesstoken_userid_fkey FOREIGN KEY (userid) REFERENCES public.account(id); - - --- --- TOC entry 5569 (class 2606 OID 240490) --- Name: account_project_rel account_project_rel_account_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account_project_rel - ADD CONSTRAINT account_project_rel_account_id_fkey FOREIGN KEY (account_id) REFERENCES public.account(id); - - --- --- TOC entry 5570 (class 2606 OID 244990) --- Name: account_project_rel account_project_rel_fk_project_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account_project_rel - ADD CONSTRAINT account_project_rel_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5612 (class 2606 OID 244995) --- Name: account_project_rel_vt account_project_rel_vt_fk_project_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.account_project_rel_vt - ADD CONSTRAINT account_project_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) REFERENCES projects.project(pk_entity); - - --- --- TOC entry 5562 (class 2606 OID 240321) --- Name: rolemapping rolemapping_roleid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.rolemapping - ADD CONSTRAINT rolemapping_roleid_fkey FOREIGN KEY (roleid) REFERENCES public.role(id); - - --- --- TOC entry 5607 (class 2606 OID 244114) --- Name: class_has_type_property class_has_type_property_fk_class_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_has_type_property - ADD CONSTRAINT class_has_type_property_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5606 (class 2606 OID 244119) --- Name: class_has_type_property class_has_type_property_fk_property_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_has_type_property - ADD CONSTRAINT class_has_type_property_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5589 (class 2606 OID 243467) --- Name: class_field fk_system_type_ng_component_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_field - ADD CONSTRAINT fk_system_type_ng_component_fkey FOREIGN KEY (fk_system_type_ng_component) REFERENCES system.system_type(pk_entity); - - --- --- TOC entry 5596 (class 2606 OID 243399) --- Name: class_field_property_rel property_set_property_rel_fk_property_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_field_property_rel - ADD CONSTRAINT property_set_property_rel_fk_property_fkey FOREIGN KEY (fk_property) REFERENCES data_for_history.property(dfh_pk_property); - - --- --- TOC entry 5597 (class 2606 OID 243394) --- Name: class_field_property_rel property_set_property_rel_fk_property_set_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.class_field_property_rel - ADD CONSTRAINT property_set_property_rel_fk_property_set_fkey FOREIGN KEY (fk_class_field) REFERENCES system.class_field(pk_entity); - - --- --- TOC entry 5610 (class 2606 OID 244749) --- Name: system_relevant_class system_relevant_class_fk_class_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_class - ADD CONSTRAINT system_relevant_class_fk_class_fkey FOREIGN KEY (fk_class) REFERENCES data_for_history.class(dfh_pk_class); - - --- --- TOC entry 5611 (class 2606 OID 244777) --- Name: system_relevant_type system_relevant_type_fk_type_fkey; Type: FK CONSTRAINT; Schema: system; Owner: - --- - -ALTER TABLE ONLY system.system_relevant_type - ADD CONSTRAINT system_relevant_type_fk_type_fkey FOREIGN KEY (fk_type) REFERENCES information.persistent_item(pk_entity); - - --- Completed on 2019-05-15 15:21:13 CEST - --- --- PostgreSQL database dump complete --- - diff --git a/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-down.sql b/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-down.sql deleted file mode 100644 index 52d6c3350..000000000 --- a/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE data_for_history.property_of_property_vt; -DROP TABLE data_for_history.property_of_property; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-up.sql b/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-up.sql deleted file mode 100644 index ad3b91190..000000000 --- a/server/db-migrate/migrations/sqls/20190515143720-dfh-t-property-of-property-up.sql +++ /dev/null @@ -1,21 +0,0 @@ -CREATE TABLE data_for_history.property_of_property ( - dfh_pk_property_of_property integer NOT NULL, - dfh_identifier_in_namespace text, - dfh_has_property_domain integer, - dfh_has_class_range integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_standard_label character varying (500), - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint, - dfh_fk_property_of_property_of_origin integer, - CONSTRAINT unique_dfh_pk_property_of_property UNIQUE (dfh_pk_property_of_property)) -INHERITS ( - data_for_history.entity -); - -SELECT - commons.init_entity_child_table ('data_for_history.property_of_property'); - diff --git a/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-down.sql b/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-down.sql deleted file mode 100644 index 5028ce381..000000000 --- a/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-down.sql +++ /dev/null @@ -1,69 +0,0 @@ --- 18 -DROP TABLE IF EXISTS data.property_of_property; -DROP TABLE IF EXISTS data.property_of_property_vt; - --- 17 -ALTER TABLE data.data_association ADD COLUMN fk_info_domain integer; -ALTER TABLE data.data_association_vt ADD COLUMN fk_info_domain integer; - --- 16 -ALTER TABLE data.data_association RENAME COLUMN fk_info_value_range TO fk_info_range; -ALTER TABLE data.data_association_vt RENAME COLUMN fk_info_value_range TO fk_info_range; - --- 15 -ALTER TABLE data.factoid_role DROP COLUMN fk_info_value_range; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_info_value_range; - --- 14 -ALTER TABLE data.factoid_role DROP COLUMN fk_data_range; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_data_range; - --- 13 -ALTER TABLE data.factoid_role ADD COLUMN fk_range_cell INTEGER REFERENCES data.cell (pk_entity); -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_range_cell INTEGER REFERENCES data.cell (pk_entity); -ALTER TABLE data.factoid_role ADD COLUMN fk_range_chunk INTEGER REFERENCES data.chunk (pk_entity); -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_range_chunk INTEGER REFERENCES data.chunk (pk_entity); - --- 12 -ALTER TABLE data.cell DROP COLUMN numeric_value; -ALTER TABLE data.cell_vt DROP COLUMN numeric_value; - --- 11 -ALTER TABLE data.column DROP COLUMN is_imported; -ALTER TABLE data.column_vt DROP COLUMN is_imported; - --- 10 -ALTER TABLE data.column DROP COLUMN fk_original_column; -ALTER TABLE data.column_vt DROP COLUMN fk_original_column; - --- 9 -ALTER TABLE data.column DROP COLUMN fk_column_type; -ALTER TABLE data.column_vt DROP COLUMN fk_column_type; - --- 8 -ALTER TABLE data.column ADD COLUMN fk_meta_data integer not null REFERENCES system.system_type (pk_entity); -ALTER TABLE data.column_vt ADD COLUMN fk_meta_data integer not null REFERENCES system.system_type (pk_entity); - --- 7 -DROP TABLE IF EXISTS data.property_of_property_mapping; -DROP TABLE IF EXISTS data.property_of_property_mapping_vt; - --- 6 -SELECT commons.rename_versioned_table('data', 'class_column_mapping', 'class_column_rel'); - --- 5 -ALTER TABLE data.data_association_mapping RENAME COLUMN fk_factoid_mapping TO fk_factoid_class_digital_rel; -ALTER TABLE data.data_association_mapping_vt RENAME COLUMN fk_factoid_mapping TO fk_factoid_class_digital_rel; - --- 4 -SELECT commons.rename_versioned_table('data', 'data_association_mapping', 'value_association_columns_rel'); - --- 3 -ALTER TABLE data.factoid_role_mapping RENAME COLUMN fk_factoid_mapping TO fk_factoid_class_digital_rel; -ALTER TABLE data.factoid_role_mapping_vt RENAME COLUMN fk_factoid_mapping TO fk_factoid_class_digital_rel; - --- 2 -SELECT commons.rename_versioned_table('data', 'factoid_role_mapping', 'factoid_property_column_rel'); - --- 1 -SELECT commons.rename_versioned_table('data', 'factoid_mapping', 'factoid_class_digital_rel') diff --git a/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-up.sql b/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-up.sql deleted file mode 100644 index c727b2973..000000000 --- a/server/db-migrate/migrations/sqls/20190515144536-dat-refactoring-up.sql +++ /dev/null @@ -1,86 +0,0 @@ --- 1 -SELECT commons.rename_versioned_table('data', 'factoid_class_digital_rel', 'factoid_mapping'); - --- 2 -SELECT commons.rename_versioned_table('data', 'factoid_property_column_rel', 'factoid_role_mapping'); - --- 3 -ALTER TABLE data.factoid_role_mapping RENAME COLUMN fk_factoid_class_digital_rel TO fk_factoid_mapping; -ALTER TABLE data.factoid_role_mapping_vt RENAME COLUMN fk_factoid_class_digital_rel TO fk_factoid_mapping; - --- 4 -SELECT commons.rename_versioned_table('data', 'value_association_columns_rel', 'data_association_mapping'); - --- 5 -ALTER TABLE data.data_association_mapping RENAME COLUMN fk_factoid_class_digital_rel TO fk_factoid_mapping; -ALTER TABLE data.data_association_mapping_vt RENAME COLUMN fk_factoid_class_digital_rel TO fk_factoid_mapping; - --- 6 -SELECT commons.rename_versioned_table('data', 'class_column_rel', 'class_column_mapping'); - --- 7 -CREATE TABLE data.property_of_property_mapping - ( - fk_property_of_property INTEGER NOT NULL REFERENCES data_for_history.property_of_property (dfh_pk_property_of_property), - fk_domain_factoid_role_mapping INTEGER REFERENCES data.factoid_role_mapping (pk_entity), - fk_domain_data_association_mapping INTEGER REFERENCES data.data_association_mapping (pk_entity), - fk_range_column INTEGER NOT NULL REFERENCES data.column (pk_entity) - ) -INHERITS (data.entity); - -SELECT commons.init_entity_child_table('data.property_of_property_mapping'); - --- 8 -ALTER TABLE data.column DROP COLUMN fk_meta_data; -ALTER TABLE data.column_vt DROP COLUMN fk_meta_data; - --- 9 -ALTER TABLE data.column ADD COLUMN fk_column_type integer not null REFERENCES system.system_type (pk_entity); -ALTER TABLE data.column_vt ADD COLUMN fk_column_type integer not null REFERENCES system.system_type (pk_entity); - --- 10 -ALTER TABLE data.column ADD COLUMN fk_original_column integer REFERENCES data.column (pk_entity); -ALTER TABLE data.column_vt ADD COLUMN fk_original_column integer REFERENCES data.column (pk_entity); - --- 11 -ALTER TABLE data.column ADD COLUMN is_imported BOOLEAN NOT NULL DEFAULT false; -ALTER TABLE data.column_vt ADD COLUMN is_imported BOOLEAN NOT NULL; - --- 12 -ALTER TABLE data.cell ADD COLUMN numeric_value NUMERIC; -ALTER TABLE data.cell_vt ADD COLUMN numeric_value NUMERIC; - --- 13 -ALTER TABLE data.factoid_role DROP COLUMN fk_range_cell; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_range_cell; -ALTER TABLE data.factoid_role DROP COLUMN fk_range_chunk; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_range_chunk; - --- 14 -ALTER TABLE data.factoid_role ADD COLUMN fk_data_range integer; -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_data_range integer; - --- 15 -ALTER TABLE data.factoid_role ADD COLUMN fk_info_value_range integer; -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_info_value_range integer; - --- 16 -ALTER TABLE data.data_association RENAME COLUMN fk_info_range TO fk_info_value_range; -ALTER TABLE data.data_association_vt RENAME COLUMN fk_info_range TO fk_info_value_range; - --- 17 -ALTER TABLE data.data_association DROP COLUMN fk_info_domain; -ALTER TABLE data.data_association_vt DROP COLUMN fk_info_domain; - --- 18 -CREATE TABLE data.property_of_property - ( - fk_property_of_property INTEGER NOT NULL REFERENCES data_for_history.property_of_property (dfh_pk_property_of_property), - fk_domain_factoid_role INTEGER REFERENCES data.factoid_role (pk_entity), - fk_domain_data_association INTEGER REFERENCES data.data_association (pk_entity), - fk_data_range INTEGER NOT NULL, - fk_info_value_range INTEGER NOT NULL - ) -INHERITS (data.entity); - -SELECT commons.init_entity_child_table('data.property_of_property'); diff --git a/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-down.sql b/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-down.sql deleted file mode 100644 index e0b0673c6..000000000 --- a/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-down.sql +++ /dev/null @@ -1,61 +0,0 @@ --- 2 -ALTER TABLE projects.argument DROP COLUMN fk_project; -ALTER TABLE projects.argument_vt DROP COLUMN fk_project; - -ALTER TABLE projects.argument RENAME COLUMN fk_argument_method_type TO fk_assertion_method_type; -ALTER TABLE projects.argument_vt RENAME COLUMN fk_argument_method_type TO fk_assertion_method_type; - -ALTER TABLE projects.argument RENAME COLUMN is_based_on_reliability TO source_reliability; -ALTER TABLE projects.argument_vt RENAME COLUMN is_based_on_reliability TO source_reliability; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_data_entity; -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_data_entity; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_info_entity; -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_info_entity; - -ALTER TABLE projects.argument DROP COLUMN fk_is_about_info_entity; -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_about_info_entity; - --- 1 -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_cell integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_factoid_role integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_persistent_item integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_entity_association integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_role integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_about_entity_association integer NOT NULL; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_about_role integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_cell integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_factoid_role integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_persistent_item integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_entity_association integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_role integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_about_entity_association integer NOT NULL; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_about_role integer NOT NULL; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-up.sql b/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-up.sql deleted file mode 100644 index 96896aba6..000000000 --- a/server/db-migrate/migrations/sqls/20190516065758-pro-t-argument-refactor-up.sql +++ /dev/null @@ -1,59 +0,0 @@ --- 1 -ALTER TABLE projects.argument DROP COLUMN fk_is_about_role; - -ALTER TABLE projects.argument DROP COLUMN fk_is_about_entity_association; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_role; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_entity_association; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_persistent_item; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_factoid_role; - -ALTER TABLE projects.argument DROP COLUMN fk_is_based_on_cell; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_about_role; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_about_entity_association; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_role; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_entity_association; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_persistent_item; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_factoid_role; - -ALTER TABLE projects.argument_vt DROP COLUMN fk_is_based_on_cell; - - --- 2 -ALTER TABLE projects.argument - ADD COLUMN fk_is_about_info_entity integer; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_about_info_entity integer; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_info_entity integer; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_info_entity integer; - -ALTER TABLE projects.argument - ADD COLUMN fk_is_based_on_data_entity integer; - -ALTER TABLE projects.argument_vt - ADD COLUMN fk_is_based_on_data_entity integer; - -ALTER TABLE projects.argument RENAME COLUMN source_reliability TO is_based_on_reliability; -ALTER TABLE projects.argument_vt RENAME COLUMN source_reliability TO is_based_on_reliability; - -ALTER TABLE projects.argument RENAME COLUMN fk_assertion_method_type TO fk_argument_method_type; -ALTER TABLE projects.argument_vt RENAME COLUMN fk_assertion_method_type TO fk_argument_method_type; - -ALTER TABLE projects.argument - ADD COLUMN fk_project integer NOT NULL REFERENCES projects.project (pk_entity); -ALTER TABLE projects.argument_vt - ADD COLUMN fk_project integer NOT NULL REFERENCES projects.project (pk_entity); diff --git a/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-down.sql b/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-down.sql deleted file mode 100644 index bdf2e6082..000000000 --- a/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 2 -DROP VIEW information.v_dimension; - --- 1 -DROP TABLE information.dimension; -DROP TABLE information.dimension_vt; diff --git a/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-up.sql b/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-up.sql deleted file mode 100644 index d2973917f..000000000 --- a/server/db-migrate/migrations/sqls/20190516073414-inf-t-dimension-up.sql +++ /dev/null @@ -1,19 +0,0 @@ --- 1 -CREATE TABLE information.dimension ( - fk_class INTEGER NOT NULL REFERENCES data_for_history.class (dfh_pk_class), - fk_measurement_unit INTEGER NOT NULL REFERENCES information.persistent_item (pk_entity), - numeric_value NUMERIC NOT NULL -) -INHERITS ( - information.entity -); - -SELECT - commons.init_entity_child_table ('information.dimension'); - -DROP TRIGGER create_entity_version_key ON information.dimension; -DROP TRIGGER update_entity_version_key ON information.dimension; - --- 2 -CREATE VIEW information.v_dimension AS -SELECT * FROM information.dimension; diff --git a/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-down.sql deleted file mode 100644 index 4c05a6547..000000000 --- a/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-down.sql +++ /dev/null @@ -1,5 +0,0 @@ --- 2 -DROP TRIGGER on_insert ON information.v_dimension; - --- 1 -DROP FUNCTION information.v_dimension_find_or_create(); diff --git a/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-up.sql deleted file mode 100644 index bf0e70bdb..000000000 --- a/server/db-migrate/migrations/sqls/20190516074322-inf-v-dimension-find-or-create-up.sql +++ /dev/null @@ -1,60 +0,0 @@ --- 1 -CREATE FUNCTION information.v_dimension_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_dimension; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.dimension - WHERE - fk_class = NEW.fk_class - AND fk_measurement_unit = NEW.fk_measurement_unit - AND numeric_value = NEW.numeric_value; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.dimension ( - fk_class, - fk_measurement_unit, - numeric_value - ) - VALUES ( - NEW.fk_class, - NEW.fk_measurement_unit, - NEW.numeric_value - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_dimension - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; - --- 2 -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_dimension - FOR EACH ROW - EXECUTE PROCEDURE information.v_dimension_find_or_create(); diff --git a/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-down.sql b/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-down.sql deleted file mode 100644 index 691486393..000000000 --- a/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-up.sql b/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-up.sql deleted file mode 100644 index 945eab716..000000000 --- a/server/db-migrate/migrations/sqls/20190516080250-drop-deprecated-pks-and-sequences-up.sql +++ /dev/null @@ -1,369 +0,0 @@ -ALTER TABLE data.digital DROP COLUMN IF EXISTS _deprecated_pk_digital_object; -ALTER TABLE data.digital_vt DROP COLUMN IF EXISTS _deprecated_pk_digital_object; -ALTER TABLE data.digital DROP COLUMN IF EXISTS _deprecated_js_quill_data; -ALTER TABLE data.digital_vt DROP COLUMN IF EXISTS _deprecated_js_quill_data; --- DROP SEQUENCE data.digital_object_pk_digital_object_seq; - -ALTER TABLE information.appellation DROP COLUMN IF EXISTS _deprecated_pk_appellation; -ALTER TABLE information.appellation_vt DROP COLUMN IF EXISTS _deprecated_pk_appellation; -ALTER TABLE information.appellation DROP COLUMN IF EXISTS _deprecated_appellation_label; -ALTER TABLE information.appellation_vt DROP COLUMN IF EXISTS _deprecated_appellation_label; --- DROP SEQUENCE information.appellation_pk_appellation_seq; - -ALTER TABLE information.entity_association DROP COLUMN IF EXISTS pk_entity_association; -ALTER TABLE information.entity_association_vt DROP COLUMN IF EXISTS pk_entity_association; --- DROP SEQUENCE information.entity_association_pk_entity_association_seq; - - -DROP VIEW information.v_persistent_item; -ALTER TABLE information.persistent_item DROP COLUMN IF EXISTS _deprecated_pk_persistent_item; -ALTER TABLE information.persistent_item_vt DROP COLUMN IF EXISTS pk_persistent_item; -CREATE VIEW information.v_persistent_item AS SELECT * FROM information.persistent_item; -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_persistent_item - FOR EACH ROW - EXECUTE PROCEDURE information.v_persistent_item_find_or_create(); - --- DROP SEQUENCE information.persistent_item_pk_persistent_item_seq; - -ALTER TABLE information.role DROP COLUMN IF EXISTS _deprecated_pk_role; -ALTER TABLE information.role_vt DROP COLUMN IF EXISTS pk_role; --- DROP SEQUENCE information.role_pk_role_seq; - -ALTER TABLE information.temporal_entity DROP COLUMN IF EXISTS _deprecated_pk_temporal_entity; -ALTER TABLE information.temporal_entity_vt DROP COLUMN IF EXISTS pk_temporal_entity; --- DROP SEQUENCE information.temporal_entity_pk_temporal_entity_seq; - -DROP view warehouse.v_entity_preview; -DROP view warehouse.v_entity_preview_non_recursive ; -DROP view warehouse.v_te_en_time_span_per_project_and_repo; -DROP view information.v_time_primitive; -ALTER TABLE information.time_primitive DROP COLUMN IF EXISTS pk_time_primitive; -ALTER TABLE information.time_primitive_vt DROP COLUMN IF EXISTS pk_time_primitive; --- DROP SEQUENCE information.time_primitive_pk_time_primitive_seq; - -DROP TABLE IF EXISTS information._deprecated_type_namespace_rel; -DROP TABLE IF EXISTS information._deprecated_type_namespace_rel_vt; - -DROP TABLE IF EXISTS information._deprecated_namespace; -DROP TABLE IF EXISTS information._deprecated_namespace_vt; - -DROP TABLE IF EXISTS projects._deprecated_label; -DROP TABLE IF EXISTS projects._deprecated_label_vt; --- DROP SEQUENCE projects.label_pk_label_seq; -DROP VIEW projects.v_info_proj_rel; -ALTER TABLE projects.info_proj_rel DROP COLUMN IF EXISTS _deprecated_pk_entity_version_project_rel; -ALTER TABLE projects.info_proj_rel_vt DROP COLUMN IF EXISTS _deprecated_pk_entity_version_project_rel; -ALTER TABLE projects.info_proj_rel DROP COLUMN IF EXISTS _deprecated_fk_project; -ALTER TABLE projects.info_proj_rel_vt DROP COLUMN IF EXISTS _deprecated_fk_project; -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS - SELECT * FROM projects.info_proj_rel; -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON projects.v_info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE projects.v_info_proj_rel_update_or_creat(); - - - --- DROP SEQUENCE projects.entity_version_project_rel_pk_entity_version_project_rel_seq; - -ALTER TABLE projects.project DROP COLUMN IF EXISTS _deprecated_pk_project; -ALTER TABLE projects.project_vt DROP COLUMN IF EXISTS _deprecated_pk_project; -ALTER TABLE projects.project DROP COLUMN IF EXISTS _deprecated_fk_language; -ALTER TABLE projects.project_vt DROP COLUMN IF EXISTS _deprecated_fk_language; --- DROP SEQUENCE projects.project_pk_project_seq; - -ALTER TABLE projects.text_property DROP COLUMN IF EXISTS _deprecated_pk_text_property; -ALTER TABLE projects.text_property_vt DROP COLUMN IF EXISTS _deprecated_pk_text_property; -ALTER TABLE projects.text_property DROP COLUMN IF EXISTS _deprecated_text_property; -ALTER TABLE projects.text_property_vt DROP COLUMN IF EXISTS _deprecated_text_property; -ALTER TABLE projects.text_property DROP COLUMN IF EXISTS _deprecated_text_property_xml; -ALTER TABLE projects.text_property_vt DROP COLUMN IF EXISTS _deprecated_text_property_xml; -ALTER TABLE projects.text_property DROP COLUMN IF EXISTS _deprecated_fk_language; -ALTER TABLE projects.text_property_vt DROP COLUMN IF EXISTS _deprecated_fk_language; - --- DROP SEQUENCE projects.text_property_pk_text_property_seq; - - - - -CREATE VIEW information.v_time_primitive AS - SELECT * FROM information.time_primitive; - -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM projects.info_proj_rel epr - JOIN information.v_role r ON r.pk_entity = epr.fk_entity - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE epr.is_in_project = true - UNION - SELECT r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity AND r.rank_for_te_ent = 1 - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN role_with_time_primitive.fk_property = 71 THEN 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN 'p82b'::text - ELSE role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-down.sql b/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-down.sql deleted file mode 100644 index f829f9554..000000000 --- a/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-down.sql +++ /dev/null @@ -1,120 +0,0 @@ --- 2 -CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.text_property - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - - $BODY$; - -CREATE TRIGGER _01_sync_quill_doc_and_string - INSTEAD OF INSERT - ON information.v_text_property - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); - ---- 1 -CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.v_appellation; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.appellation - WHERE - quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - quill_doc, - fk_class - ) - VALUES ( - NEW.quill_doc, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - -ALTER FUNCTION information.v_appellation_find_or_create() - OWNER TO postgres; - -CREATE TRIGGER _01_sync_quill_doc_and_string - INSTEAD OF INSERT - ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-up.sql b/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-up.sql deleted file mode 100644 index 7fa4e06b4..000000000 --- a/server/db-migrate/migrations/sqls/20190516115013-inf-refactor-text-children-up.sql +++ /dev/null @@ -1,121 +0,0 @@ ---- 1 - -DROP TRIGGER _01_sync_quill_doc_and_string ON information.v_appellation; - -CREATE OR REPLACE FUNCTION information.v_appellation_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_appellation; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.v_appellation - WHERE - string = COALESCE(NEW.string, commons.quill_doc_to_string(NEW.quill_doc)) - AND fk_class = NEW.fk_class; - - RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.appellation ( - string, - quill_doc, - fk_class - ) - VALUES ( - NEW.string, - NEW.quill_doc, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - SELECT * FROM INTO resulting_row information.v_appellation - WHERE pk_entity = resulting_pk; - - RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - RETURN resulting_row; - END; - $BODY$; - - --- 2 - -DROP TRIGGER _01_sync_quill_doc_and_string ON information.v_text_property; - -CREATE OR REPLACE FUNCTION information.v_text_property_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - - DECLARE - resulting_pk integer; - resulting_row information.v_text_property; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.v_text_property - WHERE - string = COALESCE(NEW.string, commons.quill_doc_to_string(NEW.quill_doc)) - AND fk_class_field = NEW.fk_class_field - AND fk_concerned_entity = NEW.fk_concerned_entity - AND fk_language = NEW.fk_language; - - -- RAISE INFO 'result of select: %', resulting_pk; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.text_property ( - string, - quill_doc, - fk_class_field, - fk_concerned_entity, - fk_language - ) - VALUES ( - NEW.string, - NEW.quill_doc::jsonb, - NEW.fk_class_field, - NEW.fk_concerned_entity, - NEW.fk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - SELECT * FROM INTO resulting_row information.v_text_property - WHERE pk_entity = resulting_pk; - - -- RAISE INFO 'result of insert: %', resulting_pk; - END IF; - - RETURN resulting_row; - END; - - $BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-down.sql deleted file mode 100644 index 87c340ac2..000000000 --- a/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TRIGGER on_insert ON information.v_time_primitive; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-up.sql deleted file mode 100644 index e3100e77e..000000000 --- a/server/db-migrate/migrations/sqls/20190516124905-inf-refactor-time-primitive-find-or-create-up.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_time_primitive - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_find_or_create(); - diff --git a/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-down.sql deleted file mode 100644 index db6a72cd9..000000000 --- a/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-down.sql +++ /dev/null @@ -1,53 +0,0 @@ -CREATE OR REPLACE FUNCTION information.v_place_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.v_place; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT - *, - NEW.long, - NEW.lat - FROM INTO resulting_row information.place - WHERE geo_point = ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.place ( - geo_point, - fk_class - ) - VALUES ( - ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT - *, - ST_X(geo_point::geometry) as long, - ST_Y(geo_point::geometry) as lat - FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - diff --git a/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-up.sql deleted file mode 100644 index 8afeff092..000000000 --- a/server/db-migrate/migrations/sqls/20190516125723-inf-refactor-place-find-or-create-up.sql +++ /dev/null @@ -1,50 +0,0 @@ -CREATE OR REPLACE FUNCTION information.v_place_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_place; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT - * - FROM INTO resulting_row information.v_place - WHERE geo_point = ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography - AND fk_class = NEW.fk_class; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.place ( - geo_point, - fk_class - ) - VALUES ( - ST_SetSRID(ST_MakePoint(NEW.long, NEW.lat), 4326)::geography, - NEW.fk_class - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - SELECT * FROM INTO resulting_row information.v_place - WHERE pk_entity = resulting_pk; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; - diff --git a/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-down.sql b/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-down.sql deleted file mode 100644 index 53fc67c9c..000000000 --- a/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-down.sql +++ /dev/null @@ -1,109 +0,0 @@ --- 2 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__get_type_label() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_type_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_type IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET type_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_type - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $BODY$; - --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - has_type_properties INT[] = ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.v_entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (ARRAY[1110, 1190, 1205, 1206, 1214, 1204, 1066]) - AND ea.fk_info_domain = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - WHERE p.dfh_pk_property = ANY (has_type_properties) - AND ea.fk_info_domain = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-up.sql b/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-up.sql deleted file mode 100644 index c72c925ef..000000000 --- a/server/db-migrate/migrations/sqls/20190516131842-war-refactor-create-fk-type-fn-up.sql +++ /dev/null @@ -1,115 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.v_entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN system.class_has_type_property p ON ea.fk_property = p.fk_property - WHERE ea.fk_info_domain = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN system.class_has_type_property p ON ea.fk_property = p.fk_property - WHERE ea.fk_info_domain = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; - - --- 2 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__get_type_label() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_type_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_type IS NOT NULL) THEN - - UPDATE warehouse.entity_preview - SET type_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_type - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - - ELSE - - UPDATE warehouse.entity_preview - SET type_label = NULL - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - - END IF; - - RETURN NEW; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-down.sql b/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-down.sql deleted file mode 100644 index 76a9a2b17..000000000 --- a/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-down.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE system.system_relevant_class RENAME COLUMN required_by_basics TO required_by_contr_vocabs; -ALTER TABLE system.system_relevant_class_vt RENAME COLUMN required_by_basics TO required_by_contr_vocabs; - -ALTER TABLE system.system_relevant_class DROP COLUMN excluded_from_entities; -ALTER TABLE system.system_relevant_class_vt DROP COLUMN excluded_from_entities; diff --git a/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-up.sql b/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-up.sql deleted file mode 100644 index a02a89396..000000000 --- a/server/db-migrate/migrations/sqls/20190516161645-sys-t-system-relevant-classes-up.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE system.system_relevant_class RENAME COLUMN required_by_contr_vocabs TO required_by_basics; -ALTER TABLE system.system_relevant_class_vt RENAME COLUMN required_by_contr_vocabs TO required_by_basics; - -ALTER TABLE system.system_relevant_class ADD COLUMN excluded_from_entities BOOLEAN; -ALTER TABLE system.system_relevant_class_vt ADD COLUMN excluded_from_entities BOOLEAN; diff --git a/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-down.sql b/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-down.sql deleted file mode 100644 index 3a7505bfc..000000000 --- a/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-down.sql +++ /dev/null @@ -1,46 +0,0 @@ --- 2 -DROP VIEW data.v_digital_version; -CREATE OR REPLACE VIEW data.v_digital_version AS - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital v -UNION ALL - SELECT v.pk_entity, - v.pk_text, - v.schema_name, - v.table_name, - v.notes, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.quill_doc, - v.string, - v.entity_version, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital_vt v; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON data.v_digital_version - FOR EACH ROW - EXECUTE PROCEDURE data.v_digital_version_insert(); - - --- 1 -ALTER TABLE data.digital_vt DROP COLUMN fk_system_type; -ALTER TABLE data.digital_vt DROP COLUMN metadata; diff --git a/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-up.sql b/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-up.sql deleted file mode 100644 index e34245dcd..000000000 --- a/server/db-migrate/migrations/sqls/20190524151304-dat-v-digital-version-update-up.sql +++ /dev/null @@ -1,57 +0,0 @@ --- 1 -ALTER TABLE data.digital_vt - ADD COLUMN metadata jsonb; - -ALTER TABLE data.digital_vt - ADD COLUMN fk_system_type integer; - --- 2 -DROP VIEW data.v_digital_version; - -CREATE OR REPLACE VIEW data.v_digital_version AS -SELECT - v.pk_entity, - v.schema_name, - v.table_name, - v.entity_version, - v.notes, - v.fk_namespace, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.metadata, - v.pk_text, - v.quill_doc, - v.string, - v.fk_system_type, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat -FROM - data.digital v -UNION ALL -SELECT - v.pk_entity, - v.schema_name, - v.table_name, - v.entity_version, - v.notes, - v.fk_namespace, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.metadata, - v.pk_text, - v.quill_doc, - v.string, - v.fk_system_type, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat -FROM - data.digital_vt v; - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON data.v_digital_version -FOR EACH ROW -EXECUTE PROCEDURE data.v_digital_version_insert (); - diff --git a/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-down.sql b/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-down.sql deleted file mode 100644 index 1b5413afa..000000000 --- a/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-down.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -DROP VIEW system.v_has_type_preview; - diff --git a/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-up.sql b/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-up.sql deleted file mode 100644 index 14a298565..000000000 --- a/server/db-migrate/migrations/sqls/20190525081925-sys-v-has-type-preview-up.sql +++ /dev/null @@ -1,15 +0,0 @@ --- 1 -CREATE VIEW system.v_has_type_preview AS ( - SELECT - ctp.pk_entity, - cpre1.dfh_pk_class AS pk_typed_class, - cpre1.class_label AS typed_class_label, - p.dfh_pk_property, - concat_ws(': ', p.dfh_identifier_in_namespace, p.dfh_standard_label) property_label, - cpre2.dfh_pk_class AS pk_type_class, - cpre2.class_label AS type_class_label - FROM - system.class_has_type_property ctp - JOIN data_for_history.property p ON p.dfh_pk_property = ctp.fk_property - JOIN information.v_class_preview cpre1 ON cpre1.dfh_pk_class = ctp.fk_class - JOIN information.v_class_preview cpre2 ON cpre2.dfh_pk_class = p.dfh_has_range) diff --git a/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-down.sql b/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-down.sql deleted file mode 100644 index c08d64101..000000000 --- a/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-down.sql +++ /dev/null @@ -1,35 +0,0 @@ - -CREATE OR REPLACE FUNCTION data.v_digital_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_concat_pk text; - resulting_row data.v_digital_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE data.digital SET - notes = NEW.notes, - quill_doc = NEW.quill_doc - WHERE pk_entity = NEW.pk_entity - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO data.digital (notes, quill_doc) - VALUES(NEW.notes, NEW.quill_doc) - RETURNING concat(pk_entity || '_' || entity_version)::text as pk_entity_version_concat INTO resulting_concat_pk; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row data.v_digital_version where pk_entity_version_concat = resulting_concat_pk; - - RETURN resulting_row; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-up.sql b/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-up.sql deleted file mode 100644 index 7807af515..000000000 --- a/server/db-migrate/migrations/sqls/20190526155143-dat-v-digital-update-trigger-fn-up.sql +++ /dev/null @@ -1,37 +0,0 @@ - -CREATE OR REPLACE FUNCTION data.v_digital_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - result data.digital; - resulting_row data.v_digital_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE data.digital SET - string = NEW.string, - quill_doc = NEW.quill_doc - WHERE pk_entity = NEW.pk_entity - RETURNING * INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO data.digital (string, quill_doc) - VALUES(NEW.string, NEW.quill_doc) - RETURNING * INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row data.v_digital_version - WHERE pk_entity = result.pk_entity - AND entity_version = result.entity_version; - - RETURN resulting_row; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190527083437-pro-add-namespace-up.sql b/server/db-migrate/migrations/sqls/20190527083437-pro-add-namespace-up.sql deleted file mode 100644 index f1d7b5c0c..000000000 --- a/server/db-migrate/migrations/sqls/20190527083437-pro-add-namespace-up.sql +++ /dev/null @@ -1,10 +0,0 @@ -INSERT INTO data.namespace (fk_project, standard_label) -WITH proj_without_nsmp AS ( - SELECT pk_entity FROM - projects.project - EXCEPT - SELECT fk_project FROM - data.namespace -) -SELECT pk_entity as fk_project, 'Default Namespace' -FROM proj_without_nsmp; diff --git a/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-down.sql b/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-down.sql deleted file mode 100644 index 63ce9cad1..000000000 --- a/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-down.sql +++ /dev/null @@ -1,45 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.string_to_quill_doc( - text text) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - IMMUTABLE -AS $BODY$ - DECLARE - latestId int; - ops jsonb; - char text; - BEGIN - ops = jsonb_build_array(); - latestId = 1; - - -- LOOP over text characters - FOREACH char IN ARRAY (SELECT chars FROM (SELECT regexp_split_to_array(text,'')) AS x(chars)) - LOOP - - IF char = E' -' THEN - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - ELSE - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('charid', to_json(latestId::text)::jsonb) - ); - END IF; - - latestId = latestId + 1; - END LOOP; - - ops = ops || jsonb_build_object( - 'insert', E' -', - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - - RETURN jsonb_build_object('latestId',latestId, 'ops', ops); - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-up.sql b/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-up.sql deleted file mode 100644 index 3a9e0492e..000000000 --- a/server/db-migrate/migrations/sqls/20190527101826-com-f-improve-string-to-quill-doc-up.sql +++ /dev/null @@ -1,48 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.string_to_quill_doc( - text text) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - IMMUTABLE -AS $BODY$ - DECLARE - latestId int; - ops jsonb; - char text; - BEGIN - ops = jsonb_build_array(); - latestId = 1; - - -- LOOP over text characters - FOREACH char IN ARRAY (SELECT - CASE - WHEN chars= ARRAY[''] THEN ARRAY[]::text[] - ELSE chars - END - FROM (SELECT regexp_split_to_array(text,'')) AS x(chars)) - LOOP - - IF char = E'\n' THEN - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - ELSE - ops = ops || jsonb_build_object( - 'insert', char, - 'attributes', jsonb_build_object('charid', to_json(latestId::text)::jsonb) - ); - END IF; - - latestId = latestId + 1; - END LOOP; - - ops = ops || jsonb_build_object( - 'insert', E'\n', - 'attributes', jsonb_build_object('blockid', to_json(latestId::text)::jsonb) - ); - - RETURN jsonb_build_object('latestId',latestId, 'ops', ops); - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-down.sql b/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-down.sql deleted file mode 100644 index 7baf8d17c..000000000 --- a/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-down.sql +++ /dev/null @@ -1,9 +0,0 @@ --- ALTER TABLE data.chunk DROP CONSTRAINT text_fkey; - -ALTER TABLE data.chunk - ADD CONSTRAINT text_fkey FOREIGN KEY (fk_entity_version, fk_text) - REFERENCES commons.text (entity_version, pk_text) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - -alter table commons.text alter column string set default ''::text; diff --git a/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-up.sql b/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-up.sql deleted file mode 100644 index 8bec92052..000000000 --- a/server/db-migrate/migrations/sqls/20190528154133-com-text-drop-default-string-value-up.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE commons.text ALTER COLUMN string DROP DEFAULT; - -ALTER TABLE data.chunk DROP CONSTRAINT text_fkey; - --- ALTER TABLE data.chunk --- ADD CONSTRAINT text_fkey FOREIGN KEY (fk_text) --- REFERENCES commons.text (pk_text); diff --git a/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-down.sql b/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-down.sql deleted file mode 100644 index 8d1e29391..000000000 --- a/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-down.sql +++ /dev/null @@ -1,35 +0,0 @@ - -CREATE OR REPLACE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_domain, ea.fk_data_domain)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_range, ea.fk_data_range)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; diff --git a/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-up.sql b/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-up.sql deleted file mode 100644 index 03fc8b52b..000000000 --- a/server/db-migrate/migrations/sqls/20190528195706-inf-v-entity-association-make-it-independent-from-dfh-property-up.sql +++ /dev/null @@ -1,35 +0,0 @@ - -CREATE OR REPLACE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_domain, ea.fk_data_domain)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_range, ea.fk_data_range)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - LEFT JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; diff --git a/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-down.sql b/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-down.sql deleted file mode 100644 index 473b0c43c..000000000 --- a/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 3 -DROP TRIGGER on_insert ON data.v_chunk; - --- 2 -DROP FUNCTION data.v_chunk_find_or_create(); - --- 1 -DROP VIEW data.v_chunk; diff --git a/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-up.sql b/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-up.sql deleted file mode 100644 index a61c72b61..000000000 --- a/server/db-migrate/migrations/sqls/20190529115142-dat-v-chunk-up.sql +++ /dev/null @@ -1,81 +0,0 @@ ---1 -CREATE VIEW data.v_chunk AS ( - SELECT * from data.chunk -); - --- 2 - -CREATE OR REPLACE FUNCTION data.v_chunk_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - same_chunk data.chunk; - same_chunk_version boolean; - resulting_row data.v_chunk; - resulting_pk int; - BEGIN - - ------ Search if such a chunk exists ----- - SELECT * FROM INTO same_chunk data.chunk - WHERE quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_text = NEW.fk_text; - - -- if not existing - IF same_chunk.pk_entity IS NULL THEN - - -- insert a new chunk - WITH _insert AS ( - INSERT INTO data.chunk ( - quill_doc, - fk_text, - fk_entity_version, - metadata, - fk_namespace - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_text, - NEW.fk_entity_version, - NEW.metadata, - NEW.fk_namespace - ) - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - - - -- if existing - ELSIF same_chunk.pk_entity IS NOT NULL THEN - - - -- if the fk_entity_version of the found chunk differs from the new - IF NEW.fk_entity_version != same_chunk.fk_entity_version THEN - -- update the chunk so that we keep track of when which version was annotated - UPDATE data.chunk - SET fk_entity_version = NEW.fk_entity_version - WHERE pk_entity = same_chunk.pk_entity; - END IF; - - -- set the resulting pk - resulting_pk = same_chunk.pk_entity; - - END IF; - - - -- select and return the latest chunk version from the view - SELECT * FROM INTO resulting_row data.v_chunk - WHERE pk_entity = resulting_pk; - RETURN resulting_row; -END; -$BODY$; - --- 3 -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON data.v_chunk - FOR EACH ROW - EXECUTE PROCEDURE data.v_chunk_find_or_create(); diff --git a/server/db-migrate/migrations/sqls/20190604161529-war-debugging-down.sql b/server/db-migrate/migrations/sqls/20190604161529-war-debugging-down.sql deleted file mode 100644 index 1afd31357..000000000 --- a/server/db-migrate/migrations/sqls/20190604161529-war-debugging-down.sql +++ /dev/null @@ -1,12 +0,0 @@ --- 2 -ALTER TABLE warehouse.entity_preview - DISABLE TRIGGER USER; - --- 1 -DROP TRIGGER before_update_on_entity_preview__related_full_texts ON warehouse.entity_preview; - -CREATE TRIGGER before_update_on_entity_preview__related_full_texts - BEFORE UPDATE OF related_full_texts - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); diff --git a/server/db-migrate/migrations/sqls/20190604161529-war-debugging-up.sql b/server/db-migrate/migrations/sqls/20190604161529-war-debugging-up.sql deleted file mode 100644 index 6fd3d3556..000000000 --- a/server/db-migrate/migrations/sqls/20190604161529-war-debugging-up.sql +++ /dev/null @@ -1,13 +0,0 @@ --- 1 -DROP TRIGGER before_update_on_entity_preview__related_full_texts ON warehouse.entity_preview; - -CREATE TRIGGER before_update_on_entity_preview__related_full_texts - BEFORE INSERT OR UPDATE OF related_full_texts - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - - --- 2 -ALTER TABLE warehouse.entity_preview - ENABLE TRIGGER USER; diff --git a/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-down.sql b/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-down.sql deleted file mode 100644 index 127a01d86..000000000 --- a/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP FUNCTION information.add_pe_its_to_projects(INTEGER[], INTEGER[], INTEGER); -DROP FUNCTION information.add_pe_it_to_project(INTEGER, INTEGER, INTEGER); diff --git a/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-up.sql b/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-up.sql deleted file mode 100644 index 9d59574eb..000000000 --- a/server/db-migrate/migrations/sqls/20190605133819-inf-add-pe-it-function-up.sql +++ /dev/null @@ -1,151 +0,0 @@ -CREATE OR REPLACE FUNCTION information.add_pe_it_to_project( - pk_entity INTEGER, - pk_project INTEGER, - account_id INTEGER - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - - EXECUTE format(' - - -- Relate given persistent item to given project -- - ---------------------------------------------------- - - WITH pe_it AS ( - select pk_entity, fk_class from information.persistent_item where pk_entity = %1$s - ), - -- Find "auto-add-properties" for all classes - -- TODO: Add a filter for properties enabled by given project - auto_add_properties AS ( - -- select the fk_class and the properties that are auto add because of a class_field_config - select p.dfh_has_domain as fk_class, p.dfh_pk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = true - UNION - select p.dfh_has_range as fk_class, p.dfh_pk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = false - UNION - -- select the fk_class and the properties that are auto add because of a property set - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = false - UNION - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = true - ), - -- Find all roles related to the given persistent item pk_entity - -- that are of an auto-add property - pe_it_roles AS ( - select r.pk_entity, r.fk_temporal_entity, r.fk_property, r.fk_entity, addp.max_quantifier, r.community_favorite_calendar as calendar - from information.v_role as r - inner join pe_it on r.fk_entity = pe_it.pk_entity - inner join auto_add_properties as addp on ( - addp.dfh_pk_property = r.fk_property AND addp.fk_class = pe_it.fk_class - ) - -- take only the max quantity of rows for that property, exclude repo-alternatives - WHERE r.rank_for_pe_it <= r.domain_max_quantifier OR r.domain_max_quantifier = -1 OR r.domain_max_quantifier IS NULL - ), - -- Find all temporal entities related to pe_it_roles - -- that are of an auto-add property - te_ents AS ( - select fk_temporal_entity as pk_entity - from pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - -- that are of an auto-add property - te_ent_roles AS ( - select r.pk_entity, r.fk_temporal_entity, r.fk_property, r.fk_entity, addp.max_quantifier, r.community_favorite_calendar as calendar - from information.v_role as r - inner join pe_it_roles as pi_r on pi_r.fk_temporal_entity = r.fk_temporal_entity - inner join information.temporal_entity as te on te.pk_entity = pi_r.fk_temporal_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = r.fk_property AND addp.fk_class = te.fk_class) - -- take only the max quantity of rows for that property, exclude repo-alternatives - WHERE r.rank_for_te_ent <= r.range_max_quantifier OR r.range_max_quantifier = -1 OR r.range_max_quantifier IS NULL - ), - -- find all entity associations that involve the pe_it - -- that are of an auto-add property - pe_it_entity_associations AS ( - -- where pe_it is domain - select ea.pk_entity, ea.fk_info_domain, ea.fk_property, ea.fk_info_domain, addp.max_quantifier - from information.v_entity_association as ea - inner join pe_it on ea.fk_info_domain = pe_it.pk_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = ea.fk_property AND addp.fk_class = pe_it.fk_class) - -- take only the max allowed rows - WHERE ea.rank_for_domain <= ea.range_max_quantifier OR ea.range_max_quantifier = -1 OR ea.range_max_quantifier IS NULL - - UNION - - -- where pe_it is range - select ea.pk_entity, ea.fk_info_domain, ea.fk_property, ea.fk_info_domain, addp.max_quantifier - from information.v_entity_association as ea - inner join pe_it on ea.fk_info_domain = pe_it.pk_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = ea.fk_property AND addp.fk_class = pe_it.fk_class) - -- take only the max allowed rows - WHERE ea.rank_for_range <= ea.domain_max_quantifier OR ea.domain_max_quantifier = -1 OR ea.domain_max_quantifier IS NULL - ), - -- TODO: find all entity associations that involve the te_ents (for types or mentionings of te_ents!) - - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select pk_entity, null::calendar_type as calendar from pe_it - UNION - select pk_entity, null::calendar_type as calendar from pe_it_entity_associations - UNION - select pk_entity, calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - ) - - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT %2$s, true, pk_entity, calendar, %3$s - from pk_entities_of_repo; - ', - pk_entity, - pk_project, - account_id - ); - - END $BODY$; - - - -CREATE OR REPLACE FUNCTION information.add_pe_its_to_projects( - entity_pks INTEGER[], - project_pks INTEGER[], - account_id INTEGER - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - - AS $BODY$ - DECLARE - pk_entity int; - pk_project int; - BEGIN - - FOREACH pk_entity IN ARRAY entity_pks - LOOP - FOREACH pk_project IN ARRAY project_pks - LOOP - PERFORM information.add_pe_it_to_project(pk_entity, pk_project, account_id); - END LOOP; - END LOOP; - - END $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-down.sql b/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-down.sql deleted file mode 100644 index 63477319d..000000000 --- a/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-down.sql +++ /dev/null @@ -1,88 +0,0 @@ --- 1 -ALTER TABLE data.entity DROP COLUMN id_for_import; - -ALTER TABLE data.avatar_vt DROP COLUMN id_for_import; -ALTER TABLE data.cell_vt DROP COLUMN id_for_import; -ALTER TABLE data.chunk_vt DROP COLUMN id_for_import; -ALTER TABLE data.class_column_mapping_vt DROP COLUMN id_for_import; -ALTER TABLE data.column_vt DROP COLUMN id_for_import; -ALTER TABLE data.data_association_mapping_vt DROP COLUMN id_for_import; -ALTER TABLE data.data_association_vt DROP COLUMN id_for_import; -ALTER TABLE data.digital_vt DROP COLUMN id_for_import; -ALTER TABLE data.factoid_mapping_vt DROP COLUMN id_for_import; -ALTER TABLE data.factoid_role_mapping_vt DROP COLUMN id_for_import; -ALTER TABLE data.factoid_role_vt DROP COLUMN id_for_import; -ALTER TABLE data.factoid_vt DROP COLUMN id_for_import; -ALTER TABLE data.namespace_vt DROP COLUMN id_for_import; -ALTER TABLE data.property_of_property_mapping_vt DROP COLUMN id_for_import; -ALTER TABLE data.property_of_property_vt DROP COLUMN id_for_import; -ALTER TABLE data.row_vt DROP COLUMN id_for_import; -ALTER TABLE data.text_property_vt DROP COLUMN id_for_import; -ALTER TABLE data.values_association_vt DROP COLUMN id_for_import; - - --- 2 -ALTER TABLE data.entity DROP COLUMN id_for_import_txt; - -ALTER TABLE data.avatar_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.cell_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.chunk_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.class_column_mapping_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.column_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.data_association_mapping_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.data_association_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.digital_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.factoid_mapping_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.factoid_role_mapping_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.factoid_role_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.factoid_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.namespace_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.property_of_property_mapping_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.property_of_property_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.row_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.text_property_vt DROP COLUMN id_for_import_txt; -ALTER TABLE data.values_association_vt DROP COLUMN id_for_import_txt; - --- 3 -ALTER TABLE data.entity DROP COLUMN fk_publication_status; - -ALTER TABLE data.avatar_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.cell_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.chunk_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.class_column_mapping_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.column_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.data_association_mapping_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.data_association_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.digital_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.factoid_mapping_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.factoid_role_mapping_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.factoid_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.namespace_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.property_of_property_mapping_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.property_of_property_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.row_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.text_property_vt DROP COLUMN fk_publication_status; -ALTER TABLE data.values_association_vt DROP COLUMN fk_publication_status; - --- 4 -ALTER TABLE data.entity DROP COLUMN fk_license; - -ALTER TABLE data.avatar_vt DROP COLUMN fk_license; -ALTER TABLE data.cell_vt DROP COLUMN fk_license; -ALTER TABLE data.chunk_vt DROP COLUMN fk_license; -ALTER TABLE data.class_column_mapping_vt DROP COLUMN fk_license; -ALTER TABLE data.column_vt DROP COLUMN fk_license; -ALTER TABLE data.data_association_mapping_vt DROP COLUMN fk_license; -ALTER TABLE data.data_association_vt DROP COLUMN fk_license; -ALTER TABLE data.digital_vt DROP COLUMN fk_license; -ALTER TABLE data.factoid_mapping_vt DROP COLUMN fk_license; -ALTER TABLE data.factoid_role_mapping_vt DROP COLUMN fk_license; -ALTER TABLE data.factoid_role_vt DROP COLUMN fk_license; -ALTER TABLE data.factoid_vt DROP COLUMN fk_license; -ALTER TABLE data.namespace_vt DROP COLUMN fk_license; -ALTER TABLE data.property_of_property_mapping_vt DROP COLUMN fk_license; -ALTER TABLE data.property_of_property_vt DROP COLUMN fk_license; -ALTER TABLE data.row_vt DROP COLUMN fk_license; -ALTER TABLE data.text_property_vt DROP COLUMN fk_license; -ALTER TABLE data.values_association_vt DROP COLUMN fk_license; diff --git a/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-up.sql b/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-up.sql deleted file mode 100644 index ad9f48ae0..000000000 --- a/server/db-migrate/migrations/sqls/20190606100039-dat-t-entity-update-up.sql +++ /dev/null @@ -1,88 +0,0 @@ --- 1 -ALTER TABLE data.entity ADD COLUMN id_for_import INT; - -ALTER TABLE data.avatar_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.cell_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.chunk_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.class_column_mapping_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.column_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.data_association_mapping_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.data_association_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.digital_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.factoid_mapping_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.factoid_role_mapping_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.factoid_role_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.factoid_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.namespace_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.property_of_property_mapping_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.property_of_property_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.row_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.text_property_vt ADD COLUMN id_for_import INT; -ALTER TABLE data.values_association_vt ADD COLUMN id_for_import INT; - - --- 2 -ALTER TABLE data.entity ADD COLUMN id_for_import_txt TEXT; - -ALTER TABLE data.avatar_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.cell_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.chunk_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.class_column_mapping_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.column_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.data_association_mapping_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.data_association_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.digital_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.factoid_mapping_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.factoid_role_mapping_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.factoid_role_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.factoid_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.namespace_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.property_of_property_mapping_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.property_of_property_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.row_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.text_property_vt ADD COLUMN id_for_import_txt TEXT; -ALTER TABLE data.values_association_vt ADD COLUMN id_for_import_txt TEXT; - --- 3 -ALTER TABLE data.entity ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); - -ALTER TABLE data.avatar_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.cell_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.chunk_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.class_column_mapping_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.column_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.data_association_mapping_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.data_association_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.digital_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_mapping_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_role_mapping_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.namespace_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.property_of_property_mapping_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.property_of_property_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.row_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.text_property_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.values_association_vt ADD COLUMN fk_publication_status INTEGER REFERENCES system.system_type (pk_entity); - --- 4 -ALTER TABLE data.entity ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); - -ALTER TABLE data.avatar_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.cell_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.chunk_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.class_column_mapping_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.column_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.data_association_mapping_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.data_association_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.digital_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_mapping_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_role_mapping_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_role_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.factoid_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.namespace_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.property_of_property_mapping_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.property_of_property_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.row_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.text_property_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); -ALTER TABLE data.values_association_vt ADD COLUMN fk_license INTEGER REFERENCES system.system_type (pk_entity); diff --git a/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-down.sql b/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-down.sql deleted file mode 100644 index 0fcd7e3d4..000000000 --- a/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-down.sql +++ /dev/null @@ -1,96 +0,0 @@ --- 2 - -CREATE OR REPLACE FUNCTION data.v_chunk_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - same_chunk data.chunk; - same_chunk_version boolean; - resulting_row data.v_chunk; - resulting_pk int; - BEGIN - - ------ Search if such a chunk exists ----- - SELECT * FROM INTO same_chunk data.chunk - WHERE quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_text = NEW.fk_text; - - -- if not existing - IF same_chunk.pk_entity IS NULL THEN - - -- insert a new chunk - WITH _insert AS ( - INSERT INTO data.chunk ( - quill_doc, - fk_text, - fk_entity_version, - metadata, - fk_namespace - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_text, - NEW.fk_entity_version, - NEW.metadata, - NEW.fk_namespace - ) - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- if existing - ELSIF same_chunk.pk_entity IS NOT NULL THEN - - -- if the fk_entity_version of the found chunk differs from the new - IF NEW.fk_entity_version != same_chunk.fk_entity_version THEN - -- update the chunk so that we keep track of when which version was annotated - UPDATE data.chunk - SET fk_entity_version = NEW.fk_entity_version - WHERE pk_entity = same_chunk.pk_entity; - END IF; - - -- set the resulting pk - resulting_pk = same_chunk.pk_entity; - - END IF; - - -- select and return the latest chunk version from the view - SELECT * FROM INTO resulting_row data.v_chunk - WHERE pk_entity = resulting_pk; - RETURN resulting_row; -END; -$BODY$; - - --- 1 - -DROP VIEW data.v_chunk; -CREATE OR REPLACE VIEW data.v_chunk AS - SELECT chunk.pk_entity, - chunk.schema_name, - chunk.table_name, - chunk.entity_version, - chunk.notes, - chunk.fk_namespace, - chunk.fk_creator, - chunk.fk_last_modifier, - chunk.tmsp_creation, - chunk.tmsp_last_modification, - chunk.sys_period, - chunk.metadata, - chunk.pk_text, - chunk.quill_doc, - chunk.string, - chunk.fk_text, - chunk.fk_entity_version - FROM data.chunk; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON data.v_chunk - FOR EACH ROW - EXECUTE PROCEDURE data.v_chunk_find_or_create(); - diff --git a/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-up.sql b/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-up.sql deleted file mode 100644 index ae917952c..000000000 --- a/server/db-migrate/migrations/sqls/20190606101525-dat-v-chunk-update-up.sql +++ /dev/null @@ -1,71 +0,0 @@ --- 1 -CREATE OR REPLACE VIEW data.v_chunk AS - SELECT * FROM data.chunk; - -CREATE OR REPLACE FUNCTION data.v_chunk_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - same_chunk data.chunk; - same_chunk_version boolean; - resulting_row data.v_chunk; - resulting_pk int; - BEGIN - - ------ Search if such a chunk exists ----- - SELECT * FROM INTO same_chunk data.chunk - WHERE quill_doc::jsonb = NEW.quill_doc::jsonb - AND fk_text = NEW.fk_text; - - -- if not existing - IF same_chunk.pk_entity IS NULL THEN - - -- insert a new chunk - WITH _insert AS ( - INSERT INTO data.chunk ( - quill_doc, - fk_text, - fk_entity_version, - metadata, - fk_namespace, - fk_license, - fk_publication_status - ) - VALUES ( - NEW.quill_doc::jsonb, - NEW.fk_text, - NEW.fk_entity_version, - NEW.metadata, - NEW.fk_namespace, - NEW.fk_license, - NEW.fk_publication_status - ) - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- if existing - ELSIF same_chunk.pk_entity IS NOT NULL THEN - - -- if the fk_entity_version of the found chunk differs from the new - IF NEW.fk_entity_version != same_chunk.fk_entity_version THEN - -- update the chunk so that we keep track of when which version was annotated - UPDATE data.chunk - SET fk_entity_version = NEW.fk_entity_version - WHERE pk_entity = same_chunk.pk_entity; - END IF; - - -- set the resulting pk - resulting_pk = same_chunk.pk_entity; - - END IF; - - -- select and return the latest chunk version from the view - SELECT * FROM INTO resulting_row data.v_chunk - WHERE pk_entity = resulting_pk; - RETURN resulting_row; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-down.sql b/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-down.sql deleted file mode 100644 index e2722a3ed..000000000 --- a/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-down.sql +++ /dev/null @@ -1,61 +0,0 @@ --- 1 - -ALTER TABLE data.digital ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.info_proj_rel ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_field ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.argument ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.dfh_class_proj_rel ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.project ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.app_context ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_field_property_rel ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_has_type_property ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_type ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE data.avatar ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.cell ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.chunk ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.class_column_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.column ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.data_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_role_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_role ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.namespace ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.row ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.data_association_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.values_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.associates_system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.class ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.class_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.label ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.profile ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE information.appellation ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.entity_association ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.language ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.persistent_item ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.place ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.role ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.temporal_entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.time_primitive ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.class_field_config ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.entity ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.query ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.visual ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.entity ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_relevant_class ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_relevant_type ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data.property_of_property_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE information.dimension ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); diff --git a/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-up.sql b/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-up.sql deleted file mode 100644 index 72a20352f..000000000 --- a/server/db-migrate/migrations/sqls/20190606104618-fix-wrong-sequences-up.sql +++ /dev/null @@ -1,61 +0,0 @@ --- 1 - -ALTER TABLE data.digital ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.info_proj_rel ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_field ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.argument ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.dfh_class_proj_rel ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.project ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.app_context ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_field_property_rel ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.class_has_type_property ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_type ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE data.avatar ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.cell ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.chunk ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.class_column_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.column ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.data_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_role_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.factoid_role ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.namespace ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.row ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.data_association_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.values_association ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.associates_system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.class ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.class_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.entity ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.label ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.profile ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property_profile_view ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.system_type ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE information.appellation ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.entity_association ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.language ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.persistent_item ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.place ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.role ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.temporal_entity ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.text_property ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE information.time_primitive ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.class_field_config ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.entity ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.query ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE projects.visual ALTER COLUMN pk_entity SET DEFAULT nextval('projects.entity_pk_entity_seq'::regclass); -ALTER TABLE system.entity ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_relevant_class ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE system.system_relevant_type ALTER COLUMN pk_entity SET DEFAULT nextval('system.entity_pk_entity_seq'::regclass); -ALTER TABLE data_for_history.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass); -ALTER TABLE data.property_of_property_mapping ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE data.property_of_property ALTER COLUMN pk_entity SET DEFAULT nextval('data.entity_pk_entity_seq'::regclass); -ALTER TABLE information.dimension ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); diff --git a/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-down.sql b/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-down.sql deleted file mode 100644 index fec4ac210..000000000 --- a/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-down.sql +++ /dev/null @@ -1,86 +0,0 @@ - - --- 1 - -CREATE OR REPLACE VIEW data.v_digital_version AS - SELECT v.pk_entity, - v.schema_name, - v.table_name, - v.entity_version, - v.notes, - v.fk_namespace, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.metadata, - v.pk_text, - v.quill_doc, - v.string, - v.fk_system_type, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital v -UNION ALL - SELECT v.pk_entity, - v.schema_name, - v.table_name, - v.entity_version, - v.notes, - v.fk_namespace, - v.fk_creator, - v.fk_last_modifier, - v.tmsp_creation, - v.tmsp_last_modification, - v.sys_period, - v.metadata, - v.pk_text, - v.quill_doc, - v.string, - v.fk_system_type, - concat((v.pk_text || '_'::text) || v.entity_version) AS pk_text_version_concat - FROM data.digital_vt v; - -CREATE FUNCTION data.v_digital_version_insert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - result data.digital; - resulting_row data.v_digital_version; - BEGIN - -- if there is a pk_entity, update the existing entity - IF (NEW.pk_entity IS NOT NULL) THEN - - UPDATE data.digital SET - string = NEW.string, - quill_doc = NEW.quill_doc - WHERE pk_entity = NEW.pk_entity - RETURNING * INTO result; - - -- else if there is no pk_entity, insert a new entity - ELSE - - INSERT INTO data.digital (string, quill_doc) - VALUES(NEW.string, NEW.quill_doc) - RETURNING * INTO result; - - END IF; - - -- in both cases return the pk_entity_version_concat, so that one can query the new version in the view - SELECT * FROM INTO resulting_row data.v_digital_version - WHERE pk_entity = result.pk_entity - AND entity_version = result.entity_version; - - RETURN resulting_row; - END; - $BODY$; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON data.v_digital_version - FOR EACH ROW - EXECUTE PROCEDURE data.v_digital_version_insert(); diff --git a/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-up.sql b/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-up.sql deleted file mode 100644 index 6cb8219bd..000000000 --- a/server/db-migrate/migrations/sqls/20190606115524-dat-v-digital-update-up.sql +++ /dev/null @@ -1,3 +0,0 @@ --- 1 -DROP VIEW data.v_digital_version; -DROP FUNCTION data.v_digital_version_insert(); diff --git a/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-down.sql b/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-down.sql deleted file mode 100644 index 1111d568b..000000000 --- a/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-down.sql +++ /dev/null @@ -1,14 +0,0 @@ --- 9 -ALTER TABLE projects.text_property_vt DROP COLUMN fk_language; - --- 2 -ALTER TABLE system.system_type_vt DROP COLUMN entity_version; -ALTER TABLE system.system_type_vt ADD COLUMN pk_system_type INT; - --- 1 -ALTER TABLE system.system_type DROP COLUMN definition; -ALTER TABLE system.system_type DROP COLUMN st_column_name; -ALTER TABLE system.system_type DROP COLUMN "group"; -ALTER TABLE system.system_type_vt DROP COLUMN definition; -ALTER TABLE system.system_type_vt DROP COLUMN st_column_name; -ALTER TABLE system.system_type_vt DROP COLUMN "group"; diff --git a/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-up.sql b/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-up.sql deleted file mode 100644 index dbc097628..000000000 --- a/server/db-migrate/migrations/sqls/20190606120608-sys-t-system-type-update-up.sql +++ /dev/null @@ -1,14 +0,0 @@ --- 1 -ALTER TABLE system.system_type ADD COLUMN definition text; -ALTER TABLE system.system_type ADD COLUMN st_column_name text; -ALTER TABLE system.system_type ADD COLUMN "group" text; -ALTER TABLE system.system_type_vt ADD COLUMN definition text; -ALTER TABLE system.system_type_vt ADD COLUMN st_column_name text; -ALTER TABLE system.system_type_vt ADD COLUMN "group" text; - --- 2 -ALTER TABLE system.system_type_vt ADD COLUMN entity_version INT; -ALTER TABLE system.system_type_vt DROP COLUMN pk_system_type; -- no way back - --- 9 -ALTER TABLE projects.text_property_vt ADD COLUMN fk_language INT; diff --git a/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-down.sql b/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-down.sql deleted file mode 100644 index 1f006e072..000000000 --- a/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE system.system_type rename column st_group TO "group"; -ALTER TABLE system.system_type_vt rename column st_group TO "group"; diff --git a/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-up.sql b/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-up.sql deleted file mode 100644 index 08be7586e..000000000 --- a/server/db-migrate/migrations/sqls/20190607152916-sys-t-system-type-rename-group-col-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE system.system_type rename column "group" TO st_group; -ALTER TABLE system.system_type_vt rename column "group" TO st_group; diff --git a/server/db-migrate/migrations/sqls/20190613082017-dat-update-down.sql b/server/db-migrate/migrations/sqls/20190613082017-dat-update-down.sql deleted file mode 100644 index 30b87e1c1..000000000 --- a/server/db-migrate/migrations/sqls/20190613082017-dat-update-down.sql +++ /dev/null @@ -1,96 +0,0 @@ --- 9 -DROP FUNCTION data.rebuild_digital_table(integer, integer[]); - --- 8 Indexes on column string of commons.text and all its children -DROP INDEX commons.text_string_idx; -DROP INDEX commons.text_vt_string_idx; - -DROP INDEX information.appellation_string_idx; -DROP INDEX information.appellation_vt_string_idx; - -DROP INDEX information.text_property_string_idx; -DROP INDEX information.text_property_vt_string_idx; - -DROP INDEX projects.text_property_string_idx; -DROP INDEX projects.text_property_vt_string_idx; - -DROP INDEX data.text_property_string_idx; -DROP INDEX data.text_property_vt_string_idx; - -DROP INDEX data.digital_string_idx; -DROP INDEX data.digital_vt_string_idx; - -DROP INDEX data.chunk_string_idx; -DROP INDEX data.chunk_vt_string_idx; - --- 7 -DROP INDEX data.cell_string_idx; -DROP INDEX data.cell_vt_string_idx; - -DROP INDEX data.cell_string_value_idx; -DROP INDEX data.cell_vt_string_value_idx; - -DROP INDEX data.cell_id_for_import_txt_idx; -DROP INDEX data.cell_vt_id_for_import_txt_idx; - --- 6 --- given - --- 5 -CREATE OR REPLACE FUNCTION commons.text__sync_quill_doc_and_string() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - string_is_new boolean; - quill_doc_is_new boolean; - BEGIN - - IF TG_OP = 'UPDATE' THEN - string_is_new = (NEW.string IS NOT NULL AND NEW.string != OLD.string); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL AND NEW.quill_doc != OLD.quill_doc); - ELSE - string_is_new = (NEW.string IS NOT NULL); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL); - END IF; - -- other code - - IF (string_is_new = true AND quill_doc_is_new = true) THEN - RAISE EXCEPTION 'You can not provide a string and a quill_doc at the same time when upserting a text.'; - ELSIF string_is_new = true THEN - NEW.quill_doc = commons.string_to_quill_doc(NEW.string); - ELSIF quill_doc_is_new = true THEN - NEW.string = commons.quill_doc_to_string(NEW.quill_doc); - ELSIF NEW.string IS NULL AND NEW.quill_doc IS NULL THEN - RAISE EXCEPTION 'No string or quill_doc provided on upsert of a text.'; - END IF; - - RETURN NEW; - END; - $BODY$; - --- 4 -ALTER TABLE data.cell ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.cell_vt ALTER COLUMN string SET NOT NULL; - -ALTER TABLE data.cell ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE data.cell_vt ALTER COLUMN quill_doc SET NOT NULL; - - --- 3 -ALTER TABLE commons.text ALTER COLUMN string SET NOT NULL; -ALTER TABLE commons.text_vt ALTER COLUMN string SET NOT NULL; - -ALTER TABLE commons.text ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE commons.text_vt ALTER COLUMN quill_doc SET NOT NULL; - - --- 2 -ALTER TABLE data.cell DROP COLUMN string_value; -ALTER TABLE data.cell_vt DROP COLUMN string_value; - --- 1 -ALTER TABLE data.row DROP COLUMN row_value; -ALTER TABLE data.row_vt DROP COLUMN row_value; diff --git a/server/db-migrate/migrations/sqls/20190613082017-dat-update-up.sql b/server/db-migrate/migrations/sqls/20190613082017-dat-update-up.sql deleted file mode 100644 index e914c3299..000000000 --- a/server/db-migrate/migrations/sqls/20190613082017-dat-update-up.sql +++ /dev/null @@ -1,237 +0,0 @@ --- 1 add column for storing cell values in the row table -ALTER TABLE data.row ADD COLUMN row_value jsonb; -ALTER TABLE data.row_vt ADD COLUMN row_value jsonb; - --- 2 add column for string values that do not need a quill_doc -ALTER TABLE data.cell ADD COLUMN string_value text; -ALTER TABLE data.cell_vt ADD COLUMN string_value text; - --- 3 DROP NOT NULL constraints of parent table commons.text -ALTER TABLE commons.text ALTER COLUMN string DROP NOT NULL; -ALTER TABLE commons.text_vt ALTER COLUMN string DROP NOT NULL; - -ALTER TABLE commons.text ALTER COLUMN quill_doc DROP NOT NULL; -ALTER TABLE commons.text_vt ALTER COLUMN quill_doc DROP NOT NULL; - --- 4 DROP NOT NULL constraints of data.cell -ALTER TABLE data.cell ALTER COLUMN string DROP NOT NULL; -ALTER TABLE data.cell_vt ALTER COLUMN string DROP NOT NULL; - -ALTER TABLE data.cell ALTER COLUMN quill_doc DROP NOT NULL; -ALTER TABLE data.cell_vt ALTER COLUMN quill_doc DROP NOT NULL; - --- 5 Change trigger function to allow string and quill_doc to be both NULL -CREATE OR REPLACE FUNCTION commons.text__sync_quill_doc_and_string() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - string_is_new boolean; - quill_doc_is_new boolean; - BEGIN - - IF TG_OP = 'UPDATE' THEN - string_is_new = (NEW.string IS NOT NULL AND NEW.string != OLD.string); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL AND NEW.quill_doc != OLD.quill_doc); - ELSE - string_is_new = (NEW.string IS NOT NULL); - quill_doc_is_new = (NEW.quill_doc IS NOT NULL); - END IF; - - -- If both string and quill_doc are NOT NULL, raise exception - IF (string_is_new = true AND quill_doc_is_new = true) THEN - RAISE EXCEPTION 'You can not provide a string and a quill_doc at the same time when upserting a text.'; - - -- If only string is NOT NULL create quill_doc - ELSIF string_is_new = true THEN - NEW.quill_doc = commons.string_to_quill_doc(NEW.string); - - -- If only quill_doc is NOT NULL create string - ELSIF quill_doc_is_new = true THEN - NEW.string = commons.quill_doc_to_string(NEW.quill_doc); - - -- If both string and quill_doc are NULL, do nothing - - END IF; - - RETURN NEW; - END; - $BODY$; - - --- 6 ADD NOT NULL constraints to all children of of table commons.text except data.cell -ALTER TABLE information.appellation ALTER COLUMN string SET NOT NULL; -ALTER TABLE information.appellation_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE information.appellation ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE information.appellation_vt ALTER COLUMN quill_doc SET NOT NULL; - -ALTER TABLE information.text_property ALTER COLUMN string SET NOT NULL; -ALTER TABLE information.text_property_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE information.text_property ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE information.text_property_vt ALTER COLUMN quill_doc SET NOT NULL; - -ALTER TABLE projects.text_property ALTER COLUMN string SET NOT NULL; -ALTER TABLE projects.text_property_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE projects.text_property ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE projects.text_property_vt ALTER COLUMN quill_doc SET NOT NULL; - -ALTER TABLE data.text_property ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.text_property_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.text_property ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE data.text_property_vt ALTER COLUMN quill_doc SET NOT NULL; - -ALTER TABLE data.digital ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.digital_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.digital ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE data.digital_vt ALTER COLUMN quill_doc SET NOT NULL; - -ALTER TABLE data.chunk ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.chunk_vt ALTER COLUMN string SET NOT NULL; -ALTER TABLE data.chunk ALTER COLUMN quill_doc SET NOT NULL; -ALTER TABLE data.chunk_vt ALTER COLUMN quill_doc SET NOT NULL; - - --- 7 Indexes on table cell -CREATE INDEX ON data.cell (string); -CREATE INDEX ON data.cell_vt (string); - -CREATE INDEX ON data.cell (string_value); -CREATE INDEX ON data.cell_vt (string_value); - -CREATE INDEX ON data.cell (id_for_import_txt); -CREATE INDEX ON data.cell_vt (id_for_import_txt); - - --- 8 Indexes on column string of commons.text and all its children -CREATE INDEX ON commons.text (string); -CREATE INDEX ON commons.text_vt (string); - -CREATE INDEX ON information.appellation (string); -CREATE INDEX ON information.appellation_vt (string); - -CREATE INDEX ON information.text_property (string); -CREATE INDEX ON information.text_property_vt (string); - -CREATE INDEX ON projects.text_property (string); -CREATE INDEX ON projects.text_property_vt (string); - -CREATE INDEX ON data.text_property (string); -CREATE INDEX ON data.text_property_vt (string); - -CREATE INDEX ON data.digital (string); -CREATE INDEX ON data.digital_vt (string); - -CREATE INDEX ON data.chunk (string); -CREATE INDEX ON data.chunk_vt (string); - - --- 9 - -CREATE OR REPLACE FUNCTION data.rebuild_digital_table( - id_digital integer, - column_list integer[]) - RETURNS text - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - -DECLARE - query_start text; - query_from text; - query text; - field text; - field_label text; - field_metadata json; - n integer = 1; - a integer; - output_query text; - -BEGIN - - query_start = 'DROP VIEW IF EXISTS tv_' || id_digital || '; - CREATE OR REPLACE TEMPORARY VIEW tv_' || id_digital || ' AS - SELECT dr.pk_entity'; - - query_from = ' FROM data.row dr'; - - - IF array_length(column_list, 1) > 0 THEN - - FOR a IN - - SELECT UNNEST(column_list) - - LOOP - - SELECT row_to_json((pk_entity,id_for_import_txt,fk_data_type)) into field_metadata - FROM data.column - WHERE pk_entity = a; - - - field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); - - IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN - field = 't'|| n ||'.numeric_value'; - ELSE - field = 't'|| n ||'.id_for_import_txt'; -- .string .id_for_import_txt - END IF; - - query_start = query_start || ', ' || field || ' AS ' || field_label; - - query_from = query_from || ' JOIN data.cell t' || n || ' ON dr.pk_entity = t' || n || '.fk_row AND t' || n || '.fk_column = ' || (field_metadata -> 'f1')::text; - - n = n + 1; - - -- RAISE NOTICE '%', query_start ; -- return current row of SELECT - - END LOOP; - - ELSE - - - FOR field_metadata IN - - SELECT row_to_json((pk_entity,id_for_import_txt,fk_data_type)) - FROM data.column - WHERE fk_digital = id_digital - ORDER BY pk_entity - - LOOP - - field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); - - IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN - field = 't'|| n ||'.numeric_value'; - ELSE - field = 't'|| n ||'.id_for_import_txt'; -- .string .id_for_import_txt - END IF; - - query_start = query_start || ', ' || field || ' AS ' || field_label; - - query_from = query_from || ' JOIN data.cell t' || n || ' ON dr.pk_entity = t' || n || '.fk_row AND t' || n || '.fk_column = ' || (field_metadata -> 'f1')::text; - - n = n + 1; - - -- RAISE NOTICE '%', query_start ; -- return current row of SELECT - - END LOOP; - - END IF; - - query := query_start || query_from || 'WHERE dr.fk_digital = ' || id_digital || ';'; - - RAISE NOTICE '%', query ; - - EXECUTE query; - - - output_query := 'SELECT * FROM tv_' || id_digital || ' LIMIT 10' ; - -RETURN output_query; -END; - -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-down.sql b/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-down.sql deleted file mode 100644 index c0a362b11..000000000 --- a/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-down.sql +++ /dev/null @@ -1,60 +0,0 @@ --- 1 -DROP INDEX data.cell_pk_entity_idx; -DROP INDEX data.class_column_mapping_pk_entity_idx; -DROP INDEX data.column_pk_entity_idx; -DROP INDEX data.data_association_pk_entity_idx; -DROP INDEX data.digital_pk_entity_idx; -DROP INDEX data.property_of_property_pk_entity_idx; -DROP INDEX data.factoid_pk_entity_idx; -DROP INDEX data.factoid_mapping_pk_entity_idx; -DROP INDEX data.property_of_property_mapping_pk_entity_idx; -DROP INDEX data.factoid_role_mapping_pk_entity_idx; -DROP INDEX data.factoid_role_pk_entity_idx; -DROP INDEX data.namespace_pk_entity_idx; -DROP INDEX data.row_pk_entity_idx; -DROP INDEX data.text_property_pk_entity_idx; -DROP INDEX data.data_association_mapping_pk_entity_idx; -DROP INDEX data.avatar_pk_entity_idx; -DROP INDEX data.chunk_pk_entity_idx; -DROP INDEX data_for_history.class_pk_entity_idx; -DROP INDEX data_for_history.class_profile_view_pk_entity_idx; -DROP INDEX data_for_history.property_of_property_pk_entity_idx; -DROP INDEX data_for_history.label_pk_entity_idx; -DROP INDEX data_for_history.profile_pk_entity_idx; -DROP INDEX data_for_history.property_pk_entity_idx; -DROP INDEX data_for_history.property_profile_view_pk_entity_idx; -DROP INDEX data_for_history.system_type_pk_entity_idx; -DROP INDEX data_for_history.text_property_pk_entity_idx; -DROP INDEX data_for_history.associates_system_type_pk_entity_idx; -DROP INDEX information.temporal_entity_pk_entity_idx; -DROP INDEX information.appellation_pk_entity_idx; -DROP INDEX information.entity_association_pk_entity_idx; -DROP INDEX information.language_pk_entity_idx; -DROP INDEX information.persistent_item_pk_entity_idx; -DROP INDEX information.place_pk_entity_idx; -DROP INDEX information.property_of_property_pk_entity_idx; -DROP INDEX information.role_pk_entity_idx; -DROP INDEX information.text_property_pk_entity_idx; -DROP INDEX information.time_primitive_pk_entity_idx; -DROP INDEX information.dimension_pk_entity_idx; -DROP INDEX projects.dfh_class_proj_rel_pk_entity_idx; -DROP INDEX projects.project_pk_entity_idx; -DROP INDEX projects.text_property_pk_entity_idx; -DROP INDEX projects.query_pk_entity_idx; -DROP INDEX projects.class_field_config_pk_entity_idx; -DROP INDEX projects.info_proj_rel_pk_entity_idx; -DROP INDEX projects.argument_pk_entity_idx; -DROP INDEX system.class_has_type_property_pk_entity_idx; -DROP INDEX system.system_type_pk_entity_idx; -DROP INDEX system.system_relevant_class_pk_entity_idx; -DROP INDEX system.system_relevant_type_pk_entity_idx; -DROP INDEX system.class_field_property_rel_pk_entity_idx; -DROP INDEX system.class_field_pk_entity_idx; -DROP INDEX system.app_context_pk_entity_idx; -DROP INDEX warehouse.entity_preview_pk_entity_idx; - --- 2 - -DROP INDEX data.cell_fk_row_idx; -DROP INDEX data.cell_fk_column_idx; -DROP INDEX data.row_fk_digital_idx; diff --git a/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-up.sql b/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-up.sql deleted file mode 100644 index 883276e7a..000000000 --- a/server/db-migrate/migrations/sqls/20190613134514-add-indexes-on-pk-entity-up.sql +++ /dev/null @@ -1,60 +0,0 @@ --- 1 -CREATE INDEX ON data.cell (pk_entity); -CREATE INDEX ON data.class_column_mapping (pk_entity); -CREATE INDEX ON data.column (pk_entity); -CREATE INDEX ON data.data_association (pk_entity); -CREATE INDEX ON data.digital (pk_entity); -CREATE INDEX ON data.property_of_property (pk_entity); -CREATE INDEX ON data.factoid (pk_entity); -CREATE INDEX ON data.factoid_mapping (pk_entity); -CREATE INDEX ON data.property_of_property_mapping (pk_entity); -CREATE INDEX ON data.factoid_role_mapping (pk_entity); -CREATE INDEX ON data.factoid_role (pk_entity); -CREATE INDEX ON data.namespace (pk_entity); -CREATE INDEX ON data.row (pk_entity); -CREATE INDEX ON data.text_property (pk_entity); -CREATE INDEX ON data.data_association_mapping (pk_entity); -CREATE INDEX ON data.avatar (pk_entity); -CREATE INDEX ON data.chunk (pk_entity); -CREATE INDEX ON data_for_history.class (pk_entity); -CREATE INDEX ON data_for_history.class_profile_view (pk_entity); -CREATE INDEX ON data_for_history.property_of_property (pk_entity); -CREATE INDEX ON data_for_history.label (pk_entity); -CREATE INDEX ON data_for_history.profile (pk_entity); -CREATE INDEX ON data_for_history.property (pk_entity); -CREATE INDEX ON data_for_history.property_profile_view (pk_entity); -CREATE INDEX ON data_for_history.system_type (pk_entity); -CREATE INDEX ON data_for_history.text_property (pk_entity); -CREATE INDEX ON data_for_history.associates_system_type (pk_entity); -CREATE INDEX ON information.temporal_entity (pk_entity); -CREATE INDEX ON information.appellation (pk_entity); -CREATE INDEX ON information.entity_association (pk_entity); -CREATE INDEX ON information.language (pk_entity); -CREATE INDEX ON information.persistent_item (pk_entity); -CREATE INDEX ON information.place (pk_entity); -CREATE INDEX ON information.property_of_property (pk_entity); -CREATE INDEX ON information.role (pk_entity); -CREATE INDEX ON information.text_property (pk_entity); -CREATE INDEX ON information.time_primitive (pk_entity); -CREATE INDEX ON information.dimension (pk_entity); -CREATE INDEX ON projects.dfh_class_proj_rel (pk_entity); -CREATE INDEX ON projects.project (pk_entity); -CREATE INDEX ON projects.text_property (pk_entity); -CREATE INDEX ON projects.query (pk_entity); -CREATE INDEX ON projects.class_field_config (pk_entity); -CREATE INDEX ON projects.info_proj_rel (pk_entity); -CREATE INDEX ON projects.argument (pk_entity); -CREATE INDEX ON system.class_has_type_property (pk_entity); -CREATE INDEX ON system.system_type (pk_entity); -CREATE INDEX ON system.system_relevant_class (pk_entity); -CREATE INDEX ON system.system_relevant_type (pk_entity); -CREATE INDEX ON system.class_field_property_rel (pk_entity); -CREATE INDEX ON system.class_field (pk_entity); -CREATE INDEX ON system.app_context (pk_entity); -CREATE INDEX ON warehouse.entity_preview (pk_entity); - --- 2 - -CREATE INDEX ON data.cell (fk_row); -CREATE INDEX ON data.cell (fk_column); -CREATE INDEX ON data.row (fk_digital); diff --git a/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-down.sql b/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-down.sql deleted file mode 100644 index 540e0d50f..000000000 --- a/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-down.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* Replace with your SQL commands */ -DROP INDEX projects.info_proj_rel_fk_entity_idx; - -DROP INDEX projects.info_proj_rel_fk_project_idx; - -DROP INDEX information.role_fk_entity_idx; - -DROP INDEX information.role_fk_temporal_entity_idx; - -DROP INDEX information.entity_association_fk_info_domain_idx; - -DROP INDEX information.entity_association_fk_info_range_idx; - -DROP INDEX information.text_property_fk_concerned_entity_idx; - diff --git a/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-up.sql b/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-up.sql deleted file mode 100644 index 5838918ca..000000000 --- a/server/db-migrate/migrations/sqls/20190613204105-add-indexes-on-relevant-fks-up.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* Replace with your SQL commands */ -CREATE INDEX ON projects.info_proj_rel (fk_entity); - -CREATE INDEX ON projects.info_proj_rel (fk_project); - -CREATE INDEX ON information.role (fk_entity); - -CREATE INDEX ON information.role (fk_temporal_entity); - -CREATE INDEX ON information.entity_association (fk_info_domain); - -CREATE INDEX ON information.entity_association (fk_info_range); - -CREATE INDEX ON information.text_property (fk_concerned_entity); diff --git a/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-down.sql b/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-down.sql deleted file mode 100644 index c8a7676a5..000000000 --- a/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-down.sql +++ /dev/null @@ -1,130 +0,0 @@ -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - PERFORM - - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_info_domain into _fk_info_domain - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_info_range into _fk_info_range - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, NULL::text]); - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-up.sql b/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-up.sql deleted file mode 100644 index 49a98359a..000000000 --- a/server/db-migrate/migrations/sqls/20190614053616-war-fix-superfluous-project-previews-up.sql +++ /dev/null @@ -1,164 +0,0 @@ -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; - BEGIN - - _fk_project = NEW.fk_project; - - SELECT table_name INTO _table_name - FROM information.entity e - WHERE e.pk_entity = NEW.fk_entity; - - - --------------------- text_property --------------------- - IF (SELECT _table_name = 'text_property') THEN - - SELECT t.fk_concerned_entity into _fk_entity - FROM information.text_property t - WHERE t.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]); - - - --------------------- role ----------------------------- - ELSIF (SELECT _table_name = 'role') THEN - - SELECT r.fk_entity into _fk_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - SELECT r.fk_temporal_entity into _fk_temporal_entity - FROM information.role r - WHERE r.pk_entity = NEW.fk_entity; - - select is_in_project into _domain_is_in_project - FROM projects.info_proj_rel - Where fk_entity = _fk_temporal_entity AND fk_project = _fk_project; - - select is_in_project into _range_is_in_project - FROM projects.info_proj_rel - Where fk_entity = _fk_entity AND fk_project = _fk_project; - - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - - ------------ init update of preview of domain entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, NULL::text]); - ------------ in project - IF (_domain_is_in_project = true) THEN - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill time span - warehouse.needs_update('entity_preview__fill_time_span'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_temporal_entity::text, _fk_project::text]); - END IF; - - ------------ init update of preview of range entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, NULL::text]); - ------------ in project - IF (_range_is_in_project = true) THEN - PERFORM - -- fill own entity label - warehouse.needs_update('entity_preview__fill_own_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update('entity_preview__fill_own_full_text'::text, ARRAY[_fk_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update('entity_preview__create_fk_entity_label'::text, ARRAY[_fk_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update('entity_preview__create_related_full_texts'::text, ARRAY[_fk_entity::text, _fk_project::text]); - END IF; - - - --------------------- entity_association ----------------- - ELSIF (SELECT _table_name = 'entity_association') THEN - SELECT ea.fk_info_domain into _fk_info_domain - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - SELECT ea.fk_info_range into _fk_info_range - FROM information.entity_association ea - WHERE ea.pk_entity = NEW.fk_entity; - - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - - PERFORM - - -- create fk type - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create_fk_type'::text, ARRAY[_fk_info_range::text, NULL::text]); - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF (SELECT _table_name IN ('temporal_entity', 'persistent_item')) THEN - - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - - IF (NEW.is_in_project = true) THEN - PERFORM - -- create fk type - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update('entity_preview__create'::text, ARRAY[NEW.fk_entity::text, NULL::text]); - - ELSIF (NEW.is_in_project = false) THEN - - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - - END IF; - END IF; - - - - RETURN NEW; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-down.sql b/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-down.sql deleted file mode 100644 index 522409fc9..000000000 --- a/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-down.sql +++ /dev/null @@ -1,29 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - label text; - entity_type text; - BEGIN - - INSERT INTO warehouse.class_preview (dfh_pk_class, class_label, entity_type) - SELECT v.dfh_pk_class, v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ON CONFLICT (dfh_pk_class) - DO - UPDATE - SET (class_label, entity_type) = ( - SELECT v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ); - - RETURN NEW; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-up.sql b/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-up.sql deleted file mode 100644 index 001502eea..000000000 --- a/server/db-migrate/migrations/sqls/20190617094318-war-bugfix-up.sql +++ /dev/null @@ -1,29 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - label text; - entity_type text; - BEGIN - - INSERT INTO warehouse.class_preview (dfh_pk_class, class_label, entity_type) - SELECT v.dfh_pk_class, v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ON CONFLICT ON CONSTRAINT dfh_pk_class_unique - DO - UPDATE - SET (class_label, entity_type) = ( - SELECT v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ); - - RETURN NEW; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-down.sql b/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-down.sql deleted file mode 100644 index b809d855a..000000000 --- a/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-down.sql +++ /dev/null @@ -1,164 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS SELECT * FROM warehouse.v_entity_preview; - - WITH previews_non_recursive AS ( - SELECT * FROM warehouse.temp - ), - fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-up.sql b/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-up.sql deleted file mode 100644 index 215c9f46d..000000000 --- a/server/db-migrate/migrations/sqls/20190618144032-war-rework-create-all-up.sql +++ /dev/null @@ -1,288 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - -- create temporary table with previews non recursive - CREATE TEMP TABLE temp_entity_preview_non_recursive AS SELECT * FROM warehouse.v_entity_preview_non_recursive; - - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS - WITH fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM temp_entity_preview_non_recursive t1 - LEFT JOIN temp_entity_preview_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - - - - WITH fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM warehouse.temp t1 - LEFT JOIN warehouse.temp t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-down.sql b/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-down.sql deleted file mode 100644 index 215c9f46d..000000000 --- a/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-down.sql +++ /dev/null @@ -1,288 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - -- create temporary table with previews non recursive - CREATE TEMP TABLE temp_entity_preview_non_recursive AS SELECT * FROM warehouse.v_entity_preview_non_recursive; - - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS - WITH fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM temp_entity_preview_non_recursive t1 - LEFT JOIN temp_entity_preview_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - - - - WITH fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM warehouse.temp t1 - LEFT JOIN warehouse.temp t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-up.sql b/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-up.sql deleted file mode 100644 index 7675bfdad..000000000 --- a/server/db-migrate/migrations/sqls/20190619094020-war-rework-create-all-2-up.sql +++ /dev/null @@ -1,391 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - - DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; - BEGIN - - t = clock_timestamp(); - - -- create temporary tables to create the temp_entity_preview_non_recursive - CREATE TEMP TABLE temp_entities AS SELECT * FROM warehouse.v_entities; - CREATE TEMP TABLE temp_own_entity_label AS SELECT * FROM warehouse.v_own_entity_label; - CREATE TEMP TABLE temp_te_en_time_span_per_project_and_repo AS SELECT * FROM warehouse.v_te_en_time_span_per_project_and_repo; - CREATE TEMP TABLE temp_own_full_text AS SELECT * FROM warehouse.v_own_full_text; - CREATE TEMP TABLE temp_fk_entity_label AS SELECT * FROM warehouse.v_fk_entity_label; - CREATE TEMP TABLE temp_fk_type AS SELECT * FROM warehouse.v_fk_type; - - -- create temporary table with previews non recursive - CREATE TEMP TABLE temp_entity_preview_non_recursive AS - WITH entities AS ( - SELECT temp_entities.pk_entity, - temp_entities.fk_project, - temp_entities.project, - temp_entities.fk_class, - temp_entities.table_name, - temp_entities.entity_type - FROM temp_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN temp_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN temp_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN temp_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN temp_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN temp_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - - - - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS - WITH fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM temp_entity_preview_non_recursive t1 - LEFT JOIN temp_entity_preview_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - - - - WITH fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM warehouse.temp t1 - LEFT JOIN warehouse.temp t2 - ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), - fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 - ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), - full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ), - related_full_text AS ( - SELECT t1.*, t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 - ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), - add_full_text AS ( - SELECT - *, - ( - SELECT array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, - array_to_string(array_agg(value), ', ') - ]::text[] , ', ') - FROM jsonb_each_text(f.related_full_texts) - ) as full_text - FROM related_full_text f - ), - add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t.full_text,'')), 'C') as ts_vector - FROM add_full_text t - ), - updated AS ( - SELECT * FROM add_ts_vector - ) - UPDATE warehouse.temp - SET entity_label = updated.entity_label - FROM updated - WHERE temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - - SELECT count(*) INTO number_of_unfinished - FROM warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - - - -- empty table entity_preview - DELETE from warehouse.entity_preview; - - INSERT INTO warehouse.entity_preview ( - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - ) - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector - FROM warehouse.temp; - - DROP TABLE warehouse.temp; - - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - - - RETURN TRUE; - - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-down.sql b/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-down.sql deleted file mode 100644 index 4c664a801..000000000 --- a/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-down.sql +++ /dev/null @@ -1,5 +0,0 @@ --- 1 -DROP VIEW warehouse.v_roles_per_project_and_repo_no_rank; - --- 0 -DROP VIEW information.v_role_tmp; diff --git a/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-up.sql b/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-up.sql deleted file mode 100644 index 258b41142..000000000 --- a/server/db-migrate/migrations/sqls/20190624081846-query-opimization-1-up.sql +++ /dev/null @@ -1,103 +0,0 @@ --- 0 -CREATE OR REPLACE VIEW information.v_role_tmp AS - SELECT t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM information.role t1 - JOIN data_for_history.property p ON t1.fk_property = p.dfh_pk_property - LEFT JOIN LATERAL ( - SELECT - count(pk_entity) is_in_project_count, - COALESCE(count(*) FILTER (WHERE ord_num = 0), 0::bigint) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY calendar) AS community_favorite_calendar - FROM projects.info_proj_rel - WHERE fk_entity = t1.pk_entity AND is_in_project = true - GROUP BY fk_entity - ) AS t2 ON TRUE; - - -CREATE OR REPLACE FUNCTION information.v_role_tmp_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_role_tmp; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.role - WHERE - fk_entity = NEW.fk_entity - AND fk_temporal_entity = NEW.fk_temporal_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.role ( - fk_entity, - fk_temporal_entity, - fk_property - ) - VALUES ( - NEW.fk_entity, - NEW.fk_temporal_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_role_tmp - WHERE pk_entity = resulting_pk; -RETURN resulting_row; - END; - $BODY$; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role_tmp - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_tmp_find_or_create(); - --- 1 -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo_no_rank AS - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS project - FROM information.v_role_tmp r - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - 0 AS project - FROM information.v_role_tmp r - WHERE r.is_in_project_count > 0; diff --git a/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-down.sql b/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-down.sql deleted file mode 100644 index f20df5494..000000000 --- a/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-down.sql +++ /dev/null @@ -1,134 +0,0 @@ --- 6 -DROP TRIGGER on_insert ON projects.v_info_proj_rel; - --- 5 -DROP FUNCTION projects.v_info_proj_rel_update_or_create(); - --- 4 - -CREATE FUNCTION projects.v_info_proj_rel_update_or_creat() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num = COALESCE(NEW.ord_num, resulting_row.ord_num), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - - --- 3 -DROP VIEW projects.v_info_proj_rel; -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.entity_version, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num_of_domain AS ord_num, - info_proj_rel.fk_project - FROM projects.info_proj_rel; - --- 2 -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON projects.v_info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE projects.v_info_proj_rel_update_or_creat(); - --- 1 -ALTER TABLE projects.info_proj_rel DROP COLUMN ord_num_of_range; -ALTER TABLE projects.info_proj_rel_vt DROP COLUMN ord_num_of_range; - -ALTER TABLE projects.info_proj_rel RENAME COLUMN ord_num_of_domain TO ord_num; -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN ord_num_of_domain TO ord_num; - -ALTER TABLE projects.info_proj_rel DROP COLUMN ord_num_of_text_property; -ALTER TABLE projects.info_proj_rel_vt DROP COLUMN ord_num_of_text_property; diff --git a/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-up.sql b/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-up.sql deleted file mode 100644 index 2c48c9219..000000000 --- a/server/db-migrate/migrations/sqls/20190624081849-pro-t-inf-proj-rel-add-proper-ord-num-cols-up.sql +++ /dev/null @@ -1,129 +0,0 @@ --- 1 add ord_num_of_range column. TODO: rename ord_num to ord_num_of_domain -ALTER TABLE projects.info_proj_rel DISABLE TRIGGER after_epr_upsert; - -ALTER TABLE projects.info_proj_rel ADD COLUMN ord_num_of_range INT; -ALTER TABLE projects.info_proj_rel_vt ADD COLUMN ord_num_of_range INT; -UPDATE projects.info_proj_rel SET ord_num_of_range = ord_num; - -ALTER TABLE projects.info_proj_rel RENAME COLUMN ord_num TO ord_num_of_domain; -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN ord_num TO ord_num_of_domain; - -ALTER TABLE projects.info_proj_rel ADD COLUMN ord_num_of_text_property INT; -ALTER TABLE projects.info_proj_rel_vt ADD COLUMN ord_num_of_text_property INT; -UPDATE projects.info_proj_rel AS t1 -SET ord_num_of_text_property = ord_num_of_domain -FROM information.text_property As t2 -WHERE t1.fk_entity = t2.pk_entity; - -ALTER TABLE projects.info_proj_rel ENABLE TRIGGER after_epr_upsert; - - --- 2 and 3 -DROP VIEW projects.v_info_proj_rel; -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS - SELECT * FROM projects.info_proj_rel; - --- 4 -DROP FUNCTION projects.v_info_proj_rel_update_or_creat(); - --- 5 - -CREATE FUNCTION projects.v_info_proj_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), - ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), - ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num_of_domain, - ord_num_of_range, - ord_num_of_text_property, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num_of_domain, - NEW.ord_num_of_range, - NEW.ord_num_of_text_property, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; - - --- 6 -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON projects.v_info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE projects.v_info_proj_rel_update_or_create(); diff --git a/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-down.sql b/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-down.sql deleted file mode 100644 index 0ca41b3d5..000000000 --- a/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-down.sql +++ /dev/null @@ -1,1516 +0,0 @@ --- 22 -ALTER TABLE warehouse.v_entity_association_per_project_and_repo RENAME TO v_entity_association_per_project_and_repo_no_ranks; - --- 22 -ALTER TABLE information.v_entity_association RENAME TO v_entity_association_tmp; - --- 21 -CREATE OR REPLACE VIEW information.v_entity_association AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_domain, ea.fk_data_domain)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_domain, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY (COALESCE(ea.fk_info_range, ea.fk_data_range)), ea.fk_property ORDER BY ea.is_in_project_count DESC, ea.tmsp_creation DESC) AS rank_for_range, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - LEFT JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - -ALTER TABLE information.v_entity_association - OWNER TO postgres; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - - --- 20 -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - epr.ord_num_of_domain AS rank_for_domain, - epr.ord_num_of_domain AS rank_for_range, - COALESCE(epr.fk_project, 0) AS project - FROM information.v_entity_association ea - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - ea.rank_for_domain, - ea.rank_for_range, - 0 AS project - FROM information.v_entity_association ea - WHERE ea.is_in_project_count > 0; - - --- 19 -CREATE OR REPLACE VIEW warehouse.v_fk_type AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT DISTINCT ea.fk_info_domain AS pk_entity, - ea.fk_project, - ea.project, - ea.fk_info_range AS fk_type - FROM warehouse.v_entity_association_per_project_and_repo ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property - JOIN system.class_has_type_property hasprop ON hasprop.fk_property = p.dfh_pk_property - WHERE ea.rank_for_domain = 1; - --- 18 -DROP VIEW warehouse.v_entity_association_per_project_and_repo_no_ranks; - --- 17 -DROP VIEW information.v_entity_association_tmp; - --- 16 -DROP VIEW warehouse.v_entity_preview; -DROP VIEW warehouse.v_entity_preview_non_recursive ; -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - --- 15 -DROP TRIGGER on_insert ON information.v_role; - --- 13 -ALTER VIEW information.v_role RENAME TO v_role_tmp; - --- 14 -CREATE FUNCTION information.v_role_tmp_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_role_tmp; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT pk_entity FROM INTO resulting_pk information.role - WHERE - fk_entity = NEW.fk_entity - AND fk_temporal_entity = NEW.fk_temporal_entity - AND fk_property = NEW.fk_property; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.role ( - fk_entity, - fk_temporal_entity, - fk_property - ) - VALUES ( - NEW.fk_entity, - NEW.fk_temporal_entity, - NEW.fk_property - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - SELECT * FROM INTO resulting_row information.v_role_tmp - WHERE pk_entity = resulting_pk; -RETURN resulting_row; - END; - $BODY$; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role_tmp - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_tmp_find_or_create(); - --- 12 -ALTER VIEW warehouse.v_roles_per_project_and_repo RENAME TO v_roles_per_project_and_repo_no_rank; - --- 11 -CREATE OR REPLACE VIEW information.v_role AS - WITH role_project_count AS ( - SELECT r_1.pk_entity, - r_1.fk_property, - r_1.fk_entity, - r_1.fk_temporal_entity, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE epr.ord_num_of_domain = 0), 0::bigint) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY epr.calendar) AS community_favorite_calendar, - r_1.notes, - r_1.tmsp_creation, - r_1.tmsp_last_modification, - r_1.sys_period - FROM information.role r_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r_1.pk_entity - GROUP BY r_1.pk_entity, r_1.fk_property, r_1.fk_entity, r_1.fk_temporal_entity, r_1.notes, r_1.tmsp_creation, r_1.tmsp_last_modification, r_1.sys_period - ) - SELECT r.pk_entity, - r.fk_property, - r.fk_entity, - r.fk_temporal_entity, - r.is_in_project_count, - r.is_standard_in_project_count, - r.community_favorite_calendar, - r.notes, - r.tmsp_creation, - r.tmsp_last_modification, - r.sys_period, - row_number() OVER (PARTITION BY r.fk_temporal_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_te_ent, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - row_number() OVER (PARTITION BY r.fk_entity, r.fk_property ORDER BY r.is_in_project_count DESC, r.tmsp_creation DESC) AS rank_for_pe_it, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM role_project_count r - JOIN data_for_history.property p ON r.fk_property = p.dfh_pk_property; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_find_or_create(); - --- 10 -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.ord_num_of_domain AS rank_for_pe_it, - epr.ord_num_of_domain AS rank_for_te_ent, - COALESCE(epr.fk_project, 0) AS project - FROM information.v_role r - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.rank_for_pe_it, - r.rank_for_te_ent, - 0 AS project - FROM information.v_role r - WHERE r.is_in_project_count > 0; - --- -- 9 --- CREATE OR REPLACE VIEW warehouse.v_entity_preview AS --- WITH previews_non_recursive AS ( --- SELECT v_entity_preview_non_recursive.pk_entity, --- v_entity_preview_non_recursive.fk_project, --- v_entity_preview_non_recursive.project, --- v_entity_preview_non_recursive.fk_class, --- v_entity_preview_non_recursive.table_name, --- v_entity_preview_non_recursive.entity_type, --- v_entity_preview_non_recursive.class_label, --- v_entity_preview_non_recursive.entity_label, --- v_entity_preview_non_recursive.time_span, --- v_entity_preview_non_recursive.own_full_text, --- v_entity_preview_non_recursive.fk_entity_label, --- v_entity_preview_non_recursive.fk_type --- FROM warehouse.v_entity_preview_non_recursive --- ), fill_entity_label AS ( --- SELECT t1.pk_entity, --- t1.fk_project, --- t1.project, --- t1.fk_class, --- t1.entity_type, --- t1.class_label, --- COALESCE(t1.entity_label, t2.entity_label) AS entity_label, --- t1.time_span, --- t1.own_full_text, --- t1.fk_entity_label, --- t1.fk_type --- FROM previews_non_recursive t1 --- LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project --- ), fill_type_label AS ( --- SELECT t1.pk_entity, --- t1.fk_project, --- t1.project, --- t1.fk_class, --- t1.entity_type, --- t1.class_label, --- t1.entity_label, --- t1.time_span, --- t1.own_full_text, --- t1.fk_entity_label, --- t1.fk_type, --- t2.entity_label AS type_label --- FROM fill_entity_label t1 --- LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project --- ), full_text_dependencies AS ( --- SELECT r.fk_temporal_entity AS pk_entity, --- r.project, --- r.fk_project, --- e.pk_entity AS pk_related_full_text, --- pre.own_full_text --- FROM warehouse.v_roles_per_project_and_repo r --- JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text --- LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project --- UNION --- SELECT r.fk_entity AS pk_entity, --- r.project, --- r.fk_project, --- e.pk_entity AS pk_related_full_text, --- pre.own_full_text --- FROM warehouse.v_roles_per_project_and_repo r --- JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text --- LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project --- ), aggregated_related_full_texts AS ( --- SELECT full_text_dependencies.pk_entity, --- full_text_dependencies.project, --- full_text_dependencies.fk_project, --- jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts --- FROM full_text_dependencies --- GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project --- ), related_full_text AS ( --- SELECT t1.pk_entity, --- t1.fk_project, --- t1.project, --- t1.fk_class, --- t1.entity_type, --- t1.class_label, --- t1.entity_label, --- t1.time_span, --- t1.own_full_text, --- t1.fk_entity_label, --- t1.fk_type, --- t1.type_label, --- t2.related_full_texts --- FROM fill_type_label t1 --- LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project --- ), add_full_text AS ( --- SELECT f.pk_entity, --- f.fk_project, --- f.project, --- f.fk_class, --- f.entity_type, --- f.class_label, --- f.entity_label, --- f.time_span, --- f.own_full_text, --- f.fk_entity_label, --- f.fk_type, --- f.type_label, --- f.related_full_texts, --- ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string --- FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text --- FROM related_full_text f --- ), add_ts_vector AS ( --- SELECT t.pk_entity, --- t.fk_project, --- t.project, --- t.fk_class, --- t.entity_type, --- t.class_label, --- t.entity_label, --- t.time_span, --- t.own_full_text, --- t.fk_entity_label, --- t.fk_type, --- t.type_label, --- t.related_full_texts, --- t.full_text, --- (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector --- FROM add_full_text t --- ) --- SELECT add_ts_vector.pk_entity, --- add_ts_vector.fk_project, --- add_ts_vector.project, --- add_ts_vector.fk_class, --- add_ts_vector.entity_type, --- add_ts_vector.class_label, --- add_ts_vector.entity_label, --- add_ts_vector.time_span, --- add_ts_vector.own_full_text, --- add_ts_vector.fk_entity_label, --- add_ts_vector.fk_type, --- add_ts_vector.type_label, --- add_ts_vector.related_full_texts, --- add_ts_vector.full_text, --- add_ts_vector.ts_vector --- FROM add_ts_vector; - - --- 8 -CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ) - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - a.fk_entity_label - FROM entities - LEFT JOIN ( SELECT r.fk_entity AS pk_entity, - r.fk_temporal_entity AS fk_entity_label, - r.fk_project, - row_number() OVER (PARTITION BY r.fk_entity, (COALESCE(r.fk_project, 0)) ORDER BY r.rank_for_pe_it) AS rank - FROM warehouse.v_roles_per_project_and_repo r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property AND ucc.ord_num = 0 AND ucc.property_is_outgoing = false AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_temporal_entity = e.pk_entity AND e.table_name::text = 'temporal_entity'::text - UNION - SELECT r.fk_temporal_entity AS pk_entity, - r.fk_entity AS fk_entity_label, - r.fk_project, - row_number() OVER (PARTITION BY r.fk_temporal_entity, (COALESCE(r.fk_project, 0)) ORDER BY r.rank_for_te_ent) AS rank - FROM warehouse.v_roles_per_project_and_repo r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property AND ucc.ord_num = 0 AND ucc.property_is_outgoing = true AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_entity = e.pk_entity AND e.table_name::text = 'persistent_item'::text) a ON a.pk_entity = entities.pk_entity AND NOT a.fk_project IS DISTINCT FROM entities.fk_project - WHERE a.rank = 1; - - --- --7 --- CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS --- WITH entities AS ( --- SELECT v_entities.pk_entity, --- v_entities.fk_project, --- v_entities.project, --- v_entities.fk_class, --- v_entities.table_name, --- v_entities.entity_type --- FROM warehouse.v_entities --- ), first_field AS ( --- SELECT e.pk_entity, --- e.fk_project, --- e.project, --- e.fk_class, --- e.table_name, --- e.entity_type, --- f.fk_property, --- f.fk_class_field, --- f.fk_class --- FROM information.v_ordered_fields_per_class f --- JOIN entities e ON f.fk_class = e.fk_class --- WHERE f.field_order = 0 --- ), string_from_first_role AS ( --- SELECT all_roles.pk_entity, --- all_roles.fk_project, --- all_roles.project, --- all_roles.fk_class, --- all_roles.table_name, --- all_roles.entity_type, --- all_roles.fk_property, --- all_roles.fk_class_field, --- all_roles.fk_class_1 AS fk_class, --- all_roles.string_from_first_role, --- all_roles.role_number --- FROM ( SELECT first_field.pk_entity, --- first_field.fk_project, --- first_field.project, --- first_field.fk_class, --- first_field.table_name, --- first_field.entity_type, --- first_field.fk_property, --- first_field.fk_class_field, --- first_field.fk_class_1 AS fk_class, --- COALESCE(appe.string, lang.notes) AS string_from_first_role, --- row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number --- FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) --- LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project --- LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity --- LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) --- WHERE all_roles.role_number = 1 --- ), string_from_first_text_prop AS ( --- SELECT all_txtp.p, --- all_txtp.pk_entity, --- all_txtp.fk_project, --- all_txtp.project, --- all_txtp.fk_class, --- all_txtp.table_name, --- all_txtp.entity_type, --- all_txtp.fk_property, --- all_txtp.fk_class_field, --- all_txtp.fk_class_1 AS fk_class, --- all_txtp.string_from_first_role, --- all_txtp.role_number, --- all_txtp.string_from_first_text_prop, --- all_txtp.txtp_number --- FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, --- string_from_first_role.pk_entity, --- string_from_first_role.fk_project, --- string_from_first_role.project, --- string_from_first_role.fk_class, --- string_from_first_role.table_name, --- string_from_first_role.entity_type, --- string_from_first_role.fk_property, --- string_from_first_role.fk_class_field, --- string_from_first_role.fk_class_1 AS fk_class, --- string_from_first_role.string_from_first_role, --- string_from_first_role.role_number, --- txtp.string AS string_from_first_text_prop, --- row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number --- FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) --- LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) --- WHERE all_txtp.txtp_number = 1 --- ) --- SELECT string_from_first_text_prop.pk_entity, --- string_from_first_text_prop.fk_project, --- COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, --- string_from_first_text_prop.project --- FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); - - --- -- 6 - --- CREATE OR REPLACE VIEW warehouse.v_own_full_text AS --- WITH entities AS ( --- SELECT v_entities.pk_entity, --- v_entities.fk_project, --- v_entities.project, --- v_entities.fk_class, --- v_entities.table_name, --- v_entities.entity_type --- FROM warehouse.v_entities --- ), field AS ( --- SELECT e.pk_entity, --- e.fk_project, --- e.project, --- e.fk_class, --- e.table_name, --- e.entity_type, --- f.fk_property, --- f.fk_class_field, --- f.fk_class, --- f.field_order --- FROM information.v_ordered_fields_per_class f --- JOIN entities e ON f.fk_class = e.fk_class --- WHERE f.field_order IS NOT NULL --- ), string_from_role AS ( --- SELECT all_roles.pk_entity, --- all_roles.fk_project, --- all_roles.project, --- all_roles.fk_class, --- all_roles.table_name, --- all_roles.entity_type, --- all_roles.fk_property, --- all_roles.fk_class_field, --- all_roles.fk_class_1 AS fk_class, --- all_roles.field_order, --- all_roles.string, --- all_roles.role_number --- FROM ( SELECT field.pk_entity, --- field.fk_project, --- field.project, --- field.fk_class, --- field.table_name, --- field.entity_type, --- field.fk_property, --- field.fk_class_field, --- field.fk_class_1 AS fk_class, --- field.field_order, --- COALESCE(appe.string, lang.notes) AS string, --- row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number --- FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) --- LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project --- LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity --- LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) --- ), string_from_text_prop AS ( --- SELECT all_txtp.pk_entity, --- all_txtp.fk_project, --- all_txtp.project, --- all_txtp.fk_class, --- all_txtp.table_name, --- all_txtp.entity_type, --- all_txtp.fk_property, --- all_txtp.fk_class_field, --- all_txtp.fk_class_1 AS fk_class, --- all_txtp.field_order, --- all_txtp.string, --- all_txtp.txtp_number --- FROM ( SELECT field.pk_entity, --- field.fk_project, --- field.project, --- field.fk_class, --- field.table_name, --- field.entity_type, --- field.fk_property, --- field.fk_class_field, --- field.fk_class_1 AS fk_class, --- field.field_order, --- regexp_replace(txtp.string, '[ - --- ]+'::text, ''::text, 'g'::text) AS string, --- row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number --- FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) --- LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) --- ), all_stings AS ( --- SELECT string_from_text_prop.pk_entity, --- string_from_text_prop.fk_project, --- string_from_text_prop.project, --- string_from_text_prop.fk_class, --- string_from_text_prop.table_name, --- string_from_text_prop.entity_type, --- string_from_text_prop.fk_property, --- string_from_text_prop.fk_class_field, --- string_from_text_prop.fk_class_1 AS fk_class, --- string_from_text_prop.field_order, --- string_from_text_prop.string, --- string_from_text_prop.txtp_number --- FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) --- UNION --- SELECT string_from_role.pk_entity, --- string_from_role.fk_project, --- string_from_role.project, --- string_from_role.fk_class, --- string_from_role.table_name, --- string_from_role.entity_type, --- string_from_role.fk_property, --- string_from_role.fk_class_field, --- string_from_role.fk_class_1 AS fk_class, --- string_from_role.field_order, --- string_from_role.string, --- string_from_role.role_number --- FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) --- ), aggregated AS ( --- SELECT all_stings.pk_entity, --- all_stings.fk_project, --- all_stings.project, --- string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text --- FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) --- GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project --- ) --- SELECT aggregated.pk_entity, --- aggregated.fk_project, --- aggregated.project, --- aggregated.own_full_text --- FROM aggregated; - --- 5 -DROP VIEW warehouse.v_text_properties_per_project_and_repo CASCADE; -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS -SELECT - t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE( - t2.fk_project, 0) AS "coalesce" -FROM - information.v_text_property t1, - projects.info_proj_rel t2 -WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = TRUE -UNION -SELECT - t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce" -FROM - information.v_text_property t1 -WHERE - t1.is_in_project_count > 0; --- re 6 -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class, - f.field_order - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order IS NOT NULL - ), string_from_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.field_order, - all_roles.string, - all_roles.role_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - COALESCE(appe.string, lang.notes) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON field.fk_property = r.fk_property AND field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), string_from_text_prop AS ( - SELECT all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.field_order, - all_txtp.string, - all_txtp.txtp_number - FROM ( SELECT field.pk_entity, - field.fk_project, - field.project, - field.fk_class, - field.table_name, - field.entity_type, - field.fk_property, - field.fk_class_field, - field.fk_class_1 AS fk_class, - field.field_order, - regexp_replace(txtp.string, '[ - -]+'::text, ''::text, 'g'::text) AS string, - row_number() OVER (PARTITION BY field.pk_entity, field.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM field field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT field.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = field.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM field.fk_project) all_txtp(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - ), all_stings AS ( - SELECT string_from_text_prop.pk_entity, - string_from_text_prop.fk_project, - string_from_text_prop.project, - string_from_text_prop.fk_class, - string_from_text_prop.table_name, - string_from_text_prop.entity_type, - string_from_text_prop.fk_property, - string_from_text_prop.fk_class_field, - string_from_text_prop.fk_class_1 AS fk_class, - string_from_text_prop.field_order, - string_from_text_prop.string, - string_from_text_prop.txtp_number - FROM string_from_text_prop string_from_text_prop(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - UNION - SELECT string_from_role.pk_entity, - string_from_role.fk_project, - string_from_role.project, - string_from_role.fk_class, - string_from_role.table_name, - string_from_role.entity_type, - string_from_role.fk_property, - string_from_role.fk_class_field, - string_from_role.fk_class_1 AS fk_class, - string_from_role.field_order, - string_from_role.string, - string_from_role.role_number - FROM string_from_role string_from_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, role_number) - ), aggregated AS ( - SELECT all_stings.pk_entity, - all_stings.fk_project, - all_stings.project, - string_agg(all_stings.string, ', '::text ORDER BY all_stings.field_order) AS own_full_text - FROM all_stings all_stings(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, field_order, string, txtp_number) - GROUP BY all_stings.pk_entity, all_stings.fk_project, all_stings.project - ) - SELECT aggregated.pk_entity, - aggregated.fk_project, - aggregated.project, - aggregated.own_full_text - FROM aggregated; ---7 -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), first_field AS ( - SELECT e.pk_entity, - e.fk_project, - e.project, - e.fk_class, - e.table_name, - e.entity_type, - f.fk_property, - f.fk_class_field, - f.fk_class - FROM information.v_ordered_fields_per_class f - JOIN entities e ON f.fk_class = e.fk_class - WHERE f.field_order = 0 - ), string_from_first_role AS ( - SELECT all_roles.pk_entity, - all_roles.fk_project, - all_roles.project, - all_roles.fk_class, - all_roles.table_name, - all_roles.entity_type, - all_roles.fk_property, - all_roles.fk_class_field, - all_roles.fk_class_1 AS fk_class, - all_roles.string_from_first_role, - all_roles.role_number - FROM ( SELECT first_field.pk_entity, - first_field.fk_project, - first_field.project, - first_field.fk_class, - first_field.table_name, - first_field.entity_type, - first_field.fk_property, - first_field.fk_class_field, - first_field.fk_class_1 AS fk_class, - COALESCE(appe.string, lang.notes) AS string_from_first_role, - row_number() OVER (PARTITION BY first_field.pk_entity, first_field.project ORDER BY r.rank_for_pe_it) AS role_number - FROM first_field first_field(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1) - LEFT JOIN warehouse.v_roles_per_project_and_repo r ON first_field.fk_property = r.fk_property AND first_field.pk_entity = r.fk_temporal_entity AND NOT r.fk_project IS DISTINCT FROM first_field.fk_project - LEFT JOIN information.v_appellation appe ON r.fk_entity = appe.pk_entity - LEFT JOIN information.v_language lang ON r.fk_entity = lang.pk_entity) all_roles(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - WHERE all_roles.role_number = 1 - ), string_from_first_text_prop AS ( - SELECT all_txtp.p, - all_txtp.pk_entity, - all_txtp.fk_project, - all_txtp.project, - all_txtp.fk_class, - all_txtp.table_name, - all_txtp.entity_type, - all_txtp.fk_property, - all_txtp.fk_class_field, - all_txtp.fk_class_1 AS fk_class, - all_txtp.string_from_first_role, - all_txtp.role_number, - all_txtp.string_from_first_text_prop, - all_txtp.txtp_number - FROM ( SELECT COALESCE(string_from_first_role.fk_project, 0) AS p, - string_from_first_role.pk_entity, - string_from_first_role.fk_project, - string_from_first_role.project, - string_from_first_role.fk_class, - string_from_first_role.table_name, - string_from_first_role.entity_type, - string_from_first_role.fk_property, - string_from_first_role.fk_class_field, - string_from_first_role.fk_class_1 AS fk_class, - string_from_first_role.string_from_first_role, - string_from_first_role.role_number, - txtp.string AS string_from_first_text_prop, - row_number() OVER (PARTITION BY string_from_first_role.pk_entity, string_from_first_role.project ORDER BY txtp.tmsp_creation DESC) AS txtp_number - FROM string_from_first_role string_from_first_role(pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number) - LEFT JOIN warehouse.v_text_properties_per_project_and_repo txtp ON NOT string_from_first_role.fk_class_field IS DISTINCT FROM txtp.fk_class_field AND txtp.fk_concerned_entity = string_from_first_role.pk_entity AND NOT txtp.fk_project IS DISTINCT FROM string_from_first_role.fk_project) all_txtp(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number) - WHERE all_txtp.txtp_number = 1 - ) - SELECT string_from_first_text_prop.pk_entity, - string_from_first_text_prop.fk_project, - COALESCE(string_from_first_text_prop.string_from_first_role, string_from_first_text_prop.string_from_first_text_prop) AS entity_label, - string_from_first_text_prop.project - FROM string_from_first_text_prop string_from_first_text_prop(p, pk_entity, fk_project, project, fk_class, table_name, entity_type, fk_property, fk_class_field, fk_class_1, string_from_first_role, role_number, string_from_first_text_prop, txtp_number); --- new - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), add_class_label AS ( - SELECT entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), add_own_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM add_class_label a - LEFT JOIN warehouse.v_own_entity_label l ON a.pk_entity = l.pk_entity AND a.project = l.project - ), add_time_span AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM add_own_entity_label a - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_own_full_text AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM add_time_span a - LEFT JOIN warehouse.v_own_full_text t ON a.pk_entity = t.pk_entity AND a.project = t.project - ), add_fk_entity_label AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM add_own_full_text a - LEFT JOIN warehouse.v_fk_entity_label t ON a.pk_entity = t.pk_entity AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), add_fk_type AS ( - SELECT a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM add_fk_entity_label a - LEFT JOIN warehouse.v_fk_type t ON a.pk_entity = t.pk_entity AND a.project = t.project - ) - SELECT add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type - FROM add_fk_type; --- 9 -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - --- 4 -DROP VIEW warehouse.v_related_full_texts; -CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS - WITH entities AS ( - SELECT v_entities.pk_entity, - v_entities.fk_project, - v_entities.project, - v_entities.fk_class, - v_entities.table_name, - v_entities.entity_type - FROM warehouse.v_entities - ), all_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - ), agg AS ( - SELECT all_dependencies.pk_entity, - all_dependencies.project, - all_dependencies.fk_project, - jsonb_object_agg(all_dependencies.pk_related_full_text::text, '') AS related_full_texts - FROM all_dependencies - GROUP BY all_dependencies.pk_entity, all_dependencies.project, all_dependencies.fk_project - ) - SELECT agg.pk_entity, - agg.project, - agg.fk_project, - agg.related_full_texts - FROM agg; - --- 3 -DROP VIEW warehouse.v_roles_per_project_and_repo_no_rank; -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo_no_rank AS SELECT DISTINCT - r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - COALESCE( - epr.fk_project, 0) AS project -FROM - information.v_role_tmp r - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - AND epr.is_in_project = TRUE - UNION - SELECT DISTINCT - r.fk_entity, - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - 0 AS project - FROM - information.v_role_tmp r -WHERE - r.is_in_project_count > 0; - --- 2 - -CREATE OR REPLACE VIEW warehouse.v_entities AS - SELECT DISTINCT e.pk_entity, - epr.fk_project, - epr.fk_project AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM projects.info_proj_rel epr - JOIN information.entity e ON e.pk_entity = epr.fk_entity - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE epr.is_in_project = true AND (e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text])) -UNION - SELECT DISTINCT e.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - CASE - WHEN pi.pk_entity IS NOT NULL THEN pi.fk_class - ELSE te.fk_class - END AS fk_class, - e.table_name, - CASE - WHEN e.table_name::text = 'persistent_item'::text THEN 'peIt'::text - WHEN e.table_name::text = 'temporal_entity'::text THEN 'teEn'::text - ELSE NULL::text - END AS entity_type - FROM information.entity e - LEFT JOIN information.persistent_item pi ON e.pk_entity = pi.pk_entity - LEFT JOIN information.temporal_entity te ON e.pk_entity = te.pk_entity - WHERE e.table_name::text = ANY (ARRAY['temporal_entity'::character varying::text, 'persistent_item'::character varying::text]) - ORDER BY 1; - --- 1 -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM projects.info_proj_rel epr - JOIN information.v_role r ON r.pk_entity = epr.fk_entity - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE epr.is_in_project = true - UNION - SELECT r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity AND r.rank_for_te_ent = 1 - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN role_with_time_primitive.fk_property = 71 THEN 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN 'p82b'::text - ELSE role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - diff --git a/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-up.sql b/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-up.sql deleted file mode 100644 index 9ad474f8d..000000000 --- a/server/db-migrate/migrations/sqls/20190715120834-inf-v-role-drop-rank-columns-up.sql +++ /dev/null @@ -1,783 +0,0 @@ --- 1 change view warehouse.v_te_en_time_span_per_project_and_repo to use v_role_tmp instead of v_role --- execution time to select * before: 21742.612 ms --- execution time to select * after: 2411.138 ms - -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS WITH role_with_time_primitive AS ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM - information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND r.fk_property IN (71, 72, 150, 151, 152, 153) - AND tp.pk_entity = r.fk_entity - AND epr.is_in_project = TRUE - UNION ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM - information.v_role_tmp r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property IN (71, 72, 150, 151, 152, 153) - ORDER BY - r.fk_temporal_entity, - r.fk_property, - r.is_in_project_count DESC, - r.tmsp_creation DESC) -) -SELECT - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE WHEN role_with_time_primitive.fk_property = 71 THEN - 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN - 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN - 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN - 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN - 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN - 'p82b'::text - ELSE - role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span -FROM - role_with_time_primitive -GROUP BY - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity; - --- 2 optimize view warehouse.v_entities --- execution time for SELECT * FROM warehouse.v_entities LIMIT 1 before: 8376.066 ms --- execution time for SELECT * FROM warehouse.v_entities LIMIT 1 after: 5234.821 ms - -CREATE OR REPLACE VIEW warehouse.v_entities AS WITH tw1 AS ( - SELECT - pk_entity, - fk_class, - 'persistent_item' ::character varying AS table_name, - 'peIt' AS entity_type - FROM - information.persistent_item - UNION - SELECT - pk_entity, - fk_class, - 'temporal_entity' ::character varying AS table_name, - 'teEn' AS entity_type - FROM - information.temporal_entity -) -SELECT - tw1.pk_entity, - epr.fk_project, - epr.fk_project AS project, - tw1.fk_class, - tw1.table_name, - tw1.entity_type -FROM - projects.info_proj_rel epr, - tw1 -WHERE - epr.is_in_project = TRUE - AND tw1.pk_entity = epr.fk_entity -UNION -SELECT - tw1.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - tw1.fk_class, - tw1.table_name, - tw1.entity_type -FROM - tw1; - --- 3 optimize view warehouse.v_roles_per_project_and_repo_no_rank --- execution time for SELECT * FROM warehouse.v_roles_per_project_and_repo_no_rank LIMIT 1 before: --- execution time for SELECT * FROM warehouse.v_roles_per_project_and_repo_no_rank LIMIT 1 after: - -DROP VIEW warehouse.v_related_full_texts; - -DROP VIEW warehouse.v_roles_per_project_and_repo_no_rank; - -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo_no_rank AS -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE( - t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role_tmp t1, - projects.info_proj_rel t2 -WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = TRUE -UNION -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role_tmp t1 -WHERE - t1.is_in_project_count > 0; - --- 4 change view warehouse.v_related_full_texts to use v_roles_per_project_and_repo_no_rank instead of v_roles_per_project_and_repo --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_related_full_texts WHERE pk_entity = 26894 before, execution time: 79937.913 ms --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_related_full_texts WHERE pk_entity = 26894 after, execution time: 3.322 ms - -CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS -SELECT - t1.fk_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg( - t1.fk_temporal_entity ::text, NULL) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo_no_rank t1 -GROUP BY - t1.fk_entity, - t1.fk_project, - t1.project -UNION -SELECT - t1.fk_temporal_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg( - t1.fk_entity ::text, NULL) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo_no_rank t1, - information.persistent_item t2 -WHERE - t1.fk_entity = t2.pk_entity -GROUP BY - t1.fk_temporal_entity, - t1.fk_project, - t1.project; - --- 5 optimize view warehouse.v_text_properties_per_project_and_repo - -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS -SELECT - t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE( - t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property -FROM - information.v_text_property t1, - projects.info_proj_rel t2 -WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = TRUE -UNION -SELECT - t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property -FROM - information.v_text_property t1 -WHERE - t1.is_in_project_count > 0; - --- 6 optimize view warehouse.v_own_full_text --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_own_full_text WHERE pk_entity IN (158076, 149787), before: 234141.028 ms --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_own_full_text WHERE pk_entity IN (158076, 149787), after: 28844.035 ms - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS WITH tw1 AS ( - -- get strings related to TeEn's from appellation and language - - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) string, - t5.field_order, - t1.ord_num_of_domain ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo_no_rank t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order IS NOT NULL - UNION ALL - -- get strings related to Entities from text_property - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1.coalesce AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field -), -tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project, tw1.string) - tw1.pk_entity, tw1.fk_project, tw1.project, tw1.string, tw1.field_order, tw1.ord_num, tw1.is_in_project_count - FROM - tw1 -) -SELECT - tw2.pk_entity, - tw2.fk_project, - tw2.project, - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order ASC, tw2.ord_num ASC, tw2.is_in_project_count DESC) own_full_text -FROM - tw2 -GROUP BY - tw2.pk_entity, - tw2.fk_project, - tw2.project; - --- 7 change view warehouse.v_own_entity_label to use v_roles_per_project_and_repo_no_rank instead of v_roles_per_project_and_repo --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_own_entity_label WHERE pk_entity IN (158076, 149787); before: Execution time: 56652.842 ms --- EXPLAIN ANALYZE SELECT * FROM warehouse.v_own_entity_label WHERE pk_entity IN (158076, 149787); after: Execution time: 26222.820 ms - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS WITH tw1 AS ( - -- get strings related to TeEn's from appellation and language - -- (todo: from time-primitive and place) - - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) string, - t5.field_order, - t1.ord_num_of_domain ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo_no_rank t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order = 0 - UNION ALL - -- get strings related to Entities from text_property - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1.coalesce AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field -AND t2.field_order = 0 -) --- takes only the firts row per pk_entity and project -SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) - tw1.pk_entity, tw1.fk_project, tw1.string entity_label, tw1.project -FROM - tw1 -ORDER BY - tw1.pk_entity, - tw1.fk_project, - tw1.field_order ASC, - tw1.ord_num ASC, - tw1.is_in_project_count DESC; - --- 8 change view warehouse.v_fk_entity_label to use v_roles_per_project_and_repo_no_rank instead of v_roles_per_project_and_repo - -CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS WITH tw1 AS ( - SELECT - temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity' ::character varying AS table_name, - 'teEnt' ::text AS entity_type - FROM - information.temporal_entity - UNION - SELECT - persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item' ::character varying AS table_name, - 'peIt' ::text AS entity_type - FROM - information.persistent_item -) SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) - t1.pk_entity, - COALESCE(t3.fk_project, t4.fk_project) AS fk_project, - COALESCE(t3.fk_project, t4.fk_project, 0) AS project, - t1.fk_class, - t1.table_name, - t1.entity_type, - COALESCE(t4.fk_temporal_entity, CASE WHEN t5.table_name IN ('persistent_item', 'temporal_entity') THEN - t3.fk_entity - ELSE - NULL - END) AS fk_entity_label -FROM - tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN warehouse.v_roles_per_project_and_repo_no_rank t3 ON t2.fk_property = t3.fk_property - AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN information.entity t5 ON t3.fk_entity = t5.pk_entity - LEFT JOIN warehouse.v_roles_per_project_and_repo_no_rank t4 ON t2.fk_property = t4.fk_property - AND t1.pk_entity = t4.fk_entity -WHERE - t2.field_order = 0 -ORDER BY - t1.pk_entity, - t3.fk_project, - t4.fk_project, - t1.fk_class, - t2.field_order, - t3.ord_num_of_domain, - t4.ord_num_of_domain, - t3.is_in_project_count DESC, - t4.is_in_project_count DESC; - --- 9 change view warehouse.v_entity_preview to use v_roles_per_project_and_repo_no_rank instead of v_roles_per_project_and_repo - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS WITH previews_non_recursive AS ( - SELECT - v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM - warehouse.v_entity_preview_non_recursive -), -fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo_no_rank r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo_no_rank r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM - full_text_dependencies - GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project -), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts) jsonb_each_text(KEY, value)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM - add_full_text t -) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - --- 10 drop view warehouse.v_roles_per_project_and_repo - -DROP VIEW warehouse.v_roles_per_project_and_repo; - --- 11 drop view information.v_role - -DROP VIEW information.v_role; - --- 12 rename v_roles_per_project_and_repo_no_rank to v_roles_per_project_and_repo - -ALTER VIEW warehouse.v_roles_per_project_and_repo_no_rank RENAME TO v_roles_per_project_and_repo; - --- 13 rename v_role_tmp to v_role - -DROP TRIGGER on_insert ON information.v_role_tmp; - -ALTER VIEW information.v_role_tmp RENAME TO v_role; - --- 14 drop the tmp trigger function - -DROP FUNCTION information.v_role_tmp_find_or_create (); - --- 15 add trigger to v_role - -CREATE TRIGGER on_insert INSTEAD OF INSERT ON information.v_role -FOR EACH ROW -EXECUTE PROCEDURE information.v_role_find_or_create (); - --- 16 improve v_entity_preview_non_recursive - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts -FROM - warehouse.v_entities t1 -LEFT JOIN - warehouse.class_preview t2 - ON t2.dfh_pk_class = t1.fk_class -LEFT JOIN - warehouse.v_own_entity_label t3 - ON t1.pk_entity = t3.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t3.fk_project -LEFT JOIN - warehouse.v_te_en_time_span_per_project_and_repo t4 - ON t1.pk_entity = t4.fk_temporal_entity - AND t1.fk_project IS NOT DISTINCT FROM t4.fk_project -LEFT JOIN - warehouse.v_own_full_text t5 - ON t1.pk_entity = t5.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t5.fk_project -LEFT JOIN - warehouse.v_fk_entity_label t6 - ON t1.pk_entity = t6.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t6.fk_project -LEFT JOIN - warehouse.v_fk_type t7 - ON t1.pk_entity = t7.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t7.fk_project -LEFT JOIN - warehouse.v_related_full_texts t8 - ON t1.pk_entity = t8.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t8.fk_project; - --- 17 make v_entity_association_tmp independent from ranks, and add trigger -CREATE OR REPLACE VIEW information.v_entity_association_tmp AS - WITH ea_project_count AS ( - SELECT ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = true), 0::bigint) AS is_in_project_count - FROM information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity - GROUP BY ea_1.pk_entity, ea_1.fk_property, ea_1.fk_info_domain, ea_1.fk_info_range, ea_1.fk_data_domain, ea_1.fk_data_range, ea_1.notes, ea_1.tmsp_creation, ea_1.tmsp_last_modification, ea_1.sys_period - ) - SELECT ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM ea_project_count ea - LEFT JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association_tmp - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - --- 18 make v_entity_association_per_project_and_repo_no_ranks independent from ranks -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo_no_ranks AS - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS project, - ea.is_in_project_count - FROM - information.v_entity_association_tmp ea, - projects.info_proj_rel epr - WHERE - epr.fk_entity = ea.pk_entity AND epr.is_in_project = true -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - 0 AS project, - ea.is_in_project_count - FROM information.v_entity_association_tmp ea - WHERE ea.is_in_project_count > 0; - --- 19 make v_fk_type independent from ranks -CREATE OR REPLACE VIEW warehouse.v_fk_type AS -WITH tw1 AS ( - SELECT DISTINCT ON ( - t1.fk_project, - t1.fk_property, - t1.fk_info_domain - ) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo_no_ranks t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL - AND - t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo_no_ranks t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL - AND - t3.fk_property = t4.fk_property - ORDER BY - fk_project, - fk_property, - fk_info_domain, - is_in_project_count DESC -) -SELECT DISTINCT ON (tw1.fk_info_domain, tw1.fk_project) - fk_info_domain as pk_entity, - fk_project, - coalesce(fk_project, 0) as project, - fk_info_range as fk_type -FROM tw1; - --- 20 drop v_entity_association_per_project_and_repo -DROP VIEW warehouse.v_entity_association_per_project_and_repo; - --- 21 drop v_entity_association -DROP VIEW information.v_entity_association; - --- 22 rename v_entity_association_tmp to v_entity_association -ALTER TABLE information.v_entity_association_tmp RENAME TO v_entity_association; - --- 23 rename v_entity_association_per_project_and_repo_no_ranks to v_entity_association_per_project_and_repo -ALTER TABLE warehouse.v_entity_association_per_project_and_repo_no_ranks RENAME TO v_entity_association_per_project_and_repo; - - diff --git a/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-down.sql b/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-down.sql deleted file mode 100644 index f24a2f4d6..000000000 --- a/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-down.sql +++ /dev/null @@ -1,1139 +0,0 @@ ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_all function - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - item record; - results warehouse.entity_preview; - t timestamptz; - number_of_unfinished INT; -BEGIN - t = clock_timestamp(); - -- create temporary tables to create the temp_entity_preview_non_recursive - CREATE TEMP TABLE temp_entities AS - SELECT - * - FROM - warehouse.v_entities; - CREATE TEMP TABLE temp_own_entity_label AS - SELECT - * - FROM - warehouse.v_own_entity_label; - CREATE TEMP TABLE temp_te_en_time_span_per_project_and_repo AS - SELECT - * - FROM - warehouse.v_te_en_time_span_per_project_and_repo; - CREATE TEMP TABLE temp_own_full_text AS - SELECT - * - FROM - warehouse.v_own_full_text; - CREATE TEMP TABLE temp_fk_entity_label AS - SELECT - * - FROM - warehouse.v_fk_entity_label; - CREATE TEMP TABLE temp_fk_type AS - SELECT - * - FROM - warehouse.v_fk_type; - -- create temporary table with previews non recursive - CREATE TEMP TABLE temp_entity_preview_non_recursive AS WITH entities AS ( - SELECT - temp_entities.pk_entity, - temp_entities.fk_project, - temp_entities.project, - temp_entities.fk_class, - temp_entities.table_name, - temp_entities.entity_type - FROM - temp_entities - ), -add_class_label AS ( - SELECT - entities.pk_entity, - entities.fk_project, - entities.project, - entities.fk_class, - entities.table_name, - entities.entity_type, - c.class_label - FROM - entities - JOIN warehouse.class_preview c ON c.dfh_pk_class = entities.fk_class - ), -add_own_entity_label AS ( - SELECT - a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - l.entity_label - FROM - add_class_label a - LEFT JOIN temp_own_entity_label l ON a.pk_entity = l.pk_entity - AND a.project = l.project - ), -add_time_span AS ( - SELECT - a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - t.time_span - FROM - add_own_entity_label a - LEFT JOIN temp_te_en_time_span_per_project_and_repo t ON a.pk_entity = t.fk_temporal_entity - AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), -add_own_full_text AS ( - SELECT - a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - t.own_full_text - FROM - add_time_span a - LEFT JOIN temp_own_full_text t ON a.pk_entity = t.pk_entity - AND a.project = t.project - ), -add_fk_entity_label AS ( - SELECT - a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - t.fk_entity_label - FROM - add_own_full_text a - LEFT JOIN temp_fk_entity_label t ON a.pk_entity = t.pk_entity - AND NOT a.fk_project IS DISTINCT FROM t.fk_project - ), -add_fk_type AS ( - SELECT - a.pk_entity, - a.fk_project, - a.project, - a.fk_class, - a.table_name, - a.entity_type, - a.class_label, - a.entity_label, - a.time_span, - a.own_full_text, - a.fk_entity_label, - t.fk_type - FROM - add_fk_entity_label a - LEFT JOIN temp_fk_type t ON a.pk_entity = t.pk_entity - AND a.project = t.project - ) -SELECT - add_fk_type.pk_entity, - add_fk_type.fk_project, - add_fk_type.project, - add_fk_type.fk_class, - add_fk_type.table_name, - add_fk_type.entity_type, - add_fk_type.class_label, - add_fk_type.entity_label, - add_fk_type.time_span, - add_fk_type.own_full_text, - add_fk_type.fk_entity_label, - add_fk_type.fk_type -FROM - add_fk_type; - -- init temp table - DROP TABLE IF EXISTS warehouse.temp; - CREATE TABLE warehouse.temp AS WITH fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label ) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - temp_entity_preview_non_recursive t1 - LEFT JOIN temp_entity_preview_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project - ), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project - ), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN temp_entity_preview_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - ), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text ) AS related_full_texts - FROM - full_text_dependencies - GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project - ), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project - ), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value ), ', '::text )], ', '::text ) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts ) jsonb_each_text(KEY, value ) ) AS full_text - FROM - related_full_text f - ), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text ) ), 'A'::"char" ) || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text ) ), 'B'::"char" ) ) || setweight(to_tsvector(COALESCE(t.full_text, ''::text ) ), 'C'::"char" ) AS ts_vector - FROM - add_full_text t - ) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - WITH fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - coalesce(t2.entity_label, t1.entity_label) entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - warehouse.temp t1 - LEFT JOIN warehouse.temp t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.*, - t2.entity_label type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.temp pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - pk_entity, - project, - fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM - full_text_dependencies - GROUP BY - pk_entity, - project, - fk_project -), -related_full_text AS ( - SELECT - t1.*, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - *, - ( - SELECT - array_to_string(ARRAY[ - --coalesce(f.type_label, f.class_label, ''), - f.own_full_text, array_to_string(array_agg(value), ', ')]::text[], ', ') - FROM - jsonb_each_text(f.related_full_texts)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.*, - setweight(to_tsvector(coalesce(t.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t.type_label, t.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t.full_text, '')), 'C') AS ts_vector - FROM - add_full_text t -), -updated AS ( - SELECT - * - FROM - add_ts_vector -) -UPDATE - warehouse.temp -SET - entity_label = updated.entity_label -FROM - updated -WHERE - temp.pk_entity = updated.pk_entity - AND temp.fk_project IS NOT DISTINCT FROM updated.fk_project; - SELECT - count(*) INTO number_of_unfinished - FROM - warehouse.temp a - JOIN warehouse.temp b ON a.fk_entity_label = b.pk_entity - AND a.entity_label IS DISTINCT FROM b.entity_label - AND a.project = b.project; - raise notice 'number_of_unfinished entity_previews (if zero, everything fine): %', number_of_unfinished; - -- empty table entity_preview - DELETE FROM warehouse.entity_preview; - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, type_label, related_full_texts, full_text, ts_vector) -SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector -FROM - warehouse.temp; - DROP TABLE warehouse.temp; - raise notice 'time spent for entity_preview__fill_own_full_text=%', clock_timestamp() - t; - RETURN TRUE; -END; -$BODY$; - -DROP FUNCTION warehouse.entity_preview__create_temporary; -DROP FUNCTION warehouse.entity_preview__add_missing; -DROP FUNCTION warehouse.entity_preview__remove_superfluous ; -DROP FUNCTION warehouse.entity_preview__update_modified; - -DROP TRIGGER after_update_on_entity_preview__entity_label ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__entity_label - AFTER UPDATE OF entity_label - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_entity_labels(); - -DROP TRIGGER after_update_on_entity_preview__fk_entity_label ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__fk_entity_label - AFTER UPDATE OF fk_entity_label - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__get_entity_label(); - -DROP TRIGGER after_update_on_entity_preview__fk_type ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__fk_type - AFTER UPDATE OF fk_type - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__get_type_label(); - -DROP TRIGGER after_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__own_full_text - AFTER UPDATE OF own_full_text - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_related_full_texts(); - -DROP TRIGGER before_update_on_entity_preview__own_full_text_or_related_full_texts ON warehouse.entity_preview; - -CREATE TRIGGER before_update_on_entity_preview__own_full_text - BEFORE UPDATE OF own_full_text - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - -CREATE TRIGGER before_update_on_entity_preview__related_full_texts - BEFORE INSERT OR UPDATE OF related_full_texts - ON warehouse.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); - -ALTER TABLE warehouse.entity_preview DROP COLUMN skip_triggers; - - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create function ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_fk_entity_label function - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label (param_pk_entity integer, param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; -BEGIN - ---------------------- REPO VERSIONS ---------------------- - IF param_fk_project IS NULL THEN - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the fk_entity_label - SELECT - pk INTO new_fk_entity_label - FROM (( - SELECT - fk_temporal_entity AS pk, - r.rank_for_pe_it AS rank - FROM - information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = FALSE - AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_temporal_entity = e.pk_entity - AND e.table_name = 'temporal_entity' - WHERE - r.fk_entity = param_pk_entity - AND r.is_in_project_count > 0) - UNION ( - SELECT - r.fk_entity AS pk, - r.rank_for_te_ent AS rank - FROM - information.v_role r - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = TRUE - AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_entity = e.pk_entity - AND e.table_name = 'persistent_item' - WHERE - r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0)) AS a - ORDER BY - rank - LIMIT 1; - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - ----- Insert or update column fk_entity_label of table entity_preview - SELECT - fk_entity_label INTO old_fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NULL; - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - ELSIF ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - fk_entity_label = new_fk_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project IS NULL; - RAISE INFO 'updated object with new_object: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - ---------------------- PROJECTS VERSIONS ---------------------- - ELSE - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the fk_entity_label - SELECT - pk INTO new_fk_entity_label - FROM (( - SELECT - fk_temporal_entity AS pk, - epr.ord_num - FROM - information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = FALSE - AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_temporal_entity = e.pk_entity - AND e.table_name = 'temporal_entity' - WHERE - r.fk_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = TRUE) - UNION ( - SELECT - r.fk_entity AS pk, - epr.ord_num - FROM - information.role r - JOIN projects.info_proj_rel epr ON epr.fk_entity = r.pk_entity - JOIN projects.class_field_config ucc ON ucc.fk_property = r.fk_property - AND ucc.ord_num = 0 - AND ucc.property_is_outgoing = TRUE - AND ucc.fk_app_context = 45 - JOIN information.entity e ON r.fk_entity = e.pk_entity - AND e.table_name = 'persistent_item' - WHERE - r.fk_temporal_entity = param_pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = TRUE)) AS a - ORDER BY - ord_num - LIMIT 1; - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - ----- Insert or update column fk_entity_label of table entity_preview - SELECT - fk_entity_label INTO old_fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project = param_fk_project; - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - ELSIF ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - fk_entity_label = new_fk_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project = param_fk_project; - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - END IF; - SELECT - jsonb_build_object ('changed', - ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', - old_fk_entity_label, - 'new_val', - new_fk_entity_label) INTO result_info; - RETURN result_info; -END; -$BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_fk_type function - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - - IF param_fk_project IS NULL THEN - ------------------------------------ REPO QUERY ------------------------------------ - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.v_entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN system.class_has_type_property p ON ea.fk_property = p.fk_property - WHERE ea.fk_info_domain = param_pk_entity - AND ea.rank_for_domain = 1 - LIMIT 1; - ELSE - ---------------------------------- PROJECT QUERY ---------------------------------- - SELECT DISTINCT ea.fk_info_range INTO new_fk_type - FROM information.entity_association ea - JOIN projects.info_proj_rel epr ON ea.pk_entity = epr.fk_entity - JOIN system.class_has_type_property p ON ea.fk_property = p.fk_property - WHERE ea.fk_info_domain = param_pk_entity - AND epr.is_in_project = true - AND epr.fk_project = param_fk_project - LIMIT 1; - END IF; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_related_full_texts function ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_own_entity_label function -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; - BEGIN - - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT ( - SELECT fk_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1 - ) IS NULL - ) THEN - - - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get the string new_own_entity_label - SELECT own_entity_label INTO new_own_entity_label - FROM warehouse.v_own_entity_label - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - - ----- Insert or update column own_entity_label of table entity_preview - - SELECT entity_label INTO old_own_entity_label FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - - ELSIF (SELECT (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - - UPDATE warehouse.entity_preview - SET entity_label = new_own_entity_label - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; - - END IF; - RETURN true; - END; - $BODY$; - - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_own_full_text function - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text (param_pk_entity integer, param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; -BEGIN - ---------------------- REPO VERSIONS ---------------------- - IF param_fk_project IS NULL THEN - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_full_text - WITH entity AS ( - SELECT - t.pk_entity, - t.fk_class - FROM - information.temporal_entity AS t - WHERE - t.pk_entity = param_pk_entity - UNION - SELECT - p.pk_entity, - p.fk_class - FROM - information.persistent_item AS p - WHERE - p.pk_entity = param_pk_entity -), -fields AS ( - -- fields - SELECT - fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM - information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL -), -strings_from_roles AS ( - SELECT - COALESCE(appe.string, lang.notes) AS string, - field_order - FROM - fields - JOIN information.v_role AS r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - AND r.is_in_project_count > 0 - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - -- appellation - LEFT JOIN information.v_appellation AS appe ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language AS lang ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- -ORDER BY - r.rank_for_te_ent -), -strings_from_text_props AS ( - SELECT - regexp_replace(txtp.string, E'[\n\r]+', '', 'g') AS string, - field_order - FROM - information.v_text_property AS txtp - INNER JOIN fields ON fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - -- TODO: Check if we need to exclude textproperties that are in 0 projects$ - -- TODO: Check if we need to order textproperties -), -all_stings AS ( - SELECT - string, - field_order - FROM - strings_from_roles - UNION - SELECT - string, - field_order - FROM - strings_from_text_props -), -aggregated AS ( - SELECT - 1, - string_agg(string, ', ' ORDER BY field_order) AS full_text - FROM - all_stings - GROUP BY - 1 -) -SELECT - full_text INTO new_own_full_text -FROM - aggregated; - RAISE INFO 'new_own_full_text: %', new_own_full_text; - ----- Insert or update column own_full_text of table entity_preview - SELECT - own_full_text INTO old_own_full_text - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NULL; - RAISE INFO 'old_own_full_text: %', old_own_full_text; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - ELSIF ( - SELECT - (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - UPDATE - warehouse.entity_preview - SET - own_full_text = new_own_full_text - WHERE - pk_entity = param_pk_entity - AND fk_project IS NULL; - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - ---------------------- PROJECTS VERSIONS ---------------------- -ELSE - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_full_text - WITH entity AS ( - SELECT - t.pk_entity, - t.fk_class - FROM - information.temporal_entity AS t - WHERE - t.pk_entity = param_pk_entity - UNION - SELECT - p.pk_entity, - p.fk_class - FROM - information.persistent_item AS p - WHERE - p.pk_entity = param_pk_entity -), -fields AS ( - -- fields - SELECT - fields.fk_property, fields.fk_class_field, entity.pk_entity, field_order - FROM - information.v_ordered_fields_per_class AS fields - JOIN entity ON fields.fk_class = entity.fk_class - AND field_order IS NOT NULL -), -strings_from_roles AS ( - SELECT - COALESCE(appe.string, lang.notes) AS string, - field_order - FROM - fields - JOIN information.v_role AS r ON fields.fk_property = r.fk_property - AND r.fk_temporal_entity = param_pk_entity - LEFT JOIN projects.info_proj_rel AS epr ON epr.fk_entity = r.pk_entity - AND epr.fk_project = param_fk_project - AND epr.is_in_project = TRUE - ----------------------------------------------------------- - -- get the strings directly connected to entity via role-fk_entity (not via intermediate entity/PeIt) - -- appellation - LEFT JOIN information.v_appellation AS appe ON r.fk_entity = appe.pk_entity - -- language - LEFT JOIN information.v_language AS lang ON r.fk_entity = lang.pk_entity - -- time_primitive - -- place - ----------------------------------------------------------- -ORDER BY - epr.ord_num -), -strings_from_text_props AS ( - SELECT - regexp_replace(txtp.string, E'[\n\r]+', '', 'g') AS string, - field_order - FROM - information.v_text_property AS txtp - INNER JOIN fields ON fields.fk_class_field = txtp.fk_class_field - AND txtp.fk_concerned_entity = param_pk_entity - INNER JOIN projects.info_proj_rel AS epr ON epr.fk_entity = txtp.pk_entity - AND epr.is_in_project = TRUE - AND epr.fk_project = param_fk_project - ORDER BY - epr.ord_num -), -all_stings AS ( - SELECT - string, - field_order - FROM - strings_from_roles - UNION - SELECT - string, - field_order - FROM - strings_from_text_props -), -aggregated AS ( - SELECT - 1, - string_agg(string, ', ' ORDER BY field_order) AS full_text - FROM - all_stings - GROUP BY - 1 -) -SELECT - full_text INTO new_own_full_text -FROM - aggregated; - RAISE INFO 'new_own_full_text: %', new_own_full_text; - ----- Insert or update column own_full_text of table entity_preview - SELECT - own_full_text INTO old_own_full_text - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project = param_fk_project; - RAISE INFO 'old_own_full_text: %', old_own_full_text; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - ELSIF ( - SELECT - (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - UPDATE - warehouse.entity_preview - SET - own_full_text = new_own_full_text - WHERE - pk_entity = param_pk_entity - AND fk_project = param_fk_project; - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; -END IF; - RETURN TRUE; -END; -$BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_time_span function -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_time_span jsonb; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_time_span - SELECT time_span INTO new_time_span - FROM warehouse.v_te_en_time_span_per_project_and_repo - WHERE fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_time_span: %', new_time_span; - - -- update this entity_preview with new_time_span - UPDATE warehouse.entity_preview - SET time_span = new_time_span - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $BODY$; - diff --git a/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-up.sql b/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-up.sql deleted file mode 100644 index 6d3d6154e..000000000 --- a/server/db-migrate/migrations/sqls/20190715154925-war-functions-tuning-up.sql +++ /dev/null @@ -1,909 +0,0 @@ ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_all function --- execution time before preceding 2 migrations: 340881.262 ms ~5.6min --- execution time after preceding 2 migrations: 359328.770 ms ~5.6min --- execution time after tuning: depending on the number of rows to upsert 15 sec to 5 min - -ALTER TABLE warehouse.entity_preview - ADD COLUMN skip_triggers BOOLEAN; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_temporary () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - DROP TABLE IF EXISTS entity_preview_temporary; - CREATE TEMP TABLE entity_preview_temporary AS - SELECT - *, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.v_entity_preview_non_recursive; - - ALTER TABLE entity_preview_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ---------- full text completion ------------ - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - UPDATE - entity_preview_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__add_missing () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, type_label, related_full_texts, full_text, ts_vector, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t1.related_full_texts, - t1.full_text, - t1.ts_vector, - TRUE -FROM - entity_preview_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - -RETURN TRUE; - -END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__remove_superfluous () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_temporary, to be deleted' AS note - FROM - entity_preview_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_modified () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) -UPDATE - warehouse.entity_preview t1 -SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - own_full_text = tw1.own_full_text, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE -FROM - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - - RETURN TRUE; -END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_all () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - PERFORM - warehouse.entity_preview__create_temporary (); - PERFORM - warehouse.entity_preview__add_missing (); - PERFORM - warehouse.entity_preview__remove_superfluous (); - PERFORM - warehouse.entity_preview__update_modified (); - RETURN TRUE; -END; -$BODY$; - -DROP TRIGGER after_update_on_entity_preview__entity_label ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__entity_label - AFTER UPDATE OF entity_label ON warehouse.entity_preview - FOR EACH ROW - WHEN (NEW.skip_triggers != TRUE) - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_entity_labels (); - -DROP TRIGGER after_update_on_entity_preview__fk_entity_label ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__fk_entity_label - AFTER UPDATE OF fk_entity_label ON warehouse.entity_preview - FOR EACH ROW - WHEN (NEW.skip_triggers != TRUE) - EXECUTE PROCEDURE warehouse.entity_preview__get_entity_label (); - -DROP TRIGGER after_update_on_entity_preview__fk_type ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__fk_type - AFTER UPDATE OF fk_type ON warehouse.entity_preview - FOR EACH ROW - WHEN (NEW.skip_triggers != TRUE) - EXECUTE PROCEDURE warehouse.entity_preview__get_type_label (); - -DROP TRIGGER after_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - -CREATE TRIGGER after_update_on_entity_preview__own_full_text - AFTER UPDATE OF own_full_text ON warehouse.entity_preview - FOR EACH ROW - WHEN (NEW.skip_triggers != TRUE) - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_related_full_texts (); - -DROP TRIGGER before_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - -DROP TRIGGER before_update_on_entity_preview__related_full_texts ON warehouse.entity_preview; - -CREATE TRIGGER before_update_on_entity_preview__own_full_text_or_related_full_texts - BEFORE INSERT - OR UPDATE OF related_full_texts, own_full_text ON warehouse.entity_preview - FOR EACH ROW - WHEN (NEW.skip_triggers != TRUE) - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text (); - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create function --- execution time before preceding 2 migrations (project / repo): 4123.498 ms / 5367.959 ms --- execution time after preceding 2 migration (project / repo): 154.646 ms / 154.646 ms --- execution time after tuning (project / repo): ---------------------------------------------------------------------------------------------------- --- tune performacek of warehouse.entity_preview__create_fk_entity_label function --- execution time before preceding 2 migrations (project / repo): 3.787 ms / 1434.483 ms --- execution time after preceding 2 migration (project / repo): CRASHED --- execution time after tuning (project / repo): 1.292 ms / 3.793 ms - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label (param_pk_entity integer, param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; -BEGIN - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the fk_entity_label - -- SELECT - -- fk_entity_label INTO new_fk_entity_label - -- FROM - -- warehouse.v_fk_entity_label - -- WHERE - -- pk_entity = param_pk_entity - -- AND fk_project IS NOT DISTINCT FROM param_fk_project; - WITH tw1 AS ( - SELECT - temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEnt'::text AS entity_type - FROM - information.temporal_entity - WHERE - pk_entity = param_pk_entity - UNION - SELECT - persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM - information.persistent_item - WHERE - pk_entity = param_pk_entity -), -tw2 AS ( - SELECT - fk_project, fk_property, fk_entity, fk_temporal_entity, ord_num_of_domain, is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo - WHERE - fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project -), -tw3 AS ( - SELECT - fk_project, fk_property, fk_entity, fk_temporal_entity, ord_num_of_domain, is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo - WHERE - fk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project -) SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) - COALESCE(t4.fk_temporal_entity, CASE WHEN EXISTS ( - SELECT - pk_entity FROM information.persistent_item - WHERE - pk_entity = t3.fk_entity - UNION - SELECT - pk_entity FROM information.temporal_entity - WHERE - pk_entity = t3.fk_entity) = TRUE THEN - t3.fk_entity - ELSE - NULL - END) INTO new_fk_entity_label - FROM - tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN tw2 t3 ON t2.fk_property = t3.fk_property - AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN tw3 t4 ON t2.fk_property = t4.fk_property - AND t1.pk_entity = t4.fk_entity -WHERE - t2.field_order = 0 -ORDER BY - t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class, t2.field_order, t3.ord_num_of_domain, t4.ord_num_of_domain, t3.is_in_project_count DESC, t4.is_in_project_count DESC; - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - ----- Insert or update column fk_entity_label of table entity_preview - SELECT - fk_entity_label INTO old_fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - ELSIF ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - fk_entity_label = new_fk_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - SELECT - jsonb_build_object ('changed', - ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', - old_fk_entity_label, - 'new_val', - new_fk_entity_label) INTO result_info; - RETURN result_info; - END; -$BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_fk_type function --- execution time before preceding 2 migrations (project / repo): 1.574 ms / 2.626 ms --- execution time after preceding 2 migration (project / repo): 1.891 ms / 3.075 ms --- execution time after tuning (project / repo): NO NEED - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - --- get the fk_type - SELECT fk_type INTO new_fk_type - FROM - warehouse.v_fk_type - WHERE - pk_entity = param_pk_entity - AND - fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__create_related_full_texts function --- execution time before preceding 2 migrations (project / repo): 2912.905 ms / 2955.224 ms --- execution time after preceding 2 migration (project / repo): 0.990 ms / 2.192 ms --- execution time after tuning (project / repo): -- NO NEED ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_own_entity_label function --- execution time before preceding 2 migrations (project / repo): 598.411 ms / 318.201 ms --- execution time after preceding 2 migration (project / repo): CRASHED --- execution time after tuning (project / repo): 0.135 ms / 0.241 ms - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label (param_pk_entity integer, param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; -BEGIN - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT - ( - SELECT - fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1) IS NULL) THEN - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_entity_label - WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order = 0 - AND t1.fk_temporal_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE - t1.fk_class_field = t2.fk_class_field - AND t2.field_order = 0 - AND t1.fk_concerned_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project -) SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) - tw1.string INTO new_own_entity_label -FROM - tw1 -ORDER BY - tw1.pk_entity, - tw1.fk_project, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count DESC; - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - ----- Insert or update column own_entity_label of table entity_preview - SELECT - entity_label INTO old_own_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - ELSIF ( - SELECT - (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - entity_label = new_own_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; -END IF; - RETURN TRUE; -END; -$BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_own_full_text function --- execution time before preceding 2 migrations (project / repo): 588.048 ms / 740.127 ms --- execution time after preceding 2 migration (project / repo): CRASHED --- execution time after tuning (project / repo): 4.473 ms / 5.979 ms - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text (param_pk_entity integer, param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; -BEGIN - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_full_text - WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order IS NOT NULL - WHERE - t1.fk_temporal_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE - t1.fk_class_field = t2.fk_class_field - AND t1.fk_concerned_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project -), -tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project, tw1.string) - tw1.pk_entity, tw1.fk_project, tw1.project, tw1.string, tw1.field_order, tw1.ord_num, tw1.is_in_project_count - FROM - tw1 -) -SELECT - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order, tw2.ord_num, tw2.is_in_project_count DESC) INTO new_own_full_text -FROM - tw2 -GROUP BY - tw2.pk_entity, - tw2.fk_project, - tw2.project; - RAISE INFO 'new_own_full_text: %', new_own_full_text; - ----- Insert or update column own_full_text of table entity_preview - SELECT - own_full_text INTO old_own_full_text - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_own_full_text: %', old_own_full_text; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - ELSIF ( - SELECT - (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - UPDATE - warehouse.entity_preview - SET - own_full_text = new_own_full_text - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - RETURN TRUE; -END; -$BODY$; - ---------------------------------------------------------------------------------------------------- --- tune performace of warehouse.entity_preview__fill_time_span function --- execution time before preceding 2 migrations (project / repo): 1472.373 ms / 1556.207 ms --- execution time after preceding 2 migration (project / repo): 136.578 ms / 115.624 ms --- execution time after tuning (project / repo): 1.445 ms / 0.898 ms - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span (param_pk_entity integer, param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - new_time_span jsonb; -BEGIN - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - -- get new_time_span - -- SELECT time_span INTO new_time_span - -- FROM warehouse.v_te_en_time_span_per_project_and_repo - -- WHERE fk_temporal_entity = param_pk_entity - -- AND fk_project IS NOT DISTINCT FROM param_fk_project; - WITH role_with_time_primitive AS ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM - information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) - AND tp.pk_entity = r.fk_entity - AND epr.is_in_project = TRUE - AND r.fk_temporal_entity = param_pk_entity - AND epr.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM - information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND r.fk_temporal_entity = param_pk_entity - ORDER BY - r.fk_temporal_entity, - r.fk_property, - r.is_in_project_count DESC, - r.tmsp_creation DESC) -) -SELECT - jsonb_object_agg( - CASE WHEN role_with_time_primitive.fk_property = 71 THEN - 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN - 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN - 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN - 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN - 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN - 'p82b'::text - ELSE - role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) INTO new_time_span -FROM - role_with_time_primitive -GROUP BY - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity; - RAISE INFO 'new_time_span: %', new_time_span; - -- update this entity_preview with new_time_span - UPDATE - warehouse.entity_preview - SET - time_span = new_time_span - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RETURN TRUE; - END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-down.sql b/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-down.sql deleted file mode 100644 index ceab27621..000000000 --- a/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-down.sql +++ /dev/null @@ -1,201 +0,0 @@ --- 2 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - --------------------- text_property --------------------- - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]); - --------------------- role ----------------------------- - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - is_in_project INTO _domain_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_temporal_entity - AND fk_project = _fk_project; - SELECT - is_in_project INTO _range_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_entity - AND fk_project = _fk_project; - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - ------------ init update of preview of domain entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]); - ------------ in project - IF (_domain_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]); - END IF; - ------------ init update of preview of range entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, NULL::text]); - ------------ in project - IF (_range_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, _fk_project::text]); - END IF; - --------------------- entity_association ----------------- - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, NULL::text]); - --------------------- temporal_entity or persistent_item ----------------- - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - IF (NEW.is_in_project = TRUE) THEN - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, NULL::text]); - ELSIF (NEW.is_in_project = FALSE) THEN - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - END IF; - END IF; - RETURN NEW; -END; -$BODY$; - --- 1 - -DROP FUNCTION information.is_persistent_item_or_temporal_entity; - diff --git a/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-up.sql b/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-up.sql deleted file mode 100644 index 673b70712..000000000 --- a/server/db-migrate/migrations/sqls/20190717132146-war-trigger-functions-tuning-up.sql +++ /dev/null @@ -1,224 +0,0 @@ --- 1 helper function to check if entity is peit or teen -CREATE FUNCTION information.is_persistent_item_or_temporal_entity (integer) - RETURNS BOOLEAN - AS $$ - SELECT - EXISTS ( - SELECT - pk_entity - FROM - information.persistent_item - WHERE - pk_entity = $1 - UNION - SELECT - pk_entity - FROM - information.temporal_entity - WHERE - pk_entity = $1) -$$ -LANGUAGE SQL; - --- 2 remove calls that tried to create previews for languages and appellations - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__upsert_entity_preview () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - --------------------- text_property --------------------- - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]); - --------------------- role ----------------------------- - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - is_in_project INTO _domain_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_temporal_entity - AND fk_project = _fk_project; - SELECT - is_in_project INTO _range_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_entity - AND fk_project = _fk_project; - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - ------------ init update of preview of domain entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]); - ------------ in project - IF (_domain_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]); - END IF; - IF ( - SELECT - information.is_persistent_item_or_temporal_entity (_fk_entity) = TRUE) THEN - ------------ init update of preview of range entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, NULL::text]); - ------------ in project - IF (_range_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, _fk_project::text]); - END IF; - END IF; - --------------------- entity_association ----------------- - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, NULL::text]); - --------------------- temporal_entity or persistent_item ----------------- - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - IF (NEW.is_in_project = TRUE) THEN - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, NULL::text]); - ELSIF (NEW.is_in_project = FALSE) THEN - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - END IF; - END IF; - RETURN NEW; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-down.sql b/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-down.sql deleted file mode 100644 index a3b21ce78..000000000 --- a/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-down.sql +++ /dev/null @@ -1,139 +0,0 @@ --- 5 -DROP FUNCTION information.add_pe_it_to_project(integer, integer, integer); - -CREATE OR REPLACE FUNCTION information.add_pe_it_to_project( - pk_entity integer, - pk_project integer, - account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - - EXECUTE format(' - - -- Relate given persistent item to given project -- - ---------------------------------------------------- - - WITH pe_it AS ( - select pk_entity, fk_class from information.persistent_item where pk_entity = %1$s - ), - -- Find "auto-add-properties" for all classes - -- TODO: Add a filter for properties enabled by given project - auto_add_properties AS ( - -- select the fk_class and the properties that are auto add because of a class_field_config - select p.dfh_has_domain as fk_class, p.dfh_pk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = true - UNION - select p.dfh_has_range as fk_class, p.dfh_pk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = false - UNION - -- select the fk_class and the properties that are auto add because of a property set - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = false - UNION - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = true - ), - -- Find all roles related to the given persistent item pk_entity - -- that are of an auto-add property - pe_it_roles AS ( - select r.pk_entity, r.fk_temporal_entity, r.fk_property, r.fk_entity, addp.max_quantifier, r.community_favorite_calendar as calendar - from information.v_role as r - inner join pe_it on r.fk_entity = pe_it.pk_entity - inner join auto_add_properties as addp on ( - addp.dfh_pk_property = r.fk_property AND addp.fk_class = pe_it.fk_class - ) - -- take only the max quantity of rows for that property, exclude repo-alternatives - WHERE r.rank_for_pe_it <= r.domain_max_quantifier OR r.domain_max_quantifier = -1 OR r.domain_max_quantifier IS NULL - ), - -- Find all temporal entities related to pe_it_roles - -- that are of an auto-add property - te_ents AS ( - select fk_temporal_entity as pk_entity - from pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - -- that are of an auto-add property - te_ent_roles AS ( - select r.pk_entity, r.fk_temporal_entity, r.fk_property, r.fk_entity, addp.max_quantifier, r.community_favorite_calendar as calendar - from information.v_role as r - inner join pe_it_roles as pi_r on pi_r.fk_temporal_entity = r.fk_temporal_entity - inner join information.temporal_entity as te on te.pk_entity = pi_r.fk_temporal_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = r.fk_property AND addp.fk_class = te.fk_class) - -- take only the max quantity of rows for that property, exclude repo-alternatives - WHERE r.rank_for_te_ent <= r.range_max_quantifier OR r.range_max_quantifier = -1 OR r.range_max_quantifier IS NULL - ), - -- find all entity associations that involve the pe_it - -- that are of an auto-add property - pe_it_entity_associations AS ( - -- where pe_it is domain - select ea.pk_entity, ea.fk_info_domain, ea.fk_property, ea.fk_info_domain, addp.max_quantifier - from information.v_entity_association as ea - inner join pe_it on ea.fk_info_domain = pe_it.pk_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = ea.fk_property AND addp.fk_class = pe_it.fk_class) - -- take only the max allowed rows - WHERE ea.rank_for_domain <= ea.range_max_quantifier OR ea.range_max_quantifier = -1 OR ea.range_max_quantifier IS NULL - - UNION - - -- where pe_it is range - select ea.pk_entity, ea.fk_info_domain, ea.fk_property, ea.fk_info_domain, addp.max_quantifier - from information.v_entity_association as ea - inner join pe_it on ea.fk_info_domain = pe_it.pk_entity - inner join auto_add_properties as addp on (addp.dfh_pk_property = ea.fk_property AND addp.fk_class = pe_it.fk_class) - -- take only the max allowed rows - WHERE ea.rank_for_range <= ea.domain_max_quantifier OR ea.domain_max_quantifier = -1 OR ea.domain_max_quantifier IS NULL - ), - -- TODO: find all entity associations that involve the te_ents (for types or mentionings of te_ents!) - - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select pk_entity, null::calendar_type as calendar from pe_it - UNION - select pk_entity, null::calendar_type as calendar from pe_it_entity_associations - UNION - select pk_entity, calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - ) - - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT %2$s, true, pk_entity, calendar, %3$s - from pk_entities_of_repo; - ', - pk_entity, - pk_project, - account_id - ); - - END $BODY$; - --- 4 -DROP FUNCTION information.get_ingoing_entity_associations_to_add (param_pk_entity INT); - --- 3 -DROP FUNCTION information.get_outgoing_entity_associations_to_add(param_pk_entity INT); - --- 2 -DROP FUNCTION information.get_outgoing_roles_to_add (param_pk_entity INT); - --- 1 -DROP FUNCTION information.get_ingoing_roles_to_add (param_pk_entity INT); - --- 0 -DROP VIEW system.v_auto_add_properties; diff --git a/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-up.sql b/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-up.sql deleted file mode 100644 index ea973c685..000000000 --- a/server/db-migrate/migrations/sqls/20190720123806-inf-f-add-pe-it-to-project-update-up.sql +++ /dev/null @@ -1,365 +0,0 @@ --- 0 -CREATE VIEW system.v_auto_add_properties AS - select p.dfh_has_domain as fk_class, p.dfh_pk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = true - UNION - select p.dfh_has_range as fk_class, p.dfh_pk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join projects.class_field_config as ctxt on p.dfh_pk_property = ctxt.fk_property - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND ctxt.property_is_outgoing = false - UNION - -- select the fk_class and the properties that are auto add because of a property set - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_domain_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = false - UNION - select ctxt.fk_class_for_class_field, psprel.fk_property, p.dfh_range_instances_max_quantifier as max_quantifier - from data_for_history.property as p - inner join system.class_field_property_rel as psprel on psprel.fk_property = p.dfh_pk_property - inner join projects.class_field_config as ctxt on psprel.fk_class_field = ctxt.fk_class_field - Where ctxt.fk_app_context = 47 AND ctxt.ord_num is not null AND psprel.property_is_outgoing = true; - - - --- 1 function that returns a table containing the ingoing_roles_to_add of an entity -CREATE OR REPLACE FUNCTION information.get_ingoing_roles_to_add (param_pk_entity INT) - RETURNS TABLE ( - pk_entity INT, - fk_class INT, - fk_temporal_entity INT, - fk_property INT, - fk_entity INT, - max_quantifier SMALLINT, - calendar calendar_type -) -AS $$ -BEGIN - RETURN QUERY - WITH tw1 AS ( - SELECT t1.pk_entity, t1.fk_class, 'persistent_item' table_name - FROM information.persistent_item t1 - WHERE t1.pk_entity = param_pk_entity - UNION ALL - SELECT t2.pk_entity, t2.fk_class, 'temporal_entity' table_name - FROM information.temporal_entity t2 - WHERE t2.pk_entity = param_pk_entity - ) - SELECT DISTINCT - ts2.pk_entity, - ts1.fk_class, - ts2.fk_temporal_entity, - ts2.fk_property, - ts2.fk_entity, - ts1.max_quantifier, - ts2.calendar - FROM - ( - SELECT - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - FROM - system.v_auto_add_properties t1, - tw1 - WHERE - t1.fk_class = tw1.fk_class - ) AS ts1 - CROSS JOIN LATERAL ( - SELECT - t1.pk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t1.fk_entity, - t1.community_favorite_calendar as calendar - FROM - information.v_role t1, - tw1 - WHERE - t1.fk_entity = tw1.pk_entity - AND - t1.fk_property = ts1.dfh_pk_property - AND - t1.is_in_project_count IS NOT NULL - ORDER BY t1.is_in_project_count DESC, t1.tmsp_creation DESC - LIMIT ( - SELECT CASE WHEN ts1.max_quantifier = -1 THEN NULL ELSE ts1.max_quantifier END - ) - ) AS ts2; - -END; $$ - -LANGUAGE 'plpgsql'; - - --- 2 function that returns a table containing the ingoing_roles_to_add of an entity - -CREATE OR REPLACE FUNCTION information.get_outgoing_roles_to_add (param_pk_entity INT) - RETURNS TABLE ( - pk_entity INT, - fk_class INT, - fk_temporal_entity INT, - fk_property INT, - fk_entity INT, - max_quantifier SMALLINT, - calendar calendar_type -) -AS $$ -BEGIN - RETURN QUERY - WITH tw1 AS ( - SELECT t1.pk_entity, t1.fk_class, 'persistent_item' table_name - FROM information.persistent_item t1 - WHERE t1.pk_entity = param_pk_entity - UNION ALL - SELECT t2.pk_entity, t2.fk_class, 'temporal_entity' table_name - FROM information.temporal_entity t2 - WHERE t2.pk_entity = param_pk_entity - ) - SELECT DISTINCT - ts2.pk_entity, - ts1.fk_class, - ts2.fk_temporal_entity, - ts2.fk_property, - ts2.fk_entity, - ts1.max_quantifier, - ts2.calendar - FROM - ( - SELECT - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - FROM - system.v_auto_add_properties t1, - tw1 - WHERE - t1.fk_class = tw1.fk_class - ) AS ts1 - CROSS JOIN LATERAL ( - SELECT - t1.pk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t1.fk_entity, - t1.community_favorite_calendar as calendar - FROM - information.v_role t1, - tw1 - WHERE - t1.fk_temporal_entity = tw1.pk_entity - AND - t1.fk_property = ts1.dfh_pk_property - AND - t1.is_in_project_count IS NOT NULL - ORDER BY t1.is_in_project_count DESC, t1.tmsp_creation DESC - LIMIT ( - SELECT CASE WHEN ts1.max_quantifier = -1 THEN NULL ELSE ts1.max_quantifier END - ) - ) AS ts2; - -END; $$ - -LANGUAGE 'plpgsql'; - - --- 3 -CREATE OR REPLACE FUNCTION information.get_outgoing_entity_associations_to_add (param_pk_entity INT) - RETURNS TABLE ( - pk_entity INT, - fk_class INT, - fk_info_domain INT, - fk_property INT, - fk_info_range INT, - max_quantifier SMALLINT -) -AS $$ -BEGIN - RETURN QUERY - WITH tw1 AS ( - SELECT t1.pk_entity, t1.fk_class, 'persistent_item' table_name - FROM information.persistent_item t1 - WHERE t1.pk_entity = param_pk_entity - UNION ALL - SELECT t2.pk_entity, t2.fk_class, 'temporal_entity' table_name - FROM information.temporal_entity t2 - WHERE t2.pk_entity = param_pk_entity - ) - SELECT DISTINCT - ts2.pk_entity, - ts1.fk_class, - ts2.fk_info_domain, - ts2.fk_property, - ts2.fk_info_range, - ts1.max_quantifier - FROM - ( - SELECT - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - FROM - system.v_auto_add_properties t1, - tw1 - WHERE - t1.fk_class = tw1.fk_class - ) AS ts1 - CROSS JOIN LATERAL ( - SELECT - t1.pk_entity, - t1.fk_info_domain, - t1.fk_property, - t1.fk_info_range - FROM - information.v_entity_association t1, - tw1 - WHERE - t1.fk_info_domain = tw1.pk_entity - AND - t1.fk_property = ts1.dfh_pk_property - AND - t1.is_in_project_count IS NOT NULL - ORDER BY t1.is_in_project_count DESC, t1.tmsp_creation DESC - LIMIT ( - SELECT CASE WHEN ts1.max_quantifier = -1 THEN NULL ELSE ts1.max_quantifier END - ) - ) AS ts2; - -END; $$ -LANGUAGE 'plpgsql'; - - --- 4 -CREATE OR REPLACE FUNCTION information.get_ingoing_entity_associations_to_add (param_pk_entity INT) - RETURNS TABLE ( - pk_entity INT, - fk_class INT, - fk_info_domain INT, - fk_property INT, - fk_info_range INT, - max_quantifier SMALLINT -) -AS $$ -BEGIN - RETURN QUERY - WITH tw1 AS ( - SELECT t1.pk_entity, t1.fk_class, 'persistent_item' table_name - FROM information.persistent_item t1 - WHERE t1.pk_entity = param_pk_entity - UNION ALL - SELECT t2.pk_entity, t2.fk_class, 'temporal_entity' table_name - FROM information.temporal_entity t2 - WHERE t2.pk_entity = param_pk_entity - ) - SELECT DISTINCT - ts2.pk_entity, - ts1.fk_class, - ts2.fk_info_domain, - ts2.fk_property, - ts2.fk_info_range, - ts1.max_quantifier - FROM - ( - SELECT - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - FROM - system.v_auto_add_properties t1, - tw1 - WHERE - t1.fk_class = tw1.fk_class - ) AS ts1 - CROSS JOIN LATERAL ( - SELECT - t1.pk_entity, - t1.fk_info_domain, - t1.fk_property, - t1.fk_info_range - FROM - information.v_entity_association t1, - tw1 - WHERE - t1.fk_info_range = tw1.pk_entity - AND - t1.fk_property = ts1.dfh_pk_property - AND - t1.is_in_project_count IS NOT NULL - ORDER BY t1.is_in_project_count DESC, t1.tmsp_creation DESC - LIMIT ( - SELECT CASE WHEN ts1.max_quantifier = -1 THEN NULL ELSE ts1.max_quantifier END - ) - ) AS ts2; - -END; $$ -LANGUAGE 'plpgsql'; - - --- 5 - -DROP FUNCTION information.add_pe_it_to_project(integer,integer,integer); -CREATE OR REPLACE FUNCTION information.add_pe_it_to_project( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - WITH pe_it_roles AS ( - SELECT * FROM information.get_ingoing_roles_to_add(param_pk_entity) - ), - -- find all entity associations that involve the pe_it - pe_it_entity_associations AS ( - -- where pe_it is domain - SELECT * FROM information.get_outgoing_entity_associations_to_add (param_pk_entity) - UNION - -- where pe_it is range - SELECT * FROM information.get_ingoing_entity_associations_to_add (param_pk_entity) - ), - -- Find all temporal entities related to pe_it_roles - -- that are of an auto-add property - te_ents AS ( - SELECT fk_temporal_entity as pk_entity - FROM pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - te_ent_roles AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_roles_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_roles_to_add(t2.pk_entity) ) AS ts2 - ), - -- Find all entity_associations of temporal entities - te_ent_entity_associations AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - ), - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select param_pk_entity as pk_entity, null::calendar_type as calendar - UNION - select pk_entity, null::calendar_type as calendar from pe_it_entity_associations - UNION - select pk_entity, calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ent_entity_associations - ) - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT param_pk_project, true, pk_entity, calendar, param_account_id - from pk_entities_of_repo; - - END $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-down.sql b/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-down.sql deleted file mode 100644 index b448d8b5e..000000000 --- a/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-down.sql +++ /dev/null @@ -1,9 +0,0 @@ --- 2 -DROP FUNCTION information.add_outgoing_roles_with_te_ens_to_project(integer[],integer,integer); - --- 1 -DROP FUNCTION information.add_te_en_to_project( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer) - diff --git a/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-up.sql b/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-up.sql deleted file mode 100644 index b6acb4d36..000000000 --- a/server/db-migrate/migrations/sqls/20190720153605-inf-f-add-te-en-to-project-up.sql +++ /dev/null @@ -1,89 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION information.add_te_en_to_project( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - -- Find all roles related to temporal entity - WITH te_ent_roles AS ( - SELECT * FROM information.get_outgoing_roles_to_add(param_pk_entity) - UNION ALL - SELECT * FROM information.get_ingoing_roles_to_add(param_pk_entity) - ), - -- Find all entity_associations of temporal entities - te_ent_entity_associations AS ( - SELECT * FROM information.get_outgoing_entity_associations_to_add(param_pk_entity) - UNION ALL - SELECT * FROM information.get_ingoing_entity_associations_to_add(param_pk_entity) - ), - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select param_pk_entity as pk_entity, null::calendar_type as calendar - UNION - select pk_entity, calendar from te_ent_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ent_entity_associations - ) - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT param_pk_project, true, pk_entity, calendar, param_account_id - from pk_entities_of_repo; - - END $BODY$; - - --- 2 -CREATE OR REPLACE FUNCTION information.add_outgoing_roles_with_te_ens_to_project( - param_pk_roles integer[], - param_pk_project integer, - param_account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - WITH pe_it_roles AS ( - select pk_entity, fk_temporal_entity - from information.v_role - where pk_entity IN (select(unnest(param_pk_roles))) - ), - te_ents AS ( - SELECT fk_temporal_entity as pk_entity - FROM pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - te_ent_roles AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_roles_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_roles_to_add(t2.pk_entity) ) AS ts2 - ), - -- Find all entity_associations of temporal entities - te_ent_entity_associations AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - ), - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select pk_entity, null::calendar_type as calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ent_entity_associations - ) - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT param_pk_project, true, pk_entity, calendar, param_account_id - from pk_entities_of_repo; - - END $BODY$; diff --git a/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-down.sql b/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-down.sql deleted file mode 100644 index dd8aad23d..000000000 --- a/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP VIEW data_for_history.v_property_profile_view; -DROP VIEW data_for_history.v_property; diff --git a/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-up.sql b/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-up.sql deleted file mode 100644 index 9883d1dea..000000000 --- a/server/db-migrate/migrations/sqls/20190723083954-dfh-v-property-up.sql +++ /dev/null @@ -1,49 +0,0 @@ -CREATE VIEW data_for_history.v_property_profile_view AS -SELECT DISTINCT - t1.pk_entity, - CASE WHEN t1.dfh_fk_property_of_origin IS NOT NULL THEN true ELSE false END is_inherited, - t1.dfh_has_domain, - coalesce(t1.dfh_fk_property_of_origin, t1.dfh_pk_property) fk_property, - t1.dfh_has_range, - t1.dfh_pk_property, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.dfh_pk_profile, - t1.dfh_profile_label, - t1.is_enabled_in_profile, - t1.removed_from_api, - t1.dfh_fk_property_of_origin, - t2.dfh_domain_instances_min_quantifier, - t2.dfh_domain_instances_max_quantifier, - t2.dfh_range_instances_min_quantifier, - t2.dfh_range_instances_max_quantifier, - t2.identity_defining -FROM -data_for_history.property_profile_view t1, -data_for_history.property t2 -WHERE t1.dfh_pk_property = t2.dfh_pk_property -ORDER BY is_inherited, fk_property, t1.dfh_pk_property; - - - -CREATE VIEW data_for_history.v_property AS -SELECT DISTINCT - t1.pk_entity, - CASE WHEN t1.dfh_fk_property_of_origin IS NOT NULL THEN true ELSE false END is_inherited, - t1.dfh_has_domain, - coalesce(t1.dfh_fk_property_of_origin, t1.dfh_pk_property) fk_property, - t1.dfh_has_range, - t1.dfh_pk_property, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.is_enabled_in_profile, - t1.removed_from_api, - t1.dfh_fk_property_of_origin, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.identity_defining -FROM -data_for_history.property t1 -ORDER BY dfh_has_domain, fk_property, is_inherited, t1.dfh_pk_property; diff --git a/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-down.sql b/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-down.sql deleted file mode 100644 index 16e8555a4..000000000 --- a/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP VIEW data_for_history.v_class; - diff --git a/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-up.sql b/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-up.sql deleted file mode 100644 index 7cbc76aa0..000000000 --- a/server/db-migrate/migrations/sqls/20190723160435-dfh-v-class-up.sql +++ /dev/null @@ -1,37 +0,0 @@ -CREATE VIEW data_for_history.v_class AS -select DISTINCT ON ( - pk_entity, - entity_version, - is_enabled_in_profile, - removed_from_api, - dfh_pk_class, - dfh_identifier_in_namespace, - dfh_standard_label, - dfh_creation_time, - dfh_modification_time -) -t1.pk_entity, -t1.entity_version, -t1.is_enabled_in_profile, -t1.removed_from_api, -t1.dfh_pk_class, -t1.dfh_identifier_in_namespace, -t1.dfh_standard_label, -t1.dfh_creation_time, -t1.dfh_modification_time, -t2.dfh_fk_system_type -from - data_for_history."class" t1, - data_for_history.class_profile_view t2 -WHERE - t1.dfh_pk_class = t2.dfh_fk_class -ORDER BY - pk_entity, - entity_version, - is_enabled_in_profile, - removed_from_api, - dfh_pk_class, - dfh_identifier_in_namespace, - dfh_standard_label, - dfh_creation_time, - dfh_modification_time; diff --git a/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-down.sql b/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-down.sql deleted file mode 100644 index 9e8456799..000000000 --- a/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back diff --git a/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-up.sql b/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-up.sql deleted file mode 100644 index 9677ff32d..000000000 --- a/server/db-migrate/migrations/sqls/20190730144210-dat-t-cell-improve-performance-up.sql +++ /dev/null @@ -1,51 +0,0 @@ -/* Replace with your SQL commands */ --- 1 -DROP TRIGGER IF EXISTS sync_quill_doc_and_string ON data.cell; - --- 2 -ALTER TABLE commons.text DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.cell DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.chunk DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.digital DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.text_property DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE information.appellation DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE information.text_property DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE projects.text_property DROP CONSTRAINT text_quill_doc_check; - -ALTER TABLE data.cell_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.chunk_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.digital_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE data.text_property_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE information.appellation_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE information.text_property_vt DROP CONSTRAINT text_quill_doc_check; -ALTER TABLE projects.text_property_vt DROP CONSTRAINT text_quill_doc_check; - - --- 3 -ALTER TABLE data.cell NO INHERIT commons.text; -ALTER TABLE data.cell -DROP COLUMN quill_doc; -ALTER TABLE data.cell - ADD COLUMN quill_doc jsonb; - - --- 4 -ALTER TABLE data.cell_vt NO INHERIT commons.text_vt; -ALTER TABLE data.cell_vt -DROP COLUMN quill_doc; -ALTER TABLE data.cell_vt - ADD COLUMN quill_doc jsonb; - --- 5 -ALTER TABLE commons.text ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE data.cell ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE data.chunk ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE data.digital ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE data.text_property ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE information.appellation ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE information.text_property ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); -ALTER TABLE projects.text_property ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc(quill_doc)); - --- 6 -ALTER TABLE data.cell INHERIT commons.text; -ALTER TABLE data.cell_vt INHERIT commons.text_vt; diff --git a/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-down.sql b/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-down.sql deleted file mode 100644 index e1f63b360..000000000 --- a/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE data.text_property DROP COLUMN fk_entity; -ALTER TABLE data.text_property_vt DROP COLUMN fk_entity; diff --git a/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-up.sql b/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-up.sql deleted file mode 100644 index 9934c3daf..000000000 --- a/server/db-migrate/migrations/sqls/20190730161751-dat-t-text-property-add-fk-entity-up.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -ALTER TABLE data.text_property ADD COLUMN fk_entity INT; -ALTER TABLE data.text_property_vt ADD COLUMN fk_entity INT; diff --git a/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-down.sql b/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-down.sql deleted file mode 100644 index 5a1837e85..000000000 --- a/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-down.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -DROP TABLE projects.property_label; -DROP TABLE projects.property_label_vt; diff --git a/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-up.sql b/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-up.sql deleted file mode 100644 index 5dd1d6616..000000000 --- a/server/db-migrate/migrations/sqls/20190802220445-pro-t-property-label-up.sql +++ /dev/null @@ -1,24 +0,0 @@ -/* Replace with your SQL commands */ -CREATE TABLE projects.property_label ( - pk_entity integer NOT NULL DEFAULT nextval('projects.entity_pk_entity_seq'::regclass), - label text, - fk_project int, - fk_language int, - fk_system_type int, - fk_property int, - fk_domain_class int, - fk_range_class int, - FOREIGN KEY (fk_project) REFERENCES projects.project (pk_entity), - FOREIGN KEY (fk_domain_class) REFERENCES data_for_history.class (dfh_pk_class), - FOREIGN KEY (fk_range_class) REFERENCES data_for_history.class (dfh_pk_class), --- FOREIGN KEY (fk_property) REFERENCES data_for_history.property (dfh_pk_property), - FOREIGN KEY (fk_system_type) REFERENCES system.system_type (pk_entity), - FOREIGN KEY (fk_language) REFERENCES information.language (pk_entity) -) -INHERITS ( - projects.entity -); - -SELECT - commons.init_entity_child_table ('projects.property_label'); - diff --git a/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-down.sql b/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-down.sql deleted file mode 100644 index 934a6a127..000000000 --- a/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -/* Replace with your SQL commands */ -DROP SCHEMA tables; diff --git a/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-up.sql b/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-up.sql deleted file mode 100644 index 33233b599..000000000 --- a/server/db-migrate/migrations/sqls/20190821121040-tab-init-schema-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -/* Replace with your SQL commands */ -CREATE SCHEMA tables; diff --git a/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-down.sql b/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-down.sql deleted file mode 100644 index 2c5d59d4a..000000000 --- a/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-down.sql +++ /dev/null @@ -1,27 +0,0 @@ --- 13 --- trigger deleted by down step 11 - --- 12 --- data migration: deleted by down step 11 - --- 11 -DROP TABLE tables.row_vt; - --- 10 -ALTER TABLE tables."row" - ALTER COLUMN pk_row DROP DEFAULT; - --- 9 -DROP SEQUENCE tables.row_pk_row_seq; - --- 5, 6, 7, 8 --- trigger deleted by down step 1 - --- 4 --- data migration: deleted by down step 1 - --- 3 -DROP INDEX tables.row_fk_digital_idx; - --- 1 -DROP TABLE tables."row" diff --git a/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-up.sql b/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-up.sql deleted file mode 100644 index f12359b17..000000000 --- a/server/db-migrate/migrations/sqls/20190821122546-tab-t-row-up.sql +++ /dev/null @@ -1,190 +0,0 @@ -/* Replace with your SQL commands */ - - --- 1 -CREATE TABLE tables."row" -( - pk_row bigint, - fk_digital integer NOT NULL, - entity_version integer NOT NULL, - fk_publication_status integer, - fk_license integer, - fk_namespace integer, - notes text COLLATE pg_catalog."default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb, - id_for_import integer, - id_for_import_txt text COLLATE pg_catalog."default", - - CONSTRAINT row_pkey PRIMARY KEY (pk_row), - CONSTRAINT row_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -); - - --- 3 - -CREATE INDEX row_fk_digital_idx - ON tables."row" USING btree - (fk_digital); - - --- 4 -/* - Migrate data from data."row" table -*/ - -INSERT INTO tables."row" ( - entity_version, - fk_creator, - fk_digital, - fk_last_modifier, - fk_license, - fk_namespace, - fk_publication_status, - id_for_import, - id_for_import_txt, - metadata, - notes, - pk_row, - sys_period, - tmsp_creation, - tmsp_last_modification - ) -SELECT entity_version, - fk_creator, - fk_digital, - fk_last_modifier, - fk_license, - fk_namespace, - fk_publication_status, - id_for_import, - id_for_import_txt, - metadata, - notes, - pk_entity, - sys_period, - tmsp_creation, - tmsp_last_modification -FROM data."row"; - - - --- 5 -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - --- 6 -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - - --- 7 -CREATE TRIGGER create_entity_version_key -- why do not simply replace by DEFAULT 1 in the field definition ? - BEFORE INSERT - ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - --- 8 -CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - - --- 9 -/* - This is the bigserial pk sequence created after the import of existing data - using the max(pk_row) value : 24615815 + 1 -*/ - -CREATE SEQUENCE tables.row_pk_row_seq AS BIGINT INCREMENT 1; -SELECT SETVAL('tables.row_pk_row_seq', COALESCE(MAX(pk_row) + 1, 1)) -FROM tables.row; - - --- 10 -/* - Sets the new sequence as pk_row default value -*/ - -ALTER TABLE tables."row" - ALTER COLUMN pk_row SET DEFAULT nextval('tables.row_pk_row_seq'); - - - --- -- 11 - -CREATE TABLE tables.row_vt ( - LIKE tables.row -); - - - --- 12 -/* - Import existing data from the data.row_vt -*/ - -INSERT INTO tables.row_vt ( - entity_version, - fk_creator, - fk_digital, - fk_last_modifier, - fk_license, - fk_namespace, - fk_publication_status, - id_for_import, - id_for_import_txt, - metadata, - notes, - pk_row, - sys_period, - tmsp_creation, - tmsp_last_modification -) -SELECT entity_version, - fk_creator, - fk_digital, - fk_last_modifier, - fk_license, - fk_namespace, - fk_publication_status, - id_for_import, - id_for_import_txt, - metadata, - notes, - pk_entity, - sys_period, - tmsp_creation, - tmsp_last_modification -FROM data.row_vt; - - - - --- 13 --- CREATE TRIGGER versioning_trigger ON tables."row"; - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'tables.row_vt', 'true'); diff --git a/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-down.sql b/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-down.sql deleted file mode 100644 index a8468ed7c..000000000 --- a/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-down.sql +++ /dev/null @@ -1,26 +0,0 @@ --- 14 -ALTER TABLE tables.cell ALTER COLUMN pk_cell DROP DEFAULT; - --- 13 --- done by down step 1 - --- 12 -DROP SEQUENCE tables.cell_pk_cell_seq; - --- 10 --- drop function again: done by down step 8 - --- 9 --- data migration: data.cell -> tables.cell, deleted by down step 1 - --- 8 -DROP FUNCTION tables.create_cell_table_for_digital(pk_digital integer); - --- 3, 4, 5, 6, 7 --- data manipulations - --- 2 -DROP table tables.cell_vt; - --- 1 -DROP table tables.cell; diff --git a/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-up.sql b/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-up.sql deleted file mode 100644 index 6fe326046..000000000 --- a/server/db-migrate/migrations/sqls/20190821125131-tab-t-cell-up.sql +++ /dev/null @@ -1,398 +0,0 @@ --- 1 -CREATE TABLE tables.cell -( - pk_cell bigint NOT NULL, -- DEFAULT nextval('tables.entity_pk_entity_seq'::regclass), - fk_column integer NOT NULL, - fk_row bigint NOT NULL, - fk_digital integer NOT NULL, - numeric_value numeric, - string_value text, - entity_version integer NOT NULL, - notes text, - fk_namespace integer, - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb, - id_for_import integer, - id_for_import_txt text, - fk_publication_status integer, - fk_license integer, - CONSTRAINT cell_pk_cell_primary_key PRIMARY KEY (pk_cell) -); - - --- 2 -CREATE TABLE tables.cell_vt ( - LIKE tables.cell -); - - -/* -Following instructions (3-7) update the 'string_value' column in the original 'data.cell' table for all cells that where created before this column was added to the table. -It also sets the entity version value back to 1 because the earlier version will not be imported into the new 'tables' schema. -*/ - --- 3 -ALTER TABLE data.cell - DISABLE TRIGGER versioning_trigger; - --- 4 -ALTER TABLE data.cell - DISABLE TRIGGER update_entity_version_key; - --- 5 -ALTER TABLE data.cell - DISABLE TRIGGER last_modification_tmsp; - --- 6 -UPDATE data.cell - SET string_value = id_for_import_txt -WHERE LENGTH(id_for_import_txt) > 0 -AND (string_value IS NULL OR string_value = ''); - --- 7 -UPDATE data.cell - SET entity_version = 1; - - - --- 8 --- DROP FUNCTION tables.create_cell_table_for_digital(pk_digital integer); - -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital(pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' -AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; - -BEGIN - - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result ; - - IF test_query_result - THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists' ; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - /* - Following INSERT has to be suppressed after migration from table data.cell - */ - INSERT INTO tables.cell_' || pk_digital::text || ' ( - entity_version, - fk_column, - fk_creator, - fk_digital, - fk_last_modifier, - fk_license, - fk_namespace, - fk_publication_status, - fk_row, - id_for_import, - id_for_import_txt, - metadata, - notes, - numeric_value, - pk_cell, - string_value, - sys_period, - tmsp_creation, - tmsp_last_modification - ) - - SELECT t1.entity_version, - t1.fk_column, - t1.fk_creator, - ' || pk_digital || ', - t1.fk_last_modifier, - t1.fk_license, - t1.fk_namespace, - t1.fk_publication_status, - t1.fk_row, - t1.id_for_import, - t1.id_for_import_txt, - t1.metadata, - t1.notes, - t1.numeric_value, - t1.pk_entity, - t1.string_value, - t1.sys_period, - t1.tmsp_creation, - t1.tmsp_last_modification - FROM data.cell t1, - data.column t2 - WHERE t2.pk_entity = t1.fk_column - AND t2.fk_digital = ' || pk_digital::text || '; - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING btree(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); ' - - - ; - - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - - END IF; - -RETURN result_text; -END; -$BODY$; - - --- 9 -/* -Get all digitals' ids that have rows, i.e. are tables. Without rows no cells. - -SELECT DISTINCT fk_digital AS id_digital -FROM data.row -ORDER BY fk_digital; - -Result: -fk_digital -82819 -82900 -98270 -98645 -277245 -293949 -303439 -303647 -303710 -304894 -305080 -305446 -306424 -386428 -387616 -419278 -599458 -1175660 -1784924 -18817346 -18836294 -18846350 -18947213 -24521730 -24612271 -*/ - - - - - - -/* - BEWARE : this takes at least 18 minutes and produces 25 tables -*/ -WITH tw1 AS -( - SELECT DISTINCT fk_digital AS id_digital - FROM data.row - --WHERE fk_digital = 82819 - ORDER BY fk_digital -) -SELECT tables.create_cell_table_for_digital(id_digital) -FROM tw1; - - - - - --- 10 --- DROP FUNCTION tables.create_cell_table_for_digital(pk_digital integer); - -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital(pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' -AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; - -BEGIN - - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result ; - - IF test_query_result - THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists' ; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING btree(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); ' - - - ; - - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - - END IF; - -RETURN result_text; -END; -$BODY$; - - - - --- 12 -/* - This is the bigserial pk sequence created after the import of existing data - using the max(pk_cell) value : 24626438 + 1 - -SELECT MAX(pk_cell) -FROM tables.cell; - -*/ - -CREATE SEQUENCE tables.cell_pk_cell_seq AS BIGINT INCREMENT 1; - - --- 13 -SELECT SETVAL('tables.cell_pk_cell_seq', COALESCE(MAX(pk_cell) + 1, 1)) -FROM tables.cell; - - - --- 14 -/* - Sets the new sequence as pk_cell default value -*/ - -ALTER TABLE tables.cell - ALTER COLUMN pk_cell SET DEFAULT nextval('tables.cell_pk_cell_seq'); diff --git a/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-down.sql b/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-down.sql deleted file mode 100644 index 8f211c716..000000000 --- a/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 3 to 16 --- done by down step 1 - --- 2 -DROP table tables.quill_doc_cell_vt CASCADE; - --- 1 -DROP TABLE tables.quill_doc_cell; diff --git a/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-up.sql b/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-up.sql deleted file mode 100644 index d3c971d98..000000000 --- a/server/db-migrate/migrations/sqls/20190821131321-tab-t-quill-doc-cell-up.sql +++ /dev/null @@ -1,164 +0,0 @@ --- 1 -CREATE TABLE tables.quill_doc_cell -( CONSTRAINT quill_doc_cell_pk_cell_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT quill_doc_cell_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT quill_doc_cell_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT quill_doc_cell_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -/* -This constraint cannot be added because the correspondent row of a child table is not 'seen' in the constraint -, - CONSTRAINT quill_doc_cell_fk_cell_fkey FOREIGN KEY (fk_original_cell) - REFERENCES tables.cell (pk_cell) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -*/ -) -INHERITS (tables.cell, commons.text); - - --- 2 -CREATE TABLE tables.quill_doc_cell_vt ( ) INHERITS (tables.cell_vt, commons.text_vt); - - --- 3 - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'tables.quill_doc_cell_vt', 'true'); - - - --- 4 - --- DROP INDEX tables.quill_doc_cell_fk_column_idx; - -CREATE INDEX quill_doc_cell_fk_column_idx - ON tables.quill_doc_cell USING btree - (fk_column) - TABLESPACE pg_default; - --- 5 - --- DROP INDEX tables.quill_doc_cell_fk_digital_idx; - -CREATE INDEX quill_doc_cell_fk_digital_idx - ON tables.quill_doc_cell USING btree - (fk_digital) - TABLESPACE pg_default; - --- 6 - --- DROP INDEX tables.quill_doc_cell_fk_row_idx; - -CREATE INDEX quill_doc_cell_fk_row_idx - ON tables.quill_doc_cell USING btree - (fk_row) - TABLESPACE pg_default; - --- 7 - --- DROP INDEX tables.quill_doc_cell_id_for_import_txt_idx; - -CREATE INDEX quill_doc_cell_id_for_import_txt_idx - ON tables.quill_doc_cell USING btree - (id_for_import_txt COLLATE pg_catalog."default") - TABLESPACE pg_default; - --- 8 - --- DROP INDEX tables.quill_doc_cell_pk_cell_idx; - -CREATE INDEX quill_doc_cell_pk_cell_idx - ON tables.quill_doc_cell USING btree - (pk_cell) - TABLESPACE pg_default; - --- 9 - --- DROP INDEX tables.quill_doc_cell_string_value_idx; - -CREATE INDEX quill_doc_cell_string_value_idx - ON tables.quill_doc_cell USING btree - (string_value COLLATE pg_catalog."default") - TABLESPACE pg_default; - --- 10 - --- DROP TRIGGER create_entity_version_key ON tables.quill_doc_cell; - -CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - --- 11 - --- DROP TRIGGER creation_tmsp ON tables.quill_doc_cell; - -CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - --- 12 - --- DROP TRIGGER last_modification_tmsp ON tables.quill_doc_cell; - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - --- 13 - --- DROP TRIGGER update_entity_version_key ON tables.quill_doc_cell; - -CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key(); - --- 14 - --- DROP TRIGGER insert_schema_table_name ON data.cell; - -CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - --- 15 - --- DROP INDEX commons.text_string_idx; - -CREATE INDEX text_string_idx - ON tables.quill_doc_cell USING btree - (string COLLATE pg_catalog."default") - TABLESPACE pg_default; - --- 16 - --- DROP TRIGGER sync_quill_doc_and_string ON commons.text; - -CREATE TRIGGER sync_quill_doc_and_string - BEFORE INSERT OR UPDATE - ON tables.quill_doc_cell - FOR EACH ROW - EXECUTE PROCEDURE commons.text__sync_quill_doc_and_string(); diff --git a/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-down.sql b/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-down.sql deleted file mode 100644 index 65eef19f6..000000000 --- a/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-down.sql +++ /dev/null @@ -1,863 +0,0 @@ --- 5 -DROP VIEW information.v_entity_association CASCADE; - -CREATE OR REPLACE VIEW information.v_entity_association AS WITH ea_project_count AS ( - SELECT - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = TRUE), 0::bigint) AS is_in_project_count - FROM - information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity -GROUP BY - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period -) -SELECT - ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier -FROM - ea_project_count ea - LEFT JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS SELECT DISTINCT - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS project, - ea.is_in_project_count -FROM - information.v_entity_association ea, - projects.info_proj_rel epr -WHERE - epr.fk_entity = ea.pk_entity - AND epr.is_in_project = TRUE -UNION -SELECT DISTINCT - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - 0 AS project, - ea.is_in_project_count -FROM - information.v_entity_association ea -WHERE - ea.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_fk_type AS WITH tw1 AS ( - SELECT DISTINCT ON (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL - AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL - AND t3.fk_property = t4.fk_property - ORDER BY - 1, - 2, - 3, - 5 DESC -) -SELECT DISTINCT ON (tw1.fk_info_domain, tw1.fk_project) - tw1.fk_info_domain AS pk_entity, - tw1.fk_project, - COALESCE(tw1.fk_project, 0) AS project, - tw1.fk_info_range AS fk_type -FROM - tw1; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts -FROM - warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity - AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS WITH previews_non_recursive AS ( - SELECT - v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM - warehouse.v_entity_preview_non_recursive -), -fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM - full_text_dependencies -GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project -), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts) jsonb_each_text(KEY, value)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM - add_full_text t -) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - --- 3 -DROP VIEW information.v_role CASCADE; - -CREATE OR REPLACE VIEW information.v_role AS -SELECT - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier -FROM - information.role t1 - JOIN data_for_history.property p ON t1.fk_property = p.dfh_pk_property - LEFT JOIN LATERAL ( - SELECT - count(info_proj_rel.pk_entity) AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE info_proj_rel.ord_num_of_domain = 0), 0::bigint) AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY info_proj_rel.calendar) AS community_favorite_calendar - FROM - projects.info_proj_rel - WHERE - info_proj_rel.fk_entity = t1.pk_entity - AND info_proj_rel.is_in_project = TRUE GROUP BY - info_proj_rel.fk_entity) t2 ON TRUE -LIMIT 1; - -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role t1, - projects.info_proj_rel t2 -WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = TRUE -UNION -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role t1 -WHERE - t1.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS WITH role_with_time_primitive AS ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM - information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, - 72, - 150, - 151, - 152, - 153])) - AND tp.pk_entity = r.fk_entity - AND epr.is_in_project = TRUE - UNION ( SELECT DISTINCT ON (r.fk_temporal_entity, - r.fk_property) - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM - information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, - 72, - 150, - 151, - 152, - 153]) - ORDER BY - r.fk_temporal_entity, - r.fk_property, - r.is_in_project_count DESC, - r.tmsp_creation DESC)) -SELECT - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE WHEN role_with_time_primitive.fk_property = 71 THEN - 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN - 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN - 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN - 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN - 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN - 'p82b'::text - ELSE - role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span -FROM - role_with_time_primitive -GROUP BY - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity; - -CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS WITH tw1 AS ( - SELECT - temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEnt'::text AS entity_type - FROM - information.temporal_entity - UNION - SELECT - persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM - information.persistent_item -) -SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) - t1.pk_entity, - COALESCE(t3.fk_project, t4.fk_project) AS fk_project, - COALESCE(t3.fk_project, t4.fk_project, 0) AS project, - t1.fk_class, - t1.table_name, - t1.entity_type, - COALESCE(t4.fk_temporal_entity, CASE WHEN t5.table_name::text = ANY (ARRAY['persistent_item'::character varying::text, 'temporal_entity'::character varying::text]) THEN - t3.fk_entity - ELSE - NULL::integer - END) AS fk_entity_label -FROM - tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN warehouse.v_roles_per_project_and_repo t3 ON t2.fk_property = t3.fk_property - AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN information.entity t5 ON t3.fk_entity = t5.pk_entity - LEFT JOIN warehouse.v_roles_per_project_and_repo t4 ON t2.fk_property = t4.fk_property - AND t1.pk_entity = t4.fk_entity -WHERE - t2.field_order = 0 -ORDER BY - t1.pk_entity, - t3.fk_project, - t4.fk_project, - t1.fk_class, - t2.field_order, - t3.ord_num_of_domain, - t4.ord_num_of_domain, - t3.is_in_project_count DESC, - t4.is_in_project_count DESC; - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order = 0 - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field - AND t2.field_order = 0 -) -SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) - tw1.pk_entity, - tw1.fk_project, - tw1.string AS entity_label, - tw1.project -FROM - tw1 -ORDER BY - tw1.pk_entity, - tw1.fk_project, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count DESC; - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order IS NOT NULL - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field -), -tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, - tw1.fk_project, - tw1.string) - tw1.pk_entity, - tw1.fk_project, - tw1.project, - tw1.string, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count - FROM - tw1 -) -SELECT - tw2.pk_entity, - tw2.fk_project, - tw2.project, - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order, tw2.ord_num, tw2.is_in_project_count DESC) AS own_full_text -FROM - tw2 -GROUP BY - tw2.pk_entity, - tw2.fk_project, - tw2.project; - -CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS -SELECT - t1.fk_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_temporal_entity::text, NULL::unknown) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo t1 -GROUP BY - t1.fk_entity, - t1.fk_project, - t1.project -UNION -SELECT - t1.fk_temporal_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_entity::text, NULL::unknown) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo t1, - information.persistent_item t2 -WHERE - t1.fk_entity = t2.pk_entity -GROUP BY - t1.fk_temporal_entity, - t1.fk_project, - t1.project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts -FROM - warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity - AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS WITH previews_non_recursive AS ( - SELECT - v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM - warehouse.v_entity_preview_non_recursive -), -fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM - full_text_dependencies -GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project -), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts) jsonb_each_text(KEY, value)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM - add_full_text t -) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - --- 2 -DROP FUNCTION commons.get_dependent_objects; - --- 1 -DROP FUNCTION commons.create_sql_for_updating_view_with_dependencies; - diff --git a/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-up.sql b/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-up.sql deleted file mode 100644 index b29db5b4c..000000000 --- a/server/db-migrate/migrations/sqls/20190823100949-inf-v-role-and-ea-parse-int-up.sql +++ /dev/null @@ -1,1142 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION commons.get_dependent_objects (object_name text) - RETURNS TABLE ( - level int, dep_name text) - LANGUAGE 'sql' - COST 100 VOLATILE - AS $BODY$ - WITH RECURSIVE dep_recursive AS ( - -- Recursion: Initial Query - SELECT - 0 AS "level", - object_name AS "dep_name", - -- <- define dependent object HERE - '' AS "dep_table", - '' AS "dep_type", - '' AS "ref_name", - '' AS "ref_type" - UNION ALL - -- Recursive Query - SELECT - level + 1 AS "level", - depedencies.dep_name, - depedencies.dep_table, - depedencies.dep_type, - depedencies.ref_name, - depedencies.ref_type - FROM ( - -- This function defines the type of any pg_class object - WITH classType AS ( - SELECT - oid, - CASE relkind - WHEN 'r' THEN - 'TABLE'::text - WHEN 'i' THEN - 'INDEX'::text - WHEN 'S' THEN - 'SEQUENCE'::text - WHEN 'v' THEN - 'VIEW'::text - WHEN 'c' THEN - 'TYPE'::text -- note: COMPOSITE type - WHEN 't' THEN - 'TABLE'::text -- note: TOAST table - END AS "type" - FROM - pg_class) - -- Note: In pg_depend, the triple (classid,objid,objsubid) describes some object that depends - -- on the object described by the tuple (refclassid,refobjid). - -- So to drop the depending object, the referenced object (refclassid,refobjid) must be dropped first - SELECT DISTINCT - -- dep_name: Name of dependent object - CASE classid - WHEN 'pg_class'::regclass THEN - objid::regclass::text - WHEN 'pg_type'::regclass THEN - objid::regtype::text - WHEN 'pg_proc'::regclass THEN - objid::regprocedure::text - WHEN 'pg_constraint'::regclass THEN - ( - SELECT - conname - FROM - pg_constraint - WHERE - OID = objid) - WHEN 'pg_attrdef'::regclass THEN - 'default' - WHEN 'pg_rewrite'::regclass THEN - ( - SELECT - ev_class::regclass::text - FROM - pg_rewrite - WHERE - OID = objid) - WHEN 'pg_trigger'::regclass THEN - ( - SELECT - tgname - FROM - pg_trigger - WHERE - OID = objid) - ELSE - objid::text - END AS "dep_name", - -- dep_table: Name of the table that is associated with the dependent object (for default values, triggers, rewrite rules) - CASE classid - WHEN 'pg_constraint'::regclass THEN - ( - SELECT - conrelid::regclass::text - FROM - pg_constraint - WHERE - OID = objid) - WHEN 'pg_attrdef'::regclass THEN - ( - SELECT - adrelid::regclass::text - FROM - pg_attrdef - WHERE - OID = objid) - WHEN 'pg_trigger'::regclass THEN - ( - SELECT - tgrelid::regclass::text - FROM - pg_trigger - WHERE - OID = objid) - ELSE - '' - END AS "dep_table", - -- dep_type: Type of the dependent object (TABLE, FUNCTION, VIEW, TYPE, TRIGGER, ...) - CASE classid - WHEN 'pg_class'::regclass THEN - ( - SELECT - TYPE - FROM - classType - WHERE - OID = objid) - WHEN 'pg_type'::regclass THEN - 'TYPE' - WHEN 'pg_proc'::regclass THEN - 'FUNCTION' - WHEN 'pg_constraint'::regclass THEN - 'TABLE CONSTRAINT' - WHEN 'pg_attrdef'::regclass THEN - 'TABLE DEFAULT' - WHEN 'pg_rewrite'::regclass THEN - ( - SELECT - TYPE - FROM - classType - WHERE - OID = ( - SELECT - ev_class - FROM - pg_rewrite - WHERE - OID = objid)) - WHEN 'pg_trigger'::regclass THEN - 'TRIGGER' - ELSE - objid::text - END AS "dep_type", - -- ref_name: Name of referenced object (the object that depends on the dependent object) - CASE refclassid - WHEN 'pg_class'::regclass THEN - refobjid::regclass::text - WHEN 'pg_type'::regclass THEN - refobjid::regtype::text - WHEN 'pg_proc'::regclass THEN - refobjid::regprocedure::text - ELSE - refobjid::text - END AS "ref_name", - -- ref_type: Type of the referenced object (TABLE, FUNCTION, VIEW, TYPE, TRIGGER, ...) - CASE refclassid - WHEN 'pg_class'::regclass THEN - ( - SELECT - TYPE - FROM - classType - WHERE - OID = refobjid) - WHEN 'pg_type'::regclass THEN - 'TYPE' - WHEN 'pg_proc'::regclass THEN - 'FUNCTION' - ELSE - refobjid::text - END AS "ref_type", - -- dependency type: Only 'normal' dependencies are relevant for DROP statements - CASE deptype - WHEN 'n' THEN - 'normal' - WHEN 'a' THEN - 'automatic' - WHEN 'i' THEN - 'internal' - WHEN 'e' THEN - 'extension' - WHEN 'p' THEN - 'pinned' - END AS "dependency type" - FROM - pg_catalog.pg_depend - WHERE - deptype = 'n' -- look at normal dependencies only - AND refclassid NOT IN (2615, - 2612) -- schema and language are ignored as dependencies -) depedencies - -- Recursion: Join with results of last query, search for dependencies recursively - JOIN dep_recursive ON (dep_recursive.dep_name = depedencies.ref_name) - WHERE - depedencies.ref_name NOT IN (depedencies.dep_name, - depedencies.dep_table) -- no self-references -) - -- Select and filter the results of the recursive query - SELECT - MAX(level) AS "level", -- drop highest level first, so no other objects depend on it - dep_name --, -- the object to drop - -- MIN(dep_table) AS "dep_table", -- the table that is associated with this object (constraints, triggers) - -- MIN(dep_type) AS "dep_type", -- the type of this object - -- string_agg(ref_name, ', ') AS "ref_names", -- list of objects that depend on this (just FYI) - -- string_agg(ref_type, ', ') AS "ref_types" -- list of their respective types (just FYI) -FROM - dep_recursive -WHERE - level > 0 -- ignore the initial object (level 0) -GROUP BY - dep_name -- ignore multiple references to dependent objects, dropping them once is enough -ORDER BY - level ASC, - dep_name; - --- level descending: deepest dependency last -$BODY$; - --- 2 -CREATE OR REPLACE FUNCTION commons.create_sql_for_updating_view_with_dependencies (view_name text) - RETURNS text - LANGUAGE 'plpgsql' - AS $BODY$ -DECLARE - _sql text; - t_row record; - t_trigger_row record; -BEGIN - _sql = ''; - FOR t_row IN - SELECT - dep_name - FROM - commons.get_dependent_objects (view_name) - LOOP - _sql = _sql || ' - CREATE OR REPLACE VIEW ' || t_row.dep_name || ' - ' || ( - SELECT - pg_get_viewdef(t_row.dep_name, TRUE)); - - END LOOP; - - -- add triggers - - --FOR t_trigger_row IN ( - -- SELECT - -- pg_get_triggerdef(oid, TRUE) AS trigger_def - -- FROM - -- pg_trigger - -- WHERE - -- tgrelid = t_row.dep_name::regclass) - -- LOOP - -- _sql = _sql || ' - -- ' || t_trigger_row.trigger_def; - -- END LOOP; - RETURN _sql; -END; -$BODY$; - --- 3 -DROP VIEW information.v_role CASCADE; - -CREATE OR REPLACE VIEW information.v_role AS -SELECT - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier -FROM - information.role t1 - JOIN data_for_history.property p ON t1.fk_property = p.dfh_pk_property - LEFT JOIN LATERAL ( - SELECT - count(info_proj_rel.pk_entity)::integer AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE info_proj_rel.ord_num_of_domain = 0), 0::integer)::integer AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY info_proj_rel.calendar) AS community_favorite_calendar - FROM - projects.info_proj_rel - WHERE - info_proj_rel.fk_entity = t1.pk_entity - AND info_proj_rel.is_in_project = TRUE GROUP BY - info_proj_rel.fk_entity) t2 ON TRUE; - - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_role - FOR EACH ROW - EXECUTE PROCEDURE information.v_role_find_or_create(); - - --- 4 -CREATE OR REPLACE VIEW warehouse.v_roles_per_project_and_repo AS -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role t1, - projects.info_proj_rel t2 -WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = TRUE -UNION -SELECT - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count -FROM - information.v_role t1 -WHERE - t1.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS WITH role_with_time_primitive AS ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM - information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, - 72, - 150, - 151, - 152, - 153])) - AND tp.pk_entity = r.fk_entity - AND epr.is_in_project = TRUE - UNION ( SELECT DISTINCT ON (r.fk_temporal_entity, - r.fk_property) - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM - information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, - 72, - 150, - 151, - 152, - 153]) - ORDER BY - r.fk_temporal_entity, - r.fk_property, - r.is_in_project_count DESC, - r.tmsp_creation DESC)) -SELECT - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE WHEN role_with_time_primitive.fk_property = 71 THEN - 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN - 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN - 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN - 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN - 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN - 'p82b'::text - ELSE - role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span -FROM - role_with_time_primitive -GROUP BY - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity; - -CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS WITH tw1 AS ( - SELECT - temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEnt'::text AS entity_type - FROM - information.temporal_entity - UNION - SELECT - persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM - information.persistent_item -) -SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) - t1.pk_entity, - COALESCE(t3.fk_project, t4.fk_project) AS fk_project, - COALESCE(t3.fk_project, t4.fk_project, 0) AS project, - t1.fk_class, - t1.table_name, - t1.entity_type, - COALESCE(t4.fk_temporal_entity, CASE WHEN t5.table_name::text = ANY (ARRAY['persistent_item'::character varying::text, 'temporal_entity'::character varying::text]) THEN - t3.fk_entity - ELSE - NULL::integer - END) AS fk_entity_label -FROM - tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN warehouse.v_roles_per_project_and_repo t3 ON t2.fk_property = t3.fk_property - AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN information.entity t5 ON t3.fk_entity = t5.pk_entity - LEFT JOIN warehouse.v_roles_per_project_and_repo t4 ON t2.fk_property = t4.fk_property - AND t1.pk_entity = t4.fk_entity -WHERE - t2.field_order = 0 -ORDER BY - t1.pk_entity, - t3.fk_project, - t4.fk_project, - t1.fk_class, - t2.field_order, - t3.ord_num_of_domain, - t4.ord_num_of_domain, - t3.is_in_project_count DESC, - t4.is_in_project_count DESC; - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order = 0 - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field - AND t2.field_order = 0 -) -SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) - tw1.pk_entity, - tw1.fk_project, - tw1.string AS entity_label, - tw1.project -FROM - tw1 -ORDER BY - tw1.pk_entity, - tw1.fk_project, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count DESC; - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order IS NOT NULL - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 -WHERE - t1.fk_class_field = t2.fk_class_field -), -tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, - tw1.fk_project, - tw1.string) - tw1.pk_entity, - tw1.fk_project, - tw1.project, - tw1.string, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count - FROM - tw1 -) -SELECT - tw2.pk_entity, - tw2.fk_project, - tw2.project, - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order, tw2.ord_num, tw2.is_in_project_count DESC) AS own_full_text -FROM - tw2 -GROUP BY - tw2.pk_entity, - tw2.fk_project, - tw2.project; - -CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS -SELECT - t1.fk_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_temporal_entity::text, NULL::unknown) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo t1 -GROUP BY - t1.fk_entity, - t1.fk_project, - t1.project -UNION -SELECT - t1.fk_temporal_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_entity::text, NULL::unknown) AS related_full_texts -FROM - warehouse.v_roles_per_project_and_repo t1, - information.persistent_item t2 -WHERE - t1.fk_entity = t2.pk_entity -GROUP BY - t1.fk_temporal_entity, - t1.fk_project, - t1.project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts -FROM - warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity - AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS WITH previews_non_recursive AS ( - SELECT - v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM - warehouse.v_entity_preview_non_recursive -), -fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM - full_text_dependencies -GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project -), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts) jsonb_each_text(KEY, value)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM - add_full_text t -) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - --- 5 -DROP VIEW information.v_entity_association CASCADE; - -CREATE OR REPLACE VIEW information.v_entity_association AS WITH ea_project_count AS ( - SELECT - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - COALESCE(count(*) FILTER (WHERE epr.is_in_project = TRUE), 0::integer)::integer AS is_in_project_count - FROM - information.entity_association ea_1 - LEFT JOIN projects.info_proj_rel epr ON epr.fk_entity = ea_1.pk_entity -GROUP BY - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period -) -SELECT - ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.dfh_range_instances_max_quantifier AS range_max_quantifier, - p.dfh_domain_instances_max_quantifier AS domain_max_quantifier -FROM - ea_project_count ea - LEFT JOIN data_for_history.property p ON ea.fk_property = p.dfh_pk_property; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT - ON information.v_entity_association - FOR EACH ROW - EXECUTE PROCEDURE information.v_entity_association_find_or_create(); - -CREATE OR REPLACE VIEW warehouse.v_entity_association_per_project_and_repo AS SELECT DISTINCT - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS project, - ea.is_in_project_count -FROM - information.v_entity_association ea, - projects.info_proj_rel epr -WHERE - epr.fk_entity = ea.pk_entity - AND epr.is_in_project = TRUE -UNION -SELECT DISTINCT - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - 0 AS project, - ea.is_in_project_count -FROM - information.v_entity_association ea -WHERE - ea.is_in_project_count > 0; - -CREATE OR REPLACE VIEW warehouse.v_fk_type AS WITH tw1 AS ( - SELECT DISTINCT ON (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL - AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - warehouse.v_entity_association_per_project_and_repo t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL - AND t3.fk_property = t4.fk_property - ORDER BY - 1, - 2, - 3, - 5 DESC -) -SELECT DISTINCT ON (tw1.fk_info_domain, tw1.fk_project) - tw1.fk_info_domain AS pk_entity, - tw1.fk_project, - COALESCE(tw1.fk_project, 0) AS project, - tw1.fk_info_range AS fk_type -FROM - tw1; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts -FROM - warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity - AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity - AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS WITH previews_non_recursive AS ( - SELECT - v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM - warehouse.v_entity_preview_non_recursive -), -fill_entity_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM - previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity - AND t1.project = t2.project -), -fill_type_label AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM - fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity - AND t1.project = t2.project -), -full_text_dependencies AS ( - SELECT - r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity - AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project - UNION - SELECT - r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM - warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity - AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity - AND pre.project = r.project -), -aggregated_related_full_texts AS ( - SELECT - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM - full_text_dependencies -GROUP BY - full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project -), -related_full_text AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM - fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity - AND t1.project = t2.project -), -add_full_text AS ( - SELECT - f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( - SELECT - array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM - jsonb_each_text(f.related_full_texts) jsonb_each_text(KEY, value)) AS full_text - FROM - related_full_text f -), -add_ts_vector AS ( - SELECT - t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM - add_full_text t -) -SELECT - add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector -FROM - add_ts_vector; - diff --git a/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-down.sql b/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-down.sql deleted file mode 100644 index 60726b209..000000000 --- a/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-down.sql +++ /dev/null @@ -1,23 +0,0 @@ - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts - FROM warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; diff --git a/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-up.sql b/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-up.sql deleted file mode 100644 index 7363c274d..000000000 --- a/server/db-migrate/migrations/sqls/20190823200757-war-v-entity-preview-non-recursive-up.sql +++ /dev/null @@ -1,24 +0,0 @@ - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - SELECT DISTINCT ON ( t1.pk_entity, t1.fk_project) - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts - FROM warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; diff --git a/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-down.sql b/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-down.sql deleted file mode 100644 index e33c496b8..000000000 --- a/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 1 -DROP INDEX data.digital_string_idx; - - -CREATE INDEX digital_string_idx -ON data.digital USING btree -(string COLLATE pg_catalog."default") -TABLESPACE pg_default; diff --git a/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-up.sql b/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-up.sql deleted file mode 100644 index 671f3cc3c..000000000 --- a/server/db-migrate/migrations/sqls/20190828144659-dat-index-on-strings-up.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 1 -DROP INDEX data.digital_string_idx; - -CREATE INDEX digital_string_idx -ON data.digital USING hash (string) -TABLESPACE pg_default; diff --git a/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-down.sql b/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-down.sql deleted file mode 100644 index aa72cf0ca..000000000 --- a/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-down.sql +++ /dev/null @@ -1,99 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital( - pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; - -BEGIN - - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result ; - - IF test_query_result - THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists' ; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING btree(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); ' - - ; - - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - - END IF; - -RETURN result_text; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-up.sql b/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-up.sql deleted file mode 100644 index dd6807469..000000000 --- a/server/db-migrate/migrations/sqls/20190828145011-tab-fn-create-cell-table-update-up.sql +++ /dev/null @@ -1,96 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital(pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' -AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; - -BEGIN - - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result ; - - IF test_query_result - THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists' ; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING hash(id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING hash(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); ' - - - ; - - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - - END IF; - -RETURN result_text; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-down.sql b/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-down.sql deleted file mode 100644 index 253ed0b88..000000000 --- a/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-down.sql +++ /dev/null @@ -1,2 +0,0 @@ ---1 -DROP FUNCTION tables.rebuild_partitioned_table(integer, text, integer[]); diff --git a/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-up.sql b/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-up.sql deleted file mode 100644 index 0c05ce47f..000000000 --- a/server/db-migrate/migrations/sqls/20190828150816-tab-fn-rebuild-partitioned-table-up.sql +++ /dev/null @@ -1,111 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION tables.rebuild_partitioned_table( - id_digital integer, - view_name text, - column_list integer[]) - RETURNS text - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - new_view_name text; - query_start text; - query_from text; - query text; - field text; - field_label text; - field_metadata json; - n integer = 1; - a integer; - output_query text; - -BEGIN - - IF view_name IS NOT NULL THEN - - new_view_name = view_name ; - ELSE - - new_view_name = 'tv_' || id_digital ; - END IF; - - query_start = 'DROP VIEW IF EXISTS ' || new_view_name || '; - CREATE OR REPLACE TEMPORARY VIEW ' || new_view_name || ' AS - SELECT dr.pk_row'; - - query_from = ' FROM tables.row dr'; - - IF array_length(column_list, 1) > 0 THEN - - FOR a IN - - SELECT UNNEST(column_list) - - LOOP - - SELECT row_to_json((pk_entity,pk_entity::text,fk_data_type)) INTO field_metadata --id_for_import_txt - FROM data.column - WHERE pk_entity = a; - - field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); - - IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN - field = 't'|| n ||'.numeric_value'; - ELSE - field = 't'|| n ||'.string_value'; -- .string .id_for_import_txt - END IF; - - query_start = query_start || ', ' || field || ' AS ' || field_label; - - query_from = query_from || ' LEFT JOIN tables.cell_' || id_digital || ' t' || n || ' ON dr.pk_row = t' || n || '.fk_row AND t' || n || '.fk_column = ' || (field_metadata -> 'f1')::text; - - n = n + 1; - - -- RAISE NOTICE '%', query_start ; -- return current row of SELECT - - END LOOP; - - ELSE - - FOR field_metadata IN - - SELECT row_to_json((pk_entity, pk_entity::text,fk_data_type)) --id_for_import_txt - FROM data.column - WHERE fk_digital = id_digital - ORDER BY pk_entity - - LOOP - - field_label = replace(trim((field_metadata -> 'f2')::text), ' ', '_'); - - IF (field_metadata -> 'f3')::varchar::integer = 3293 THEN - field = 't'|| n ||'.numeric_value'; - ELSE - field = 't'|| n ||'.string_value'; -- .string .id_for_import_txt - END IF; - - query_start = query_start || ', ' || field || ' AS ' || field_label; - - query_from = query_from || ' LEFT JOIN tables.cell_' || id_digital || ' t' || n || ' ON dr.pk_row = t' || n || '.fk_row AND t' || n || '.fk_column = ' || (field_metadata -> 'f1')::text; - - n = n + 1; - - -- RAISE NOTICE '%', query_start ; -- return current row of SELECT - - END LOOP; - - END IF; - - query := query_start || query_from || ' WHERE dr.fk_digital = ' || id_digital || ';'; - - RAISE NOTICE '%', query ; - - EXECUTE query; - - output_query := 'SELECT * FROM ' || new_view_name || ' LIMIT 10' ; - -RETURN output_query; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-down.sql b/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-down.sql deleted file mode 100644 index 927f011b2..000000000 --- a/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-down.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 1 -DROP INDEX information.entity_association_fk_cell_domain_idx; -DROP INDEX information.entity_association_fk_cell_range_idx; - -DROP INDEX data.data_association_fk_info_domain_idx; -DROP INDEX data.data_association_fk_info_range_idx; - -DROP INDEX data.data_association_fk_cell_domain_idx; -DROP INDEX data.data_association_fk_cell_range_idx; - -ALTER TABLE information.entity_association DROP COLUMN fk_cell_domain; -ALTER TABLE information.entity_association DROP COLUMN fk_cell_range; - - -ALTER TABLE data.data_association DROP COLUMN fk_info_domain; -ALTER TABLE data.data_association DROP COLUMN fk_info_range; -ALTER TABLE data.data_association DROP COLUMN fk_cell_domain; -ALTER TABLE data.data_association DROP COLUMN fk_cell_range; - - diff --git a/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-up.sql b/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-up.sql deleted file mode 100644 index 3809c3b34..000000000 --- a/server/db-migrate/migrations/sqls/20190828151011-enitity-and-data-associations-up.sql +++ /dev/null @@ -1,32 +0,0 @@ --- 1 -ALTER TABLE information.entity_association ADD COLUMN fk_cell_domain BIGINT; -ALTER TABLE information.entity_association ADD COLUMN fk_cell_range BIGINT; - - -ALTER TABLE data.data_association ADD COLUMN fk_info_domain BIGINT; -ALTER TABLE data.data_association ADD COLUMN fk_info_range BIGINT; -ALTER TABLE data.data_association ADD COLUMN fk_cell_domain BIGINT; -ALTER TABLE data.data_association ADD COLUMN fk_cell_range BIGINT; - - - - -CREATE INDEX entity_association_fk_cell_domain_idx - ON information.entity_association USING btree - (fk_cell_domain); -CREATE INDEX entity_association_fk_cell_range_idx - ON information.entity_association USING btree - (fk_cell_range); - - -CREATE INDEX data_association_fk_info_domain_idx - ON data.data_association USING btree - (fk_info_domain); -CREATE INDEX data_association_fk_info_range_idx - ON data.data_association USING btree - (fk_info_range); - -CREATE INDEX data_association_fk_cell_domain_idx - ON data.data_association USING btree(fk_cell_domain); -CREATE INDEX data_association_fk_cell_range_idx - ON data.data_association USING btree(fk_cell_range); diff --git a/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-down.sql b/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-down.sql deleted file mode 100644 index fda1c756c..000000000 --- a/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 1 -DROP INDEX data.digital_vt_string_idx; - - -CREATE INDEX digital_vt_string_idx -ON data.digital_vt USING btree -(string COLLATE pg_catalog."default") -TABLESPACE pg_default; diff --git a/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-up.sql b/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-up.sql deleted file mode 100644 index 58d735280..000000000 --- a/server/db-migrate/migrations/sqls/20190911070249-dat-vt-index-on-strings-up.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 1 -DROP INDEX data.digital_vt_string_idx; - -CREATE INDEX digital_vt_string_idx -ON data.digital_vt USING hash (string) -TABLESPACE pg_default; diff --git a/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-down.sql b/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-down.sql deleted file mode 100644 index 231010b99..000000000 --- a/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -/* Replace with your SQL commands */ -DROP TABLE warehouse.entity_preview_non_recursive; diff --git a/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-up.sql b/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-up.sql deleted file mode 100644 index c9b7bed7b..000000000 --- a/server/db-migrate/migrations/sqls/20191003195445-war-t-entity-preview-non-recursive-up.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* Replace with your SQL commands */ -CREATE TABLE warehouse.entity_preview_non_recursive ( - pk_entity INT, - fk_class INT, - fk_project INT, - table_name VARCHAR, - class_label VARCHAR, - own_full_text TEXT, - own_entity_label TEXT, - time_span JSONB, - related_full_texts JSONB, - fk_entity_label INT, - fk_type INT -); - --- Add partial unique for where fk_project is null --- See: https://dba.stackexchange.com/questions/151431/postgresql-upsert-issue-with-null-values -CREATE UNIQUE INDEX pk_entity_fk_project_unique -ON warehouse.entity_preview_non_recursive (pk_entity, COALESCE(fk_project, 0)); diff --git a/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-down.sql b/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-down.sql deleted file mode 100644 index 2a5312fcc..000000000 --- a/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP FUNCTION warehouse.entity_preview_non_recursive__create; diff --git a/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-up.sql b/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-up.sql deleted file mode 100644 index 3cdd143ec..000000000 --- a/server/db-migrate/migrations/sqls/20191003200029-war-f-entity-preview-non-recursive-create-up.sql +++ /dev/null @@ -1,504 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create( - param_pk_entities INT[] - ) - RETURNS SETOF warehouse.entity_preview_non_recursive -AS $$ - - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- select roles with time primitive - tw9 AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.fk_temporal_entity = ANY(param_pk_entities) - AND - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND tp.pk_entity = r.fk_entity AND epr.is_in_project = true - UNION - ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_temporal_entity = ANY(param_pk_entities) - AND - r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - ORDER BY r.fk_temporal_entity, r.fk_property, r.is_in_project_count DESC, r.tmsp_creation DESC) - ), - -- create time spans - tw10 AS ( - SELECT - tw9.fk_project, - tw9.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN tw9.fk_property = 71 THEN 'p81'::text - WHEN tw9.fk_property = 72 THEN 'p82'::text - WHEN tw9.fk_property = 150 THEN 'p81a'::text - WHEN tw9.fk_property = 151 THEN 'p81b'::text - WHEN tw9.fk_property = 152 THEN 'p82a'::text - WHEN tw9.fk_property = 153 THEN 'p82b'::text - ELSE tw9.fk_property::text - END, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) AS time_span - FROM tw9 - GROUP BY tw9.fk_project, tw9.fk_temporal_entity - ), - tw11 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span - FROM - tw8 t1 - LEFT JOIN - tw10 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw11 t1 - LEFT JOIN - tw12 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw14 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw15 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw14 t1, - system.class_has_type_property t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw14 t3, - system.class_has_type_property t4 - WHERE - ( - t3.fk_info_domain = ANY(param_pk_entities) - OR - t3.fk_info_range = ANY(param_pk_entities) - ) - AND - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw16 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type - FROM - tw13 t1 - LEFT JOIN - tw15 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw16; - -$$ LANGUAGE SQL; - diff --git a/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-down.sql b/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-down.sql deleted file mode 100644 index 85eca714b..000000000 --- a/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP FUNCTION warehouse.entity_preview_non_recursive__create_all; diff --git a/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-up.sql b/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-up.sql deleted file mode 100644 index 8e470e238..000000000 --- a/server/db-migrate/migrations/sqls/20191003210727-war-f-entity-preview-non-recursive-create-all-up.sql +++ /dev/null @@ -1,449 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all() - RETURNS SETOF warehouse.entity_preview_non_recursive -AS $$ - - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- select roles with time primitive - tw9 AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND tp.pk_entity = r.fk_entity AND epr.is_in_project = true - UNION - ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - ORDER BY r.fk_temporal_entity, r.fk_property, r.is_in_project_count DESC, r.tmsp_creation DESC) - ), - -- create time spans - tw10 AS ( - SELECT - tw9.fk_project, - tw9.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN tw9.fk_property = 71 THEN 'p81'::text - WHEN tw9.fk_property = 72 THEN 'p82'::text - WHEN tw9.fk_property = 150 THEN 'p81a'::text - WHEN tw9.fk_property = 151 THEN 'p81b'::text - WHEN tw9.fk_property = 152 THEN 'p82a'::text - WHEN tw9.fk_property = 153 THEN 'p82b'::text - ELSE tw9.fk_property::text - END, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) AS time_span - FROM tw9 - GROUP BY tw9.fk_project, tw9.fk_temporal_entity - ), - tw11 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span - FROM - tw8 t1 - LEFT JOIN - tw10 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw11 t1 - LEFT JOIN - tw12 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw14 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw15 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw14 t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw14 t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw16 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type - FROM - tw13 t1 - LEFT JOIN - tw15 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw16; - -$$ LANGUAGE SQL; - diff --git a/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-down.sql b/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-down.sql deleted file mode 100644 index 179a20217..000000000 --- a/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER FUNCTION warehouse.entity_preview__update_all -RENAME TO entity_preview__create_all; diff --git a/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-up.sql b/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-up.sql deleted file mode 100644 index ef4d82c10..000000000 --- a/server/db-migrate/migrations/sqls/20191003212744-war-f-entity-preview-update-from-non-recursive-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER FUNCTION warehouse.entity_preview__create_all -RENAME TO entity_preview__update_all; diff --git a/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-down.sql b/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-down.sql deleted file mode 100644 index dde7a13a3..000000000 --- a/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-down.sql +++ /dev/null @@ -1,164 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_temporary( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - DROP TABLE IF EXISTS entity_preview_temporary; - CREATE TEMP TABLE entity_preview_temporary AS - SELECT - *, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.v_entity_preview_non_recursive; - - ALTER TABLE entity_preview_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ---------- full text completion ------------ - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - UPDATE - entity_preview_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-up.sql b/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-up.sql deleted file mode 100644 index 2f8e1e7c0..000000000 --- a/server/db-migrate/migrations/sqls/20191003212939-war-f-entity-preview-create-temporary-up.sql +++ /dev/null @@ -1,169 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_temporary( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - DROP TABLE IF EXISTS entity_preview_temporary; - CREATE TEMP TABLE entity_preview_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ---------- full text completion ------------ - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - UPDATE - entity_preview_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-down.sql b/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-down.sql deleted file mode 100644 index 2177d7e5a..000000000 --- a/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-down.sql +++ /dev/null @@ -1,2 +0,0 @@ ---1 -DROP FUNCTION warehouse.entity_preview_non_recursive__refresh diff --git a/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-up.sql b/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-up.sql deleted file mode 100644 index bcc2ddab1..000000000 --- a/server/db-migrate/migrations/sqls/20191003213848-war-f-entity-preview-non-recursive-helpers-up.sql +++ /dev/null @@ -1,10 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__refresh() -returns void -AS $$ - - DELETE FROM warehouse.entity_preview_non_recursive; - INSERT INTO warehouse.entity_preview_non_recursive - SELECT * FROM warehouse.entity_preview_non_recursive__create_all(); - -$$ LANGUAGE SQL; diff --git a/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-down.sql b/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-down.sql deleted file mode 100644 index 6fad1d428..000000000 --- a/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP FUNCTION warehouse.entity_preview_non_recursive__upsert; diff --git a/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-up.sql b/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-up.sql deleted file mode 100644 index 2ae1881b8..000000000 --- a/server/db-migrate/migrations/sqls/20191004101109-war-f-entity-preview-non-recursive-upsert-up.sql +++ /dev/null @@ -1,29 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__upsert(param_pk_entities integer[], param_fk_project integer) -returns void -AS $$ - - /** - * UPSERT the entity previews of the entities with given param_pk_entities - * for the given param_fk_project and the repo version (fk_project = NULL) - */ - INSERT INTO - warehouse.entity_preview_non_recursive - ( - SELECT * FROM warehouse.entity_preview_non_recursive__create(param_pk_entities) - WHERE fk_project IS NULL OR fk_project = param_fk_project - ) - ON CONFLICT (pk_entity, COALESCE(fk_project, 0)) - DO UPDATE - SET - fk_class = EXCLUDED.fk_class, - table_name = EXCLUDED.table_name, - class_label = EXCLUDED.class_label, - own_full_text = EXCLUDED.own_full_text, - own_entity_label = EXCLUDED.own_entity_label, - time_span = EXCLUDED.time_span, - related_full_texts = EXCLUDED.related_full_texts, - fk_entity_label = EXCLUDED.fk_entity_label, - fk_type = EXCLUDED.fk_type; - -$$ LANGUAGE SQL; diff --git a/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-down.sql b/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-down.sql deleted file mode 100644 index 90e5e5e43..000000000 --- a/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP FUNCTION warehouse.entity_preview_non_recursive__delete; diff --git a/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-up.sql b/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-up.sql deleted file mode 100644 index c234f86f1..000000000 --- a/server/db-migrate/migrations/sqls/20191004110430-war-f-entity-preview-non-recursive-delete-up.sql +++ /dev/null @@ -1,33 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__delete(param_pk_entities integer[], param_fk_project integer) -returns void -AS $$ - - /** - * Delete the entity previews of the entities with given param_pk_entities - * for the given param_fk_project - */ - DELETE FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - /** - * Clean up the repo - * Delete repo entity_previews if the entity is removed from all projects - */ - DELETE FROM warehouse.entity_preview_non_recursive - WHERE pk_entity IN ( - -- find entities that are in no project anymore - SELECT pk_entity - FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - EXCEPT - SELECT pk_entity - FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - AND fk_project IS NOT NULL - ) - AND fk_project IS NULL; - - -$$ LANGUAGE SQL; diff --git a/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-down.sql b/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-down.sql deleted file mode 100644 index 4c9435dba..000000000 --- a/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-down.sql +++ /dev/null @@ -1,214 +0,0 @@ --- 4 -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; - --- 3 -DROP FUNCTION warehouse.after_info_proj_rel_upsert; - --- 2 -CREATE FUNCTION warehouse.entity_preview__upsert_entity_preview() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - --------------------- text_property --------------------- - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]); - --------------------- role ----------------------------- - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - is_in_project INTO _domain_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_temporal_entity - AND fk_project = _fk_project; - SELECT - is_in_project INTO _range_is_in_project - FROM - projects.info_proj_rel - WHERE - fk_entity = _fk_entity - AND fk_project = _fk_project; - RAISE INFO 'updated epr of role of pk_entity: %, fk_temporal_entity: %, fk_project: %', _fk_entity, _fk_temporal_entity, _fk_project; - ------------ init update of preview of domain entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, NULL::text]); - ------------ in project - IF (_domain_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- fill time span - warehouse.needs_update ('entity_preview__fill_time_span'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_temporal_entity::text, _fk_project::text]); - END IF; - IF ( - SELECT - information.is_persistent_item_or_temporal_entity (_fk_entity) = TRUE) THEN - ------------ init update of preview of range entity --------- - ------------ in repo - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, NULL::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, NULL::text]); - ------------ in project - IF (_range_is_in_project = TRUE) THEN - PERFORM - -- fill own entity label - warehouse.needs_update ('entity_preview__fill_own_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- fill own full text - warehouse.needs_update ('entity_preview__fill_own_full_text'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create fk entity label - warehouse.needs_update ('entity_preview__create_fk_entity_label'::text, - ARRAY[_fk_entity::text, _fk_project::text]), - -- create related full texts - warehouse.needs_update ('entity_preview__create_related_full_texts'::text, - ARRAY[_fk_entity::text, _fk_project::text]); - END IF; - END IF; - --------------------- entity_association ----------------- - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_domain::text, NULL::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create_fk_type'::text, - ARRAY[_fk_info_range::text, NULL::text]); - --------------------- temporal_entity or persistent_item ----------------- - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - IF (NEW.is_in_project = TRUE) THEN - PERFORM - -- create fk type - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, _fk_project::text]), - warehouse.needs_update ('entity_preview__create'::text, - ARRAY[NEW.fk_entity::text, NULL::text]); - ELSIF (NEW.is_in_project = FALSE) THEN - DELETE FROM warehouse.entity_preview - WHERE fk_project IS NOT DISTINCT FROM NEW.fk_project - AND pk_entity = NEW.fk_entity; - END IF; - END IF; - RETURN NEW; -END; -$BODY$; - --- 1 -CREATE TRIGGER after_epr_upsert - AFTER INSERT OR UPDATE - ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.entity_preview__upsert_entity_preview(); diff --git a/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-up.sql b/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-up.sql deleted file mode 100644 index 607cdf7d4..000000000 --- a/server/db-migrate/migrations/sqls/20191004112546-war-tf-info-proj-rel-upsert-up.sql +++ /dev/null @@ -1,133 +0,0 @@ --- 1 -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; - --- 2 -DROP FUNCTION warehouse.entity_preview__upsert_entity_preview (); - --- 3 -CREATE FUNCTION warehouse.after_info_proj_rel_upsert () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - -- find the table name of the affected table - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - --------------------- text_property --------------------- - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_entity::text || ']'::text, _fk_project::text]); - - --------------------- role ----------------------------- - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_entity::text || ']'::text, _fk_project::text]); - - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_temporal_entity::text || ']'::text, _fk_project::text]); - - - --------------------- entity_association ----------------- - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - - - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_info_domain::text || ']'::text, _fk_project::text]); - - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_info_range::text || ']'::text, _fk_project::text]); - - - - --------------------- temporal_entity or persistent_item ----------------- - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - IF (NEW.is_in_project = TRUE) THEN - - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || NEW.fk_entity::text || ']'::text, _fk_project::text]); - - ELSIF (NEW.is_in_project = FALSE) THEN - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__delete'::text, - ARRAY['ARRAY[' || NEW.fk_entity::text || ']'::text, _fk_project::text]); - END IF; - END IF; - RETURN NEW; -END; -$BODY$; - --- 4 -CREATE TRIGGER after_epr_upsert - AFTER INSERT - OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.after_info_proj_rel_upsert (); - diff --git a/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-down.sql b/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-down.sql deleted file mode 100644 index 523a77341..000000000 --- a/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-down.sql +++ /dev/null @@ -1,19 +0,0 @@ --- 2 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_class_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; dfh_pk_class: % class_label: %', NEW.dfh_pk_class, NEW.class_label; - - PERFORM warehouse.entity_preview__fill_dependent_class_labels(NEW.dfh_pk_class, NEW.class_label); - - RETURN NEW; - END; - $BODY$; - --- 1 -DROP FUNCTION warehouse.entity_preview_non_recursive__update_class_labels; diff --git a/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-up.sql b/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-up.sql deleted file mode 100644 index 7bba8bb77..000000000 --- a/server/db-migrate/migrations/sqls/20191004143037-war-f-update-class-labels-up.sql +++ /dev/null @@ -1,55 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__update_class_labels( - pk_class integer, - param_class_label text DEFAULT NULL::text) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_class_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview_non_recursive__update_class_labels of pk_class: %', pk_class; - - -- get new_class_label - IF (param_class_label IS NULL) THEN - SELECT class_label INTO new_class_label - FROM warehouse.class_preview - WHERE dfh_pk_class = pk_class; - ELSE - new_class_label = param_class_label; - END IF; - - RAISE INFO 'new_class_label: %', new_class_label; - - -- update all dependent entity_previews with new_class_label (if DISTINCT) - UPDATE warehouse.entity_preview_non_recursive - SET class_label = new_class_label - WHERE fk_class = pk_class - AND class_label IS DISTINCT FROM new_class_label; - - RETURN true; - END; - $BODY$; - --- 2 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_dependent_class_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; dfh_pk_class: % class_label: %', NEW.dfh_pk_class, NEW.class_label; - - PERFORM warehouse.entity_preview_non_recursive__update_class_labels(NEW.dfh_pk_class, NEW.class_label); - - RETURN NEW; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-down.sql b/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-down.sql deleted file mode 100644 index 386c6b9cf..000000000 --- a/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-down.sql +++ /dev/null @@ -1,1399 +0,0 @@ --- 4 - -CREATE OR REPLACE VIEW warehouse.v_text_properties_per_project_and_repo AS - SELECT t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true -UNION - SELECT t1.pk_entity, - t1.schema_name, - t1.table_name, - t1.notes, - t1.fk_creator, - t1.fk_last_modifier, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE t1.is_in_project_count > 0; - - -CREATE OR REPLACE VIEW warehouse.v_te_en_time_span_per_project_and_repo AS - WITH role_with_time_primitive AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE r.pk_entity = epr.fk_entity AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND tp.pk_entity = r.fk_entity AND epr.is_in_project = true - UNION - ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - ORDER BY r.fk_temporal_entity, r.fk_property, r.is_in_project_count DESC, r.tmsp_creation DESC) - ) - SELECT role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN role_with_time_primitive.fk_property = 71 THEN 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN 'p82b'::text - ELSE role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) AS time_span - FROM role_with_time_primitive - GROUP BY role_with_time_primitive.fk_project, role_with_time_primitive.fk_temporal_entity; - -CREATE OR REPLACE VIEW warehouse.v_related_full_texts AS - SELECT t1.fk_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_temporal_entity::text, NULL::unknown) AS related_full_texts - FROM warehouse.v_roles_per_project_and_repo t1 - GROUP BY t1.fk_entity, t1.fk_project, t1.project -UNION - SELECT t1.fk_temporal_entity AS pk_entity, - t1.project, - t1.fk_project, - jsonb_object_agg(t1.fk_entity::text, NULL::unknown) AS related_full_texts - FROM warehouse.v_roles_per_project_and_repo t1, - information.persistent_item t2 - WHERE t1.fk_entity = t2.pk_entity - GROUP BY t1.fk_temporal_entity, t1.fk_project, t1.project; - - -CREATE OR REPLACE VIEW warehouse.v_own_full_text AS - WITH tw1 AS ( - SELECT t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property AND t5.fk_class = t4.fk_class AND t5.field_order IS NOT NULL - UNION ALL - SELECT t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1."coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE t1.fk_class_field = t2.fk_class_field - ), tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project, tw1.string) tw1.pk_entity, - tw1.fk_project, - tw1.project, - tw1.string, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count - FROM tw1 - ) - SELECT tw2.pk_entity, - tw2.fk_project, - tw2.project, - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order, tw2.ord_num, tw2.is_in_project_count DESC) AS own_full_text - FROM tw2 - GROUP BY tw2.pk_entity, tw2.fk_project, tw2.project; - - -CREATE OR REPLACE VIEW warehouse.v_own_entity_label AS - WITH tw1 AS ( - SELECT t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property AND t5.fk_class = t4.fk_class AND t5.field_order = 0 - UNION ALL - SELECT t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1."coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE t1.fk_class_field = t2.fk_class_field AND t2.field_order = 0 - ) - SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) tw1.pk_entity, - tw1.fk_project, - tw1.string AS entity_label, - tw1.project - FROM tw1 - ORDER BY tw1.pk_entity, tw1.fk_project, tw1.field_order, tw1.ord_num, tw1.is_in_project_count DESC; - - - -CREATE OR REPLACE VIEW warehouse.v_fk_entity_label AS - WITH tw1 AS ( - SELECT temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEnt'::text AS entity_type - FROM information.temporal_entity - UNION - SELECT persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM information.persistent_item - ) - SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) t1.pk_entity, - COALESCE(t3.fk_project, t4.fk_project) AS fk_project, - COALESCE(t3.fk_project, t4.fk_project, 0) AS project, - t1.fk_class, - t1.table_name, - t1.entity_type, - COALESCE(t4.fk_temporal_entity, - CASE - WHEN t5.table_name::text = ANY (ARRAY['persistent_item'::character varying::text, 'temporal_entity'::character varying::text]) THEN t3.fk_entity - ELSE NULL::integer - END) AS fk_entity_label - FROM tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN warehouse.v_roles_per_project_and_repo t3 ON t2.fk_property = t3.fk_property AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN information.entity t5 ON t3.fk_entity = t5.pk_entity - LEFT JOIN warehouse.v_roles_per_project_and_repo t4 ON t2.fk_property = t4.fk_property AND t1.pk_entity = t4.fk_entity - WHERE t2.field_order = 0 - ORDER BY t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class, t2.field_order, t3.ord_num_of_domain, t4.ord_num_of_domain, t3.is_in_project_count DESC, t4.is_in_project_count DESC; - -CREATE OR REPLACE VIEW warehouse.v_fk_type AS - WITH tw1 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM warehouse.v_entity_association_per_project_and_repo t1, - system.class_has_type_property t2 - WHERE t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM warehouse.v_entity_association_per_project_and_repo t3, - system.class_has_type_property t4 - WHERE t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ) - SELECT DISTINCT ON (tw1.fk_info_domain, tw1.fk_project) tw1.fk_info_domain AS pk_entity, - tw1.fk_project, - COALESCE(tw1.fk_project, 0) AS project, - tw1.fk_info_range AS fk_type - FROM tw1; - -CREATE OR REPLACE VIEW warehouse.v_entities AS - WITH tw1 AS ( - SELECT persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM information.persistent_item - UNION - SELECT temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEn'::text AS entity_type - FROM information.temporal_entity - ) - SELECT tw1.pk_entity, - epr.fk_project, - epr.fk_project AS project, - tw1.fk_class, - tw1.table_name, - tw1.entity_type - FROM projects.info_proj_rel epr, - tw1 - WHERE epr.is_in_project = true AND tw1.pk_entity = epr.fk_entity -UNION - SELECT tw1.pk_entity, - NULL::integer AS fk_project, - 0 AS project, - tw1.fk_class, - tw1.table_name, - tw1.entity_type - FROM tw1; - -CREATE OR REPLACE VIEW warehouse.v_entity_preview_non_recursive AS - SELECT DISTINCT ON (t1.pk_entity, t1.fk_project) t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.table_name, - t1.entity_type, - t2.class_label, - t3.entity_label, - t4.time_span, - t5.own_full_text, - t6.fk_entity_label, - t7.fk_type, - t8.related_full_texts - FROM warehouse.v_entities t1 - LEFT JOIN warehouse.class_preview t2 ON t2.dfh_pk_class = t1.fk_class - LEFT JOIN warehouse.v_own_entity_label t3 ON t1.pk_entity = t3.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t3.fk_project - LEFT JOIN warehouse.v_te_en_time_span_per_project_and_repo t4 ON t1.pk_entity = t4.fk_temporal_entity AND NOT t1.fk_project IS DISTINCT FROM t4.fk_project - LEFT JOIN warehouse.v_own_full_text t5 ON t1.pk_entity = t5.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t5.fk_project - LEFT JOIN warehouse.v_fk_entity_label t6 ON t1.pk_entity = t6.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t6.fk_project - LEFT JOIN warehouse.v_fk_type t7 ON t1.pk_entity = t7.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t7.fk_project - LEFT JOIN warehouse.v_related_full_texts t8 ON t1.pk_entity = t8.pk_entity AND NOT t1.fk_project IS DISTINCT FROM t8.fk_project; - - -CREATE OR REPLACE VIEW warehouse.v_entity_preview AS - WITH previews_non_recursive AS ( - SELECT v_entity_preview_non_recursive.pk_entity, - v_entity_preview_non_recursive.fk_project, - v_entity_preview_non_recursive.project, - v_entity_preview_non_recursive.fk_class, - v_entity_preview_non_recursive.table_name, - v_entity_preview_non_recursive.entity_type, - v_entity_preview_non_recursive.class_label, - v_entity_preview_non_recursive.entity_label, - v_entity_preview_non_recursive.time_span, - v_entity_preview_non_recursive.own_full_text, - v_entity_preview_non_recursive.fk_entity_label, - v_entity_preview_non_recursive.fk_type - FROM warehouse.v_entity_preview_non_recursive - ), fill_entity_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - COALESCE(t1.entity_label, t2.entity_label) AS entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type - FROM previews_non_recursive t1 - LEFT JOIN previews_non_recursive t2 ON t1.fk_entity_label = t2.pk_entity AND t1.project = t2.project - ), fill_type_label AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t2.entity_label AS type_label - FROM fill_entity_label t1 - LEFT JOIN fill_entity_label t2 ON t1.fk_type = t2.pk_entity AND t1.project = t2.project - ), full_text_dependencies AS ( - SELECT r.fk_temporal_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name::text = 'persistent_item'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - UNION - SELECT r.fk_entity AS pk_entity, - r.project, - r.fk_project, - e.pk_entity AS pk_related_full_text, - pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name::text = 'temporal_entity'::text - LEFT JOIN previews_non_recursive pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - ), aggregated_related_full_texts AS ( - SELECT full_text_dependencies.pk_entity, - full_text_dependencies.project, - full_text_dependencies.fk_project, - jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) AS related_full_texts - FROM full_text_dependencies - GROUP BY full_text_dependencies.pk_entity, full_text_dependencies.project, full_text_dependencies.fk_project - ), related_full_text AS ( - SELECT t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t2.related_full_texts - FROM fill_type_label t1 - LEFT JOIN aggregated_related_full_texts t2 ON t1.pk_entity = t2.pk_entity AND t1.project = t2.project - ), add_full_text AS ( - SELECT f.pk_entity, - f.fk_project, - f.project, - f.fk_class, - f.entity_type, - f.class_label, - f.entity_label, - f.time_span, - f.own_full_text, - f.fk_entity_label, - f.fk_type, - f.type_label, - f.related_full_texts, - ( SELECT array_to_string(ARRAY[f.own_full_text, array_to_string(array_agg(jsonb_each_text.value), ', '::text)], ', '::text) AS array_to_string - FROM jsonb_each_text(f.related_full_texts) jsonb_each_text(key, value)) AS full_text - FROM related_full_text f - ), add_ts_vector AS ( - SELECT t.pk_entity, - t.fk_project, - t.project, - t.fk_class, - t.entity_type, - t.class_label, - t.entity_label, - t.time_span, - t.own_full_text, - t.fk_entity_label, - t.fk_type, - t.type_label, - t.related_full_texts, - t.full_text, - (setweight(to_tsvector(COALESCE(t.entity_label, ''::text)), 'A'::"char") || setweight(to_tsvector(COALESCE(t.type_label, t.class_label::text, ''::text)), 'B'::"char")) || setweight(to_tsvector(COALESCE(t.full_text, ''::text)), 'C'::"char") AS ts_vector - FROM add_full_text t - ) - SELECT add_ts_vector.pk_entity, - add_ts_vector.fk_project, - add_ts_vector.project, - add_ts_vector.fk_class, - add_ts_vector.entity_type, - add_ts_vector.class_label, - add_ts_vector.entity_label, - add_ts_vector.time_span, - add_ts_vector.own_full_text, - add_ts_vector.fk_entity_label, - add_ts_vector.fk_type, - add_ts_vector.type_label, - add_ts_vector.related_full_texts, - add_ts_vector.full_text, - add_ts_vector.ts_vector - FROM add_ts_vector; - --- 3 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_time_span( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - new_time_span jsonb; -BEGIN - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - RAISE INFO 'entity_preview__fill_time_span: %, fk_project: %', param_pk_entity, param_fk_project; - -- get new_time_span - -- SELECT time_span INTO new_time_span - -- FROM warehouse.v_te_en_time_span_per_project_and_repo - -- WHERE fk_temporal_entity = param_pk_entity - -- AND fk_project IS NOT DISTINCT FROM param_fk_project; - WITH role_with_time_primitive AS ( - SELECT - r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM - information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) - AND tp.pk_entity = r.fk_entity - AND epr.is_in_project = TRUE - AND r.fk_temporal_entity = param_pk_entity - AND epr.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) - r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM - information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND r.fk_temporal_entity = param_pk_entity - ORDER BY - r.fk_temporal_entity, - r.fk_property, - r.is_in_project_count DESC, - r.tmsp_creation DESC) -) -SELECT - jsonb_object_agg( - CASE WHEN role_with_time_primitive.fk_property = 71 THEN - 'p81'::text - WHEN role_with_time_primitive.fk_property = 72 THEN - 'p82'::text - WHEN role_with_time_primitive.fk_property = 150 THEN - 'p81a'::text - WHEN role_with_time_primitive.fk_property = 151 THEN - 'p81b'::text - WHEN role_with_time_primitive.fk_property = 152 THEN - 'p82a'::text - WHEN role_with_time_primitive.fk_property = 153 THEN - 'p82b'::text - ELSE - role_with_time_primitive.fk_property::text - END, json_build_object('julianDay', role_with_time_primitive.julian_day, 'duration', role_with_time_primitive.duration, 'calendar', role_with_time_primitive.calendar)) INTO new_time_span -FROM - role_with_time_primitive -GROUP BY - role_with_time_primitive.fk_project, - role_with_time_primitive.fk_temporal_entity; - RAISE INFO 'new_time_span: %', new_time_span; - -- update this entity_preview with new_time_span - UPDATE - warehouse.entity_preview - SET - time_span = new_time_span - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RETURN TRUE; - END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_full_text( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - old_own_full_text TEXT; - new_own_full_text TEXT; -BEGIN - RAISE INFO 'entity_preview__fill_own_full_text of: pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_full_text - WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order IS NOT NULL - WHERE - t1.fk_temporal_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE - t1.fk_class_field = t2.fk_class_field - AND t1.fk_concerned_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project -), -tw2 AS ( - SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project, tw1.string) - tw1.pk_entity, tw1.fk_project, tw1.project, tw1.string, tw1.field_order, tw1.ord_num, tw1.is_in_project_count - FROM - tw1 -) -SELECT - string_agg(tw2.string, ', '::text ORDER BY tw2.field_order, tw2.ord_num, tw2.is_in_project_count DESC) INTO new_own_full_text -FROM - tw2 -GROUP BY - tw2.pk_entity, - tw2.fk_project, - tw2.project; - RAISE INFO 'new_own_full_text: %', new_own_full_text; - ----- Insert or update column own_full_text of table entity_preview - SELECT - own_full_text INTO old_own_full_text - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_own_full_text: %', old_own_full_text; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, own_full_text) - VALUES (param_pk_entity, param_fk_project, new_own_full_text); - RAISE INFO 'inserted new_own_full_text: %', new_own_full_text; - ELSIF ( - SELECT - (old_own_full_text IS DISTINCT FROM new_own_full_text)) THEN - UPDATE - warehouse.entity_preview - SET - own_full_text = new_own_full_text - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_own_full_text: %', new_own_full_text; - ELSE - RAISE INFO 'no update needed: %', new_own_full_text; - END IF; - RETURN TRUE; -END; -$BODY$; - - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_own_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - old_own_entity_label TEXT; - new_own_entity_label TEXT; -BEGIN - -- if this has a fk_entity_label skip the whole function - -- because the entity label is provided by that other entity - IF ( - SELECT - ( - SELECT - fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project - LIMIT 1) IS NULL) THEN - RAISE INFO 'entity_preview__fill_own_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the string new_own_entity_label - WITH tw1 AS ( - SELECT - t1.fk_temporal_entity AS pk_entity, - t1.fk_project, - t1.project, - COALESCE(t2.string, t3.notes) AS string, - t5.field_order, - t1.ord_num_of_domain AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo t1 - LEFT JOIN information.appellation t2 ON t1.fk_entity = t2.pk_entity - LEFT JOIN information.language t3 ON t1.fk_entity = t3.pk_entity - JOIN information.temporal_entity t4 ON t1.fk_temporal_entity = t4.pk_entity - JOIN information.v_ordered_fields_per_class t5 ON t5.fk_property = t1.fk_property - AND t5.fk_class = t4.fk_class - AND t5.field_order = 0 - AND t1.fk_temporal_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project - UNION ALL - SELECT - t1.fk_concerned_entity AS pk_entity, - t1.fk_project, - t1. "coalesce" AS project, - t1.string, - t2.field_order, - t1.ord_num_of_text_property AS ord_num, - t1.is_in_project_count - FROM - warehouse.v_text_properties_per_project_and_repo t1, - information.v_ordered_fields_per_class t2 - WHERE - t1.fk_class_field = t2.fk_class_field - AND t2.field_order = 0 - AND t1.fk_concerned_entity = param_pk_entity - AND t1.fk_project IS NOT DISTINCT FROM param_fk_project -) SELECT DISTINCT ON (tw1.pk_entity, tw1.fk_project) - tw1.string INTO new_own_entity_label -FROM - tw1 -ORDER BY - tw1.pk_entity, - tw1.fk_project, - tw1.field_order, - tw1.ord_num, - tw1.is_in_project_count DESC; - RAISE INFO 'new_own_entity_label: %', new_own_entity_label; - ----- Insert or update column own_entity_label of table entity_preview - SELECT - entity_label INTO old_own_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_own_entity_label: %', old_own_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, entity_label) - VALUES (param_pk_entity, param_fk_project, new_own_entity_label); - RAISE INFO 'inserted new_own_entity_label: %', new_own_entity_label; - ELSIF ( - SELECT - (old_own_entity_label IS DISTINCT FROM new_own_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - entity_label = new_own_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_own_entity_label: %', new_own_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_own_entity_label; - END IF; -END IF; - RETURN TRUE; -END; -$BODY$; - - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_type_labels( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_type_label TEXT; - dependent_type_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_type_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_type_label - SELECT entity_label INTO new_type_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_type_label: %', new_type_label; - - -- update all dependent entity_previews with new_type_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET type_label = new_type_label - WHERE fk_type = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND type_label IS DISTINCT FROM new_type_label; - - RETURN true; - END; - $BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_related_full_texts( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_own_full_text TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_related_full_texts of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_own_full_text - SELECT own_full_text INTO new_own_full_text - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_own_full_text: %', new_own_full_text; - - - -- update all related_full_texts with new_own_full_text (if DISTINCT) - UPDATE warehouse.entity_preview - SET related_full_texts = ( - SELECT jsonb_set( - related_full_texts, - array_agg(param_pk_entity::text), - to_jsonb(new_own_full_text) - ) - ) - WHERE related_full_texts ? param_pk_entity::text - AND related_full_texts->>param_pk_entity::text IS DISTINCT FROM new_own_full_text - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RETURN true; - END; - $BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_entity_labels( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_entity_label TEXT; - dependent_entity_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_entity_labels of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - -- get new_entity_label - SELECT entity_label INTO new_entity_label - FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_entity_label: %', new_entity_label; - - -- update all dependent entity_previews with new_entity_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET entity_label = new_entity_label - WHERE fk_entity_label = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project - AND entity_label IS DISTINCT FROM new_entity_label; - - - RETURN true; - END; - $BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__fill_dependent_class_labels( - pk_class integer, - param_class_label text DEFAULT NULL::text) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_class_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview__fill_dependent_class_labels of pk_entity: %', pk_class; - - -- get new_class_label - IF (param_class_label IS NULL) THEN - SELECT class_label INTO new_class_label - FROM warehouse.class_preview - WHERE dfh_pk_class = pk_class; - ELSE - new_class_label = param_class_label; - END IF; - - RAISE INFO 'new_class_label: %', new_class_label; - - -- update all dependent entity_previews with new_class_label (if DISTINCT) - UPDATE warehouse.entity_preview - SET class_label = new_class_label - WHERE fk_class = pk_class - AND class_label IS DISTINCT FROM new_class_label; - - RETURN true; - END; - $BODY$; - - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_related_full_texts( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - new_related_full_texts jsonb; - param_project INT; - BEGIN - RAISE INFO 'entity_preview__create_related_full_texts pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - param_project = coalesce(param_fk_project, 0); - - ---------------------- REPO AND PROJECT VERSIONS ---------------------- - WITH full_text_dependencies AS ( - SELECT r.fk_temporal_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_entity AND e.table_name = 'persistent_item' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_temporal_entity = param_pk_entity - UNION - SELECT r.fk_entity as pk_entity, r.project, r.fk_project, e.pk_entity as pk_related_full_text, pre.own_full_text - FROM warehouse.v_roles_per_project_and_repo r - JOIN information.entity e ON e.pk_entity = r.fk_temporal_entity AND e.table_name = 'temporal_entity' - LEFT JOIN warehouse.entity_preview pre ON pre.pk_entity = e.pk_entity AND pre.project = r.project - WHERE r.fk_entity = param_pk_entity - ), - aggregated_related_full_texts AS( - select pk_entity, project, fk_project, jsonb_object_agg(full_text_dependencies.pk_related_full_text::text, full_text_dependencies.own_full_text) related_full_texts - FROM full_text_dependencies - group by pk_entity, project, fk_project - ) - select related_full_texts INTO new_related_full_texts - FROM aggregated_related_full_texts; - - RAISE INFO 'new_related_full_texts: %', new_related_full_texts; - - ----- Insert or update the entity_preview - - PERFORM pk_entity - FROM warehouse.entity_preview pre - WHERE pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project; - - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, related_full_texts) - VALUES (param_pk_entity, param_fk_project, param_project, new_related_full_texts); - - RAISE INFO 'inserted new_related_full_texts: %', new_related_full_texts; - - ELSE - - UPDATE warehouse.entity_preview pre - SET related_full_texts = new_related_full_texts - where pre.pk_entity = param_pk_entity - AND pre.fk_project IS NOT DISTINCT FROM param_fk_project - AND ( - pre.related_full_texts @> new_related_full_texts - AND - pre.related_full_texts <@ new_related_full_texts - ) IS DISTINCT FROM true; - - END IF; - - RETURN true; - END; - $BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_type( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - old_fk_type INT; - new_fk_type INT; - result_info JSONB; - BEGIN - - RAISE INFO 'entity_preview__create_fk_type of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - - --- get the fk_type - SELECT fk_type INTO new_fk_type - FROM - warehouse.v_fk_type - WHERE - pk_entity = param_pk_entity - AND - fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'new_fk_type: %', new_fk_type; - - ----- Insert or update column fk_type of table entity_preview - - SELECT fk_type INTO old_fk_type FROM warehouse.entity_preview - WHERE pk_entity = param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'old_fk_type: %', old_fk_type; - - IF NOT FOUND THEN - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_type) - VALUES (param_pk_entity, param_fk_project, new_fk_type); - - RAISE INFO 'inserted new_fk_type: %', new_fk_type; - - ELSIF (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)) THEN - - UPDATE warehouse.entity_preview - SET fk_type = new_fk_type - where pk_entity=param_pk_entity AND fk_project IS NOT DISTINCT FROM param_fk_project; - - RAISE INFO 'updated object with new_fk_type: %', new_fk_type; - ELSE - RAISE INFO 'no update needed: %', new_fk_type; - END IF; - - SELECT jsonb_build_object( - 'changed', (SELECT (old_fk_type IS DISTINCT FROM new_fk_type)), - 'old_val', old_fk_type, - 'new_val', new_fk_type) - INTO result_info; - - RETURN result_info; - - END; - $BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create_fk_entity_label( - param_pk_entity integer, - param_fk_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -DECLARE - old_fk_entity_label INT; - new_fk_entity_label INT; - result_info JSONB; -BEGIN - RAISE INFO 'entity_preview__create_fk_entity_label of pk_entity: %, fk_project: %', param_pk_entity, param_fk_project; - -- get the fk_entity_label - -- SELECT - -- fk_entity_label INTO new_fk_entity_label - -- FROM - -- warehouse.v_fk_entity_label - -- WHERE - -- pk_entity = param_pk_entity - -- AND fk_project IS NOT DISTINCT FROM param_fk_project; - WITH tw1 AS ( - SELECT - temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::character varying AS table_name, - 'teEnt'::text AS entity_type - FROM - information.temporal_entity - WHERE - pk_entity = param_pk_entity - UNION - SELECT - persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::character varying AS table_name, - 'peIt'::text AS entity_type - FROM - information.persistent_item - WHERE - pk_entity = param_pk_entity -), -tw2 AS ( - SELECT - fk_project, fk_property, fk_entity, fk_temporal_entity, ord_num_of_domain, is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo - WHERE - fk_temporal_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project -), -tw3 AS ( - SELECT - fk_project, fk_property, fk_entity, fk_temporal_entity, ord_num_of_domain, is_in_project_count - FROM - warehouse.v_roles_per_project_and_repo - WHERE - fk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project -) SELECT DISTINCT ON (t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class) - COALESCE(t4.fk_temporal_entity, CASE WHEN EXISTS ( - SELECT - pk_entity FROM information.persistent_item - WHERE - pk_entity = t3.fk_entity - UNION - SELECT - pk_entity FROM information.temporal_entity - WHERE - pk_entity = t3.fk_entity) = TRUE THEN - t3.fk_entity - ELSE - NULL - END) INTO new_fk_entity_label - FROM - tw1 t1 - JOIN information.v_ordered_fields_per_class t2 ON t1.fk_class = t2.fk_class - LEFT JOIN tw2 t3 ON t2.fk_property = t3.fk_property - AND t1.pk_entity = t3.fk_temporal_entity - LEFT JOIN tw3 t4 ON t2.fk_property = t4.fk_property - AND t1.pk_entity = t4.fk_entity -WHERE - t2.field_order = 0 -ORDER BY - t1.pk_entity, t3.fk_project, t4.fk_project, t1.fk_class, t2.field_order, t3.ord_num_of_domain, t4.ord_num_of_domain, t3.is_in_project_count DESC, t4.is_in_project_count DESC; - RAISE INFO 'new_fk_entity_label: %', new_fk_entity_label; - ----- Insert or update column fk_entity_label of table entity_preview - SELECT - fk_entity_label INTO old_fk_entity_label - FROM - warehouse.entity_preview - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'old_fk_entity_label: %', old_fk_entity_label; - IF NOT FOUND THEN - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, fk_entity_label) - VALUES (param_pk_entity, param_fk_project, new_fk_entity_label); - RAISE INFO 'inserted new_fk_entity_label: %', new_fk_entity_label; - ELSIF ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)) THEN - UPDATE - warehouse.entity_preview - SET - fk_entity_label = new_fk_entity_label - WHERE - pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - RAISE INFO 'updated object with new_fk_entity_label: %', new_fk_entity_label; - ELSE - RAISE INFO 'no update needed: %', new_fk_entity_label; - END IF; - SELECT - jsonb_build_object ('changed', - ( - SELECT - (old_fk_entity_label IS DISTINCT FROM new_fk_entity_label)), - 'old_val', - old_fk_entity_label, - 'new_val', - new_fk_entity_label) INTO result_info; - RETURN result_info; - END; -$BODY$; - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__create( - param_pk_entity integer, - param_fk_project integer) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ - DECLARE - e warehouse.v_entities; - c warehouse.class_preview; - p INT; - BEGIN - - ---------- upsert the unchagable rows ---------- - - p = coalesce(param_fk_project, 0); - - SELECT * INTO e - FROM warehouse.v_entities - WHERE pk_entity = param_pk_entity - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - SELECT * INTO c - FROM warehouse.class_preview as cpre - WHERE cpre.dfh_pk_class = e.fk_class; - - - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label) - VALUES ( - param_pk_entity, - param_fk_project, - p, -- project - e.fk_class, - e.entity_type, - c.class_label - ) - ON CONFLICT (pk_entity, project) - DO - UPDATE - SET fk_class = e.fk_class, entity_type = e.entity_type, class_label = c.class_label - WHERE entity_preview.pk_entity = param_pk_entity AND entity_preview.project = p; - - ---------- first create the dependency indexes ---------- - - PERFORM warehouse.entity_preview__create_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__create_fk_type(param_pk_entity, param_fk_project); - - ---------- second fill the own entity_label and own_full_text ---------- - - PERFORM warehouse.entity_preview__fill_own_entity_label(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_own_full_text(param_pk_entity, param_fk_project); - - - ---------- third fill the dependencies ---------- - - PERFORM warehouse.entity_preview__fill_dependent_entity_labels(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(param_pk_entity, param_fk_project); - - PERFORM warehouse.entity_preview__fill_dependent_type_labels(param_pk_entity, param_fk_project); - - RETURN true; - END; - $BODY$; - - --- 2 -CREATE FUNCTION warehouse.entity_preview__update_dependent_entity_labels() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_entity_labels; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM - warehouse.entity_preview__fill_dependent_entity_labels(NEW.pk_entity, NEW.fk_project), - warehouse.entity_preview__fill_dependent_type_labels(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $BODY$; - -CREATE FUNCTION warehouse.entity_preview__get_entity_label() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_entity_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_entity_label IS NOT NULL) THEN - UPDATE warehouse.entity_preview - SET entity_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_entity_label - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - END IF; - - RETURN NEW; - END; - $BODY$; - -CREATE FUNCTION warehouse.entity_preview__get_type_label() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__get_type_label; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - IF (NEW.fk_type IS NOT NULL) THEN - - UPDATE warehouse.entity_preview - SET type_label = pre.entity_label - FROM ( - SELECT entity_label - FROM warehouse.entity_preview - WHERE pk_entity = NEW.fk_type - AND fk_project IS NOT DISTINCT FROM NEW.fk_project - ) as pre - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - - ELSE - - UPDATE warehouse.entity_preview - SET type_label = NULL - WHERE pk_entity = NEW.pk_entity - AND fk_project IS NOT DISTINCT FROM NEW.fk_project; - - END IF; - - RETURN NEW; - END; - $BODY$; - -CREATE FUNCTION warehouse.entity_preview__update_dependent_related_full_texts() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_related_full_texts; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - PERFORM warehouse.entity_preview__fill_dependent_related_full_texts(NEW.pk_entity, NEW.fk_project); - - RETURN NEW; - END; - $BODY$; - - -CREATE FUNCTION warehouse.entity_preview__concat_full_text() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__concat_full_text; pk_entity: % fk_project: %', NEW.pk_entity, NEW.fk_project; - - - SELECT string_agg into NEW.full_text from ( - SELECT 1, string_agg(txt, ', ' ORDER BY rank) from ( - SELECT rank, txt - FROM ( - select 1 rank, coalesce(NEW.type_label, NEW.class_label, '') as txt - UNION - select 2 rank, NEW.own_full_text as txt - UNION - select 3 rank, value as txt - from jsonb_each_text(NEW.related_full_texts) - ) AS all_strings - WHERE txt != '' - ) AS items - GROUP BY 1 - ) as x; - - SELECT setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(NEW.type_label, NEW.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(NEW.full_text,'')), 'C') - INTO NEW.ts_vector; - - RETURN NEW; - END; - $BODY$; - --- 1 -CREATE TRIGGER after_update_on_entity_preview__entity_label - AFTER UPDATE OF entity_label - ON warehouse.entity_preview - FOR EACH ROW - WHEN ((new.skip_triggers <> true)) - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_entity_labels(); - - -CREATE TRIGGER after_update_on_entity_preview__fk_entity_label - AFTER UPDATE OF fk_entity_label - ON warehouse.entity_preview - FOR EACH ROW - WHEN ((new.skip_triggers <> true)) - EXECUTE PROCEDURE warehouse.entity_preview__get_entity_label(); - -CREATE TRIGGER after_update_on_entity_preview__fk_type - AFTER UPDATE OF fk_type - ON warehouse.entity_preview - FOR EACH ROW - WHEN ((new.skip_triggers <> true)) - EXECUTE PROCEDURE warehouse.entity_preview__get_type_label(); - -CREATE TRIGGER after_update_on_entity_preview__own_full_text - AFTER UPDATE OF own_full_text - ON warehouse.entity_preview - FOR EACH ROW - WHEN ((new.skip_triggers <> true)) - EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_related_full_texts(); - -CREATE TRIGGER before_update_on_entity_preview__own_full_text_or_related_full_ - BEFORE INSERT OR UPDATE OF own_full_text, related_full_texts - ON warehouse.entity_preview - FOR EACH ROW - WHEN ((new.skip_triggers <> true)) - EXECUTE PROCEDURE warehouse.entity_preview__concat_full_text(); diff --git a/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-up.sql b/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-up.sql deleted file mode 100644 index cfb61ada6..000000000 --- a/server/db-migrate/migrations/sqls/20191004144005-war-cleanup-up.sql +++ /dev/null @@ -1,68 +0,0 @@ --- 1 DROP triggers of warehouse.entity_preview -DROP TRIGGER after_update_on_entity_preview__entity_label ON warehouse.entity_preview; - -DROP TRIGGER after_update_on_entity_preview__fk_entity_label ON warehouse.entity_preview; - -DROP TRIGGER after_update_on_entity_preview__fk_type ON warehouse.entity_preview; - -DROP TRIGGER after_update_on_entity_preview__own_full_text ON warehouse.entity_preview; - -DROP TRIGGER before_update_on_entity_preview__own_full_text_or_related_full_ ON warehouse.entity_preview; - - --- 2 DROP warehouse trigger functions -DROP FUNCTION warehouse.entity_preview__update_dependent_entity_labels(); - -DROP FUNCTION warehouse.entity_preview__get_entity_label(); - -DROP FUNCTION warehouse.entity_preview__get_type_label(); - -DROP FUNCTION warehouse.entity_preview__update_dependent_related_full_texts(); - -DROP FUNCTION warehouse.entity_preview__concat_full_text(); - - --- 3 DROP warehouse functions -DROP FUNCTION warehouse.entity_preview__create(integer, integer); - -DROP FUNCTION warehouse.entity_preview__create_fk_entity_label(integer, integer); - -DROP FUNCTION warehouse.entity_preview__create_fk_type(integer, integer); - -DROP FUNCTION warehouse.entity_preview__create_related_full_texts(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_dependent_class_labels(integer, text); - -DROP FUNCTION warehouse.entity_preview__fill_dependent_entity_labels(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_dependent_related_full_texts(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_dependent_type_labels(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_own_entity_label(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_own_full_text(integer, integer); - -DROP FUNCTION warehouse.entity_preview__fill_time_span(integer, integer); - - --- 4 DROP warehouse views -DROP VIEW warehouse.v_entity_preview; - -DROP VIEW warehouse.v_entity_preview_non_recursive; - -DROP VIEW warehouse.v_entities; - -DROP VIEW warehouse.v_fk_type; - -DROP VIEW warehouse.v_fk_entity_label; - -DROP VIEW warehouse.v_own_entity_label; - -DROP VIEW warehouse.v_own_full_text; - -DROP VIEW warehouse.v_related_full_texts; - -DROP VIEW warehouse.v_te_en_time_span_per_project_and_repo; - -DROP VIEW warehouse.v_text_properties_per_project_and_repo; diff --git a/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-down.sql b/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-down.sql deleted file mode 100644 index a299427f4..000000000 --- a/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-down.sql +++ /dev/null @@ -1,31 +0,0 @@ --- 10 -DROP FUNCTION warehouse.entity_preview__full_text__update_all; - --- 9 -DROP FUNCTION warehouse.entity_preview__full_text__update_modified; - --- 8 -DROP FUNCTION warehouse.entity_preview__full_text__remove_superfluous; - --- 7 -DROP FUNCTION warehouse.entity_preview__full_text__add_missing; - --- 6 -DROP FUNCTION warehouse.entity_preview__full_text__create_temporary; - - - --- 5 -DROP FUNCTION warehouse.entity_preview__labels__update_all; - --- 4 -DROP FUNCTION warehouse.entity_preview__labels__update_modified; - --- 3 -DROP FUNCTION warehouse.entity_preview__labels__remove_superfluous; - --- 2 -DROP FUNCTION warehouse.entity_preview__labels__add_missing; - --- 1 -DROP FUNCTION warehouse.entity_preview__labels__create_temporary; diff --git a/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-up.sql b/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-up.sql deleted file mode 100644 index f945b0bcf..000000000 --- a/server/db-migrate/migrations/sqls/20191007102252-war-split-part-1-and-2-up.sql +++ /dev/null @@ -1,568 +0,0 @@ --- 1 create function entity_preview__labels__create_temporary (); -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__create_temporary( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - DROP TABLE IF EXISTS entity_preview_labels_temporary; - CREATE TEMP TABLE entity_preview_labels_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_labels_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_labels_temporary t1, - entity_preview_labels_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_labels_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_labels_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_labels_temporary t1, - entity_preview_labels_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_labels_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_labels_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - RETURN TRUE; -END; -$BODY$; - - --- 2 create function entity_preview__labels_add_missing - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__add_missing( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_entity_label, fk_type, type_label, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - TRUE -FROM - entity_preview_labels_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - -RETURN TRUE; - -END; -$BODY$; - - --- 3 create function entity_preview__labels_remove_superfluous - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__remove_superfluous( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_labels_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_labels_temporary, to be deleted' AS note - FROM - entity_preview_labels_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$BODY$; - --- 4 create function entity_preview__labels__update_modified (); -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; - --- 5 create function entity_preview__labels__update_all (); -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__update_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - PERFORM - warehouse.entity_preview__labels__create_temporary (); - PERFORM - warehouse.entity_preview__labels__add_missing (); - PERFORM - warehouse.entity_preview__labels__remove_superfluous (); - PERFORM - warehouse.entity_preview__labels__update_modified (); - RETURN TRUE; -END; -$BODY$; - --- 6 create function entity_preview__full_text__create_temporary (); -CREATE OR REPLACE FUNCTION warehouse.entity_preview__full_text__create_temporary( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - DROP TABLE IF EXISTS entity_preview_full_text_temporary; - CREATE TEMP TABLE entity_preview_full_text_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_full_text_temporary ADD UNIQUE (pk_entity, fk_project); - - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_full_text_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_full_text_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_full_text_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - - ----------- create full text --------- - UPDATE - entity_preview_full_text_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_full_text_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$BODY$; - - --- 7 create function entity_preview__full_text__add_missing (); - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__full_text__add_missing( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_full_text_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, type_label, related_full_texts, full_text, ts_vector, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t1.related_full_texts, - t1.full_text, - t1.ts_vector, - TRUE -FROM - entity_preview_full_text_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - -RETURN TRUE; - -END; -$BODY$; - - --- 8 create function entity_preview__full_text__remove_superfluous (); - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__full_text__remove_superfluous( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_full_text_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_full_text_temporary, to be deleted' AS note - FROM - entity_preview_full_text_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$BODY$; - --- 9 create function entity_preview__full_text__update_modified (); - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__full_text__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - own_full_text, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_full_text_temporary, to be updated' AS note - FROM - entity_preview_full_text_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - own_full_text, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_full_text_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) -UPDATE - warehouse.entity_preview t1 -SET - own_full_text = tw1.own_full_text, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE -FROM - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; - --- 10 create function entity_preview__full_text__update_all (); -CREATE OR REPLACE FUNCTION warehouse.entity_preview__full_text__update_all( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - PERFORM - warehouse.entity_preview__full_text__create_temporary (); - PERFORM - warehouse.entity_preview__full_text__add_missing (); - PERFORM - warehouse.entity_preview__full_text__remove_superfluous (); - PERFORM - warehouse.entity_preview__full_text__update_modified (); - RETURN TRUE; -END; -$BODY$; - - --- 11 drop function entity_preview__create_temporary (); --- 14 drop function entity_preview__update_modified (); --- 15 drop function entity_preview__update_all (); diff --git a/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-down.sql b/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-up.sql b/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-up.sql deleted file mode 100644 index d1fb46e15..000000000 --- a/server/db-migrate/migrations/sqls/20191007171501-war-init-entity-previews-up.sql +++ /dev/null @@ -1,5 +0,0 @@ --- data operation, no way back --- initializes all entity_previews via migration to avoid a period without entity_previews on production --- this will take some time (minutes) -SELECT warehouse.entity_preview_non_recursive__refresh(); -SELECT warehouse.entity_preview__update_all(); diff --git a/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-down.sql b/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-down.sql deleted file mode 100644 index f6f1d065a..000000000 --- a/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP FUNCTION commons.isnumeric; -DROP FUNCTION commons.get_entity_appellation; diff --git a/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-up.sql b/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-up.sql deleted file mode 100644 index aff5b017f..000000000 --- a/server/db-migrate/migrations/sqls/20191008134112-com-f-is-numeric-up.sql +++ /dev/null @@ -1,36 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.isnumeric( - text) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - IMMUTABLE STRICT -AS $BODY$ -DECLARE x NUMERIC; -BEGIN - x = $1::NUMERIC; - RETURN TRUE; -EXCEPTION WHEN others THEN - RETURN FALSE; -END; -$BODY$; - - -CREATE OR REPLACE FUNCTION commons.get_entity_appellation( - pk_entity integer) - RETURNS character varying - LANGUAGE 'sql' - - COST 100 - VOLATILE -AS $BODY$ -SELECT t3.string -FROM information.role t1, - information.role t2, - information.appellation t3 - -WHERE t1.fk_entity = $1 -AND t2.fk_temporal_entity = t1.fk_temporal_entity -AND t2.fk_property = 1113 -AND t2.fk_entity = t3.pk_entity; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-down.sql b/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-down.sql deleted file mode 100644 index caeadb3ca..000000000 --- a/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-down.sql +++ /dev/null @@ -1,69 +0,0 @@ - --- 2 extend add pe it to project to also add text properties -CREATE OR REPLACE FUNCTION information.add_pe_it_to_project( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - WITH pe_it_roles AS ( - SELECT * FROM information.get_ingoing_roles_to_add(param_pk_entity) - ), - -- find all entity associations that involve the pe_it - pe_it_entity_associations AS ( - -- where pe_it is domain - SELECT * FROM information.get_outgoing_entity_associations_to_add (param_pk_entity) - UNION - -- where pe_it is range - SELECT * FROM information.get_ingoing_entity_associations_to_add (param_pk_entity) - ), - -- Find all temporal entities related to pe_it_roles - -- that are of an auto-add property - te_ents AS ( - SELECT fk_temporal_entity as pk_entity - FROM pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - te_ent_roles AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_roles_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_roles_to_add(t2.pk_entity) ) AS ts2 - ), - -- Find all entity_associations of temporal entities - te_ent_entity_associations AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - ), - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select param_pk_entity as pk_entity, null::calendar_type as calendar - UNION - select pk_entity, null::calendar_type as calendar from pe_it_entity_associations - UNION - select pk_entity, calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ent_entity_associations - ) - insert into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT param_pk_project, true, pk_entity, calendar, param_account_id - from pk_entities_of_repo; - - END $BODY$; - - --- 1 - -DROP FUNCTION information.get_accociated_text_properties; diff --git a/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-up.sql b/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-up.sql deleted file mode 100644 index 276f41078..000000000 --- a/server/db-migrate/migrations/sqls/20191009064252-inf-f-add-pe-it-up.sql +++ /dev/null @@ -1,84 +0,0 @@ --- 1 create function that gets all text properties of an entity - -CREATE OR REPLACE FUNCTION information.get_accociated_text_properties( - param_pk_entity integer) - RETURNS TABLE(pk_entity integer, fk_class_field integer) - LANGUAGE 'plpgsql' -AS $BODY$ -BEGIN - RETURN QUERY - SELECT t1.pk_entity, t1.fk_class_field - FROM information.text_property t1 - WHERE fk_concerned_entity = param_pk_entity; -END; $BODY$; - --- 2 extend add pe it to project to also add text properties -CREATE OR REPLACE FUNCTION information.add_pe_it_to_project( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ BEGIN - WITH pe_it_roles AS ( - SELECT * FROM information.get_ingoing_roles_to_add(param_pk_entity) - ), - -- find all entity associations that involve the pe_it - pe_it_entity_associations AS ( - -- where pe_it is domain - SELECT * FROM information.get_outgoing_entity_associations_to_add (param_pk_entity) - UNION - -- where pe_it is range - SELECT * FROM information.get_ingoing_entity_associations_to_add (param_pk_entity) - ), - -- Find all temporal entities related to pe_it_roles - -- that are of an auto-add property - te_ents AS ( - SELECT fk_temporal_entity as pk_entity - FROM pe_it_roles - ), - -- Find all roles related to temporal entities mached by pe_it_roles - te_ent_roles AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_roles_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_roles_to_add(t2.pk_entity) ) AS ts2 - ), - -- Find all entity_associations of temporal entities - te_ent_entity_associations AS ( - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_outgoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - UNION ALL - SELECT ts2.* FROM te_ents t2 - CROSS JOIN LATERAL ( SELECT * FROM information.get_ingoing_entity_associations_to_add(t2.pk_entity) ) AS ts2 - ), - -- get a list of all pk_entities of repo version - pk_entities_of_repo AS ( - select param_pk_entity as pk_entity, null::calendar_type as calendar - UNION - select pk_entity, null::calendar_type as calendar from pe_it_entity_associations - UNION - select pk_entity, calendar from pe_it_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ents - UNION - select pk_entity, calendar from te_ent_roles - UNION - select pk_entity, null::calendar_type as calendar from te_ent_entity_associations - UNION - select pk_entity, null::calendar_type as calendar from information.get_accociated_text_properties(param_pk_entity) - ) - insert into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - SELECT param_pk_project, true, pk_entity, calendar, param_account_id - FROM pk_entities_of_repo t1 - ON CONFLICT ON CONSTRAINT entity_version_project_rel_fk_entity_fk_project_key DO UPDATE SET - is_in_project = EXCLUDED.is_in_project, - calendar = EXCLUDED.calendar, - fk_last_modifier = EXCLUDED.fk_last_modifier ; - - - END $BODY$; diff --git a/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-down.sql b/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-down.sql deleted file mode 100644 index 5d7bde6c1..000000000 --- a/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-down.sql +++ /dev/null @@ -1,112 +0,0 @@ --- 4 -DROP FUNCTION warehouse.entity_preview_update_queue_worker; - --- 3 -CREATE OR REPLACE FUNCTION warehouse.after_info_proj_rel_upsert () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - -- find the table name of the affected table - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - --------------------- text_property --------------------- - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of text_property for entity: %, fk_project: %', _fk_entity, _fk_project; - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_entity::text || ']'::text, _fk_project::text]); - --------------------- role ----------------------------- - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_entity::text || ']'::text, _fk_project::text]); - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_temporal_entity::text || ']'::text, _fk_project::text]); - --------------------- entity_association ----------------- - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - RAISE INFO 'updated epr of entity_association with fk_info_domain: %, fk_info_range: %, fk_project: %', _fk_info_domain, _fk_info_range, _fk_project; - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_info_domain::text || ']'::text, _fk_project::text]); - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || _fk_info_range::text || ']'::text, _fk_project::text]); - --------------------- temporal_entity or persistent_item ----------------- - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - RAISE INFO 'updated crm entity with pk_entity: %, fk_project: %', NEW.fk_entity, _fk_project; - IF (NEW.is_in_project = TRUE) THEN - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__upsert'::text, - ARRAY['ARRAY[' || NEW.fk_entity::text || ']'::text, _fk_project::text]); - ELSIF (NEW.is_in_project = FALSE) THEN - PERFORM - warehouse.needs_update ('entity_preview_non_recursive__delete'::text, - ARRAY['ARRAY[' || NEW.fk_entity::text || ']'::text, _fk_project::text]); - END IF; - END IF; - RETURN NEW; -END; -$BODY$; - --- 2 -DROP TABLE warehouse.entity_preview_update_queue; - diff --git a/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-up.sql b/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-up.sql deleted file mode 100644 index 054dc0dcf..000000000 --- a/server/db-migrate/migrations/sqls/20191009083127-war-warehouse-update-request-change-up.sql +++ /dev/null @@ -1,266 +0,0 @@ --- 2 -CREATE TABLE warehouse.entity_preview_update_queue ( - fk_project integer NOT NULL, - pk_entity integer NOT NULL, - ord_num SERIAL -); - --- 3 -CREATE OR REPLACE FUNCTION warehouse.after_info_proj_rel_upsert () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - -- find the table name of the affected table - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - - /****************************************************************** - * text_property - ******************************************************************/ - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - - /** - * Add concerned entity to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * role - ******************************************************************/ - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - - /** - * Add domain and range entities to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_entity), (_fk_project, _fk_temporal_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * entity_association - ******************************************************************/ - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - - /** - * Add domain and range entities to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_info_domain), (_fk_project, _fk_info_range) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * temporal_entity or persistent_item - ******************************************************************/ - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - /** - * Add entity to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, NEW.fk_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - END IF; - RETURN NEW; -END; -$BODY$; - --- 4 function to work through the update queue -CREATE OR REPLACE FUNCTION warehouse.entity_preview_update_queue_worker () - RETURNS boolean - LANGUAGE 'plpgsql' - AS $BODY$ -BEGIN - /* - * Check if we have at least one record in the update queue - */ - IF ( - SELECT - EXISTS ( - SELECT - * - FROM - warehouse.entity_preview_update_queue)) THEN - /********** - * Creates a temp table useful for later steps. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true, ord_num 4 - * - entity 207386, project 24, is_in_project false, ord_num 3 - * - entity 207386, project 82, is_in_project true, ord_num 2 - * - entity 207386, project 24, is_in_project true, ord_num 1 - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - DROP TABLE IF EXISTS tmp_update_queue_table; - CREATE TEMP TABLE tmp_update_queue_table AS SELECT DISTINCT ON (t1.fk_project, t1.pk_entity) - t1.fk_project, - t1.pk_entity, - t3.is_in_project, - t1.ord_num - FROM - warehouse.entity_preview_update_queue t1 - INNER JOIN ( - SELECT - pk_entity - FROM - information.persistent_item - UNION - SELECT - pk_entity - FROM - information.temporal_entity) t2 ON t1.pk_entity = t2.pk_entity - INNER JOIN projects.info_proj_rel t3 ON t3.fk_entity = t1.pk_entity - AND t3.fk_project = t1.fk_project - ORDER BY - t1.fk_project, - t1.pk_entity, - t1.ord_num DESC; - - /********** - * Group the remaining update request by is_in_project and fk_projects and - * Perform the updates on entity_preview_non_recursive - ***********/ - /* - * Perform the updates on entity_preview_non_recursive - */ - PERFORM - CASE WHEN t1.is_in_project = TRUE THEN - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - WHEN t1.is_in_project = FALSE THEN - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - END - FROM ( - /* - * Group the remaining update request by is_in_project and fk_projects - */ - SELECT - is_in_project, - fk_project, - array_agg(pk_entity) pk_entities --, count(pk_entity) - FROM - tmp_update_queue_table - GROUP BY - fk_project, - is_in_project) t1; - - /********** - * Cleanup queue by deleting all rows with ord_num smaller than the - * highest ord_num considered when creating the updates - **********/ - DELETE FROM warehouse.entity_preview_update_queue - WHERE ord_num <= ( - SELECT - max(ord_num) max_ord_num - FROM - tmp_update_queue_table); - - /******** - * reset serial if queue is empty. - * this prevents from exceeding maximum of integer / serial - *********/ - IF ( - SELECT - EXISTS ( - SELECT - * - FROM - warehouse.entity_preview_update_queue) = FALSE) THEN - PERFORM - setval('warehouse.entity_preview_update_queue_ord_num_seq', 1); - END IF; - - /****** - * Return true if there has been at least one update on entity_preview_non_recursive - *******/ - RETURN ( - SELECT - EXISTS ( - SELECT - * - FROM - tmp_update_queue_table)); - ELSE - /* - * Return false if we had no record in the update queue - */ - RETURN FALSE; - END IF; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-down.sql b/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-down.sql deleted file mode 100644 index 6e342feac..000000000 --- a/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-down.sql +++ /dev/null @@ -1,280 +0,0 @@ --- 6 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_update_queue_worker () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - /* - * Check if we have at least one record in the update queue - */ - IF ( - SELECT - EXISTS ( - SELECT - * - FROM - warehouse.entity_preview_update_queue)) THEN - /********** - * Creates a temp table useful for later steps. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true, ord_num 4 - * - entity 207386, project 24, is_in_project false, ord_num 3 - * - entity 207386, project 82, is_in_project true, ord_num 2 - * - entity 207386, project 24, is_in_project true, ord_num 1 - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - DROP TABLE IF EXISTS tmp_update_queue_table; - CREATE TEMP TABLE tmp_update_queue_table AS SELECT DISTINCT ON (t1.fk_project, t1.pk_entity) - t1.fk_project, - t1.pk_entity, - t3.is_in_project, - t1.ord_num - FROM - warehouse.entity_preview_update_queue t1 - INNER JOIN ( - SELECT - pk_entity - FROM - information.persistent_item - UNION - SELECT - pk_entity - FROM - information.temporal_entity) t2 ON t1.pk_entity = t2.pk_entity - INNER JOIN projects.info_proj_rel t3 ON t3.fk_entity = t1.pk_entity - AND t3.fk_project = t1.fk_project - ORDER BY - t1.fk_project, - t1.pk_entity, - t1.ord_num DESC; - - /********** - * Group the remaining update request by is_in_project and fk_projects and - * Perform the updates on entity_preview_non_recursive - ***********/ - /* - * Perform the updates on entity_preview_non_recursive - */ - PERFORM - CASE WHEN t1.is_in_project = TRUE THEN - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - WHEN t1.is_in_project = FALSE THEN - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - END - FROM ( - /* - * Group the remaining update request by is_in_project and fk_projects - */ - SELECT - is_in_project, - fk_project, - array_agg(pk_entity) pk_entities --, count(pk_entity) - FROM - tmp_update_queue_table - GROUP BY - fk_project, - is_in_project) t1; - - /********** - * Cleanup queue by deleting all rows with ord_num smaller than the - * highest ord_num considered when creating the updates - **********/ - DELETE FROM warehouse.entity_preview_update_queue - WHERE ord_num <= ( - SELECT - max(ord_num) max_ord_num - FROM - tmp_update_queue_table); - - /******** - * reset serial if queue is empty. - * this prevents from exceeding maximum of integer / serial - *********/ - IF ( - SELECT - EXISTS ( - SELECT - * - FROM - warehouse.entity_preview_update_queue) = FALSE) THEN - PERFORM - setval('warehouse.entity_preview_update_queue_ord_num_seq', 1); - END IF; - - /****** - * Return true if there has been at least one update on entity_preview_non_recursive - *******/ - RETURN ( - SELECT - EXISTS ( - SELECT - * - FROM - tmp_update_queue_table)); - ELSE - /* - * Return false if we had no record in the update queue - */ - RETURN FALSE; - END IF; -END; -$BODY$; - --- 5 - - --- 4 -CREATE OR REPLACE FUNCTION warehouse.after_info_proj_rel_upsert () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - _table_name VARCHAR; - _fk_project INT; - _fk_entity INT; - _fk_temporal_entity INT; - _fk_info_domain INT; - _fk_info_range INT; - _domain_is_in_project BOOLEAN; - _range_is_in_project BOOLEAN; - _BOOL BOOLEAN; - _result JSONB; - _new_label TEXT; -BEGIN - _fk_project = NEW.fk_project; - -- find the table name of the affected table - SELECT - table_name INTO _table_name - FROM - information.entity e - WHERE - e.pk_entity = NEW.fk_entity; - - /****************************************************************** - * text_property - ******************************************************************/ - IF ( - SELECT - _table_name = 'text_property') THEN - SELECT - t.fk_concerned_entity INTO _fk_entity - FROM - information.text_property t - WHERE - t.pk_entity = NEW.fk_entity; - - /** - * Add concerned entity to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * role - ******************************************************************/ - ELSIF ( - SELECT - _table_name = 'role') THEN - SELECT - r.fk_entity INTO _fk_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - SELECT - r.fk_temporal_entity INTO _fk_temporal_entity - FROM - information.role r - WHERE - r.pk_entity = NEW.fk_entity; - - /** - * Add domain and range entities to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_entity), (_fk_project, _fk_temporal_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * entity_association - ******************************************************************/ - ELSIF ( - SELECT - _table_name = 'entity_association') THEN - SELECT - ea.fk_info_domain INTO _fk_info_domain - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - SELECT - ea.fk_info_range INTO _fk_info_range - FROM - information.entity_association ea - WHERE - ea.pk_entity = NEW.fk_entity; - - /** - * Add domain and range entities to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, _fk_info_domain), (_fk_project, _fk_info_range) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - - /****************************************************************** - * temporal_entity or persistent_item - ******************************************************************/ - ELSIF ( - SELECT - _table_name IN ('temporal_entity', - 'persistent_item')) THEN - /** - * Add entity to the update queue - */ - INSERT INTO warehouse.entity_preview_update_queue (fk_project, pk_entity) - VALUES (_fk_project, NEW.fk_entity) ON CONFLICT DO NOTHING; - PERFORM - pg_notify('queue_updated', 'true'); - END IF; - RETURN NEW; -END; -$BODY$; - --- 3 -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; - -CREATE TRIGGER after_epr_upsert - AFTER INSERT - OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE warehouse.after_info_proj_rel_upsert (); - --- 2 -CREATE TABLE warehouse.entity_preview_update_queue ( - fk_project integer NOT NULL, - pk_entity integer NOT NULL, - ord_num SERIAL); --- 1 -DROP TABLE warehouse.entity_preview_non_recursive_updates; - diff --git a/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-up.sql b/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-up.sql deleted file mode 100644 index de537d078..000000000 --- a/server/db-migrate/migrations/sqls/20191010155210-war-functions-update-up.sql +++ /dev/null @@ -1,196 +0,0 @@ --- 1 -CREATE TABLE warehouse.entity_preview_non_recursive_updates ( - pk_entity serial, - tmsp_update_begin timestamp without time zone, - tmsp_update_end timestamp without time zone -); - --- 2 -DROP TABLE warehouse.entity_preview_update_queue; - --- 3 -DROP TRIGGER after_epr_upsert ON projects.info_proj_rel; - -CREATE TRIGGER after_epr_upsert - AFTER INSERT - OR UPDATE ON projects.info_proj_rel - FOR EACH STATEMENT - EXECUTE PROCEDURE warehouse.after_info_proj_rel_upsert (); - --- 4 -CREATE OR REPLACE FUNCTION warehouse.after_info_proj_rel_upsert () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - AS $BODY$ -BEGIN - PERFORM - pg_notify('queue_updated', 'true'); - RETURN NEW; -END; -$BODY$; - --- 5 -CREATE OR REPLACE FUNCTION warehouse.do_updates_for_time_after (tmsp timestamp) - RETURNS void - LANGUAGE 'sql' - AS $BODY$ - WITH tw1 AS ( - /********** - * Selects the info_proj_rel that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - SELECT DISTINCT ON (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification - FROM - projects.info_proj_rel t1, - ( - SELECT - pk_entity - FROM - information.persistent_item - UNION - SELECT - pk_entity - FROM - information.temporal_entity) t2 - WHERE - t1.tmsp_last_modification::timestamp >= tmsp - AND t1.fk_entity = t2.pk_entity - ORDER BY - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification DESC -), -tw2 AS ( - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - SELECT - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - FROM - tw1 - GROUP BY - fk_project, - is_in_project) -/******* - * Perform the updates on entity_preview_non_recursive - *******/ -SELECT - CASE WHEN t1.is_in_project = TRUE THEN - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - WHEN t1.is_in_project = FALSE THEN - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - END -FROM - tw2 t1; - -$BODY$; - --- 6 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_update_queue_worker () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - last_warehouse_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -BEGIN - /* - * Get the timestamp of the last warehouse.entity_preview_non_recursive update - */ - SELECT - tmsp_update_begin INTO last_warehouse_update - FROM - warehouse.entity_preview_non_recursive_updates - ORDER BY - pk_entity DESC - LIMIT 1; - -- set very early default - IF last_warehouse_update IS NULL THEN - last_warehouse_update = '1970-01-01 00:00:00.000000'::timestamp; - END IF; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - SELECT - tmsp_last_modification::timestamp INTO last_project_modification - FROM - projects.info_proj_rel - ORDER BY - tmsp_last_modification DESC - LIMIT 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of warehouse - */ - IF (last_project_modification > last_warehouse_update) THEN - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - INSERT INTO warehouse.entity_preview_non_recursive_updates (tmsp_update_begin) - VALUES (now()::timestamp) - RETURNING - pk_entity INTO pk_update; - - /***** - * Perform the updates - ******/ - PERFORM - warehouse.do_updates_for_time_after (last_warehouse_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - UPDATE - warehouse.entity_preview_non_recursive_updates - SET - tmsp_update_end = clock_timestamp()::timestamp; - - /****** - * Return true for indicating that tehere has been an update - *******/ - RETURN TRUE; - ELSE - /* - * Return false for indicating that there has been no update - */ - RETURN FALSE; - END IF; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-down.sql b/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-down.sql deleted file mode 100644 index 4ef22ab57..000000000 --- a/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-down.sql +++ /dev/null @@ -1,15 +0,0 @@ --- 4 -DROP FUNCTION commons.clone_sandbox_project; - --- 3 -ALTER TABLE projects.query_vt - DROP COLUMN fk_cloned_from_query; - --- 2 -ALTER TABLE projects.query - DROP COLUMN fk_cloned_from_query; - --- 1 -ALTER TABLE projects.project - DROP COLUMN fk_cloned_from_project; - diff --git a/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-up.sql b/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-up.sql deleted file mode 100644 index f679e5238..000000000 --- a/server/db-migrate/migrations/sqls/20191010155211-com-f-clone-project-up.sql +++ /dev/null @@ -1,357 +0,0 @@ --- 1 -ALTER TABLE projects.project - ADD COLUMN fk_cloned_from_project INTEGER REFERENCES projects.project (pk_entity); - --- 2 -ALTER TABLE projects.query - ADD COLUMN fk_cloned_from_query INTEGER REFERENCES projects.query (pk_entity); - --- 3 -ALTER TABLE projects.query_vt - ADD COLUMN fk_cloned_from_query INTEGER; - --- 4 -CREATE OR REPLACE FUNCTION commons.clone_sandbox_project (account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ -DECLARE - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_sandbox_project) ON CONFLICT DO NOTHING -RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_entity, string, fk_system_type, fk_language) - VALUES (pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_entity, string, fk_system_type, fk_language) - VALUES (pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_entity, enabled_in_entities) -SELECT - pk_new_project AS fk_project, - fk_entity, - enabled_in_entities -FROM - projects.dfh_class_proj_rel -WHERE - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') -RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add account to project - */ - INSERT INTO public.account_project_rel (fk_project, account_id, ROLE) - VALUES (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for entity_associations referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an entity_association associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_sandbox_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.entity_association t2 - WHERE - fk_project = pk_sandbox_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_cell_domain IS NOT NULL - OR t2.fk_cell_range IS NOT NULL - OR t2.fk_data_domain IS NOT NULL - OR t2.fk_data_range IS NOT NULL)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) -SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version -FROM - projects.info_proj_rel t1, - tw1 t2 -WHERE - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.digital t2 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace; - - /* - * copy entity_associations pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new digital's fk_cloned_from - SELECT - t3.pk_entity AS fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.entity_association t2, - data.digital t3 - WHERE - fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.quill_doc, - t4.pk_text, - t4.entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace - AND t3.pk_text = t2.fk_text - AND t3.entity_version = t2.fk_entity_version - AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy entity_associations pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new chunk's fk_cloned_from - SELECT - t3.pk_entity AS fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.entity_association t2, - data.chunk t3 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the entity_associations pointing to data to the new project - */ - INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) -SELECT - t1.pk_entity AS fk_entity, - pk_new_project AS fk_project, - TRUE AS is_in_project -FROM - information.entity_association t1, - data.entity t2 -WHERE - t1.fk_data_domain = t2.pk_entity - AND t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_preview_non_recursive from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO warehouse.entity_preview_non_recursive (pk_entity, fk_class, fk_project, table_name, class_label, own_full_text, own_entity_label, time_span, related_full_texts, fk_entity_label, fk_type) -SELECT - pk_entity, - fk_class, - pk_new_project AS fk_project, - table_name, - class_label, - own_full_text, - own_entity_label, - time_span, - related_full_texts, - fk_entity_label, - fk_type -FROM - warehouse.entity_preview_non_recursive -WHERE - fk_project = pk_sandbox_project ON CONFLICT (pk_entity, COALESCE(fk_project, 0)) - DO NOTHING; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, related_full_texts, full_text, ts_vector) -SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - related_full_texts, - full_text, - ts_vector -FROM - warehouse.entity_preview -WHERE - fk_project = pk_sandbox_project ON CONFLICT ON CONSTRAINT entity_preview_unique DO NOTHING; - - /* - * Clone query - */ - INSERT INTO projects.query (fk_last_modifier, name, description, query, fk_project, fk_cloned_from_query) -SELECT - account_id AS fk_last_modifier, - name, - description, - query, - pk_new_project AS fk_project, - pk_entity -FROM - projects.query -WHERE - fk_project = pk_sandbox_project; - - /* - * Clone visual - */ - INSERT INTO projects.visual (fk_last_modifier, name, description, visual, fk_project) - WITH tw1 AS ( - -- unnest all queryLayers - SELECT - pk_entity, - visual, - jsonb_array_elements(visual -> 'settings' -> 'queryLayers') AS layer - FROM - projects.visual - WHERE - fk_project = pk_sandbox_project), - tw2 AS ( - -- replace the pk of original query with pk of new query and set queryVersion=1 - SELECT - t1.pk_entity, - t1.visual, - jsonb_set(jsonb_set(t1.layer, '{queryPk}', t2.pk_entity::text::jsonb), '{queryVersion}', '1'::jsonb) AS modified_layer - FROM - tw1 t1, - projects.query t2 - WHERE - t2.fk_project = pk_new_project - AND - t2.fk_cloned_from_query = (t1.layer ->> 'queryPk')::integer - ), - tw3 AS ( - -- aggregate modified query layers and insert them into the visuals object - SELECT - t1.pk_entity, - jsonb_set(t1.visual, '{settings,queryLayers}', jsonb_agg(t1.modified_layer)) AS modified_visual - FROM - tw2 t1 - GROUP BY - t1.pk_entity, - t1.visual -) - SELECT - account_id AS fk_last_modifier, - t2.name, - t2.description, - t1.modified_visual AS visual, - pk_new_project AS fk_project - FROM - tw3 t1, - projects.visual t2 - WHERE - t1.pk_entity = t2.pk_entity; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-down.sql b/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-down.sql deleted file mode 100644 index 581ae0e3b..000000000 --- a/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-down.sql +++ /dev/null @@ -1,32 +0,0 @@ --- 11 -DROP FUNCTION commons.time_primitive__get_last_second; - --- 10 -DROP FUNCTION commons.time_primitive__get_first_second; - --- 9 -DROP FUNCTION commons.julian_cal__add_1_month; - --- 8 -DROP TYPE public.year_month_day; - --- 7 -DROP FUNCTION commons.julian_cal__year_month_day; - --- 6 -DROP TYPE public.month_and_day_of_month; - --- 5 -DROP TYPE public.year_and_day_of_year; - --- 4 -DROP FUNCTION commons.julian_cal__month_and_day_of_month; - --- 3 -DROP FUNCTION commons.julian_cal__add_1_year; - --- 2 -DROP FUNCTION commons.julian_cal__year_and_day_of_year; - --- 1 -DROP FUNCTION commons.julian_cal__is_leap_year; diff --git a/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-up.sql b/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-up.sql deleted file mode 100644 index 5fa1f60f2..000000000 --- a/server/db-migrate/migrations/sqls/20191016104029-com-f-julian-calendar-functions-up.sql +++ /dev/null @@ -1,296 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION commons.julian_cal__is_leap_year(year integer) - RETURNS boolean - LANGUAGE 'plpgsql' - AS $BODY$ BEGIN - -- year is the year BC: no year 0. - IF(year > 0) THEN - -- if devisable by 4 without remainder - RETURN ((year % 4) = 0); - ELSE - -- if devisable by 4 without remainder = -1 - RETURN ((year % 4) = -1); - END IF; - - END; - $BODY$; - --- 2 -CREATE OR REPLACE FUNCTION commons.julian_cal__year_and_day_of_year( - julian_day integer) - RETURNS TABLE ( - year integer, - day_of_year integer - ) - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - -- number of full 4 year cycles - n4 integer; - -- number of days of the last uncomplete 4 years cycle - r4 integer; - -- number of full years of the last uncomplete 4 years cycle - n1 integer; - -- number of days in the last year, zero-based (begins with 0) - day_of_year integer; - -- number of years (counted from julian year 0 (=4713 BC)) - julian_year integer; - -- year in christian counting - year integer; - BEGIN - /* - * Inspired by - * https://de.wikipedia.org/wiki/Umrechnung_zwischen_julianischem_Datum_und_julianischem_Kalender - */ - - -- number of full 4 year cycles - n4 = floor((julian_day + (3 * 365)) / 1461::numeric)::integer; - - -- number of days of the last uncomplete 4 years cycle - r4 = (julian_day + (3 * 365)) % 1461 ; - - -- number of full years of the last uncomplete 4 years cycle - n1 = floor(r4 / 365::numeric); - - -- number of days in the last year - day_of_year = r4 % 365; - - IF (n1 = 4) THEN - n1 = 3; - day_of_year = 365; - END IF; - - -- number of years (counted from julian year 0 (=4713 BC)) - julian_year = 4 * n4 + n1; - - -- if BC - IF (julian_year <= 4715) THEN - -- resulting year - year = julian_year - 4716; - -- if AD - ELSE - year = julian_year - 4715; - END IF; - - RETURN QUERY (SELECT year, day_of_year); - END; - $BODY$; - --- 3 -CREATE OR REPLACE FUNCTION commons.julian_cal__add_1_year( - julian_day integer) - RETURNS integer - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - _year integer; - BEGIN - SELECT year INTO _year from commons.julian_cal__year_and_day_of_year(julian_day); - IF (_year % 4) = 0 THEN - RETURN julian_day + 366; - ELSE - RETURN julian_day + 365; - END IF; - END; - $BODY$; - --- 4 -CREATE OR REPLACE FUNCTION commons.julian_cal__month_and_day_of_month(year integer, day_of_year integer) - RETURNS TABLE ( - month integer, - day_of_month integer - ) - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - -- true, if year is a leap year according to julian calendar - is_leap boolean; - -- month corrections (note that january has index 0) - month_correnctions int[]; - -- month correction - mc int; - -- leap year correction - lc int; - -- resulting month, one-based (begins with 1) - month int; - -- resulting day of month, one-based (begins with 1) - day_of_month int; - - BEGIN - -- leap year - is_leap = commons.julian_cal__is_leap_year(year); - - -- month corrections (note that january has index 0) - month_correnctions = ARRAY[-1, 0, -2, -1, -1, 0, 0, 1, +2, +2, +3, +3]; - -- resulting month - month = floor((day_of_year + 1) / 30::numeric) + 1; - -- month correction - mc = month_correnctions[month]; - -- leap year correction - IF (is_leap = true AND month > 2) THEN - lc = 1; - ELSE - lc = 0; - END IF; - -- resulting day - day_of_month = day_of_year - 30 * (month - 1) - (lc + mc); - - -- check if month and day still valid - IF (month > 12 OR day_of_month < 1) THEN - - month = month-1; - - IF (month < 1) THEN - is_leap = NOT is_leap; - END IF; - - -- leap year correction - IF (is_leap = true AND month > 2) THEN - lc = 1; - ELSE - lc = 0; - END IF; - -- month correction - mc = month_correnctions[month]; - - -- resulting day - day_of_month = day_of_year - 30 * (month - 1) - (lc + mc); - - END IF; - - RETURN QUERY SELECT month, day_of_month; - - END; - $BODY$; - --- 5 -CREATE TYPE year_and_day_of_year AS ( - year integer, - day_of_year integer -); - --- 6 -CREATE TYPE month_and_day_of_month AS ( - month integer, - day_of_month integer -); - --- 7 -CREATE OR REPLACE FUNCTION commons.julian_cal__year_month_day(julian_day integer) - RETURNS TABLE ( - year integer, - month integer, - day integer - ) - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - -- year and day_of_year according to julian calendar - y year_and_day_of_year; - -- month and day_of_month according to julian calendar - m month_and_day_of_month; - BEGIN - - SELECT * FROM commons.julian_cal__year_and_day_of_year(julian_day) INTO y; - SELECT * FROM commons.julian_cal__month_and_day_of_month(y.year, y.day_of_year) INTO m; - - RETURN QUERY SELECT y.year, m.month, m.day_of_month; - - END; - $BODY$; - --- 8 -CREATE TYPE year_month_day AS ( - year integer, - month integer, - day integer -); - --- 9 -CREATE OR REPLACE FUNCTION commons.julian_cal__add_1_month( julian_day integer) - RETURNS integer - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - x year_month_day; - is_leap boolean; - days_in_month int[]; - BEGIN - SELECT * from commons.julian_cal__year_month_day(julian_day) INTO x; - is_leap = commons.julian_cal__is_leap_year(x.year); - - IF (is_leap = false) THEN - days_in_month = ARRAY[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; - ELSE - days_in_month = ARRAY[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; - END IF; - - RETURN julian_day + days_in_month[x.month]; - END; - $BODY$; - --- 10 -CREATE OR REPLACE FUNCTION commons.time_primitive__get_first_second(julian_day integer) - RETURNS bigint - LANGUAGE 'sql' - AS $BODY$ - SELECT (julian_day::bigint * 86400::bigint) ; -- 86400 = 60 * 60 * 24 = number of seconds per day - $BODY$; - --- 11 -CREATE OR REPLACE FUNCTION commons.time_primitive__get_last_second( - julian_day integer, - duration calendar_granularities, - calendar calendar_type) - RETURNS bigint - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - day_after_added_duration int; - BEGIN - - IF(calendar IS NULL) THEN - RAISE WARNING 'No calendar provided'; - IF(julian_day < 2299161) THEN - calendar = 'julian'; - ELSE - calendar = 'gregorian'; - END IF; - END IF; - - IF(calendar = 'gregorian') THEN - IF(duration = '1 day') THEN - SELECT julian_day + 1 INTO day_after_added_duration; - ELSIF(duration = '1 month') THEN - SELECT to_char((('J' || julian_day::text)::DATE + INTERVAL '1 month'), 'J') INTO day_after_added_duration; - ELSIF(duration = '1 year') THEN - SELECT to_char((('J' || julian_day::text)::DATE + INTERVAL '1 year'), 'J') INTO day_after_added_duration; - ELSE - RAISE EXCEPTION 'duration not supported --> %', duration - USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; - END IF; - - ELSIF (calendar = 'julian') THEN - - IF(duration = '1 day') THEN - SELECT julian_day + 1 INTO day_after_added_duration; - ELSIF(duration = '1 month') THEN - SELECT commons.julian_cal__add_1_month(julian_day) INTO day_after_added_duration; - ELSIF(duration = '1 year') THEN - SELECT commons.julian_cal__add_1_year(julian_day) INTO day_after_added_duration; - ELSE - RAISE EXCEPTION 'duration not supported --> %', duration - USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; - END IF; - - ELSE - RAISE EXCEPTION 'calendar not supported --> %', calendar - USING HINT = 'Supported calendars: "gregorian", "julian"'; - END IF; - - -- calculate the first second of the day after the added duration and subtract one second - -- so that we get the last second of the duration - RETURN commons.time_primitive__get_first_second(day_after_added_duration) - 1; - END; - $BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-down.sql b/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-down.sql deleted file mode 100644 index e5ef4641b..000000000 --- a/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-down.sql +++ /dev/null @@ -1,1165 +0,0 @@ --- 2 -ALTER TABLE warehouse.entity_preview DROP COLUMN first_second; -ALTER TABLE warehouse.entity_preview DROP COLUMN last_second; - --- 1 -ALTER TABLE warehouse.entity_preview_non_recursive DROP COLUMN first_second; -ALTER TABLE warehouse.entity_preview_non_recursive DROP COLUMN last_second; - --- 7 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__upsert( - param_pk_entities integer[], - param_fk_project integer) - RETURNS void - LANGUAGE 'sql' - - COST 100 - VOLATILE -AS $BODY$ - - /** - * UPSERT the entity previews of the entities with given param_pk_entities - * for the given param_fk_project and the repo version (fk_project = NULL) - */ - INSERT INTO - warehouse.entity_preview_non_recursive - ( - SELECT * FROM warehouse.entity_preview_non_recursive__create(param_pk_entities) - WHERE fk_project IS NULL OR fk_project = param_fk_project - ) - ON CONFLICT (pk_entity, COALESCE(fk_project, 0)) - DO UPDATE - SET - fk_class = EXCLUDED.fk_class, - table_name = EXCLUDED.table_name, - class_label = EXCLUDED.class_label, - own_full_text = EXCLUDED.own_full_text, - own_entity_label = EXCLUDED.own_entity_label, - time_span = EXCLUDED.time_span, - related_full_texts = EXCLUDED.related_full_texts, - fk_entity_label = EXCLUDED.fk_entity_label, - fk_type = EXCLUDED.fk_type; - -$BODY$; - --- 6 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; - - --- 5 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) -UPDATE - warehouse.entity_preview t1 -SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - own_full_text = tw1.own_full_text, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE -FROM - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; - --- 4 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create( - param_pk_entities integer[]) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- select roles with time primitive - tw9 AS ( - SELECT - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second(t3.julian_day) as first_second, - commons.time_primitive__get_last_second(t3.julian_day, t3.duration, t2.calendar) as last_second - FROM information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - WHERE - t1.fk_temporal_entity = ANY(param_pk_entities) - AND - t1.pk_entity = t2.fk_entity - AND (t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND t3.pk_entity = t1.fk_entity AND t2.is_in_project = true - UNION - ( SELECT DISTINCT ON (t1.fk_temporal_entity, t1.fk_property) t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second(t3.julian_day) as first_second, - commons.time_primitive__get_last_second(t3.julian_day, t3.duration, t1.community_favorite_calendar) as last_second - FROM information.v_role t1 - JOIN information.v_time_primitive t3 ON t3.pk_entity = t1.fk_entity - WHERE - t1.fk_temporal_entity = ANY(param_pk_entities) - AND - t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - ORDER BY t1.fk_temporal_entity, t1.fk_property, t1.is_in_project_count DESC, t1.tmsp_creation DESC) - ), - -- create time spans - tw10 AS ( - SELECT - tw9.fk_project, - tw9.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN tw9.fk_property = 71 THEN 'p81'::text - WHEN tw9.fk_property = 72 THEN 'p82'::text - WHEN tw9.fk_property = 150 THEN 'p81a'::text - WHEN tw9.fk_property = 151 THEN 'p81b'::text - WHEN tw9.fk_property = 152 THEN 'p82a'::text - WHEN tw9.fk_property = 153 THEN 'p82b'::text - ELSE tw9.fk_property::text - END, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) AS time_span - FROM tw9 - GROUP BY tw9.fk_project, tw9.fk_temporal_entity - ), - tw11 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span - FROM - tw8 t1 - LEFT JOIN - tw10 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw11 t1 - LEFT JOIN - tw12 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw14 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw15 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw14 t1, - system.class_has_type_property t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw14 t3, - system.class_has_type_property t4 - WHERE - ( - t3.fk_info_domain = ANY(param_pk_entities) - OR - t3.fk_info_range = ANY(param_pk_entities) - ) - AND - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw16 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type - FROM - tw13 t1 - LEFT JOIN - tw15 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw16; - -$BODY$; - --- 3 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all( - ) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- select roles with time primitive - tw9 AS ( - SELECT r.fk_temporal_entity, - r.fk_property, - epr.fk_project, - epr.calendar, - tp.julian_day, - tp.duration - FROM information.role r, - projects.info_proj_rel epr, - information.v_time_primitive tp - WHERE - r.pk_entity = epr.fk_entity - AND (r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND tp.pk_entity = r.fk_entity AND epr.is_in_project = true - UNION - ( SELECT DISTINCT ON (r.fk_temporal_entity, r.fk_property) r.fk_temporal_entity, - r.fk_property, - NULL::integer AS fk_project, - r.community_favorite_calendar, - tp.julian_day, - tp.duration - FROM information.v_role r - JOIN information.v_time_primitive tp ON tp.pk_entity = r.fk_entity - WHERE - r.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - ORDER BY r.fk_temporal_entity, r.fk_property, r.is_in_project_count DESC, r.tmsp_creation DESC) - ), - -- create time spans - tw10 AS ( - SELECT - tw9.fk_project, - tw9.fk_temporal_entity, - jsonb_object_agg( - CASE - WHEN tw9.fk_property = 71 THEN 'p81'::text - WHEN tw9.fk_property = 72 THEN 'p82'::text - WHEN tw9.fk_property = 150 THEN 'p81a'::text - WHEN tw9.fk_property = 151 THEN 'p81b'::text - WHEN tw9.fk_property = 152 THEN 'p82a'::text - WHEN tw9.fk_property = 153 THEN 'p82b'::text - ELSE tw9.fk_property::text - END, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) AS time_span - FROM tw9 - GROUP BY tw9.fk_project, tw9.fk_temporal_entity - ), - tw11 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span - FROM - tw8 t1 - LEFT JOIN - tw10 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw11 t1 - LEFT JOIN - tw12 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw14 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw15 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw14 t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw14 t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw16 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type - FROM - tw13 t1 - LEFT JOIN - tw15 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw16; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-up.sql b/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-up.sql deleted file mode 100644 index c79d73623..000000000 --- a/server/db-migrate/migrations/sqls/20191016121842-war-add-first-and-last-julian-second-up.sql +++ /dev/null @@ -1,1223 +0,0 @@ --- 1 -ALTER TABLE warehouse.entity_preview_non_recursive ADD COLUMN first_second bigint; -ALTER TABLE warehouse.entity_preview_non_recursive ADD COLUMN last_second bigint; - --- 2 -ALTER TABLE warehouse.entity_preview ADD COLUMN first_second bigint; -ALTER TABLE warehouse.entity_preview ADD COLUMN last_second bigint; - --- 3 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all( - ) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - -- 1 - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - tw9 AS ( - -- get first and last second of all time primitives - SELECT - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second(t1.julian_day) as first_second, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'gregorian') as last_second_julian, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'julian') as last_second_gregorian - FROM information.time_primitive t1 - ), - -- select roles with time primitive, first and last second - tw10 AS ( - SELECT - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t3.calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.role t1, - tw9 t2, - projects.info_proj_rel t3 - WHERE t1.pk_entity = t3.fk_entity - AND (t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) - AND t2.pk_entity = t1.fk_entity - AND t3.is_in_project = true - UNION - ( - SELECT DISTINCT ON (t1.fk_temporal_entity, t1.fk_property) t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t1.community_favorite_calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.v_role t1 - JOIN tw9 t2 ON t2.pk_entity = t1.fk_entity - WHERE - t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND - t1.is_in_project_count > 0 - ORDER BY t1.fk_temporal_entity, t1.fk_property, t1.is_in_project_count DESC, t1.tmsp_creation DESC) - - ), - -- create time spans, first_second and last_second - tw11 AS ( - SELECT - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - CASE - WHEN tw10.fk_property = 71 THEN 'p81'::text - WHEN tw10.fk_property = 72 THEN 'p82'::text - WHEN tw10.fk_property = 150 THEN 'p81a'::text - WHEN tw10.fk_property = 151 THEN 'p81b'::text - WHEN tw10.fk_property = 152 THEN 'p82a'::text - WHEN tw10.fk_property = 153 THEN 'p82b'::text - ELSE tw10.fk_property::text - END, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) AS time_span - FROM tw10 - GROUP BY tw10.fk_project, tw10.fk_temporal_entity - ), - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - FROM - tw8 t1 - LEFT JOIN - tw11 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw14 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw12 t1 - LEFT JOIN - tw13 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw15 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw16 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw15 t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw15 t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw17 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type, - t1.first_second, - t1.last_second - FROM - tw14 t1 - LEFT JOIN - tw16 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw17; -$BODY$; - --- 4 -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create( - param_pk_entities integer[]) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t1.pk_entity = ANY(param_pk_entities) - AND - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - WHERE - t1.pk_entity = ANY(param_pk_entities) - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - ( - t1.fk_entity = ANY(param_pk_entities) - OR - t1.fk_temporal_entity = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.fk_concerned_entity = ANY(param_pk_entities) - AND - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- select roles with time primitive, first and last second - tw9 AS ( - SELECT - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second(t3.julian_day) as first_second, - commons.time_primitive__get_last_second(t3.julian_day, t3.duration, t2.calendar) as last_second - FROM information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - WHERE - t1.fk_temporal_entity = ANY(param_pk_entities) - AND - t1.pk_entity = t2.fk_entity - AND (t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) AND t3.pk_entity = t1.fk_entity AND t2.is_in_project = true - UNION - ( SELECT DISTINCT ON (t1.fk_temporal_entity, t1.fk_property) t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second(t3.julian_day) as first_second, - commons.time_primitive__get_last_second(t3.julian_day, t3.duration, t1.community_favorite_calendar) as last_second - FROM information.v_role t1 - JOIN information.v_time_primitive t3 ON t3.pk_entity = t1.fk_entity - WHERE - t1.fk_temporal_entity = ANY(param_pk_entities) - AND - t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND - t1.is_in_project_count > 0 - ORDER BY t1.fk_temporal_entity, t1.fk_property, t1.is_in_project_count DESC, t1.tmsp_creation DESC) - ), - -- create time spans, first_second and last_second - tw10 AS ( - SELECT - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - CASE - WHEN tw9.fk_property = 71 THEN 'p81'::text - WHEN tw9.fk_property = 72 THEN 'p82'::text - WHEN tw9.fk_property = 150 THEN 'p81a'::text - WHEN tw9.fk_property = 151 THEN 'p81b'::text - WHEN tw9.fk_property = 152 THEN 'p82a'::text - WHEN tw9.fk_property = 153 THEN 'p82b'::text - ELSE tw9.fk_property::text - END, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) AS time_span - FROM tw9 - GROUP BY tw9.fk_project, tw9.fk_temporal_entity - ), - tw11 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - FROM - tw8 t1 - LEFT JOIN - tw10 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw11 t1 - LEFT JOIN - tw12 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw14 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw15 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw14 t1, - system.class_has_type_property t2 - WHERE - ( - t1.fk_info_domain = ANY(param_pk_entities) - OR - t1.fk_info_range = ANY(param_pk_entities) - ) - AND - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw14 t3, - system.class_has_type_property t4 - WHERE - ( - t3.fk_info_domain = ANY(param_pk_entities) - OR - t3.fk_info_range = ANY(param_pk_entities) - ) - AND - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw16 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type, - t1.first_second, - t1.last_second - FROM - tw13 t1 - LEFT JOIN - tw15 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw16; - -$BODY$; - - --- 5 -CREATE OR REPLACE FUNCTION warehouse.entity_preview__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - warehouse.entity_preview - ) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second, - own_full_text = tw1.own_full_text, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; - --- 6 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview__labels__update_modified( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$BODY$; --- 7 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__upsert( - param_pk_entities integer[], - param_fk_project integer) - RETURNS void - LANGUAGE 'sql' - - COST 100 - VOLATILE -AS $BODY$ - - /** - * UPSERT the entity previews of the entities with given param_pk_entities - * for the given param_fk_project and the repo version (fk_project = NULL) - */ - INSERT INTO - warehouse.entity_preview_non_recursive - ( - SELECT * FROM warehouse.entity_preview_non_recursive__create(param_pk_entities) - WHERE fk_project IS NULL OR fk_project = param_fk_project - ) - ON CONFLICT (pk_entity, COALESCE(fk_project, 0)) - DO UPDATE - SET - fk_class = EXCLUDED.fk_class, - table_name = EXCLUDED.table_name, - class_label = EXCLUDED.class_label, - own_full_text = EXCLUDED.own_full_text, - own_entity_label = EXCLUDED.own_entity_label, - time_span = EXCLUDED.time_span, - first_second = EXCLUDED.first_second, - last_second = EXCLUDED.last_second, - related_full_texts = EXCLUDED.related_full_texts, - fk_entity_label = EXCLUDED.fk_entity_label, - fk_type = EXCLUDED.fk_type; - -$BODY$; - - --- 8 data manipulation: update all entity_preview_non_recursive -DELETE FROM warehouse.entity_preview_non_recursive; -INSERT INTO warehouse.entity_preview_non_recursive -SELECT * FROM warehouse.entity_preview_non_recursive__create_all(); diff --git a/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-down.sql b/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-down.sql deleted file mode 100644 index 90373b731..000000000 --- a/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-down.sql +++ /dev/null @@ -1,86 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.do_updates_for_time_after( - tmsp timestamp without time zone) - RETURNS void - LANGUAGE 'sql' - - COST 100 - VOLATILE -AS $BODY$ - WITH tw1 AS ( - /********** - * Selects the info_proj_rel that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - SELECT DISTINCT ON (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification - FROM - projects.info_proj_rel t1, - ( - SELECT - pk_entity - FROM - information.persistent_item - UNION - SELECT - pk_entity - FROM - information.temporal_entity) t2 - WHERE - t1.tmsp_last_modification::timestamp >= tmsp - AND t1.fk_entity = t2.pk_entity - ORDER BY - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification DESC -), -tw2 AS ( - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - SELECT - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - FROM - tw1 - GROUP BY - fk_project, - is_in_project) -/******* - * Perform the updates on entity_preview_non_recursive - *******/ -SELECT - CASE WHEN t1.is_in_project = TRUE THEN - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - WHEN t1.is_in_project = FALSE THEN - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - END -FROM - tw2 t1; - -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-up.sql b/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-up.sql deleted file mode 100644 index 3b9cb7e0a..000000000 --- a/server/db-migrate/migrations/sqls/20191016134407-war-do-update-function-up.sql +++ /dev/null @@ -1,121 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.do_updates_for_time_after( - tmsp timestamp without time zone) - RETURNS void - LANGUAGE 'sql' - - COST 100 - VOLATILE -AS $BODY$ -/********** -* Selects the pk_entities that need to be updated. -* -* takes only the latest item for each pk_entity and project. -* this helps to skip unneeded intermediate updates. For example: -* Those update requests: -* - entity 207386, project 24, is_in_project true -* - entity 207386, project 24, is_in_project false -* - entity 207386, project 82, is_in_project true -* - entity 207386, project 24, is_in_project true -* -* is reduced to the latest ones per project and entity: -* - entity 207386, project 24, is_in_project true -* - entity 207386, project 82, is_in_project true -* -* also takes only pk_entity of persistent_item or temporal_entity -* by joining a union of information.persistent_item and information.temporal_entity -* -* also takes only pk_entity of items that have a info_proj_rel. -* this excludes entities that are related by project's properties (roles) but are not in project -* themselfes. -***********/ -WITH tw1 AS ( - SELECT t1.fk_entity, t1.fk_project, t1.tmsp_last_modification::timestamp - FROM - projects.info_proj_rel t1 - WHERE - t1.tmsp_last_modification::timestamp >= tmsp -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 AS ( - -- persistent_items where info_proj_rel changed - SELECT t1.pk_entity as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.persistent_item t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- temporal_entities where info_proj_rel changed - SELECT t1.pk_entity as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.temporal_entity t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- domain entities of roles where info_proj_rel changed - SELECT t1.fk_temporal_entity as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.role t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- range entities of roles where info_proj_rel changed - SELECT t1.fk_entity as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.role t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- domain entities of entity_associations where info_proj_rel changed - SELECT t1.fk_info_domain as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.entity_association t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- range entities of entity_associations where info_proj_rel changed - SELECT t1.fk_info_range as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.entity_association t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity - UNION ALL - -- concerned entities of text_properties where info_proj_rel changed - SELECT t1.fk_concerned_entity as fk_entity, t2.fk_project, t2.tmsp_last_modification - FROM information.text_property t1, tw1 t2 - WHERE t1.pk_entity = t2.fk_entity -), -tw3 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - FROM - tw2 t1, - projects.info_proj_rel t2 - WHERE - t1.fk_entity = t2.fk_entity - AND - t1.fk_project = t2.fk_project - ORDER BY - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification DESC -), -tw4 AS ( - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - SELECT - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - FROM - tw3 - GROUP BY - fk_project, - is_in_project) -/******* - * Perform the updates on entity_preview_non_recursive - *******/ -SELECT - CASE WHEN t1.is_in_project = TRUE THEN - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - WHEN t1.is_in_project = FALSE THEN - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - END -FROM - tw4 t1; - -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-down.sql b/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-down.sql deleted file mode 100644 index d0b639ad6..000000000 --- a/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-down.sql +++ /dev/null @@ -1,482 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all( - ) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - -- 1 - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - tw9 AS ( - -- get first and last second of all time primitives - SELECT - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second(t1.julian_day) as first_second, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'gregorian') as last_second_julian, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'julian') as last_second_gregorian - FROM information.time_primitive t1 - ), - -- select roles with time primitive, first and last second - tw10 AS ( - SELECT - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t3.calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.role t1, - tw9 t2, - projects.info_proj_rel t3 - WHERE t1.pk_entity = t3.fk_entity - AND (t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) - AND t2.pk_entity = t1.fk_entity - AND t3.is_in_project = true - UNION - ( - SELECT DISTINCT ON (t1.fk_temporal_entity, t1.fk_property) t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t1.community_favorite_calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.v_role t1 - JOIN tw9 t2 ON t2.pk_entity = t1.fk_entity - WHERE - t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND - t1.is_in_project_count > 0 - ORDER BY t1.fk_temporal_entity, t1.fk_property, t1.is_in_project_count DESC, t1.tmsp_creation DESC) - - ), - -- create time spans, first_second and last_second - tw11 AS ( - SELECT - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - CASE - WHEN tw10.fk_property = 71 THEN 'p81'::text - WHEN tw10.fk_property = 72 THEN 'p82'::text - WHEN tw10.fk_property = 150 THEN 'p81a'::text - WHEN tw10.fk_property = 151 THEN 'p81b'::text - WHEN tw10.fk_property = 152 THEN 'p82a'::text - WHEN tw10.fk_property = 153 THEN 'p82b'::text - ELSE tw10.fk_property::text - END, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) AS time_span - FROM tw10 - GROUP BY tw10.fk_project, tw10.fk_temporal_entity - ), - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - FROM - tw8 t1 - LEFT JOIN - tw11 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw14 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw12 t1 - LEFT JOIN - tw13 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw15 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw16 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw15 t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw15 t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw17 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type, - t1.first_second, - t1.last_second - FROM - tw14 t1 - LEFT JOIN - tw16 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw17; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-up.sql b/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-up.sql deleted file mode 100644 index 3a6345fda..000000000 --- a/server/db-migrate/migrations/sqls/20191029104556-war-entity-preview-non-rec-create-all-fix-up.sql +++ /dev/null @@ -1,482 +0,0 @@ - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all( - ) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - -- 1 - WITH - -- all entities per project with class label - tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar AS table_name, - t3.class_label - FROM - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - UNION - SELECT - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar AS table_name, - t3.class_label - FROM - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - WHERE - t2.is_in_project = true - AND - t1.pk_entity = t2.fk_entity - AND - t1.fk_class = t3.dfh_pk_class - ), - -- all entities per project and repo - tw2 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - UNION - SELECT DISTINCT ON (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer AS fk_project, - t1.table_name, - t1.class_label - FROM - tw1 t1 - ), - -- fields (deprecated/to be changed with pk_property) - tw3 AS ( - SELECT - t1.pk_entity, - t1.ord_num AS field_order, - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END AS fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain as fk_domain_class, - t2.dfh_has_range as fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - FROM - projects.class_field_config t1 - LEFT JOIN - data_for_history.property t2 ON t2.dfh_pk_property = t1.fk_property - LEFT JOIN - system.class_field t3 ON t3.pk_entity = t1.fk_class_field - WHERE - t1.fk_app_context = 45 - AND - t1.ord_num IS NOT NULL - ORDER BY ( - CASE - WHEN t1.property_is_outgoing = true THEN t2.dfh_has_domain - WHEN t1.property_is_outgoing = false THEN t2.dfh_has_range - ELSE t1.fk_class_for_class_field - END), t1.ord_num - ), - -- explode with all fields: join all entities with their fields - tw4 AS ( - -- - SELECT - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - FROM - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - WHERE - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class - ), - -- select all roles per project with ord_num - tw5 AS ( - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity - AND t2.is_in_project = true - UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM information.v_role t1 - WHERE - t1.is_in_project_count > 0 - ), - -- select all text_properties per project with ord_num - tw6 AS ( - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS "coalesce", - t2.ord_num_of_text_property - FROM information.v_text_property t1, - projects.info_proj_rel t2 - WHERE - t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer AS fk_project, - 0 AS "coalesce", - NULL::integer AS ord_num_of_text_property - FROM information.v_text_property t1 - WHERE - t1.is_in_project_count > 0 - ), - -- join directly related things and create string - tw7 AS ( - SELECT - t1.*, - COALESCE(t2.ord_num_of_range, t7.ord_num_of_text_property) AS ord_num, - COALESCE(t3.string, t4.notes, t7.string) AS string, - COALESCE(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) AS fk_related_entity - FROM - tw4 t1 - -- join outgoing roles - LEFT JOIN - tw5 t2 - ON - t1.fk_property = t2.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND - t1.property_is_outgoing = TRUE - AND - t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - LEFT JOIN - information.appellation t3 - ON - t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - LEFT JOIN - information.language t4 - ON - t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - LEFT JOIN - information.persistent_item t5 - ON - t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - LEFT JOIN - information.temporal_entity t6 - ON - t2.fk_entity = t6.pk_entity - -- join text properties - LEFT JOIN - tw6 t7 - ON - t1.pk_entity = t7.fk_concerned_entity - AND - t1.fk_class_field = t7.fk_class_field - AND - t1.fk_project IS NOT DISTINCT FROM t7.fk_project - -- join ingoing roles - LEFT JOIN - tw5 t8 - ON - t1.fk_property = t8.fk_property - AND - t1.fk_project IS NOT DISTINCT FROM t8.fk_project - AND - t1.property_is_outgoing = FALSE - AND - t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - LEFT JOIN - information.persistent_item t9 - ON - t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - LEFT JOIN - information.temporal_entity t10 - ON - t8.fk_temporal_entity = t10.pk_entity - ), - -- group for ordered array of strings - tw8 AS ( - SELECT pk_entity, fk_class, fk_project, table_name, class_label, - array_agg(string - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) string_array - FROM tw7 t1 - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - tw9 AS ( - -- get first and last second of all time primitives - SELECT - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second(t1.julian_day) as first_second, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'gregorian') as last_second_gregorian, - commons.time_primitive__get_last_second(t1.julian_day, t1.duration, 'julian') as last_second_julian - FROM information.time_primitive t1 - ), - -- select roles with time primitive, first and last second - tw10 AS ( - SELECT - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t3.calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.role t1, - tw9 t2, - projects.info_proj_rel t3 - WHERE t1.pk_entity = t3.fk_entity - AND (t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153])) - AND t2.pk_entity = t1.fk_entity - AND t3.is_in_project = true - UNION - ( - SELECT DISTINCT ON (t1.fk_temporal_entity, t1.fk_property) t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - CASE WHEN t1.community_favorite_calendar = 'gregorian' THEN t2.last_second_gregorian ELSE t2.last_second_julian END last_second - FROM information.v_role t1 - JOIN tw9 t2 ON t2.pk_entity = t1.fk_entity - WHERE - t1.fk_property = ANY (ARRAY[71, 72, 150, 151, 152, 153]) - AND - t1.is_in_project_count > 0 - ORDER BY t1.fk_temporal_entity, t1.fk_property, t1.is_in_project_count DESC, t1.tmsp_creation DESC) - - ), - -- create time spans, first_second and last_second - tw11 AS ( - SELECT - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - CASE - WHEN tw10.fk_property = 71 THEN 'p81'::text - WHEN tw10.fk_property = 72 THEN 'p82'::text - WHEN tw10.fk_property = 150 THEN 'p81a'::text - WHEN tw10.fk_property = 151 THEN 'p81b'::text - WHEN tw10.fk_property = 152 THEN 'p82a'::text - WHEN tw10.fk_property = 153 THEN 'p82b'::text - ELSE tw10.fk_property::text - END, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) AS time_span - FROM tw10 - GROUP BY tw10.fk_project, tw10.fk_temporal_entity - ), - tw12 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - FROM - tw8 t1 - LEFT JOIN - tw11 t2 - ON - t1.pk_entity = t2.fk_temporal_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- group related things and create object with fk_related_entities - tw13 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) AS related_full_texts, - array_agg(t1.fk_related_entity - ORDER BY - t1.field_order ASC, - t1.ord_num ASC - ) AS fk_entity_labels - FROM tw7 t1 - WHERE t1.fk_related_entity IS NOT NULL - GROUP BY pk_entity, fk_class, fk_project, table_name, class_label - ), - -- join fk_entity_label and related_full_texts - tw14 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - CASE WHEN t1.own_entity_label IS NOT NULL THEN NULL::integer - ELSE t2.fk_entity_labels[1] - END AS fk_entity_label - FROM - tw12 t1 - LEFT JOIN - tw13 t2 - ON - t1.pk_entity = t2.pk_entity - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select all entity associations per project with ord_num - tw15 AS ( - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t1.is_in_project_count - FROM information.v_entity_association t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity AND t2.is_in_project = true - UNION - SELECT DISTINCT t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - t1.is_in_project_count - FROM information.v_entity_association t1 - WHERE t1.is_in_project_count > 0 - ), - -- get type entity_associations (DEPRECATED) - tw16 AS ( - SELECT DISTINCT ON (t1.fk_project, t1.fk_property, t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - FROM - tw15 t1, - system.class_has_type_property t2 - WHERE - t1.fk_project IS NULL AND t1.fk_property = t2.fk_property - UNION - SELECT - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - FROM - tw15 t3, - system.class_has_type_property t4 - WHERE - t3.fk_project IS NOT NULL AND t3.fk_property = t4.fk_property - ORDER BY 1, 2, 3, 5 DESC - ), - -- join fk_type - tw17 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range AS fk_type, - t1.first_second, - t1.last_second - FROM - tw14 t1 - LEFT JOIN - tw16 t2 - ON - t1.pk_entity = t2.fk_info_domain - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ) - SELECT * FROM tw17; -$BODY$; diff --git a/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-down.sql b/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-down.sql deleted file mode 100644 index 809bd1091..000000000 --- a/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE system.analysis_type_vt; -DROP TABLE system.analysis_type; diff --git a/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-up.sql b/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-up.sql deleted file mode 100644 index 4caf8f58e..000000000 --- a/server/db-migrate/migrations/sqls/20191101150953-sys-t-analysis-type-up.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* Replace with your SQL commands */ -CREATE TABLE system.analysis_type ( - standard_label text, - rows_limit integer) -INHERITS ( - system.entity -); - -SELECT - commons.init_entity_child_table ('system.analysis_type'); - diff --git a/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-down.sql b/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-down.sql deleted file mode 100644 index 4a50ec8ed..000000000 --- a/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE projects.analysis_vt; -DROP TABLE projects.analysis; diff --git a/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-up.sql b/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-up.sql deleted file mode 100644 index 544761321..000000000 --- a/server/db-migrate/migrations/sqls/20191101151422-pro-t-analysis-up.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* Replace with your SQL commands */ -CREATE TABLE projects.analysis ( - fk_project INTEGER NOT NULL REFERENCES projects.project (pk_entity), - fk_analysis_type INTEGER NOT NULL REFERENCES system.analysis_type (pk_entity), - name text, - description text, - analysis_definition jsonb) -INHERITS ( - projects.entity -); - -SELECT - commons.init_entity_child_table ('projects.analysis'); - diff --git a/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-down.sql b/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-down.sql deleted file mode 100644 index 133eb4aab..000000000 --- a/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-down.sql +++ /dev/null @@ -1,12 +0,0 @@ -Drop Function commons.analysis__create_temporal_distribution (integer[], integer); - -Drop Index warehouse.entity_preview_fk_class_idx; - -Drop Index warehouse.entity_preview_first_second_idx; - -Drop Index warehouse.entity_preview_last_second_idx; - -Drop Index warehouse.entity_preview_fk_project_idx; - -Drop Index warehouse.entity_preview_project_idx; - diff --git a/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-up.sql b/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-up.sql deleted file mode 100644 index 2be4b4e55..000000000 --- a/server/db-migrate/migrations/sqls/20191106183035-ana-f-time-chart-cont-up.sql +++ /dev/null @@ -1,174 +0,0 @@ -Create Index On warehouse.entity_preview (fk_class); - -Create Index On warehouse.entity_preview -Using Hash (first_second); - -Create Index On warehouse.entity_preview -Using Hash (last_second); - -Create Index On warehouse.entity_preview (fk_project); - -Create Index On warehouse.entity_preview (project); - -Create Or Replace Function commons.analysis__create_temporal_distribution ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - json_strip_nulls (json_agg(t2.pk_entity)) As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - y, - data, - x1, - x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - Select - 1, - x2 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - y, - data, - x1, - x2 - From - tw7 - Order By - x, - 1 -) -Select - jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) Into res -From - tw8; - Return coalesce(res, '[]'::jsonb); -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-down.sql b/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-down.sql deleted file mode 100644 index b9e36eaa1..000000000 --- a/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop Materialized View warehouse.vm_statement; - diff --git a/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-up.sql b/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-up.sql deleted file mode 100644 index 976bfa6d6..000000000 --- a/server/db-migrate/migrations/sqls/20191119144114-war-mv-statement-up.sql +++ /dev/null @@ -1,45 +0,0 @@ -Create Materialized View warehouse.vm_statement As -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where - t1.is_in_project_count > 0; - -Create Unique Index On warehouse.vm_statement (pk_entity, project); - -Create Index On warehouse.vm_statement (pk_entity); - -Create Index On warehouse.vm_statement (fk_temporal_entity); - -Create Index On warehouse.vm_statement (fk_property); - -Create Index On warehouse.vm_statement (fk_entity); - -Create Index On warehouse.vm_statement (fk_project); - diff --git a/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-down.sql b/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-down.sql deleted file mode 100644 index 2239349c7..000000000 --- a/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 2 -Drop Function commons.analysis__time_chart_cont__czml_time_values; - --- 1 -Drop Function commons.julian_second__to_iso_8601; - diff --git a/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-up.sql b/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-up.sql deleted file mode 100644 index 6be048bae..000000000 --- a/server/db-migrate/migrations/sqls/20191119160856-com-f-analysis-space-time-cont-up.sql +++ /dev/null @@ -1,208 +0,0 @@ --- 1 -Create Or Replace Function commons.julian_second__to_iso_8601 ( - julian_second bigint -) - Returns text - As $$ - Select - to_char((('J' || (julian_second / 86400)::text)::timestamp + (julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') -$$ -Language SQL; - --- 2 -Create Or Replace Function commons.analysis__time_chart_cont__czml_time_values ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - -- temporal entities - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601 (t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601 (t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) Filter (Where t2.pk_entity Is Not Null), '[]') As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - commons.julian_second__to_iso_8601 (x1 - 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - commons.julian_second__to_iso_8601 (x2 + 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - Select - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw7 - Order By - x, - 1 -), -tw9 As ( - Select - row_number() Over () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From tw8 -) -Select - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '[]'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) Into res -From - tw9; - Return res; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-down.sql b/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-down.sql deleted file mode 100644 index 6be048bae..000000000 --- a/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-down.sql +++ /dev/null @@ -1,208 +0,0 @@ --- 1 -Create Or Replace Function commons.julian_second__to_iso_8601 ( - julian_second bigint -) - Returns text - As $$ - Select - to_char((('J' || (julian_second / 86400)::text)::timestamp + (julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') -$$ -Language SQL; - --- 2 -Create Or Replace Function commons.analysis__time_chart_cont__czml_time_values ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - -- temporal entities - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601 (t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601 (t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) Filter (Where t2.pk_entity Is Not Null), '[]') As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - commons.julian_second__to_iso_8601 (x1 - 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - commons.julian_second__to_iso_8601 (x2 + 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - Select - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw7 - Order By - x, - 1 -), -tw9 As ( - Select - row_number() Over () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From tw8 -) -Select - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '[]'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) Into res -From - tw9; - Return res; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-up.sql b/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-up.sql deleted file mode 100644 index 7b478a379..000000000 --- a/server/db-migrate/migrations/sqls/20191203145034-com-f-analysis-space-time-cont-2-up.sql +++ /dev/null @@ -1,208 +0,0 @@ --- 1 -Create Or Replace Function commons.julian_second__to_iso_8601 ( - julian_second bigint -) - Returns text - As $$ - Select - to_char((('J' || (julian_second / 86400)::text)::timestamp + (julian_second % 86400) * interval '1 second'), 'YYYY-MM-DD"T"HH24:MI:SS"Z"') -$$ -Language SQL; - --- 2 -Create Or Replace Function commons.analysis__time_chart_cont__czml_time_values ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - -- temporal entities - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601 (t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601 (t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) Filter (Where t2.pk_entity Is Not Null), '[]') As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - commons.julian_second__to_iso_8601 (x1 - 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - commons.julian_second__to_iso_8601 (x2 + 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - Select - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw7 - Order By - x, - 1 -), -tw9 As ( - Select - row_number() Over () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From tw8 -) -Select - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) Into res -From - tw9; - Return res; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-down.sql b/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-down.sql deleted file mode 100644 index b428a4e84..000000000 --- a/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-down.sql +++ /dev/null @@ -1,92 +0,0 @@ --- 12 -Delete From projects.class_field_config; - -Insert Into projects.class_field_config -Select - * -From - projects._backup_class_field_config; - -Drop Table projects._backup_class_field_config; - --- 11 -Drop Index projects.class_field_config_fk_app_context_fk_project_fk_property_fk_idx; - --- 10 -Alter Table projects.class_field_config - Alter Column fk_project Drop Not Null; - --- 9 -Update - projects.class_field_config -Set - fk_project = Null; - --- 8 -Update - projects.class_field_config -Set - fk_property = fk_property_deprecated; - --- 7 -Alter Table projects.class_field_config - Add Constraint ui_context_config_fk_property_fkey Foreign Key (fk_property) References data_for_history.property (dfh_pk_property) Match SIMPLE On - Update - No ACTION On Delete No ACTION; - --- 6 -Create Unique Index ui_context_config_for_prop_and_proj_uni_idx On projects.class_field_config -Using btree (fk_app_context, _deprecated_fk_project, fk_property, property_is_outgoing) Tablespace pg_default -Where - _deprecated_fk_project Is Not Null; - -Create Unique Index ui_context_config_for_prop_no_proj_uni_idx On projects.class_field_config -Using btree (fk_app_context, fk_property, property_is_outgoing) Tablespace pg_default -Where - _deprecated_fk_project Is Null; - -Create Unique Index ui_context_config_for_prop_set_and_proj_uni_idx On projects.class_field_config -Using btree (fk_app_context, _deprecated_fk_project, fk_class_field, fk_class_for_class_field) Tablespace pg_default -Where - _deprecated_fk_project Is Not Null; - -Create Unique Index ui_context_config_for_prop_set_no_proj_uni_idx On projects.class_field_config -Using btree (fk_app_context, fk_class_field, fk_class_for_class_field) Tablespace pg_default -Where - _deprecated_fk_project Is Null; - --- 5 -Update - projects.class_field_config -Set - fk_range_class = Null; - --- 4 -Update - projects.class_field_config -Set - fk_domain_class = Null; - --- 3 --- no need (step 2 does the job) --- 2 - -Alter Table projects.class_field_config - Drop Column fk_property_deprecated; - -Alter Table projects.class_field_config_vt - Drop Column fk_property_deprecated; - --- 1 -Alter Table projects.class_field_config - Drop Column fk_domain_class; - -Alter Table projects.class_field_config - Drop Column fk_range_class; - -Alter Table projects.class_field_config_vt - Drop Column fk_domain_class; - -Alter Table projects.class_field_config_vt - Drop Column fk_range_class; - diff --git a/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-up.sql b/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-up.sql deleted file mode 100644 index 0fcf0480a..000000000 --- a/server/db-migrate/migrations/sqls/20191205082041-pro-t-class-field-config-update-up.sql +++ /dev/null @@ -1,151 +0,0 @@ --- 1 -Alter Table projects.class_field_config - Add Column fk_domain_class INT; - -Alter Table projects.class_field_config - Add Column fk_range_class INT; - -Alter Table projects.class_field_config_vt - Add Column fk_domain_class INT; - -Alter Table projects.class_field_config_vt - Add Column fk_range_class INT; - --- 2 -Alter Table projects.class_field_config - Add Column fk_property_deprecated INT; - -Alter Table projects.class_field_config_vt - Add Column fk_property_deprecated INT; - --- 3 fill fk_property_deprecated with fk_property -Update - projects.class_field_config -Set - fk_property_deprecated = fk_property; - --- 4 fill fk_domain_class with domain of property (if property_is_outgoing = true) -With tw1 As ( - Select - t1.pk_entity, - t2.dfh_has_domain - From - projects.class_field_config t1, - data_for_history.v_property t2 - Where - t1.fk_property = t2.dfh_pk_property - And t1.fk_property Is Not Null - And t1.property_is_outgoing = True) -Update - projects.class_field_config t1 -Set - fk_domain_class = t2.dfh_has_domain -From - tw1 t2 -Where - t2.pk_entity = t1.pk_entity; - --- 5 fill fk_range_class with range of property (if property_is_outgoing = false) -With tw1 As ( - Select - t1.pk_entity, - t2.dfh_has_range - From - projects.class_field_config t1, - data_for_history.v_property t2 - Where - t1.fk_property = t2.dfh_pk_property - And t1.fk_property Is Not Null - And t1.property_is_outgoing = False) -Update - projects.class_field_config t1 -Set - fk_range_class = t2.dfh_has_range -From - tw1 t2 -Where - t2.pk_entity = t1.pk_entity; - --- 6 drop the unique constraints -Drop Index projects.ui_context_config_for_prop_and_proj_uni_idx; - -Drop Index projects.ui_context_config_for_prop_no_proj_uni_idx; - -Drop Index projects.ui_context_config_for_prop_set_and_proj_uni_idx; - -Drop Index projects.ui_context_config_for_prop_set_no_proj_uni_idx; - --- 7 drop the foreign key constraint referencing the dfh_pk_property (should be added after updateing dfh schema) -Alter Table projects.class_field_config - Drop Constraint ui_context_config_fk_property_fkey; - --- 8 fill fk_property with: fk_property_of_origin or opriginal pk_property -With tw1 As ( - Select - t1.pk_entity, - t2.fk_property As new_fk_property - From - projects.class_field_config t1, - data_for_history.v_property t2 - Where - t1.fk_property = t2.dfh_pk_property - And t1.fk_property Is Not Null) -Update - projects.class_field_config t1 -Set - fk_property = t2.new_fk_property -From - tw1 t2 -Where - t2.pk_entity = t1.pk_entity; - --- 9 fill fk_project with pk of 'default configuration project' -Update - projects.class_field_config -Set - fk_project = 375669; - --- 10 add fk_project not null constraint -Alter Table projects.class_field_config - Alter Column fk_project Set Not Null; - --- 11 add unique constraints -Create Unique Index On projects.class_field_config -Using btree (fk_app_context, fk_project, fk_property, fk_domain_class, fk_range_class); - --- 12 create backup -Create Table projects._backup_class_field_config As -Select - * -From - projects.class_field_config; - --- 13 Delete superfluous fields -Delete From projects.class_field_config; - -Insert Into projects.class_field_config - WITH tw1 AS ( - SELECT * FROM - projects._backup_class_field_config - ) - SELECT DISTINCT ON ( - tw1.fk_app_context, - tw1.fk_property, - tw1.fk_domain_class, - tw1.fk_range_class, - tw1.fk_class_for_class_field, - tw1.fk_project - ) - * - FROM - tw1 - WHERE - tw1.ord_num IS NOT NULL - ORDER BY - tw1.fk_app_context, - tw1.fk_property, - tw1.fk_domain_class, - tw1.fk_range_class, - tw1.fk_class_for_class_field, - tw1.fk_project, - tw1.ord_num desc diff --git a/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-down.sql b/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-down.sql deleted file mode 100644 index 143883737..000000000 --- a/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-down.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 3 -Update - information.role t1 -Set - fk_property = t2.fk_property -From - information._backup_role t2 -Where - t1.pk_entity = t2.pk_entity - And t1.fk_property != t2.fk_property; - --- 2 -Alter Table information.role - Add Constraint role_fk_property_fkey Foreign Key (fk_property) References data_for_history.property (dfh_pk_property) Match SIMPLE On - Update - No ACTION On Delete No ACTION; - --- 1 -Drop Table information._backup_role; - diff --git a/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-up.sql b/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-up.sql deleted file mode 100644 index 10b007b92..000000000 --- a/server/db-migrate/migrations/sqls/20191205174623-inf-migrate-fk-property-up.sql +++ /dev/null @@ -1,34 +0,0 @@ --- 1 -Create Table information._backup_role As -Select - * -From - information.role; - --- 2 -Alter Table information.role - Drop Constraint role_fk_property_fkey; - --- 3 -With tw1 As ( - Select - t1.pk_entity, - t1.fk_property, - t2.fk_property As new_fk_property - From - information.role t1, - data_for_history.v_property t2 - Where - t1.fk_property = t2.dfh_pk_property - And t2.fk_property != t1.fk_property - Order By - t1.fk_property Desc) -Update - information.role t1 -Set - fk_property = t2.new_fk_property -From - tw1 t2 -Where - t1.pk_entity = t2.pk_entity; - diff --git a/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-down.sql b/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-down.sql deleted file mode 100644 index 38501a66a..000000000 --- a/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-down.sql +++ /dev/null @@ -1,499 +0,0 @@ --- 1 -Create Or Replace Function warehouse.entity_preview_non_recursive__create ( - param_pk_entities integer[] -) - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) -), --- fields (deprecated/to be changed with pk_property) -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - Case When t1.property_is_outgoing = True Then - t2.dfh_has_domain - When t1.property_is_outgoing = False Then - t2.dfh_has_range - Else - t1.fk_class_for_class_field - End As fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain As fk_domain_class, - t2.dfh_has_range As fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - From - projects.class_field_config t1 - Left Join data_for_history.property t2 On t2.dfh_pk_property = t1.fk_property - Left Join system.class_field t3 On t3.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - ( - Case When t1.property_is_outgoing = True Then - t2.dfh_has_domain - When t1.property_is_outgoing = False Then - t2.dfh_has_range - Else - t1.fk_class_for_class_field - End), - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - Where - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- select roles with time primitive, first and last second -tw9 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t2.calendar) As last_second - From - information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t3.pk_entity = t1.fk_entity - And t2.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t1.community_favorite_calendar) As last_second - From - information.v_role t1 - Join information.v_time_primitive t3 On t3.pk_entity = t1.fk_entity - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw10 As ( - Select - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - Case When tw9.fk_property = 71 Then - 'p81'::text - When tw9.fk_property = 72 Then - 'p82'::text - When tw9.fk_property = 150 Then - 'p81a'::text - When tw9.fk_property = 151 Then - 'p81b'::text - When tw9.fk_property = 152 Then - 'p82a'::text - When tw9.fk_property = 153 Then - 'p82b'::text - Else - tw9.fk_property::text - End, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) As time_span - From - tw9 - Group By - tw9.fk_project, - tw9.fk_temporal_entity -), -tw11 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw10 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw12 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw13 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw11 t1 - Left Join tw12 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw14 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t2.fk_entity = t1.pk_entity -And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw15 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw14 t1, - system.class_has_type_property t2 - Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) - And t1.fk_project Is Null - And t1.fk_property = t2.fk_property -Union -Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count -From - tw14 t3, - system.class_has_type_property t4 -Where (t3.fk_info_domain = Any (param_pk_entities) - Or t3.fk_info_range = Any (param_pk_entities)) -And t3.fk_project Is Not Null -And t3.fk_property = t4.fk_property -Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw16 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw13 t1 - Left Join tw15 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw16; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-up.sql b/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-up.sql deleted file mode 100644 index 5e94cf1cc..000000000 --- a/server/db-migrate/migrations/sqls/20191206101554-war-f-entity-preview-non-recursive--create-up.sql +++ /dev/null @@ -1,487 +0,0 @@ --- 1 -Create Or Replace Function warehouse.entity_preview_non_recursive__create ( - param_pk_entities integer[] -) - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) -), --- fields --- TODO: add fk_project for consideration of project-settings -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - coalesce(t1.fk_range_class, t1.fk_domain_class, t1.fk_class_for_class_field) fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - -- t1.fk_project, - t2.used_table - From - projects.class_field_config t1 - Left Join system.class_field t2 On t2.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - fk_class, - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw3 t2 - Where - -- TODO: join by fk_project or default for consideration of project-settings - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- select roles with time primitive, first and last second -tw9 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t2.calendar) As last_second - From - information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t3.pk_entity = t1.fk_entity - And t2.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t1.community_favorite_calendar) As last_second - From - information.v_role t1 - Join information.v_time_primitive t3 On t3.pk_entity = t1.fk_entity - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw10 As ( - Select - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - Case When tw9.fk_property = 71 Then - 'p81'::text - When tw9.fk_property = 72 Then - 'p82'::text - When tw9.fk_property = 150 Then - 'p81a'::text - When tw9.fk_property = 151 Then - 'p81b'::text - When tw9.fk_property = 152 Then - 'p82a'::text - When tw9.fk_property = 153 Then - 'p82b'::text - Else - tw9.fk_property::text - End, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) As time_span - From - tw9 - Group By - tw9.fk_project, - tw9.fk_temporal_entity -), -tw11 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw10 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw12 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw13 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw11 t1 - Left Join tw12 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw14 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t2.fk_entity = t1.pk_entity -And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw15 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw14 t1, - system.class_has_type_property t2 - Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) - And t1.fk_project Is Null - And t1.fk_property = t2.fk_property -Union -Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count -From - tw14 t3, - system.class_has_type_property t4 -Where (t3.fk_info_domain = Any (param_pk_entities) - Or t3.fk_info_range = Any (param_pk_entities)) -And t3.fk_project Is Not Null -And t3.fk_property = t4.fk_property -Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw16 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw13 t1 - Left Join tw15 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw16; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-down.sql b/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-down.sql deleted file mode 100644 index 26d265fc0..000000000 --- a/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-down.sql +++ /dev/null @@ -1,81 +0,0 @@ -Create Or Replace Function warehouse.entity_preview_update_queue_worker () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_warehouse_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the last warehouse.entity_preview_non_recursive update - */ - Select - tmsp_update_begin Into last_warehouse_update - From - warehouse.entity_preview_non_recursive_updates - Order By - pk_entity Desc - Limit 1; - -- set very early default - If last_warehouse_update Is Null Then - last_warehouse_update = '1970-01-01 00:00:00.000000'::timestamp; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of warehouse - */ - If (last_project_modification > last_warehouse_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into warehouse.entity_preview_non_recursive_updates (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - warehouse.do_updates_for_time_after (last_warehouse_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - warehouse.entity_preview_non_recursive_updates - Set - tmsp_update_end = clock_timestamp()::timestamp; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-up.sql b/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-up.sql deleted file mode 100644 index ea282bb7a..000000000 --- a/server/db-migrate/migrations/sqls/20191206111710-war-f-entity-preview-update-queue-worker-up.sql +++ /dev/null @@ -1,83 +0,0 @@ -Create Or Replace Function warehouse.entity_preview_update_queue_worker () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_warehouse_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the last warehouse.entity_preview_non_recursive update - */ - Select - tmsp_update_begin Into last_warehouse_update - From - warehouse.entity_preview_non_recursive_updates - Order By - pk_entity Desc - Limit 1; - -- set very early default - If last_warehouse_update Is Null Then - last_warehouse_update = '1970-01-01 00:00:00.000000'::timestamp; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of warehouse - */ - If (last_project_modification > last_warehouse_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into warehouse.entity_preview_non_recursive_updates (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - warehouse.do_updates_for_time_after (last_warehouse_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - warehouse.entity_preview_non_recursive_updates - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-down.sql b/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-down.sql deleted file mode 100644 index b4513501f..000000000 --- a/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-down.sql +++ /dev/null @@ -1,501 +0,0 @@ -Create Or Replace Function warehouse.entity_preview_non_recursive__create_all () - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - -- 1 - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 -), --- fields (deprecated/to be changed with pk_property) -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - Case When t1.property_is_outgoing = True Then - t2.dfh_has_domain - When t1.property_is_outgoing = False Then - t2.dfh_has_range - Else - t1.fk_class_for_class_field - End As fk_class, - t1.fk_class_for_class_field, - t2.dfh_has_domain As fk_domain_class, - t2.dfh_has_range As fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t3.used_table - From - projects.class_field_config t1 - Left Join data_for_history.property t2 On t2.dfh_pk_property = t1.fk_property - Left Join system.class_field t3 On t3.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - ( - Case When t1.property_is_outgoing = True Then - t2.dfh_has_domain - When t1.property_is_outgoing = False Then - t2.dfh_has_range - Else - t1.fk_class_for_class_field - End), - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - -- Deprecated: Replace with new pk_property system asap - tw3 t2 - Where - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1 - Where - t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), -tw9 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw10 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw9 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw9 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw11 As ( - Select - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - Case When tw10.fk_property = 71 Then - 'p81'::text - When tw10.fk_property = 72 Then - 'p82'::text - When tw10.fk_property = 150 Then - 'p81a'::text - When tw10.fk_property = 151 Then - 'p81b'::text - When tw10.fk_property = 152 Then - 'p82a'::text - When tw10.fk_property = 153 Then - 'p82b'::text - Else - tw10.fk_property::text - End, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) As time_span - From - tw10 - Group By - tw10.fk_project, - tw10.fk_temporal_entity -), -tw12 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw11 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw13 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw12 t1 - Left Join tw13 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw15 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where - t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw16 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw15 t1, - system.class_has_type_property t2 - Where - t1.fk_project Is Null - And t1.fk_property = t2.fk_property - Union - Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - From - tw15 t3, - system.class_has_type_property t4 - Where - t3.fk_project Is Not Null - And t3.fk_property = t4.fk_property - Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw17 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw14 t1 - Left Join tw16 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw17; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-up.sql b/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-up.sql deleted file mode 100644 index 9ed2bce29..000000000 --- a/server/db-migrate/migrations/sqls/20191206112815-war-f-entity-preview-non-recursive--create-all-up.sql +++ /dev/null @@ -1,488 +0,0 @@ -Create Or Replace Function warehouse.entity_preview_non_recursive__create_all () - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - -- 1 - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 -), --- fields --- TODO: add fk_project for consideration of project-settings -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - coalesce(t1.fk_range_class, t1.fk_domain_class, t1.fk_class_for_class_field) fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - -- t1.fk_project, - t2.used_table - From - projects.class_field_config t1 - Left Join system.class_field t2 On t2.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - fk_class, - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw3 t2 - Where - -- TODO: join by fk_project or default for consideration of project-settings - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1 - Where - t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), -tw9 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw10 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw9 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw9 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw11 As ( - Select - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - Case When tw10.fk_property = 71 Then - 'p81'::text - When tw10.fk_property = 72 Then - 'p82'::text - When tw10.fk_property = 150 Then - 'p81a'::text - When tw10.fk_property = 151 Then - 'p81b'::text - When tw10.fk_property = 152 Then - 'p82a'::text - When tw10.fk_property = 153 Then - 'p82b'::text - Else - tw10.fk_property::text - End, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) As time_span - From - tw10 - Group By - tw10.fk_project, - tw10.fk_temporal_entity -), -tw12 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw11 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw13 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw12 t1 - Left Join tw13 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw15 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where - t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw16 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw15 t1, - system.class_has_type_property t2 - Where - t1.fk_project Is Null - And t1.fk_property = t2.fk_property - Union - Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - From - tw15 t3, - system.class_has_type_property t4 - Where - t3.fk_project Is Not Null - And t3.fk_property = t4.fk_property - Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw17 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw14 t1 - Left Join tw16 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw17; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-down.sql b/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-down.sql deleted file mode 100644 index 5a794e02a..000000000 --- a/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop Function warehouse.entity_preview__refresh_all; - diff --git a/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-up.sql b/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-up.sql deleted file mode 100644 index b4ed61695..000000000 --- a/server/db-migrate/migrations/sqls/20191206113445-war-f-entity-preview--refresh-all-up.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* Replace with your SQL commands */ -Create Or Replace Function warehouse.entity_preview__refresh_all () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Begin - -- performs a complete refresh of entity preview from scratch - Perform - warehouse.entity_preview_non_recursive__refresh (); - Perform - warehouse.entity_preview__update_all (); - Return True; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-down.sql b/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-down.sql deleted file mode 100644 index d19b1fe7a..000000000 --- a/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-down.sql +++ /dev/null @@ -1,165 +0,0 @@ -Create Or Replace Function warehouse.do_updates_for_time_after ( - tmsp timestamp without time zone -) - Returns void - Language 'sql' - Cost 100 Volatile - As $BODY$ - /********** - * Selects the pk_entities that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_domain As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_range As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc -), -tw4 As ( - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project) -/******* - * Perform the updates on entity_preview_non_recursive - *******/ -Select - Case When t1.is_in_project = True Then - warehouse.entity_preview_non_recursive__upsert (t1.pk_entities, - t1.fk_project) - When t1.is_in_project = False Then - warehouse.entity_preview_non_recursive__delete (t1.pk_entities, - t1.fk_project) - End -From - tw4 t1; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-up.sql b/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-up.sql deleted file mode 100644 index d28660d4e..000000000 --- a/server/db-migrate/migrations/sqls/20191206130212-war-f-do-updates-for-time-after-up.sql +++ /dev/null @@ -1,167 +0,0 @@ -Create Or Replace Function warehouse.do_updates_for_time_after ( - tmsp timestamp without time zone -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - t_row record; -Begin - For t_row In ( - /********** - * Selects the pk_entities that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp), - -- select fk_entity and fk_project of all affected persistent_items and temporal_entities - tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_domain As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_range As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity), - tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project) - /******* - * Perform the updates on entity_preview_non_recursive - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - warehouse.entity_preview_non_recursive__upsert (t_row.pk_entities, - t_row.fk_project); - --RAISE INFO 'upserted entity_preview_non_recursive for fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - ELSEIF (t_row.is_in_project = False) Then - Perform - warehouse.entity_preview_non_recursive__delete (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-down.sql b/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-down.sql deleted file mode 100644 index 94c1ca735..000000000 --- a/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-down.sql +++ /dev/null @@ -1,122 +0,0 @@ --- 3 -Create Or Replace View information.v_role As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - p.dfh_range_instances_max_quantifier As range_max_quantifier, - p.dfh_domain_instances_max_quantifier As domain_max_quantifier -From - information.role t1 - Join data_for_history.property p On t1.fk_property = p.dfh_pk_property - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - -Create Trigger on_insert Instead Of Insert On information.v_role For Each Row -Execute Procedure information.v_role_find_or_create (); - --- 2 -Drop Materialized View warehouse.vm_statement; - -Create Materialized View warehouse.vm_statement As -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where - t1.is_in_project_count > 0; - -Create Index vm_statement_fk_entity_idx On warehouse.vm_statement -Using btree (fk_entity); - -Create Index vm_statement_fk_project_idx On warehouse.vm_statement -Using btree (fk_project); - -Create Index vm_statement_fk_property_idx On warehouse.vm_statement -Using btree (fk_property); - -Create Index vm_statement_fk_temporal_entity_idx On warehouse.vm_statement -Using btree (fk_temporal_entity); - -Create Index vm_statement_pk_entity_idx On warehouse.vm_statement -Using btree (pk_entity); - -Create Unique Index vm_statement_pk_entity_project_idx On warehouse.vm_statement -Using btree (pk_entity, project); - --- 1 -Create Or Replace View warehouse.v_roles_per_project_and_repo As -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where - t1.is_in_project_count > 0; - diff --git a/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-up.sql b/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-up.sql deleted file mode 100644 index f2899063b..000000000 --- a/server/db-migrate/migrations/sqls/20191206134715-inf-v-role-up.sql +++ /dev/null @@ -1,218 +0,0 @@ --- 1 make v_roles_per_project_and_repo independent from v_role -Create Or Replace View warehouse.v_roles_per_project_and_repo As With tw1 As ( - Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True - Group By - info_proj_rel.fk_entity) t2 On True -) -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - tw1 t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - tw1 t1 -Where - t1.is_in_project_count > 0; - --- 2 make warehouse.vm_statement independent from v_role -Drop Materialized View warehouse.vm_statement; - -Create Materialized View warehouse.vm_statement As With tw1 As ( - Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True - Group By - info_proj_rel.fk_entity) t2 On True -) -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - tw1 t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - tw1 t1 -Where - t1.is_in_project_count > 0; - -Create Index vm_statement_fk_entity_idx On warehouse.vm_statement -Using btree (fk_entity); - -Create Index vm_statement_fk_project_idx On warehouse.vm_statement -Using btree (fk_project); - -Create Index vm_statement_fk_property_idx On warehouse.vm_statement -Using btree (fk_property); - -Create Index vm_statement_fk_temporal_entity_idx On warehouse.vm_statement -Using btree (fk_temporal_entity); - -Create Index vm_statement_pk_entity_idx On warehouse.vm_statement -Using btree (pk_entity); - -Create Unique Index vm_statement_pk_entity_project_idx On warehouse.vm_statement -Using btree (pk_entity, project); - --- 3 make v_role independent of dfh.property table -Drop View information.v_role; - -Create View information.v_role As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - -Create Trigger on_insert Instead Of Insert On information.v_role -For Each Row -Execute Procedure information.v_role_find_or_create (); - - -/* Joins property via domain and range class - quite slow ! - -WITH tw1 AS ( - select pk_entity, fk_class - FROM information.persistent_item - UNION ALL - select pk_entity, fk_class - FROM information.temporal_entity - UNION ALL - select pk_entity, fk_class - FROM information.appellation - UNION ALL - select pk_entity, fk_class - FROM information.time_primitive - UNION ALL - select pk_entity, fk_class - FROM information.place - UNION ALL - select pk_entity, fk_class - FROM information.language -) -SELECT t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t5.is_in_project_count, - t5.is_standard_in_project_count, - t5.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period, - t4.dfh_range_instances_max_quantifier AS range_max_quantifier, - t4.dfh_domain_instances_max_quantifier AS domain_max_quantifier - FROM - information.role t1 - JOIN tw1 t2 ON t2.pk_entity = t1.fk_entity - JOIN tw1 t3 ON t3.pk_entity = t1.fk_temporal_entity - JOIN data_for_history.v_property t4 - ON t1.fk_property = t4.fk_property - AND t2.fk_class = t4.dfh_has_range - AND t3.fk_class = t4.dfh_has_domain - LEFT JOIN LATERAL ( SELECT count(info_proj_rel.pk_entity)::integer AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY info_proj_rel.calendar) AS community_favorite_calendar - FROM projects.info_proj_rel - WHERE info_proj_rel.fk_entity = t1.pk_entity AND info_proj_rel.is_in_project = true - GROUP BY info_proj_rel.fk_entity) t5 ON true; - */ diff --git a/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-down.sql b/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-down.sql deleted file mode 100644 index a8323928a..000000000 --- a/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-down.sql +++ /dev/null @@ -1,29 +0,0 @@ -Drop View data_for_history.v_class; - -Create Or Replace View data_for_history.v_class As Select Distinct On (t1.pk_entity, t1.entity_version, t1.is_enabled_in_profile, t1.removed_from_api, t1.dfh_pk_class, t1.dfh_identifier_in_namespace, t1.dfh_standard_label, t1.dfh_creation_time, t1.dfh_modification_time) - t1.pk_entity, - t1.entity_version, - t1.is_enabled_in_profile, - t1.removed_from_api, - t1.dfh_pk_class, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.dfh_creation_time, - t1.dfh_modification_time, - t2.dfh_fk_system_type -From - data_for_history.class t1, - data_for_history.class_profile_view t2 -Where - t1.dfh_pk_class = t2.dfh_fk_class -Order By - t1.pk_entity, - t1.entity_version, - t1.is_enabled_in_profile, - t1.removed_from_api, - t1.dfh_pk_class, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.dfh_creation_time, - t1.dfh_modification_time; - diff --git a/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-up.sql b/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-up.sql deleted file mode 100644 index 102c9ec8c..000000000 --- a/server/db-migrate/migrations/sqls/20191211080436-dfh-v-class-up.sql +++ /dev/null @@ -1,39 +0,0 @@ -Drop View data_for_history.v_class; - -Create View data_for_history.v_class As With tw1 As ( - Select - dfh_fk_class, - dfh_fk_profile, - removed_from_api, - dfh_fk_system_type - From - data_for_history.class_profile_view -) -Select - t1.pk_entity, - t1.entity_version, - t1.is_enabled_in_profile, - jsonb_agg(json_build_object('fk_profile', t2.dfh_fk_profile, 'removed_from_api', t2.removed_from_api)) As removed_from_api, - t1.dfh_pk_class, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.dfh_creation_time, - t1.dfh_modification_time, - ( - Select - (array_agg(t2.dfh_fk_system_type) Filter (Where t2.dfh_fk_system_type Is Not Null))[1]) As dfh_fk_system_type -From - data_for_history.class t1, - tw1 t2 -Where - t1.dfh_pk_class = t2.dfh_fk_class -Group By - t1.pk_entity, - t1.entity_version, - t1.is_enabled_in_profile, - t1.dfh_pk_class, - t1.dfh_identifier_in_namespace, - t1.dfh_standard_label, - t1.dfh_creation_time, - t1.dfh_modification_time; - diff --git a/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-down.sql b/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-down.sql deleted file mode 100644 index 75f72bccd..000000000 --- a/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-down.sql +++ /dev/null @@ -1,52 +0,0 @@ --- 1 -Create Or Replace View system.v_auto_add_properties As -Select - p.dfh_has_domain As fk_class, - p.dfh_pk_property, - p.dfh_range_instances_max_quantifier As max_quantifier -From - data_for_history.property p - Join projects.class_field_config ctxt On p.dfh_pk_property = ctxt.fk_property -Where - ctxt.fk_app_context = 47 - And ctxt.ord_num Is Not Null - And ctxt.property_is_outgoing = True -Union -Select - p.dfh_has_range As fk_class, - p.dfh_pk_property, - p.dfh_domain_instances_max_quantifier As max_quantifier -From - data_for_history.property p - Join projects.class_field_config ctxt On p.dfh_pk_property = ctxt.fk_property -Where - ctxt.fk_app_context = 47 - And ctxt.ord_num Is Not Null - And ctxt.property_is_outgoing = False -Union -Select - ctxt.fk_class_for_class_field As fk_class, - psprel.fk_property As dfh_pk_property, - p.dfh_domain_instances_max_quantifier As max_quantifier -From - data_for_history.property p - Join system.class_field_property_rel psprel On psprel.fk_property = p.dfh_pk_property - Join projects.class_field_config ctxt On psprel.fk_class_field = ctxt.fk_class_field -Where - ctxt.fk_app_context = 47 - And ctxt.ord_num Is Not Null - And psprel.property_is_outgoing = False -Union -Select - ctxt.fk_class_for_class_field As fk_class, - psprel.fk_property As dfh_pk_property, - p.dfh_range_instances_max_quantifier As max_quantifier -From - data_for_history.property p - Join system.class_field_property_rel psprel On psprel.fk_property = p.dfh_pk_property - Join projects.class_field_config ctxt On psprel.fk_class_field = ctxt.fk_class_field -Where - ctxt.fk_app_context = 47 - And ctxt.ord_num Is Not Null - And psprel.property_is_outgoing = True; - diff --git a/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-up.sql b/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-up.sql deleted file mode 100644 index 8a26d4b8b..000000000 --- a/server/db-migrate/migrations/sqls/20191211130640-inf-f-add-functions-up.sql +++ /dev/null @@ -1,52 +0,0 @@ --- 1 -Create Or Replace View system.v_auto_add_properties As -Select - p.dfh_has_domain As fk_class, - p.fk_property dfh_pk_property, - p.dfh_range_instances_max_quantifier As max_quantifier -From - data_for_history.v_property p - Join projects.class_field_config ctxt On p.fk_property = ctxt.fk_property -Where - ctxt.fk_app_context = 45 - And ctxt.ord_num Is Not Null - And ctxt.property_is_outgoing = True -Union -Select - p.dfh_has_range As fk_class, - p.fk_property dfh_pk_property, - p.dfh_domain_instances_max_quantifier As max_quantifier -From - data_for_history.v_property p - Join projects.class_field_config ctxt On p.fk_property = ctxt.fk_property -Where - ctxt.fk_app_context = 45 - And ctxt.ord_num Is Not Null - And ctxt.property_is_outgoing = False -Union -Select - ctxt.fk_class_for_class_field As fk_class, - psprel.fk_property As dfh_pk_property, - p.dfh_domain_instances_max_quantifier As max_quantifier -From - data_for_history.v_property p - Join system.class_field_property_rel psprel On psprel.fk_property = p.fk_property - Join projects.class_field_config ctxt On psprel.fk_class_field = ctxt.fk_class_field -Where - ctxt.fk_app_context = 45 - And ctxt.ord_num Is Not Null - And psprel.property_is_outgoing = False -Union -Select - ctxt.fk_class_for_class_field As fk_class, - psprel.fk_property As dfh_pk_property, - p.dfh_range_instances_max_quantifier As max_quantifier -From - data_for_history.v_property p - Join system.class_field_property_rel psprel On psprel.fk_property = p.fk_property - Join projects.class_field_config ctxt On psprel.fk_class_field = ctxt.fk_class_field -Where - ctxt.fk_app_context = 45 - And ctxt.ord_num Is Not Null - And psprel.property_is_outgoing = True; - diff --git a/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-down.sql b/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-down.sql deleted file mode 100644 index c3ff0883b..000000000 --- a/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-down.sql +++ /dev/null @@ -1,144 +0,0 @@ -Delete From data_for_history.api_profile; - -Delete From data_for_history.api_profile_vt; - --- 21 -Alter Table data_for_history.api_profile - Drop Constraint unique_dfh_pk_profile_requested_language; - --- 20 -Alter Table data_for_history.api_profile - Add Constraint unique_dfh_pk_profile Unique (dfh_pk_profile); - --- 19 -Alter Table data_for_history.api_profile - Add Column dfh_modification_time timestamp without time zone; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_modification_time timestamp without time zone; - --- 18 -Alter Table data_for_history.api_profile - Add Column dfh_creation_time timestamp without time zone; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_creation_time timestamp without time zone; - --- 17 -Alter Table data_for_history.api_profile - Add Column dfh_end_date date; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_end_date date; - --- 16 -Alter Table data_for_history.api_profile - Add Column dfh_start_date date; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_start_date date; - --- 15 -Alter Table data_for_history.api_profile - Add Column dfh_fk_project_of_belonging integer; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_fk_project_of_belonging integer; - --- 14 -Alter Table data_for_history.api_profile - Add Column dfh_standard_label character varying(500); - -Alter Table data_for_history.api_profile_vt - Add Column dfh_standard_label character varying(500); - --- 13 -Alter Table data_for_history.api_profile - Add Column dfh_fk_is_subprofile_of INT; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_fk_is_subprofile_of INT; - --- 12 -Alter Table data_for_history.api_profile - Drop Column dfh_date_profile_deprecated; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_date_profile_deprecated; - --- 11 -Alter Table data_for_history.api_profile - Drop Column dfh_date_profile_published; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_date_profile_published; - --- 10 -Alter Table data_for_history.api_profile - Drop Column dfh_is_ongoing_forced_publication; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_is_ongoing_forced_publication; - --- 9 -Alter Table data_for_history.api_profile - Drop Column dfh_project_label; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_project_label; - --- 8 -Alter Table data_for_history.api_profile - Drop Column dfh_project_label_language; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_project_label_language; - --- 7 -Alter Table data_for_history.api_profile - Drop Column dfh_owned_by_project; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_owned_by_project; - --- 6 -Alter Table data_for_history.api_profile - Drop Column dfh_profile_definition; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_profile_definition; - --- 5 -Alter Table data_for_history.api_profile - Drop Column dfh_profile_definition_language; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_profile_definition_language; - --- 4 -Alter Table data_for_history.api_profile - Drop Column dfh_profile_label; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_profile_label; - --- 3 -Alter Table data_for_history.api_profile - Drop Column dfh_profile_label_language; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_profile_label_language; - --- 2 -Alter Table data_for_history.api_profile - Drop Column requested_language; - -Alter Table data_for_history.api_profile_vt - Drop Column requested_language; - --- 1 -Select - commons.rename_versioned_table ('data_for_history', - 'api_profile', - 'profile'); - diff --git a/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-up.sql b/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-up.sql deleted file mode 100644 index 99d773a75..000000000 --- a/server/db-migrate/migrations/sqls/20191212080452-dfh-t-api-profile-up.sql +++ /dev/null @@ -1,140 +0,0 @@ --- 1 -Select - commons.rename_versioned_table ('data_for_history', - 'profile', - 'api_profile'); - --- 2 -Alter Table data_for_history.api_profile - Add Column requested_language varchar(4); - -Alter Table data_for_history.api_profile_vt - Add Column requested_language varchar(4); - --- 3 -Alter Table data_for_history.api_profile - Add Column dfh_profile_label_language varchar(4); - -Alter Table data_for_history.api_profile_vt - Add Column dfh_profile_label_language varchar(4); - --- 4 -Alter Table data_for_history.api_profile - Add Column dfh_profile_label text; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_profile_label text; - --- 5 -Alter Table data_for_history.api_profile - Add Column dfh_profile_definition_language varchar(4); - -Alter Table data_for_history.api_profile_vt - Add Column dfh_profile_definition_language varchar(4); - --- 6 -Alter Table data_for_history.api_profile - Add Column dfh_profile_definition text; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_profile_definition text; - --- 7 -Alter Table data_for_history.api_profile - Add Column dfh_owned_by_project INTEGER; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_owned_by_project INTEGER; - --- 8 -Alter Table data_for_history.api_profile - Add Column dfh_project_label_language varchar(4); - -Alter Table data_for_history.api_profile_vt - Add Column dfh_project_label_language varchar(4); - --- 9 -Alter Table data_for_history.api_profile - Add Column dfh_project_label text; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_project_label text; - --- 10 -Alter Table data_for_history.api_profile - Add Column dfh_is_ongoing_forced_publication Boolean; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_is_ongoing_forced_publication Boolean; - --- 11 -Alter Table data_for_history.api_profile - Add Column dfh_date_profile_published DATE; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_date_profile_published DATE; - --- 12 -Alter Table data_for_history.api_profile - Add Column dfh_date_profile_deprecated DATE; - -Alter Table data_for_history.api_profile_vt - Add Column dfh_date_profile_deprecated DATE; - --- 13 -Alter Table data_for_history.api_profile - Drop Column dfh_fk_is_subprofile_of; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_fk_is_subprofile_of; - --- 14 -Alter Table data_for_history.api_profile - Drop Column dfh_standard_label; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_standard_label; - --- 15 -Alter Table data_for_history.api_profile - Drop Column dfh_fk_project_of_belonging; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_fk_project_of_belonging; - --- 16 -Alter Table data_for_history.api_profile - Drop Column dfh_start_date; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_start_date; - --- 17 -Alter Table data_for_history.api_profile - Drop Column dfh_end_date; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_end_date; - --- 18 -Alter Table data_for_history.api_profile - Drop Column dfh_creation_time; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_creation_time; - --- 19 -Alter Table data_for_history.api_profile - Drop Column dfh_modification_time; - -Alter Table data_for_history.api_profile_vt - Drop Column dfh_modification_time; - --- 20 -Alter Table data_for_history.api_profile - Drop Constraint unique_dfh_pk_profile; - --- 21 -Alter Table data_for_history.api_profile - Add Constraint unique_dfh_pk_profile_requested_language Unique (dfh_pk_profile, requested_language); - diff --git a/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-down.sql b/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-down.sql deleted file mode 100644 index b38085aa0..000000000 --- a/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- 2 --- no need, since step 1 does job --- 1 - -Drop Table projects.dfh_profile_proj_rel; - -Drop Table projects.dfh_profile_proj_rel_vt; - diff --git a/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-up.sql b/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-up.sql deleted file mode 100644 index f643d86b1..000000000 --- a/server/db-migrate/migrations/sqls/20191212084248-pro-t-dfh-profile-proj-rel-up.sql +++ /dev/null @@ -1,54 +0,0 @@ --- 1 -Create Table projects.dfh_profile_proj_rel ( - fk_project INTEGER Not Null References projects.project (pk_entity), - fk_profile INTEGER Not Null, - enabled boolean Not Null) -Inherits ( - projects.entity -); - -Select - commons.init_entity_child_table ('projects.dfh_profile_proj_rel'); - -Alter Table projects.dfh_profile_proj_rel - Add Constraint unique_fk_project_fk_profile Unique (fk_project, fk_profile); - --- 2 add relations according to the needs -/* - --- This query shows that all projects need all 4 existing profiles according to the --- enabled classes - -WITH tw1 AS ( - SELECT t1.fk_project, t3.dfh_fk_profile - FROM - projects.dfh_class_proj_rel t1, - data_for_history.class t2, - data_for_history.class_profile_view t3 - - WHERE t1.enabled_in_entities - AND t1.fk_entity = t2.pk_entity - AND t2.dfh_pk_class = t3.dfh_fk_class - GROUP BY - t1.fk_project, t3.dfh_fk_profile -) -SELECT - t1.fk_project, count( t1.dfh_fk_profile) -FROM tw1 t1 -GROUP BY - t1.fk_project -ORDER BY count asc - */ -Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) -Select Distinct - t2.pk_entity, - t1.dfh_fk_profile, - True -From - data_for_history.class_profile_view t1, - projects.project t2 -Where - t1.dfh_fk_profile != 5 -- exclude the geovistory basics -Order By - t2.pk_entity; - diff --git a/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-down.sql b/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-down.sql deleted file mode 100644 index 23b646969..000000000 --- a/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-down.sql +++ /dev/null @@ -1,5 +0,0 @@ ---1 -Drop Table data_for_history.api_class; - -Drop Table data_for_history.api_class_vt; - diff --git a/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-up.sql b/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-up.sql deleted file mode 100644 index 6c07322ab..000000000 --- a/server/db-migrate/migrations/sqls/20191212161931-dfh-t-api-classes-profile-up.sql +++ /dev/null @@ -1,29 +0,0 @@ --- 1 -Create Table data_for_history.api_class ( - requested_language varchar, - dfh_pk_class INTEGER, - dfh_class_identifier_in_namespace varchar, - dfh_class_label_language varchar, - dfh_class_label text, - dfh_class_scope_note_language varchar, - dfh_class_scope_note text, - dfh_basic_type integer, - dfh_basic_type_label text, - dfh_fk_namespace integer, - dfh_namespace_label_language varchar, - dfh_namespace_label text, - dfh_namespace_uri text, - dfh_profile_association_type text, - dfh_fk_profile integer, - dfh_profile_label_language varchar, - dfh_profile_label text) -Inherits ( - data_for_history.entity -); - -Select - commons.init_entity_child_table ('data_for_history.api_class'); - -Alter Table data_for_history.api_class - Add Constraint unique_requested_language_dfh_pk_class_dfh_fk_profile Unique (requested_language, dfh_pk_class, dfh_fk_profile); - diff --git a/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-down.sql b/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-down.sql deleted file mode 100644 index 32b29f378..000000000 --- a/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-down.sql +++ /dev/null @@ -1,5 +0,0 @@ ---1 -Drop Table data_for_history.api_property; - -Drop Table data_for_history.api_property_vt; - diff --git a/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-up.sql b/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-up.sql deleted file mode 100644 index 07d56dfb5..000000000 --- a/server/db-migrate/migrations/sqls/20191212162208-dfh-t-api-properties-profile-up.sql +++ /dev/null @@ -1,36 +0,0 @@ --- 1 -Create Table data_for_history.api_property ( - requested_language varchar, - dfh_pk_property integer, - dfh_property_label_language varchar, - dfh_property_label text, - dfh_property_scope_note_language varchar, - dfh_property_scope_note text, - dfh_is_inherited boolean, - dfh_property_domain integer, - dfh_domain_instances_min_quantifier integer, - dfh_domain_instances_max_quantifier integer, - dfh_property_range integer, - dfh_range_instances_min_quantifier integer, - dfh_range_instances_max_quantifier integer, - dfh_identity_defining boolean, - dfh_is_has_type_subproperty boolean, - dfh_property_identifier_in_namespace varchar, - dfh_namespace_uri text, - dfh_fk_namespace integer, - dfh_namespace_label_language varchar, - dfh_namespace_label text, - dfh_profile_association_type varchar, - dfh_fk_profile integer, - dfh_profile_label_language varchar, - dfh_profile_label text) -Inherits ( - data_for_history.entity -); - -Select - commons.init_entity_child_table ('data_for_history.api_property'); - -Alter Table data_for_history.api_property - Add Constraint unique_requested_language_dfh_pk_property_dfh_fk_profile Unique (requested_language, dfh_pk_property, dfh_property_domain, dfh_property_range, dfh_fk_profile); - diff --git a/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-down.sql b/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-down.sql deleted file mode 100644 index 29dd2e362..000000000 --- a/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-down.sql +++ /dev/null @@ -1,8 +0,0 @@ -Drop Function data_for_history.update_api_profiles_table; - -Drop Function data_for_history.update_api_classes_profile_table; - -Drop Function data_for_history.update_api_properties_profile_table; - -Drop Function data_for_history.update_api_tables; - diff --git a/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-up.sql b/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-up.sql deleted file mode 100644 index fa48eff69..000000000 --- a/server/db-migrate/migrations/sqls/20191212162209-dfh-f-udate-api-tables-up.sql +++ /dev/null @@ -1,835 +0,0 @@ --- 1 update_api_profiles_table -Create Or Replace Function data_for_history.update_api_profiles_table ( - param_profile_id INT, - param_requested_language VARCHAR, - param_tmsp_last_dfh_update TIMESTAMP With TIME ZONE, - param_profile_data JSON Default Null -) - Returns JSON - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - removed JSON; - updated JSON; - inserted JSON; -Begin - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - Update - data_for_history.api_profile - Set - tmsp_last_dfh_update = param_tmsp_last_dfh_update - Where - dfh_pk_profile = param_profile_id; - - /* - * Q: Is profile still present in API ? - */ - If (param_profile_data Is Null) Then - /* - * A: No. Profile is removed from API - */ - With tw1 As ( - Update - data_for_history.api_profile - Set - removed_from_api = True - Where - dfh_pk_profile = param_profile_id - And removed_from_api = False - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_profile_label', dfh_profile_label)) Into removed - From - tw1; - Else - /* - * A: Yes. Profile is still present in API - */ - /* - * Update profile_label - */ - Update - data_for_history.api_profile - Set - dfh_profile_label = param_profile_data ->> 'profileLabel' - Where - dfh_pk_profile = param_profile_id - And dfh_profile_label_language = param_profile_data ->> 'profileLabelLanguage'; - - /* - * Update profile_definition - */ - Update - data_for_history.api_profile - Set - dfh_profile_definition = param_profile_data ->> 'profileDefinition' - Where - dfh_pk_profile = param_profile_id - And dfh_profile_definition_language = param_profile_data ->> 'profileDefinitionLanguage'; - - /* - * Update project_label - */ - Update - data_for_history.api_profile - Set - dfh_project_label = param_profile_data ->> 'ownedByProjectLabel' - Where - dfh_pk_profile = param_profile_id - And dfh_project_label_language = param_profile_data ->> 'ownedByProjectLabelLanguage'; - - /* - * Update language independent fields of existing records - * of the queried profile - */ - With tw1 As ( - Update - data_for_history.api_profile - Set - removed_from_api = False, - dfh_owned_by_project = (param_profile_data ->> 'ownedByProjectID')::int, - dfh_is_ongoing_forced_publication = (param_profile_data ->> 'isOngoingForcedPublication')::bool, - dfh_date_profile_published = (param_profile_data ->> 'dateProfilePublished')::TIMESTAMP With TIME ZONE, - dfh_date_profile_deprecated = (param_profile_data ->> 'dateProfileDeprecated')::TIMESTAMP With TIME ZONE - Where - dfh_pk_profile = param_profile_id - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) Into updated - From - tw1; - - /* - * Insert or update all fields - * of the queried profile and the requested language - */ - With tw1 As ( -Insert Into data_for_history.api_profile (tmsp_last_dfh_update, - requested_language, - dfh_pk_profile, - dfh_profile_label_language, - dfh_profile_label, - dfh_profile_definition_language, - dfh_profile_definition, - dfh_owned_by_project, - dfh_project_label_language, - dfh_project_label, - dfh_is_ongoing_forced_publication, - dfh_date_profile_published, - dfh_date_profile_deprecated) - Values (param_tmsp_last_dfh_update, - param_requested_language, - (param_profile_data ->> 'profileID')::INT, - param_profile_data ->> 'profileLabelLanguage', - param_profile_data ->> 'profileLabel', - param_profile_data ->> 'profileDefinitionLanguage', - param_profile_data ->> 'profileDefinition', - (param_profile_data ->> 'ownedByProjectID')::INT, - param_profile_data ->> 'ownedByProjectLabelLanguage', - param_profile_data ->> 'ownedByProjectLabel', - (param_profile_data ->> 'isOngoingForcedPublication')::bool, - (param_profile_data ->> 'dateProfilePublished')::TIMESTAMP With TIME ZONE, - (param_profile_data ->> 'dateProfileDeprecated')::TIMESTAMP With TIME ZONE) On Conflict (dfh_pk_profile, - requested_language) - Do - Update - Set - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - requested_language = EXCLUDED.requested_language, - dfh_pk_profile = EXCLUDED.dfh_pk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label, - dfh_profile_definition_language = EXCLUDED.dfh_profile_definition_language, - dfh_profile_definition = EXCLUDED.dfh_profile_definition, - dfh_owned_by_project = EXCLUDED.dfh_owned_by_project, - dfh_project_label_language = EXCLUDED.dfh_project_label_language, - dfh_project_label = EXCLUDED.dfh_project_label, - dfh_is_ongoing_forced_publication = EXCLUDED.dfh_is_ongoing_forced_publication, - dfh_date_profile_published = EXCLUDED.dfh_date_profile_published, - dfh_date_profile_deprecated = EXCLUDED.dfh_date_profile_deprecated - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) Into inserted - From - tw1; - End If; - Return json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -End; -$BODY$; - --- 2 update_api_classes_profile_table -Create Or Replace Function data_for_history.update_api_classes_profile_table ( - param_profile_id INT, - param_requested_language VARCHAR, - param_tmsp_last_dfh_update TIMESTAMP With TIME ZONE, - param_classes_profile_data JSON Default '[]' ::JSON -) - Returns JSON - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - removed JSON; - updated JSON; - inserted JSON; -Begin - /* - * create a table with same type as from json - */ - Drop Table If Exists classes_profile_from_api; - Create TEMP Table classes_profile_from_api As - Select - param_requested_language As requested_language, - "classID" As dfh_pk_class, - "classIdentifierInNamespace" As dfh_class_identifier_in_namespace, - "classLabelLanguage" As dfh_class_label_language, - "classLabel" As dfh_class_label, - "classScopeNoteLanguage" As dfh_class_scope_note_language, - "classScopeNote" As dfh_class_scope_note, - "entityBasicType" As dfh_basic_type, - "entityBasicTypeLabel" As dfh_basic_type_label, - "namespaceID" As dfh_fk_namespace, - "namespaceLabelLanguage" As dfh_namespace_label_language, - "namespaceLabel" As dfh_namespace_label, - "namespaceURI" As dfh_namespace_uri, - "profileAssociationType" As dfh_profile_association_type, - "profileID" As dfh_fk_profile, - "profileLabelLanguage" As dfh_profile_label_language, - "profileLabel" As dfh_profile_label - From - json_to_recordset(param_classes_profile_data) As x ("classID" int, - "classIdentifierInNamespace" varchar, - "classLabel" text, - "classLabelLanguage" varchar, - "classScopeNote" text, - "classScopeNoteLanguage" varchar, - "entityBasicType" int, - "entityBasicTypeLabel" text, - "namespaceID" int, - "namespaceLabel" text, - "namespaceLabelLanguage" varchar, - "namespaceURI" text, - "profileAssociationType" text, - "profileID" int, - "profileLabel" text, - "profileLabelLanguage" varchar); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - Update - data_for_history.api_class - Set - tmsp_last_dfh_update = param_tmsp_last_dfh_update - Where - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - With tw1 As ( - Select - dfh_pk_class, - dfh_fk_profile - From - data_for_history.api_class - Where - dfh_fk_profile = param_profile_id - Except - Select - dfh_pk_class, - dfh_fk_profile - From - classes_profile_from_api - Where - dfh_fk_profile = param_profile_id -), -tw2 As ( - Update - data_for_history.api_class t1 - Set - removed_from_api = True - From - tw1 t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class - Returning - t1.* -) -Select - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) Into removed -From - tw2; - - /* - * Update class_label - */ - Update - data_for_history.api_class t1 - Set - dfh_class_label = t2.dfh_class_label - From - classes_profile_from_api t2 - Where - t1.dfh_class_label_language = t2.dfh_class_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update class_scope_note - */ - Update - data_for_history.api_class t1 - Set - dfh_class_scope_note = t2.dfh_class_scope_note - From - classes_profile_from_api t2 - Where - t1.dfh_class_scope_note_language = t2.dfh_class_scope_note_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update namespace_label - */ - Update - data_for_history.api_class t1 - Set - dfh_namespace_label = t2.dfh_namespace_label - From - classes_profile_from_api t2 - Where - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update profile_label - */ - Update - data_for_history.api_class t1 - Set - dfh_profile_label = t2.dfh_profile_label - From - classes_profile_from_api t2 - Where - t1.dfh_profile_label_language = t2.dfh_profile_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - With tw1 As ( - Update - data_for_history.api_class t1 - Set - removed_from_api = False, - dfh_class_identifier_in_namespace = t2.dfh_class_identifier_in_namespace, - dfh_basic_type = t2.dfh_basic_type, - dfh_basic_type_label = t2.dfh_basic_type_label, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_profile_association_type = t2.dfh_profile_association_type - From - classes_profile_from_api t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_class = t2.dfh_pk_class - Returning - t1.* -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) Into updated - From - tw1; - - /* - * Insert all new records - */ - With tw1 As ( -Insert Into data_for_history.api_class (tmsp_last_dfh_update, - removed_from_api, - requested_language, - dfh_pk_class, - dfh_class_identifier_in_namespace, - dfh_class_label_language, - dfh_class_label, - dfh_class_scope_note_language, - dfh_class_scope_note, - dfh_basic_type, - dfh_basic_type_label, - dfh_fk_namespace, - dfh_namespace_label_language, - dfh_namespace_label, - dfh_namespace_uri, - dfh_profile_association_type, - dfh_fk_profile, - dfh_profile_label_language, - dfh_profile_label) - Select Distinct On (t1.requested_language, - t1.dfh_pk_class, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - False, - t1.requested_language, - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_class_label_language, - t1.dfh_class_label, - t1.dfh_class_scope_note_language, - t1.dfh_class_scope_note, - t1.dfh_basic_type, - t1.dfh_basic_type_label, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_namespace_uri, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - From - classes_profile_from_api t1 - Where - t1.requested_language = param_requested_language - And t1.dfh_fk_profile = param_profile_id On Conflict (requested_language, - dfh_pk_class, - dfh_fk_profile) - Do - Update - Set - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - --requested_language = EXCLUDED.requested_language, - --dfh_pk_class = EXCLUDED.dfh_pk_class, - dfh_class_identifier_in_namespace = EXCLUDED.dfh_class_identifier_in_namespace, - dfh_class_label_language = EXCLUDED.dfh_class_label_language, - dfh_class_label = EXCLUDED.dfh_class_label, - dfh_class_scope_note_language = EXCLUDED.dfh_class_scope_note_language, - dfh_class_scope_note = EXCLUDED.dfh_class_scope_note, - dfh_basic_type = EXCLUDED.dfh_basic_type, - dfh_basic_type_label = EXCLUDED.dfh_basic_type_label, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - -- dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) Into inserted - From - tw1; - - /* - * Return kind of a protocol - */ - Return json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -End; -$BODY$; - --- 2 update_api_properties_profile_table -Create Or Replace Function data_for_history.update_api_properties_profile_table ( - param_profile_id integer, - param_requested_language character varying, - param_tmsp_last_dfh_update timestamp With time zone, - param_properties_profile_data json Default '[]' ::json -) - Returns json - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - removed JSON; - updated JSON; - inserted JSON; -Begin - /* - * create a table with same type as from json - */ - Drop Table If Exists properties_profile_from_api; - Create Table properties_profile_from_api As - Select - param_requested_language As requested_language, - "propertyID" As dfh_pk_property, - "propertyLabelLanguage" As dfh_property_label_language, - "propertyLabel" As dfh_property_label, - "propertyScopeNoteLanguage" As dfh_property_scope_note_language, - "propertyScopeNote" As dfh_property_scope_note, - "isInherited" As dfh_is_inherited, - "propertyDomain" As dfh_property_domain, - "domainInstancesMinQuantifier" As dfh_domain_instances_min_quantifier, - "domainInstancesMaxQuantifier" As dfh_domain_instances_max_quantifier, - "propertyRange" As dfh_property_range, - "rangeInstancesMinQuantifier" As dfh_range_instances_min_quantifier, - "rangeInstancesMaxQuantifier" As dfh_range_instances_max_quantifier, - "identityDefining" As dfh_identity_defining, - "isHasTypeSubproperty" As dfh_is_has_type_subproperty, - "propertyIdentifierInNamespace" As dfh_property_identifier_in_namespace, - "namespaceURI" As dfh_namespace_uri, - "namespaceID" As dfh_fk_namespace, - "namespaceLabelLanguage" As dfh_namespace_label_language, - "namespaceLabel" As dfh_namespace_label, - "profileAssociationType" As dfh_profile_association_type, - "profileID" As dfh_fk_profile, - "profileLabelLanguage" As dfh_profile_label_language, - "profileLabel" As dfh_profile_label - From - json_to_recordset(param_properties_profile_data) As x ("propertyID" INT, - "propertyLabelLanguage" VARCHAR, - "propertyLabel" TEXT, - "propertyScopeNoteLanguage" VARCHAR, - "propertyScopeNote" TEXT, - "isInherited" BOOLEAN, - "propertyDomain" INTEGER, - "domainInstancesMinQuantifier" INTEGER, - "domainInstancesMaxQuantifier" INTEGER, - "propertyRange" INTEGER, - "rangeInstancesMinQuantifier" INTEGER, - "rangeInstancesMaxQuantifier" INTEGER, - "identityDefining" BOOLEAN, - "isHasTypeSubproperty" BOOLEAN, - "propertyIdentifierInNamespace" VARCHAR, - "namespaceURI" TEXT, - "namespaceID" INTEGER, - "namespaceLabelLanguage" VARCHAR, - "namespaceLabel" TEXT, - "profileAssociationType" TEXT, - "profileID" INTEGER, - "profileLabelLanguage" VARCHAR, - "profileLabel" TEXT); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - Update - data_for_history.api_property - Set - tmsp_last_dfh_update = param_tmsp_last_dfh_update - Where - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - With tw1 As ( - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - data_for_history.api_property - Where - dfh_fk_profile = param_profile_id - Except - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - properties_profile_from_api - Where - dfh_fk_profile = param_profile_id -), -tw2 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = True - From - tw1 t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) -Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into removed -From - tw2; - - /* - * Update language dependent fields of existing records - */ - /* - * Update property_labels - */ - Update - data_for_history.api_property t1 - Set - dfh_property_label = t2.dfh_property_label - From - properties_profile_from_api t2 - Where - t1.dfh_property_label_language = t2.dfh_property_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update scope_notes - */ - Update - data_for_history.api_property t1 - Set - dfh_property_scope_note = t2.dfh_property_scope_note - From - properties_profile_from_api t2 - Where - t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_namespace_label - */ - Update - data_for_history.api_property t1 - Set - dfh_namespace_label = t2.dfh_namespace_label - From - properties_profile_from_api t2 - Where - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_profile_label - */ - Update - data_for_history.api_property t1 - Set - dfh_profile_label = t2.dfh_profile_label - From - properties_profile_from_api t2 - Where - t1.dfh_profile_label_language = t2.dfh_profile_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - With tw1 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = False, - dfh_pk_property = t2.dfh_pk_property, - dfh_is_inherited = t2.dfh_is_inherited, - dfh_property_domain = t2.dfh_property_domain, - dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, - dfh_property_range = t2.dfh_property_range, - dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, - dfh_identity_defining = t2.dfh_identity_defining, - dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_fk_profile = t2.dfh_fk_profile - From - properties_profile_from_api t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into updated - From - tw1; - - /* - * Insert or update all new records - */ - With tw1 As ( -Insert Into data_for_history.api_property (tmsp_last_dfh_update, - removed_from_api, - requested_language, - dfh_pk_property, - dfh_property_label_language, - dfh_property_label, - dfh_property_scope_note_language, - dfh_property_scope_note, - dfh_is_inherited, - dfh_property_domain, - dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier, - dfh_property_range, - dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier, - dfh_identity_defining, - dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace, - dfh_namespace_uri, - dfh_fk_namespace, - dfh_namespace_label_language, - dfh_namespace_label, - dfh_profile_association_type, - dfh_fk_profile, - dfh_profile_label_language, - dfh_profile_label) - Select Distinct On (t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - False, - t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_label_language, - t1.dfh_property_label, - t1.dfh_property_scope_note_language, - t1.dfh_property_scope_note, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_namespace_uri, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - From - properties_profile_from_api t1 - Where - t1.requested_language = param_requested_language - And t1.dfh_fk_profile = param_profile_id On Conflict (requested_language, - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile) - Do - Update - Set - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - requested_language = EXCLUDED.requested_language, - dfh_pk_property = EXCLUDED.dfh_pk_property, - dfh_property_label_language = EXCLUDED.dfh_property_label_language, - dfh_property_label = EXCLUDED.dfh_property_label, - dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, - dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, - dfh_is_inherited = EXCLUDED.dfh_is_inherited, - dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, - dfh_identity_defining = EXCLUDED.dfh_identity_defining, - dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into inserted - From - tw1; - - /* - * Return kind of a protocol - */ - Return json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -End; -$BODY$; - -Create Or Replace Function data_for_history.update_api_tables ( - param_profile_id INT, - param_requested_language VARCHAR, - param_tmsp_last_dfh_update TIMESTAMP With TIME ZONE, - param_profile_data JSON Default Null, - param_classes_profile_data JSON Default Null, - param_properties_profile_data JSON Default Null -) - Returns JSON - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - api_profile JSON; - api_class JSON; - api_property JSON; -Begin - /************************************************************** - * Profiles - ***************************************************************/ - Select - data_for_history.update_api_profiles_table (param_profile_id, - param_requested_language, - param_tmsp_last_dfh_update, - param_profile_data) Into api_profile; - - /************************************************************** - * Classes-Profile - ***************************************************************/ - Select - data_for_history.update_api_classes_profile_table (param_profile_id, - param_requested_language, - param_tmsp_last_dfh_update, - param_classes_profile_data) Into api_class; - - /************************************************************** - * Properties-Profile - ***************************************************************/ - Select - data_for_history.update_api_properties_profile_table (param_profile_id, - param_requested_language, - param_tmsp_last_dfh_update, - param_properties_profile_data) Into api_property; - Return json_build_object('api_profile', api_profile, 'api_class', api_class, 'api_property', api_property); -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-down.sql b/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-down.sql deleted file mode 100644 index 2341bc693..000000000 --- a/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop View data_for_history.v_profile; - diff --git a/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-up.sql b/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-up.sql deleted file mode 100644 index 5e31bd0dd..000000000 --- a/server/db-migrate/migrations/sqls/20191213104121-dfh-v-profile-up.sql +++ /dev/null @@ -1,10 +0,0 @@ -Create Or Replace View data_for_history.v_profile As Select Distinct - t1.dfh_pk_profile As pk_profile, - t1.dfh_owned_by_project As owned_by_project, - t1.dfh_is_ongoing_forced_publication As is_ongoing_forced_publication, - t1.dfh_date_profile_published As date_profile_published, - t1.dfh_date_profile_deprecated As date_profile_deprecated, - t1.tmsp_last_dfh_update As tmsp_last_dfh_update -From - data_for_history.api_profile t1; - diff --git a/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-down.sql b/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-down.sql deleted file mode 100644 index af0bed2f4..000000000 --- a/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop View data_for_history.v_label; - diff --git a/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-up.sql b/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-up.sql deleted file mode 100644 index b5a39837a..000000000 --- a/server/db-migrate/migrations/sqls/20191213131829-dfh-v-label-up.sql +++ /dev/null @@ -1,101 +0,0 @@ -Create Or Replace View data_for_history.v_label As -/* - * Language Dependent Texts from table api_profile - */ -Select Distinct On (label, - Language) - 'label' As Type, - t1.dfh_profile_label As label, - t1.dfh_profile_label_language As - Language, - t1.dfh_pk_profile As fk_profile, - NULL::INT As fk_project, - NULL::INT As fk_property, - NULL::INT As fk_class -From - data_for_history.api_profile t1 -Union -Select Distinct On (label, - Language) - 'definition' As Type, - t1.dfh_profile_definition As label, - t1.dfh_profile_definition_language As - Language, - t1.dfh_pk_profile As dfh_fk_profile, - NULL::INT As fk_project, - NULL::INT As fk_property, - NULL::INT As fk_class -From - data_for_history.api_profile t1 -Union -Select Distinct On (label, - Language) - 'label' As Type, - t1.dfh_project_label As label, - t1.dfh_project_label_language As - Language, - NULL::INT As dfh_fk_project, - t1.dfh_owned_by_project As fk_project, - NULL::INT As fk_property, - NULL::INT As fk_class -From - data_for_history.api_profile t1 - /* - * Language Dependent Texts from table api_property - */ -Union -Select Distinct On (label, - Language) - 'label' As Type, - t1.dfh_property_label As label, - t1.dfh_property_label_language As - Language, - NULL::INT As dfh_fk_project, - NULL::INT As fk_project, - t1.dfh_pk_property As fk_property, - NULL::INT As fk_class -From - data_for_history.api_property t1 -Union -Select Distinct On (label, - Language) - 'scope_note' As Type, - t1.dfh_property_scope_note As label, - t1.dfh_property_scope_note_language As - Language, - NULL::INT As dfh_fk_project, - NULL::INT As fk_project, - t1.dfh_pk_property As fk_property, - NULL::INT As fk_class -From - data_for_history.api_property t1 - /* - * Language Dependent Texts from table api_property - */ -Union -Select Distinct On (label, - Language) - 'label' As Type, - t1.dfh_class_label As label, - t1.dfh_class_label_language As - Language, - NULL::INT As dfh_fk_project, - NULL::INT As fk_project, - NULL::INT As fk_property, - t1.dfh_pk_class As fk_class -From - data_for_history.api_class t1 -Union -Select Distinct On (label, - Language) - 'scope_note' As Type, - t1.dfh_class_scope_note As label, - t1.dfh_class_scope_note_language As - Language, - NULL::INT As dfh_fk_project, - NULL::INT As fk_project, - NULL::INT As fk_property, - t1.dfh_pk_class As fk_class -From - data_for_history.api_class t1; - diff --git a/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-down.sql b/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-down.sql deleted file mode 100644 index ca6c78b83..000000000 --- a/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 2 -Drop View data_for_history.v_class; - --- 1 -Alter View data_for_history.v_class_deprecated Rename To v_class; - diff --git a/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-up.sql b/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-up.sql deleted file mode 100644 index 3bd3e49a9..000000000 --- a/server/db-migrate/migrations/sqls/20191213132001-dfh-v-class-up.sql +++ /dev/null @@ -1,19 +0,0 @@ --- 1 -Alter View data_for_history.v_class Rename To v_class_deprecated; - --- 2 -Create View data_for_history.v_class As -Select - t1.dfh_pk_class As pk_class, - t1.dfh_class_identifier_in_namespace As identifier_in_namespace, - t1.dfh_basic_type As basic_type, - t1.dfh_basic_type_label As basic_type_label, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) As profiles -From - data_for_history.api_class t1 -Group By - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_basic_type, - t1.dfh_basic_type_label; - diff --git a/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-down.sql b/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-down.sql deleted file mode 100644 index 883ce9dcb..000000000 --- a/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-down.sql +++ /dev/null @@ -1,9 +0,0 @@ --- 3 -Alter View data_for_history.v_property_profile_view_deprecated Rename To v_property_profile_view; - --- 2 -Drop View data_for_history.v_property; - --- 1 -Alter View data_for_history.v_property_deprecated Rename To v_property; - diff --git a/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-up.sql b/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-up.sql deleted file mode 100644 index 1e004a325..000000000 --- a/server/db-migrate/migrations/sqls/20191213134241-dfh-v-property-up.sql +++ /dev/null @@ -1,36 +0,0 @@ --- 1 -Alter View data_for_history.v_property Rename To v_property_deprecated; - --- 2 -Create View data_for_history.v_property As -Select - t1.dfh_pk_property As pk_property, - t1.dfh_is_inherited As is_inherited, - t1.dfh_property_domain As has_domain, - t1.dfh_domain_instances_min_quantifier As domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier As domain_instances_max_quantifier, - t1.dfh_property_range As has_range, - t1.dfh_range_instances_min_quantifier As range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier As range_instances_max_quantifier, - t1.dfh_identity_defining As identity_defining, - t1.dfh_is_has_type_subproperty As is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) As profiles -From - data_for_history.api_property t1 -Group By - t1.dfh_pk_property, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace; - --- 3 -Alter View data_for_history.v_property_profile_view Rename To v_property_profile_view_deprecated; - diff --git a/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-down.sql b/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-down.sql deleted file mode 100644 index 79d729387..000000000 --- a/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-down.sql +++ /dev/null @@ -1,22 +0,0 @@ -/* Replace with your SQL commands */ --- 4 - -Alter Table projects.dfh_class_proj_rel - Drop Constraint dfh_class_project_rel__class_and_project_unique; - -Alter Table projects.dfh_class_proj_rel - Add Constraint dfh_class_project_rel__entity_and_project_unique Unique (fk_entity_deprecated, fk_project); - --- 3 -Alter Table projects.dfh_class_proj_rel Rename Column fk_entity_deprecated To fk_entity; - --- 2 --- no need, since 1 does job --- 1 - -Alter Table projects.dfh_class_proj_rel - Drop Column fk_class; - -Alter Table projects.dfh_class_proj_rel_vt - Drop Column fk_class; - diff --git a/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-up.sql b/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-up.sql deleted file mode 100644 index 4e6cc6935..000000000 --- a/server/db-migrate/migrations/sqls/20191213135247-pro-t-dfh-class-proj-rel-data-migration-up.sql +++ /dev/null @@ -1,38 +0,0 @@ -/* Replace with your SQL commands */ --- 1 - -Alter Table projects.dfh_class_proj_rel - Add Column fk_class INTEGER; - -Alter Table projects.dfh_class_proj_rel_vt - Add Column fk_class INTEGER; - --- 2 -With tw1 As ( - Select Distinct - t1.fk_entity, - t2.dfh_pk_class - From - projects.dfh_class_proj_rel t1, - data_for_history. "class" t2 - Where - t1.fk_entity = t2.pk_entity) -Update - projects.dfh_class_proj_rel t1 -Set - fk_class = t2.dfh_pk_class -From - tw1 t2 -Where - t1.fk_entity = t2.fk_entity; - --- 3 -Alter Table projects.dfh_class_proj_rel Rename Column fk_entity To fk_entity_deprecated; - --- 4 -Alter Table projects.dfh_class_proj_rel - Drop Constraint dfh_class_project_rel__entity_and_project_unique; - -Alter Table projects.dfh_class_proj_rel - Add Constraint dfh_class_project_rel__class_and_project_unique Unique (fk_class, fk_project); - diff --git a/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-down.sql b/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-down.sql deleted file mode 100644 index 5242858c7..000000000 --- a/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-down.sql +++ /dev/null @@ -1,46 +0,0 @@ --- 5 -Alter Table projects.property_label_deprecated Rename To property_label; - -Alter Table projects.property_label_deprecated_vt Rename To property_label_vt; - --- 4 -Delete From projects.text_property -Where notes = 'migrated from data_for_history.label'; - --- 3 -Delete From projects.text_property -Where notes = 'migrated from projects.property_label'; - --- 2 --- no need, since column dropped in 1 --- 1 - -Alter Table projects.text_property - Drop Column fk_project; - -Alter Table projects.text_property Rename Column fk_pro_project To fk_entity; - -Alter Table projects.text_property - Drop Column fk_dfh_property; - -Alter Table projects.text_property_vt - Drop Column fk_dfh_property; - -Alter Table projects.text_property - Drop Column fk_dfh_property_domain; - -Alter Table projects.text_property_vt - Drop Column fk_dfh_property_domain; - -Alter Table projects.text_property - Drop Column fk_dfh_property_range; - -Alter Table projects.text_property_vt - Drop Column fk_dfh_property_range; - -Alter Table projects.text_property - Drop Column fk_dfh_class; - -Alter Table projects.text_property_vt - Drop Column fk_dfh_class; - diff --git a/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-up.sql b/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-up.sql deleted file mode 100644 index 1bd5d6b74..000000000 --- a/server/db-migrate/migrations/sqls/20191214182047-pro-t-text-property-extention-up.sql +++ /dev/null @@ -1,74 +0,0 @@ --- 1 -Alter Table projects.text_property - Add Column fk_project INT; - -Alter Table projects.text_property Rename Column fk_entity To fk_pro_project; - -Alter Table projects.text_property - Add Column fk_dfh_property INT; - -Alter Table projects.text_property_vt - Add Column fk_dfh_property INT; - -Alter Table projects.text_property - Add Column fk_dfh_property_domain INT; - -Alter Table projects.text_property_vt - Add Column fk_dfh_property_domain INT; - -Alter Table projects.text_property - Add Column fk_dfh_property_range INT; - -Alter Table projects.text_property_vt - Add Column fk_dfh_property_range INT; - -Alter Table projects.text_property - Add Column fk_dfh_class INT; - -Alter Table projects.text_property_vt - Add Column fk_dfh_class INT; - --- 2 fill fk_project field as -Update - projects.text_property -Set - fk_project = fk_pro_project; - --- 3 add property labels from projects.property_label -Insert Into projects.text_property (string, fk_language, fk_system_type, fk_project, fk_creator, fk_last_modifier, fk_dfh_property, fk_dfh_property_domain, fk_dfh_property_range, notes) -Select - label, - fk_language, - 639, -- label - fk_project, - fk_creator, - fk_last_modifier, - fk_property, - fk_domain_class, - fk_range_class, - 'migrated from projects.property_label' -From - projects.property_label; - --- 4 add class labels from data_for_history.label -Insert Into projects.text_property (string, fk_language, fk_system_type, fk_project, fk_creator, fk_last_modifier, fk_dfh_class, notes) -Select - dfh_label, - inf_fk_language, - 639, -- label - 375669, -- default config project - 7, -- jonas - 7, -- jonas - dfh_fk_class, - 'migrated from data_for_history.label' -From - data_for_history. "label" -Where - "label".dfh_fk_class Is Not Null - And "label".inf_fk_language Is Not Null; - --- 5 -Alter Table projects.property_label Rename To property_label_deprecated; - -Alter Table projects.property_label_vt Rename To property_label_deprecated_vt; - diff --git a/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-down.sql b/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-down.sql deleted file mode 100644 index 5c26509d3..000000000 --- a/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-down.sql +++ /dev/null @@ -1,17 +0,0 @@ --- no way back -Update - projects.class_field_config -Set - fk_app_context = 45; - -Update - projects.class_field_config_vt -Set - fk_app_context = 45; - -Alter Table projects.class_field_config - Alter Column fk_app_context Set Not Null; - -Alter Table projects.class_field_config - Alter Column fk_app_context Set Not Null; - diff --git a/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-up.sql b/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-up.sql deleted file mode 100644 index 532fe8060..000000000 --- a/server/db-migrate/migrations/sqls/20191218124631-pro-class-field-config-reset-up.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Replace with your SQL commands */ -Delete From projects.class_field_config; - -Alter Table projects.class_field_config - Alter Column fk_app_context Drop Not Null; - -Alter Table projects.class_field_config_vt - Alter Column fk_app_context Drop Not Null; - diff --git a/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-down.sql b/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-down.sql deleted file mode 100644 index ad069aee5..000000000 --- a/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-down.sql +++ /dev/null @@ -1,985 +0,0 @@ --- 2 - - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create( - param_pk_entities integer[]) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) -), --- fields --- TODO: add fk_project for consideration of project-settings -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - coalesce(t1.fk_range_class, t1.fk_domain_class, t1.fk_class_for_class_field) fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - -- t1.fk_project, - t2.used_table - From - projects.class_field_config t1 - Left Join system.class_field t2 On t2.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - fk_class, - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw3 t2 - Where - -- TODO: join by fk_project or default for consideration of project-settings - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- select roles with time primitive, first and last second -tw9 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t2.calendar) As last_second - From - information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t3.pk_entity = t1.fk_entity - And t2.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t1.community_favorite_calendar) As last_second - From - information.v_role t1 - Join information.v_time_primitive t3 On t3.pk_entity = t1.fk_entity - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw10 As ( - Select - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - Case When tw9.fk_property = 71 Then - 'p81'::text - When tw9.fk_property = 72 Then - 'p82'::text - When tw9.fk_property = 150 Then - 'p81a'::text - When tw9.fk_property = 151 Then - 'p81b'::text - When tw9.fk_property = 152 Then - 'p82a'::text - When tw9.fk_property = 153 Then - 'p82b'::text - Else - tw9.fk_property::text - End, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) As time_span - From - tw9 - Group By - tw9.fk_project, - tw9.fk_temporal_entity -), -tw11 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw10 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw12 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw13 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw11 t1 - Left Join tw12 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw14 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t2.fk_entity = t1.pk_entity -And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw15 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw14 t1, - system.class_has_type_property t2 - Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) - And t1.fk_project Is Null - And t1.fk_property = t2.fk_property -Union -Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count -From - tw14 t3, - system.class_has_type_property t4 -Where (t3.fk_info_domain = Any (param_pk_entities) - Or t3.fk_info_range = Any (param_pk_entities)) -And t3.fk_project Is Not Null -And t3.fk_property = t4.fk_property -Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw16 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw13 t1 - Left Join tw15 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw16; - -$BODY$; - - --- 1 - -CREATE OR REPLACE FUNCTION warehouse.entity_preview_non_recursive__create_all( - ) - RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - -- 1 - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 -), --- fields --- TODO: add fk_project for consideration of project-settings -tw3 As ( - Select - t1.pk_entity, - t1.ord_num As field_order, - coalesce(t1.fk_range_class, t1.fk_domain_class, t1.fk_class_for_class_field) fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - -- t1.fk_project, - t2.used_table - From - projects.class_field_config t1 - Left Join system.class_field t2 On t2.pk_entity = t1.fk_class_field -Where - t1.fk_app_context = 45 - And t1.ord_num Is Not Null -Order By - fk_class, - t1.ord_num -), --- explode with all fields: join all entities with their fields -tw4 As ( - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw3 t2 - Where - -- TODO: join by fk_project or default for consideration of project-settings - --AND - --tw2.fk_project - tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1 - Where - t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), -tw9 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw10 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw9 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw9 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw11 As ( - Select - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - Case When tw10.fk_property = 71 Then - 'p81'::text - When tw10.fk_property = 72 Then - 'p82'::text - When tw10.fk_property = 150 Then - 'p81a'::text - When tw10.fk_property = 151 Then - 'p81b'::text - When tw10.fk_property = 152 Then - 'p82a'::text - When tw10.fk_property = 153 Then - 'p82b'::text - Else - tw10.fk_property::text - End, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) As time_span - From - tw10 - Group By - tw10.fk_project, - tw10.fk_temporal_entity -), -tw12 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw11 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw13 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw12 t1 - Left Join tw13 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw15 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where - t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw16 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw15 t1, - system.class_has_type_property t2 - Where - t1.fk_project Is Null - And t1.fk_property = t2.fk_property - Union - Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - From - tw15 t3, - system.class_has_type_property t4 - Where - t3.fk_project Is Not Null - And t3.fk_property = t4.fk_property - Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw17 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw14 t1 - Left Join tw16 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw17; - -$BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-up.sql b/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-up.sql deleted file mode 100644 index 45451b80e..000000000 --- a/server/db-migrate/migrations/sqls/20191218210956-war-f-create-non-recursive-up.sql +++ /dev/null @@ -1,1343 +0,0 @@ --- 1 -Create Or Replace Function warehouse.entity_preview_non_recursive__create_all () - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - -- 1 - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 -), --- fields -/** - * Start of selecting ordered fields per class and project - */ --- all text_properties except comments -tw02 As ( - Select - Case t2.pk_entity - When 217 Then - - 9 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_class As fk_class, - t1.pk_class As fk_class_for_class_field, - null::int As fk_domain_class, - null::int As fk_range_class, - null::int As fk_property, - null::boolean As property_is_outgoing, - t2.pk_entity As fk_class_field, - t3.pk_entity As fk_project - From - data_for_history.v_class t1, - "system".class_field t2, - projects.project t3 - Where - pk_class != 365 - And t2.used_table = 'information.text_property' - And t2.pk_entity != 3364 -), --- all outgoing property fields --- outgoing property fields -tw05 As ( - Select Distinct - t3.ord_num As field_order, - t2.has_domain As fk_class, - null::int As fk_class_for_class_field, - t2.has_domain As fk_domain_class, - null::int As fk_range_class, - t2.pk_property As fk_property, - True As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join data_for_history.v_class t1 On True --t1.pk_class IN (365) AND t0.pk_entity IN (375669, 24, 27) - Join data_for_history.v_property t2 On t1.pk_class = t2.has_domain - Left Join projects.class_field_config t3 On t2.has_domain = t3.fk_domain_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw06 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw05 t1 -), --- field order comes from project -tw07 As ( - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw05 t1, - tw06 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw05 t1 - Join tw06 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw05 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- ingoing property fields -tw08 As ( - Select Distinct - Case t2.pk_property - When 1111 Then - - 10::int - Else - t3.ord_num - End As field_order, - t2.has_range As fk_class, - null::int As fk_class_for_class_field, - null::int As fk_domain_class, - t2.has_range As fk_range_class, - t2.pk_property As fk_property, - False As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join data_for_history.v_class t1 On t1.pk_class != 365 - Join data_for_history.v_property t2 On t1.pk_class = t2.has_range - Left Join projects.class_field_config t3 On t2.has_range = t3.fk_range_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw09 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw08 t1 -), -tw010 As ( - -- field order comes from project - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw08 t1, - tw09 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw08 t1 - Join tw09 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw08 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- all fields for all projects and all classes -tw011 As ( - Select - * - From - tw02 - Union All - Select - * - From - tw07 - Union All - Select - * - From - tw010 -), -/* - * End of selecting ordered fields per class and project - **/ --- explode with all fields: join all entities with their fields -tw4 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2 t1, - tw011 t2 -Where - t1.fk_project = t2.fk_project - And t1.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1 - Where - t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) Filter (Where string Is Not Null) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), -tw9 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw10 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw9 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw9 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw11 As ( - Select - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - Case When tw10.fk_property = 71 Then - 'p81'::text - When tw10.fk_property = 72 Then - 'p82'::text - When tw10.fk_property = 150 Then - 'p81a'::text - When tw10.fk_property = 151 Then - 'p81b'::text - When tw10.fk_property = 152 Then - 'p82a'::text - When tw10.fk_property = 153 Then - 'p82b'::text - Else - tw10.fk_property::text - End, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) As time_span - From - tw10 - Group By - tw10.fk_project, - tw10.fk_temporal_entity -), -tw12 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw11 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw13 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw12 t1 - Left Join tw13 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw15 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where - t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw16 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw15 t1, - system.class_has_type_property t2 - Where - t1.fk_project Is Null - And t1.fk_property = t2.fk_property - Union - Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - From - tw15 t3, - system.class_has_type_property t4 - Where - t3.fk_project Is Not Null - And t3.fk_property = t4.fk_property - Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw17 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw14 t1 - Left Join tw16 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw17; - -$BODY$; - --- 2 -Create Or Replace Function warehouse.entity_preview_non_recursive__create ( - param_pk_entities integer[] -) - Returns Setof warehouse.entity_preview_non_recursive - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) -), --- fields --- TODO: add fk_project for consideration of project-settings -/** - * Start of selecting ordered fields per class and project - */ --- all text_properties except comments -tw02 As ( - Select - Case t2.pk_entity - When 217 Then - - 9 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_class As fk_class, - t1.pk_class As fk_class_for_class_field, - null::int As fk_domain_class, - null::int As fk_range_class, - null::int As fk_property, - null::boolean As property_is_outgoing, - t2.pk_entity As fk_class_field, - t3.pk_entity As fk_project - From - tw2 t0, - data_for_history.v_class t1, - "system".class_field t2, - projects.project t3 - Where - pk_class != 365 - And t1.pk_class = t0.fk_class - And t2.used_table = 'information.text_property' - And t2.pk_entity != 3364 -), --- all outgoing property fields --- outgoing property fields -tw05 As ( - Select Distinct - t3.ord_num As field_order, - t2.has_domain As fk_class, - null::int As fk_class_for_class_field, - t2.has_domain As fk_domain_class, - null::int As fk_range_class, - t2.pk_property As fk_property, - True As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join ( Select Distinct - fk_class As pk_class - From - tw2) t1 On True --t1.pk_class IN (365) AND t0.pk_entity IN (375669, 24, 27) - Join data_for_history.v_property t2 On t1.pk_class = t2.has_domain - Left Join projects.class_field_config t3 On t2.has_domain = t3.fk_domain_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw06 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw05 t1 -), --- field order comes from project -tw07 As ( - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw05 t1, - tw06 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw05 t1 - Join tw06 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw05 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- ingoing property fields -tw08 As ( - Select Distinct - Case t2.pk_property - When 1111 Then - - 10::int - Else - t3.ord_num - End As field_order, - t2.has_range As fk_class, - null::int As fk_class_for_class_field, - null::int As fk_domain_class, - t2.has_range As fk_range_class, - t2.pk_property As fk_property, - False As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join ( Select Distinct - fk_class As pk_class - From - tw2) t1 On t1.pk_class != 365 - Join data_for_history.v_property t2 On t1.pk_class = t2.has_range - Left Join projects.class_field_config t3 On t2.has_range = t3.fk_range_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw09 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw08 t1 -), -tw010 As ( - -- field order comes from project - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw08 t1, - tw09 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw08 t1 - Join tw09 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw08 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- all fields for all projects and all classes -tw011 As ( - Select - * - From - tw02 - Union All - Select - * - From - tw07 - Union All - Select - * - From - tw010 -), -/* - * End of selecting ordered fields per class and project - **/ --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw011 t2 -Where - tw2.fk_project = t2.fk_project - And tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) Filter (Where string Is Not Null) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- select roles with time primitive, first and last second -tw9 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t2.calendar) As last_second - From - information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t3.pk_entity = t1.fk_entity - And t2.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t1.community_favorite_calendar) As last_second - From - information.v_role t1 - Join information.v_time_primitive t3 On t3.pk_entity = t1.fk_entity - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw10 As ( - Select - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - Case When tw9.fk_property = 71 Then - 'p81'::text - When tw9.fk_property = 72 Then - 'p82'::text - When tw9.fk_property = 150 Then - 'p81a'::text - When tw9.fk_property = 151 Then - 'p81b'::text - When tw9.fk_property = 152 Then - 'p82a'::text - When tw9.fk_property = 153 Then - 'p82b'::text - Else - tw9.fk_property::text - End, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) As time_span - From - tw9 - Group By - tw9.fk_project, - tw9.fk_temporal_entity -), -tw11 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw10 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw12 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw13 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw11 t1 - Left Join tw12 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw14 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t2.fk_entity = t1.pk_entity -And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw15 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw14 t1, - system.class_has_type_property t2 - Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) - And t1.fk_project Is Null - And t1.fk_property = t2.fk_property -Union -Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count -From - tw14 t3, - system.class_has_type_property t4 -Where (t3.fk_info_domain = Any (param_pk_entities) - Or t3.fk_info_range = Any (param_pk_entities)) -And t3.fk_project Is Not Null -And t3.fk_property = t4.fk_property -Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw16 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw13 t1 - Left Join tw15 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw16; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191223123045-war-update-down.sql b/server/db-migrate/migrations/sqls/20191223123045-war-update-down.sql deleted file mode 100644 index 349669f10..000000000 --- a/server/db-migrate/migrations/sqls/20191223123045-war-update-down.sql +++ /dev/null @@ -1,46 +0,0 @@ --- 3 -Drop Trigger after_api_class_upsert On data_for_history.api_class; - -Drop Trigger after_update_or_insert_of_class_label On projects.text_property; - --- 2 -Drop Trigger after_epr_upsert On projects.info_proj_rel; - -Create Trigger after_epr_upsert - After Insert - Or Update On projects.info_proj_rel For Each STATEMENT - Execute Procedure warehouse.after_info_proj_rel_upsert (); - --- 1 -Drop Schema war Cascade; - --- 0 -Create Or Replace View data_for_history.v_property As -Select - t1.dfh_pk_property As pk_property, - t1.dfh_is_inherited As is_inherited, - t1.dfh_property_domain As has_domain, - t1.dfh_domain_instances_min_quantifier As domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier As domain_instances_max_quantifier, - t1.dfh_property_range As has_range, - t1.dfh_range_instances_min_quantifier As range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier As range_instances_max_quantifier, - t1.dfh_identity_defining As identity_defining, - t1.dfh_is_has_type_subproperty As is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) As profiles -From - data_for_history.api_property t1 -Group By - t1.dfh_pk_property, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace; - diff --git a/server/db-migrate/migrations/sqls/20191223123045-war-update-up.sql b/server/db-migrate/migrations/sqls/20191223123045-war-update-up.sql deleted file mode 100644 index 857dcb91c..000000000 --- a/server/db-migrate/migrations/sqls/20191223123045-war-update-up.sql +++ /dev/null @@ -1,3016 +0,0 @@ --- 0 prepare workaround for missing is_has_type_subproperty in ontome api -Create Or Replace View data_for_history.v_property As With tw1 As ( - Select - t1.dfh_pk_property As pk_property, - t1.dfh_is_inherited As is_inherited, - t1.dfh_property_domain As has_domain, - t1.dfh_domain_instances_min_quantifier As domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier As domain_instances_max_quantifier, - t1.dfh_property_range As has_range, - t1.dfh_range_instances_min_quantifier As range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier As range_instances_max_quantifier, - t1.dfh_identity_defining As identity_defining, - t1.dfh_is_has_type_subproperty As is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) As profiles - From - data_for_history.api_property t1 - Group By - t1.dfh_pk_property, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace -) -Select - t1.pk_property, - t1.is_inherited, - t1.has_domain, - t1.domain_instances_min_quantifier, - t1.domain_instances_max_quantifier, - t1.has_range, - t1.range_instances_min_quantifier, - t1.range_instances_max_quantifier, - t1.identity_defining, - Case When (t2.pk_entity Is Not Null) Then - True - Else - t1.is_has_type_subproperty - End As is_has_type_subproperty, - t1.identifier_in_namespace, - t1.profiles -From - tw1 t1 - Left Join system.class_has_type_property t2 On t1.pk_property = t2.fk_property; - - --- 1 add schema war -/** -* ADD SCHEMA WAR START -**/ -SET check_function_bodies = false; - --- --- Name: war; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA war; - - --- --- Name: edge_target_type; Type: TYPE; Schema: war; Owner: - --- - -CREATE TYPE war.edge_target_type AS ENUM ( - 'text', - 'type' -); - - --- --- Name: node_id; Type: TYPE; Schema: war; Owner: - --- - -CREATE TYPE war.node_id AS ( - pk_entity integer, - fk_project integer -); - - --- --- Name: edge; Type: TABLE; Schema: war; Owner: - --- - -CREATE TABLE war.edge ( - fk_source integer, - fk_project integer, - fk_target integer, - target_provides war.edge_target_type, - ord_num_within_field integer, - field_order integer, - fk_role integer -); - --- --- Name: node; Type: TABLE; Schema: war; Owner: - --- - -CREATE TABLE war.node ( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - entity_type text, - own_entity_label text, - own_full_text text, - time_span jsonb, - first_second bigint, - last_second bigint, - own_entity_label_field_order integer -); - --- --- Name: enriched_node; Type: TABLE; Schema: war; Owner: - --- - -CREATE TABLE war.enriched_node ( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - class_label character varying, - entity_type text, - own_entity_label text, - own_full_text text, - time_span jsonb, - first_second bigint, - last_second bigint, - own_entity_label_field_order integer, - entity_label text, - fk_type integer, - type_label text, - full_text text, - ts_vector tsvector -); - - --- --- Name: entity_preview; Type: TABLE; Schema: war; Owner: - --- - -CREATE TABLE war.entity_preview ( - pk_entity integer, - fk_project integer, - project integer, - entity_type text, - fk_class integer, - class_label character varying, - entity_label text, - full_text text, - ts_vector tsvector, - type_label text, - fk_type integer, - time_span jsonb, - first_second bigint, - last_second bigint, - tmsp_last_modification timestamp with time zone -); - - --- --- Name: update_log; Type: TABLE; Schema: war; Owner: - --- - -CREATE TABLE war.update_log ( - pk_entity serial, - tmsp_update_begin timestamp without time zone, - tmsp_update_end timestamp without time zone -); - - --- --- Name: v_class_preview; Type: VIEW; Schema: war; Owner: - --- - -CREATE VIEW war.v_class_preview AS - WITH tw0 AS ( - SELECT project.pk_entity, - project.fk_language - FROM projects.project - UNION ALL - SELECT NULL::integer AS int4, - 18889 - ), tw1 AS ( - SELECT t2.fk_dfh_class AS fk_class, - t1.pk_entity AS fk_project, - t2.string AS label, - 1 AS rank, - 'project label'::text - FROM tw0 t1, - projects.text_property t2 - WHERE ((t1.pk_entity = t2.fk_project) AND (t2.fk_dfh_class IS NOT NULL) AND (t2.fk_language = t1.fk_language)) - UNION ALL - SELECT t2.fk_dfh_class AS fk_class, - t1.pk_entity AS fk_project, - t2.string AS label, - 2 AS rank, - 'default project label in default lang'::text - FROM tw0 t1, - projects.text_property t2 - WHERE ((375669 = t2.fk_project) AND (t2.fk_dfh_class IS NOT NULL) AND (t2.fk_language = t1.fk_language)) - UNION ALL - SELECT t3.fk_class, - t1.pk_entity AS fk_project, - t3.label, - 3 AS rank, - 'ontome label in default lang'::text - FROM tw0 t1, - information.language t2, - data_for_history.v_label t3 - WHERE ((t3.fk_class IS NOT NULL) AND ((t3.language)::bpchar = t2.iso6391) AND (t3.type = 'label'::text)) - UNION ALL - SELECT t2.fk_dfh_class AS fk_class, - t1.pk_entity AS fk_project, - t2.string AS label, - 4 AS rank, - 'default project label in en'::text - FROM tw0 t1, - projects.text_property t2 - WHERE ((375669 = t2.fk_project) AND (t2.fk_dfh_class IS NOT NULL) AND (t2.fk_language = 18889)) - UNION ALL - SELECT t3.fk_class, - t1.pk_entity AS fk_project, - t3.label, - 3 AS rank, - 'ontome label in en'::text - FROM tw0 t1, - data_for_history.v_label t3 - WHERE ((t3.fk_class IS NOT NULL) AND ((t3.language)::text = 'en'::text) AND (t3.type = 'label'::text)) - ) - SELECT DISTINCT ON (tw1.fk_project, tw1.fk_class) tw1.fk_class, - tw1.fk_project, - tw1.label - FROM tw1 - ORDER BY tw1.fk_project, tw1.fk_class, tw1.rank; - - --- --- Name: vm_statement; Type: MATERIALIZED VIEW; Schema: war; Owner: - --- - -CREATE MATERIALIZED VIEW war.vm_statement AS - WITH tw1 AS ( - SELECT t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - FROM (information.role t1 - LEFT JOIN LATERAL ( SELECT (count(info_proj_rel.pk_entity))::integer AS is_in_project_count - FROM projects.info_proj_rel - WHERE ((info_proj_rel.fk_entity = t1.pk_entity) AND (info_proj_rel.is_in_project = true)) - GROUP BY info_proj_rel.fk_entity) t2 ON (true)) - ) - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM tw1 t1, - projects.info_proj_rel t2 - WHERE ((t2.fk_entity = t1.pk_entity) AND (t2.is_in_project = true)) -UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM tw1 t1 - WHERE (t1.is_in_project_count > 0) - WITH NO DATA; - - --- --- Name: enriched_node enriched_node_unique; Type: CONSTRAINT; Schema: war; Owner: - --- - -ALTER TABLE ONLY war.enriched_node - ADD CONSTRAINT enriched_node_unique UNIQUE (pk_entity, project); - - --- --- Name: node entity_preview_unique; Type: CONSTRAINT; Schema: war; Owner: - --- - -ALTER TABLE ONLY war.node - ADD CONSTRAINT entity_preview_unique UNIQUE (pk_entity, project); - - --- --- Name: entity_preview war_entity_preview_unique; Type: CONSTRAINT; Schema: war; Owner: - --- - -ALTER TABLE ONLY war.entity_preview - ADD CONSTRAINT war_entity_preview_unique UNIQUE (pk_entity, project); - - - - --- --- Name: after_info_proj_rel_upsert(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.after_info_proj_rel_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - pg_notify('project_updated', 'true'); - RETURN NEW; -END; -$$; - - --- --- Name: do_updates_for_difference_since(timestamp without time zone); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.do_updates_for_difference_since(tmsp timestamp without time zone) RETURNS void - LANGUAGE plpgsql - AS $$ -Declare - t_row record; -Begin - For t_row In ( - /********** - * Selects the pk_entities of nodes that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp), - -- select fk_entity and fk_project of all affected persistent_items and temporal_entities - tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity), - tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project) - /******* - * Perform the updates on nodes - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - war.nodes__upsert_some (t_row.pk_entities, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.nodes__delete_some (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; - - - For t_row In ( - - /********** - * Selects the pk_roles of edges that need to be updated. - * - ***********/ - - Select - array_agg(t1.fk_entity) as fk_roles, - t1.fk_project, - t1.is_in_project - From - projects.info_proj_rel t1, - information.role t2 - Where - t1.tmsp_last_modification::timestamp >= tmsp - AND t1.fk_entity = t2.pk_entity - Group By - t1.fk_project, - t1.is_in_project - ) - /******* - * Perform the updates on nodes - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - war.edges__upsert_some (t_row.fk_roles, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.edges__delete_some (t_row.fk_roles, - t_row.fk_project); - End If; - End Loop; -End; -$$; - - --- --- Name: do_updates_for_difference_since2(timestamp without time zone); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.do_updates_for_difference_since2(tmsp timestamp without time zone) RETURNS SETOF war.node_id - LANGUAGE plpgsql - AS $$ -Declare - t_row record; - node_ids war.node_id[]; -Begin - DROP TABLE IF EXISTS to_enrich; - CREATE TEMP TABLE to_enrich( - pk_entity int, - fk_project int - ); - - - DROP TABLE IF EXISTS temp_node_changes; - CREATE TEMP TABLE temp_node_changes As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp), - -- select fk_entity and fk_project of all affected persistent_items and temporal_entities - tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity), - tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project; - - - DROP TABLE IF EXISTS temp_edge_changes; - CREATE TEMP TABLE temp_edge_changes As - /********** - * Selects the pk_roles of edges that need to be updated or deleted - ***********/ - Select - array_agg(t1.fk_entity) as fk_roles, - t1.fk_project, - t1.is_in_project - From - projects.info_proj_rel t1, - information.role t2 - Where - t1.tmsp_last_modification::timestamp >= tmsp - AND t1.fk_entity = t2.pk_entity - Group By - t1.fk_project, - t1.is_in_project; - - /******* - * Perform the updates on nodes - *******/ - For t_row In (SELECT * FROM temp_node_changes) - Loop - If (t_row.is_in_project = True) Then - - INSERT INTO to_enrich - SELECT pk_entity, fk_project - FROM war.nodes__upsert_some (t_row.pk_entities, t_row.fk_project); - - ELSEIF (t_row.is_in_project = False) Then - - Perform - war.nodes__delete_some (t_row.pk_entities, t_row.fk_project); - - End If; - End Loop; - - /******* - * Perform the updates on edges - *******/ - For t_row In (SELECT * FROM temp_edge_changes) - Loop - If (t_row.is_in_project = True) Then - - INSERT INTO to_enrich - SELECT fk_source, fk_project - FROM war.edges__upsert_some(t_row.fk_roles, t_row.fk_project); - - ELSEIF (t_row.is_in_project = False) Then - - INSERT INTO to_enrich - SELECT fk_source, fk_project - FROM war.edges__delete_some(t_row.fk_roles, t_row.fk_project); - - End If; - End Loop; - - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - - -- Step 1: get the keys of nodes that need enrichment: - -- - source node keys of updated, inserted or deleted edges - -- - keys of updated or inserted nodes - -- This is done above in the loops - - /******* - * REMARK: THE FOLLOWING LOOP HAS UNEXPECTED SIDE EFFECTS! - * IT DELETES THE LABELS OF SOME ENTITIES - *******/ - - -- start a loop that runs while to_enrich is not empty - --WHILE (SELECT count(*) > 0 FROM to_enrich) - --LOOP - -- -- get the war.node_id[] from to_enrich - -- SELECT array_agg(ROW(pk_entity, fk_project)::war.node_id) INTO node_ids - -- FROM ( - -- SELECT DISTINCT pk_entity,fk_project - -- FROM to_enrich - -- ) x; - -- - -- RAISE NOTICE 'node_ids %', node_ids; - -- - -- -- empty table to_enrich - -- DELETE FROM to_enrich; - -- - -- -- enrich the nodes and - -- -- query keys of nodes that depend on changed nodes - -- -- put those source nodes in to_enrich - -- INSERT INTO to_enrich - -- SELECT DISTINCT t1.fk_source, t1.fk_project - -- FROM - -- war.edge t1, - -- ( - -- -- enrich the nodes - -- SELECT pk_entity, fk_project - -- FROM war.enriched_nodes__enrich_some(node_ids) - -- ) t2 - -- WHERE t1.fk_target = t2.pk_entity - -- AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project; - -- - --END LOOP; - - - /******* - * update the entity_preview - *******/ - -- todo - RETURN QUERY SELECT DISTINCT * FROM to_enrich; -End; - -$$; - - --- --- Name: edges__create_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.edges__create_all() RETURNS SETOF war.edge - LANGUAGE sql - AS $$ - WITH tw1 AS ( - ---- outgoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_temporal_entity as fk_source, - t1.fk_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_range as ord_num_within_field, - t1.is_in_project_count, - CASE WHEN t5.is_has_type_subproperty THEN 'type'::war.edge_target_type - ELSE 'text'::war.edge_target_type - END as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_domain = t3.fk_class - AND t5.has_range = t4.fk_class - UNION ALL - ---- ingoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_entity as fk_source, - t1.fk_temporal_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_domain as ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity, fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_range = t3.fk_class - AND t5.has_domain = t4.fk_class - - ) - SELECT - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - WHEN project_has_own_field_order = true THEN field_order_of_project - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1 - UNION ALL - SELECT - fk_source, - NULL::INT AS fk_project, - fk_target, - target_provides, - is_in_project_count as ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1; - -$$; - - --- --- Name: edges__create_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.edges__create_some(param_pk_roles integer[], param_fk_project integer) RETURNS SETOF war.edge - LANGUAGE sql - AS $$ -WITH tw1 AS ( - ---- outgoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_temporal_entity as fk_source, - t1.fk_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_range as ord_num_within_field, - t1.is_in_project_count, - CASE WHEN t5.is_has_type_subproperty THEN 'type'::war.edge_target_type - ELSE 'text'::war.edge_target_type - END as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = ANY(param_pk_roles) - AND t2.fk_project = param_fk_project - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_domain = t3.fk_class - AND t5.has_range = t4.fk_class - UNION ALL - ---- ingoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_entity as fk_source, - t1.fk_temporal_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_domain as ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity, fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = ANY(param_pk_roles) - AND t2.fk_project = param_fk_project - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_range = t3.fk_class - AND t5.has_domain = t4.fk_class - - ) - SELECT - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - WHEN project_has_own_field_order = true THEN field_order_of_project - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1 - UNION ALL - SELECT - fk_source, - NULL::INT AS fk_project, - fk_target, - target_provides, - is_in_project_count as ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1; -$$; - - --- --- Name: edges__delete_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.edges__delete_some(param_pk_roles integer[], param_fk_project integer) RETURNS SETOF war.edge - LANGUAGE sql - AS $$ - - DELETE - FROM war.edge - WHERE fk_role = ANY(param_pk_roles) - AND ( - fk_project IS NULL - OR - fk_project = param_fk_project - ) - RETURNING *; - -$$; - - --- --- Name: edges__upsert_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.edges__upsert_some(param_pk_roles integer[], param_fk_project integer) RETURNS SETOF war.edge - LANGUAGE sql - AS $$ - - SELECT war.edges__delete_some(param_pk_roles, param_fk_project); - INSERT INTO war.edge - SELECT * FROM war.edges__create_some(param_pk_roles, param_fk_project) - RETURNING *; - -$$; - - - --- --- Name: enriched_nodes__create_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__create_all() RETURNS SETOF war.enriched_node - LANGUAGE sql - AS $$ - - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t2.label as class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t1.time_span, - t1.first_second, - t1.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label AS entity_label, - NULL:: integer fk_type, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - war.node t1, - war.v_class_preview t2 - WHERE t1.fk_class = t2.fk_class - AND t1.fk_project is not distinct from t2.fk_project; - -$$; - - --- --- Name: enriched_nodes__create_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__create_some(param_pk_entities integer[], param_fk_project integer) RETURNS SETOF war.enriched_node - LANGUAGE sql - AS $$ - - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t2.label as class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t1.time_span, - t1.first_second, - t1.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label AS entity_label, - NULL:: integer fk_type, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - war.nodes__create_some(param_pk_entities, param_fk_project) t1, - war.v_class_preview t2 - WHERE t1.fk_class = t2.fk_class - AND t1.fk_project is not distinct from t2.fk_project; - - -$$; - - --- --- Name: enriched_nodes__enrich(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__enrich() RETURNS void - LANGUAGE plpgsql - AS $$ -BEGIN - - perform war.enriched_nodes__enrich_entity_label(); - perform war.enriched_nodes__enrich_full_text(); - perform war.enriched_nodes__enrich_type_label(); - -END; -$$; - - --- --- Name: enriched_nodes__enrich_entity_label(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_entity_label() RETURNS void - LANGUAGE plpgsql - AS $$ -DECLARE - needs_update boolean; -BEGIN - needs_update = true; - - ---------- entity label completion ------------ - WHILE ( needs_update = true) - LOOP - -- fill entity label - WITH tw0 AS ( - SELECT t1.pk_entity, t1.fk_project, t1.entity_label old_l, t3.entity_label, t1.own_entity_label_field_order, t2.field_order - FROM - war.enriched_node t1 - JOIN ( - SELECT DISTINCT ON (fk_source, fk_project) - * - FROM war.edge j1 - ORDER BY fk_source, fk_project, j1.field_order asc, j1.ord_num_within_field asc - ) t2 ON - coalesce(t1.own_entity_label_field_order,10000) > coalesce(t2.field_order,10000) - AND t1.pk_entity = t2.fk_source - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - JOIN LATERAL ( - -- join the target enriched_node, in project variant, else in repo variant - SELECT DISTINCT ON (j2.pk_entity) - j2.entity_label--, j2.pk_entity, j2.fk_project - FROM - ( - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - UNION ALL - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t3.fk_project IS NULL - ) j2 - ) t3 ON - t1.entity_label IS DISTINCT FROM t3.entity_label - - ), - tw1 AS ( - UPDATE - war.enriched_node t1 - SET - entity_label = t2.entity_label - FROM - tw0 t2 - WHERE t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - RETURNING * - ) - SELECT count(*) > 0 into needs_update - FROM tw1; - END LOOP; - -END; -$$; - - --- --- Name: enriched_nodes__enrich_full_text(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__enrich_full_text() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN ------------ create full text --------- -WITH tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.entity_label, - t1.class_label, - t1.type_label, - array_to_string(array_remove(ARRAY[ - t1.class_label, - t1.type_label, - t1.own_full_text, - string_agg(t3.own_full_text, ', ' ORDER BY t2.field_order asc, t2.ord_num_within_field), - t1.entity_label - ], null), ', ') as full_text - FROM - war.enriched_node t1, - war.edge t2, - war.enriched_node t3 - WHERE - t1.pk_entity = t2.fk_source AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t2.fk_target = t3.pk_entity AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - -- todo: join target nodes of repo too, order by fk_project, select distinct on fk_source, fk_property?, fk_target - GROUP BY - t1.pk_entity - , t1.fk_project - , t1.class_label - , t1.type_label - , t1.entity_label - , t1.own_full_text -) -UPDATE - war.enriched_node t1 -SET - full_text = t2.full_text, - ----------- create tsvector ---------- - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t2.type_label, t2.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t2.full_text, '')), 'C') - ) -FROM - tw1 t2 -WHERE - t1.pk_entity = t2.pk_entity -AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project -AND - t1.full_text IS DISTINCT FROM t2.full_text; - - - RETURN TRUE; -END; -$$; - - --- --- Name: enriched_nodes__enrich_some(war.node_id[]); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__enrich_some(node_ids war.node_id[]) RETURNS SETOF war.enriched_node - LANGUAGE sql - AS $$ - - WITH tw1 AS( - SELECT t1.* - FROM war.enriched_node t1, - unnest(node_ids) t2 - WHERE t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - ), - -- select entity_label - tw2 AS ( - SELECT t1.pk_entity, t1.fk_project, t1.entity_label old_l, t3.entity_label, t1.own_entity_label_field_order, t2.field_order - FROM - tw1 t1 - JOIN LATERAL ( - SELECT DISTINCT ON (fk_source, fk_project) - * - FROM war.edge j1 - WHERE - coalesce(t1.own_entity_label_field_order,10000) > coalesce(j1.field_order,10000) - AND - t1.pk_entity = j1.fk_source - AND t1.fk_project IS NOT DISTINCT FROM j1.fk_project - ORDER BY fk_source, fk_project, j1.field_order asc, j1.ord_num_within_field asc - ) t2 ON TRUE - JOIN LATERAL ( - -- join the target enriched_node, in project variant, else in repo variant - SELECT DISTINCT ON (j2.pk_entity) - j2.entity_label, j2.pk_entity--, j2.fk_project - FROM - ( - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - UNION ALL - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t3.fk_project IS NULL - ) j2 - ) t3 ON TRUE - ), - -- select type_label - tw3 AS ( - SELECT t1.pk_entity, t1.fk_project, t3.entity_label type_label, t3.pk_entity fk_type - FROM - tw1 t1 - JOIN LATERAL ( - SELECT * - FROM war.edge j1 - WHERE j1.target_provides = 'type' - AND j1.fk_source = t1.pk_entity - AND j1.fk_project IS NOT DISTINCT FROM t1.fk_project - ORDER BY j1.field_order asc, j1.ord_num_within_field - LIMIT 1 - ) t2 ON TRUE - JOIN LATERAL ( - -- join the target enriched_node, in project variant, else in repo variant - SELECT DISTINCT ON (j2.pk_entity) - j2.entity_label, j2.pk_entity --, j2.fk_project - FROM - ( - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - UNION ALL - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t3.fk_project IS NULL - ) j2 - ) t3 ON true - ), - -- select full_text - tw4 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t4.entity_label, - t1.class_label, - t5.type_label, - array_to_string(array_remove(ARRAY[ - t1.class_label, - t5.type_label, - t1.own_full_text, - string_agg(t3.own_full_text, ', ' ORDER BY t2.field_order asc, t2.ord_num_within_field), - t4.entity_label - ], null), ', ') as full_text - FROM - tw1 t1 - JOIN war.edge t2 ON t1.pk_entity = t2.fk_source AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - JOIN war.enriched_node t3 ON t2.fk_target = t3.pk_entity AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - LEFT JOIN tw2 t4 ON t1.pk_entity = t4.pk_entity AND t1.fk_project IS NOT DISTINCT FROM t4.fk_project - LEFT JOIN tw3 t5 ON t1.pk_entity = t5.pk_entity AND t1.fk_project IS NOT DISTINCT FROM t5.fk_project - GROUP BY - t1.pk_entity - , t1.fk_project - , t1.class_label - , t5.type_label - , t4.entity_label - , t1.own_full_text - ), - -- left join entity_label, full_text, fk_type and type_label, where at least one needs update - tw5 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.entity_label old_label, t2.entity_label, - t1.fk_type old_fk_type, t2.fk_type, - t1.type_label old_type_label, t3.type_label, - t1.full_text old_full_text, t4.full_text - FROM tw1 t1 - LEFT JOIN tw2 t2 - ON - t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - LEFT JOIN tw3 t3 - ON - t1.pk_entity = t3.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t3.fk_project - LEFT JOIN tw4 t4 - ON - t1.pk_entity = t4.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t4.fk_project - WHERE ( - t1.entity_label IS DISTINCT FROM t2.entity_label - OR - t1.type_label IS DISTINCT FROM t3.type_label - OR - t1.fk_type IS DISTINCT FROM t3.fk_type - OR - t1.full_text IS DISTINCT FROM t4.full_text - ) - ) - UPDATE - war.enriched_node t1 - SET - entity_label = t2.entity_label, - fk_type = t2.fk_type, - type_label = t2.type_label, - full_text = t2.full_text, - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t2.type_label, t1.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t2.full_text, '')), 'C') - ) - FROM - tw5 t2 - WHERE t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - RETURNING t1.*; - - -$$; - - --- --- Name: enriched_nodes__enrich_type_label(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.enriched_nodes__enrich_type_label() RETURNS void - LANGUAGE plpgsql - AS $$ -DECLARE - needs_update boolean; -BEGIN - needs_update = true; - - ---------- type label completion ------------ - WHILE ( needs_update = true) - LOOP - -- fill type label - WITH tw0 AS ( - SELECT t1.pk_entity, t1.fk_project, t3.entity_label type_label, t3.pk_entity fk_type - FROM - war.enriched_node t1 - JOIN LATERAL ( - SELECT * - FROM war.edge j1 - WHERE j1.target_provides = 'type' - AND j1.fk_source = t1.pk_entity - AND j1.fk_project IS NOT DISTINCT FROM t1.fk_project - ORDER BY j1.field_order asc, j1.ord_num_within_field - LIMIT 1 - ) t2 ON TRUE - JOIN LATERAL ( - -- join the target enriched_node, in project variant, else in repo variant - SELECT DISTINCT ON (j2.pk_entity) - j2.entity_label, j2.pk_entity--, j2.fk_project - FROM - ( - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - UNION ALL - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t3.fk_project IS NULL - ) j2 - ) t3 ON - ( - t1.type_label IS DISTINCT FROM t3.entity_label - OR - t1.fk_type IS DISTINCT FROM t3.pk_entity - ) - - ), - tw1 AS ( - UPDATE - war.enriched_node t1 - SET - type_label = t2.type_label, - fk_type = t2.fk_type - FROM - tw0 t2 - WHERE t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - RETURNING t1.*, t2.type_label - ) - SELECT count(*) > 0 into needs_update - FROM tw1; - END LOOP; - -END; -$$; - - --- --- Name: entity_preview__add_missing(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_preview__add_missing() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - war.enriched_node - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - war.entity_preview -) INSERT INTO war.entity_preview ( - pk_entity, fk_project, project, entity_type, fk_class, class_label, entity_label, full_text, ts_vector, type_label, fk_type, time_span, first_second, last_second) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - FROM - war.enriched_node t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__remove_superfluous(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_preview__remove_superfluous() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in enriched_node, to be deleted' AS note - FROM - war.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in enriched_node, to be deleted' AS note - FROM - war.enriched_node -) DELETE FROM war.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__update_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_preview__update_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - war.entity_preview__add_missing (); - PERFORM - war.entity_preview__remove_superfluous (); - PERFORM - war.entity_preview__update_modified (); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__update_class_labels(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_preview__update_class_labels() RETURNS void - LANGUAGE plpgsql - AS $$ -BEGIN - -WITH tw1 AS ( - SELECT fk_class, fk_project, class_label - FROM - war.enriched_node t1 - GROUP BY - fk_class, fk_project, class_label -), tw2 AS ( - select - t2.* - FROM - tw1 t1, - war.v_class_preview t2 - WHERE - t1.fk_class = t2.fk_class - AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.class_label IS DISTINCT FROM t2.label -) -UPDATE war.enriched_node t1 -SET class_label = t2.label -FROM - tw2 t2 -WHERE -t1.fk_class = t2.fk_class -AND -t1.fk_project IS NOT DISTINCT FROM t2.fk_project; - -PERFORM war.enriched_nodes__enrich_full_text(); -PERFORM war.entity_preview__update_modified(); - - -END; -$$; - - --- --- Name: entity_preview__update_modified(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_preview__update_modified() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - entity_type, - fk_class, - class_label, - entity_label, - full_text, - ts_vector, - type_label, - fk_type, - time_span, - first_second, - last_second, - 'different from war.enriched_node, to be updated' AS note - FROM - war.enriched_node - EXCEPT - SELECT - pk_entity, - fk_project, - project, - entity_type, - fk_class, - class_label, - entity_label, - full_text, - ts_vector, - type_label, - fk_type, - time_span, - first_second, - last_second, - 'different from war.enriched_node, to be updated' AS note - FROM - war.entity_preview - ) - UPDATE - war.entity_preview t1 - SET - entity_type = tw1.entity_type, - fk_class = tw1.fk_class, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - type_label = tw1.type_label, - fk_type = tw1.fk_type, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - RETURN TRUE; -END; -$$; - - --- --- Name: entity_previews__notify_upsert(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.entity_previews__notify_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ -DECLARE - notification text; -BEGIN - - - SELECT DISTINCT tmsp_last_modification::text into notification - FROM new_table - WHERE tmsp_last_modification is not null - LIMIT 1; - - if notification is not null then - PERFORM pg_notify('entity_previews_updated'::text, notification); - end if; - - -RETURN NEW; -END; -$$; - - --- --- Name: nodes__create_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.nodes__create_all() RETURNS SETOF war.node - LANGUAGE sql - AS $$ - - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - -10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - AND t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - CASE t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) as field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g' ) As string - From - tw2 t1 - -- join outgoing roles - Left Join tw5 t2 - On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 - On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 - On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 AS ( - select distinct on (fk_project, pk_entity) - fk_project, - pk_entity, - string as own_entity_label, - field_order as own_entity_label_field_order - from tw7 - where string is not null - ORDER BY fk_project, pk_entity, field_order asc, ord_num asc -), --- own_full_text per project -tw9 AS ( - select - fk_project, - pk_entity, - string_agg(string, '; ') as own_full_text - from tw7 - where string is not null - GROUP BY fk_project, pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 AS ( - select distinct on (pk_entity) - null::int as fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - from tw8 - group by pk_entity, own_entity_label, own_entity_label_field_order - ORDER BY pk_entity, count(fk_project) desc -), --- own_full_text per repo -tw11 AS ( - select - null::int as fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') as own_full_text - FROM ( - select pk_entity, string - from tw7 - where string is not null - GROUP BY pk_entity, string - ORDER BY count(pk_entity) desc - ) as t1 - GROUP BY t1.pk_entity -), --- project variant -tw12 AS ( - Select distinct on (t1.pk_entity, t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - LEFT JOIN tw8 t2 - ON t2.pk_entity = t1.pk_entity - AND t2.fk_project = t1.fk_project - LEFT JOIN tw9 t3 - ON t3.pk_entity = t1.pk_entity - AND t3.fk_project = t1.fk_project -), --- repo variant -tw13 AS ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - LEFT JOIN tw10 t2 ON t2.pk_entity = t1.pk_entity - LEFT JOIN tw11 t3 ON t3.pk_entity = t1.pk_entity -), -tw14 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - FROM tw12 t1 - UNION ALL - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - FROM tw13 t1 -), -/** -* Add time spans -*/ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ALL - ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw15 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity -) - -/* -* time spans added -**/ -select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project,0), - t1.fk_class, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order -from tw14 t1 -LEFT JOIN tw17 t2 - ON t1.pk_entity = t2.fk_temporal_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - -$$; - - --- --- Name: nodes__create_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.nodes__create_some(param_pk_entities integer[], param_fk_project integer) RETURNS SETOF war.node - LANGUAGE sql - AS $$ - - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - AND t1.pk_entity = ANY(param_pk_entities) - And t1.pk_entity = t2.fk_entity - AND t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - AND t1.pk_entity = ANY(param_pk_entities) - And t1.pk_entity = t2.fk_entity - AND t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - -10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - AND t1.fk_temporal_entity = ANY(param_pk_entities) - AND t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - CASE t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = ANY(param_pk_entities) - AND t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) as field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g' ) As string - From - tw1 t1 - -- join outgoing roles - Left Join tw5 t2 - On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 - On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 - On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 AS ( - select distinct on (fk_project, pk_entity) - fk_project, - pk_entity, - string as own_entity_label, - field_order as own_entity_label_field_order - from tw7 - where string is not null - ORDER BY fk_project, pk_entity, field_order asc, ord_num asc -), --- own_full_text per project -tw9 AS ( - select - fk_project, - pk_entity, - string_agg(string, '; ') as own_full_text - from tw7 - where string is not null - GROUP BY fk_project, pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 AS ( - select distinct on (pk_entity) - null::int as fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - from tw8 - group by pk_entity, own_entity_label, own_entity_label_field_order - ORDER BY pk_entity, count(fk_project) desc -), --- own_full_text per repo -tw11 AS ( - select - null::int as fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') as own_full_text - FROM ( - select pk_entity, string - from tw7 - where string is not null - GROUP BY pk_entity, string - ORDER BY count(pk_entity) desc - ) as t1 - GROUP BY t1.pk_entity -), --- project variant -tw12 AS ( - Select distinct on (t1.pk_entity, t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - LEFT JOIN tw8 t2 - ON t2.pk_entity = t1.pk_entity - AND t2.fk_project = t1.fk_project - AND t2.fk_project = param_fk_project - LEFT JOIN tw9 t3 - ON t3.pk_entity = t1.pk_entity - AND t3.fk_project = t1.fk_project - AND t3.fk_project = param_fk_project -), --- repo variant -tw13 AS ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - LEFT JOIN tw10 t2 ON t2.pk_entity = t1.pk_entity - LEFT JOIN tw11 t3 ON t3.pk_entity = t1.pk_entity -), -tw14 AS ( - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - FROM tw12 t1 - UNION ALL - SELECT - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - FROM tw13 t1 -), -/** -* Add time spans -*/ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1 - JOIN LATERAL ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - WHERE j1.pk_entity = t1.fk_entity - ) t2 ON - t1.fk_temporal_entity = ANY(param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity, - projects.info_proj_rel t3 - WHERE t1.pk_entity = t3.fk_entity - AND t3.is_in_project = True - Union ALL - ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - JOIN LATERAL ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - WHERE j1.pk_entity = t1.fk_entity - ) t2 ON - t1.fk_temporal_entity = ANY(param_pk_entities) - AND t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity -) - -/* -* time spans added -**/ -select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project,0), - t1.fk_class, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order -from tw14 t1 -LEFT JOIN tw17 t2 - ON t1.pk_entity = t2.fk_temporal_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - -$$; - - --- --- Name: nodes__delete_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.nodes__delete_some(param_pk_entities integer[], param_fk_project integer) RETURNS SETOF war.node - LANGUAGE sql - AS $$ - - /** - * Delete the enriched_nodes with param_pk_entities and - * fk_project is param_fk_project or null (repo) - */ - DELETE FROM war.enriched_node - WHERE pk_entity = ANY(param_pk_entities) - AND ( - fk_project IS NOT DISTINCT FROM param_fk_project OR - fk_project IS NULL - ); - - - /** - * Delete the nodes with param_pk_entities and - * fk_project is param_fk_project or null (repo) - */ - DELETE FROM war.node - WHERE - pk_entity = ANY(param_pk_entities) - AND ( - fk_project IS NOT DISTINCT FROM param_fk_project OR - fk_project IS NULL - ) - RETURNING *; - -$$; - - --- --- Name: nodes__upsert_some(integer[], integer); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.nodes__upsert_some(param_pk_entities integer[], param_fk_project integer) RETURNS SETOF war.node - LANGUAGE sql - AS $$ - -- delete nodes and enriched_nodes - SELECT war.nodes__delete_some(param_pk_entities, param_fk_project); - - INSERT INTO war.enriched_node - SELECT * FROM war.enriched_nodes__create_some(param_pk_entities, param_fk_project); - - INSERT INTO war.node - SELECT * FROM war.nodes__create_some(param_pk_entities, param_fk_project) - RETURNING *; - -$$; - - --- --- Name: nodes_and_edges__update_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.nodes_and_edges__update_all() RETURNS void - LANGUAGE sql - AS $$ - - DELETE FROM war.node; - DELETE FROM war.edge; - DELETE FROM war.enriched_node; - - INSERT INTO war.node - SELECT * FROM war.nodes__create_all(); - - INSERT INTO war.edge - SELECT * FROM war.edges__create_all(); - - INSERT INTO war.enriched_node - SELECT * FROM war.enriched_nodes__create_all(); - -$$; - - --- --- Name: notify__need_to_check_class_labels(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.notify__need_to_check_class_labels() RETURNS trigger - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM pg_notify('need_to_check_class_labels', 'check for updates'); -RETURN NULL; -END; -$$; - - --- --- Name: updater(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.updater() RETURNS boolean - LANGUAGE plpgsql - AS $$ -Declare - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the begin of the last update - */ - Select - tmsp_update_begin Into last_war_update - From - war.update_log - Order By - pk_entity Desc - Limit 1; - - -- if the update_log is empty - If last_war_update Is Null Then - - -- update the whole warehouse (this will also add a record in update_log) - PERFORM war.warehouse_update_all(); - - --Return true for indicating that tehere has been an update - RETURN true; - - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - If (last_project_modification > last_war_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - war.do_updates_for_difference_since (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$$; - - --- --- Name: warehouse_update_all(); Type: FUNCTION; Schema: war; Owner: - --- - -CREATE FUNCTION war.warehouse_update_all() RETURNS void - LANGUAGE plpgsql - AS $$ -DECLARE - pk_update bigint; -Begin - - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - PERFORM war.nodes_and_edges__update_all(); - PERFORM war.enriched_nodes__enrich(); - PERFORM war.entity_preview__update_all(); - - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - -End; -$$; - --- --- Name: edge_fk_project_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX edge_fk_project_idx ON war.edge USING btree (fk_project); - - --- --- Name: edge_fk_source_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX edge_fk_source_idx ON war.edge USING btree (fk_source); - - --- --- Name: edge_fk_target_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX edge_fk_target_idx ON war.edge USING btree (fk_target); - - --- --- Name: edge_priority_of_text_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX edge_priority_of_text_idx ON war.edge USING btree (ord_num_within_field); - - --- --- Name: enriched_node_class_label_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_class_label_idx ON war.enriched_node USING btree (class_label); - - --- --- Name: enriched_node_entity_label_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_entity_label_idx ON war.enriched_node USING btree (entity_label); - - --- --- Name: enriched_node_entity_type_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_entity_type_idx ON war.enriched_node USING btree (entity_type); - - --- --- Name: enriched_node_fk_class_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_fk_class_idx ON war.enriched_node USING btree (fk_class); - -CREATE INDEX enriched_node_fk_type_idx ON war.enriched_node USING btree (fk_type); - - --- --- Name: enriched_node_fk_project_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_fk_project_idx ON war.enriched_node USING btree (fk_project); - - --- --- Name: enriched_node_full_text_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_full_text_idx ON war.enriched_node USING btree (full_text); - - --- --- Name: enriched_node_own_entity_label_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_own_entity_label_idx ON war.enriched_node USING btree (own_entity_label); - - --- --- Name: enriched_node_own_entity_label_idx1; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_own_entity_label_idx1 ON war.enriched_node USING btree (own_entity_label); - - --- --- Name: enriched_node_own_full_text_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_own_full_text_idx ON war.enriched_node USING btree (own_full_text); - - --- --- Name: enriched_node_pk_entity_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_pk_entity_idx ON war.enriched_node USING btree (pk_entity); - - --- --- Name: enriched_node_type_label_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX enriched_node_type_label_idx ON war.enriched_node USING btree (type_label); - - --- --- Name: entity_preview_entity_label_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX entity_preview_entity_label_idx ON war.entity_preview USING btree (entity_label); - - --- --- Name: entity_preview_full_text_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX entity_preview_full_text_idx ON war.entity_preview USING btree (full_text); - - --- --- Name: entity_preview_pk_entity_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX entity_preview_pk_entity_idx ON war.entity_preview USING btree (pk_entity); - - --- --- Name: vm_statement_fk_entity_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX vm_statement_fk_entity_idx ON war.vm_statement USING btree (fk_entity); - - --- --- Name: vm_statement_fk_project_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX vm_statement_fk_project_idx ON war.vm_statement USING btree (fk_project); - - --- --- Name: vm_statement_fk_property_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX vm_statement_fk_property_idx ON war.vm_statement USING btree (fk_property); - - --- --- Name: vm_statement_fk_temporal_entity_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX vm_statement_fk_temporal_entity_idx ON war.vm_statement USING btree (fk_temporal_entity); - - --- --- Name: vm_statement_pk_entity_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE INDEX vm_statement_pk_entity_idx ON war.vm_statement USING btree (pk_entity); - - --- --- Name: vm_statement_pk_entity_project_idx; Type: INDEX; Schema: war; Owner: - --- - -CREATE UNIQUE INDEX vm_statement_pk_entity_project_idx ON war.vm_statement USING btree (pk_entity, project); - - --- --- Name: entity_preview after_insert_on_entity_preview; Type: TRIGGER; Schema: war; Owner: - --- - -CREATE TRIGGER after_insert_on_entity_preview AFTER INSERT ON war.entity_preview REFERENCING NEW TABLE AS new_table FOR EACH STATEMENT EXECUTE PROCEDURE war.entity_previews__notify_upsert(); - - --- --- Name: entity_preview after_update_on_entity_preview; Type: TRIGGER; Schema: war; Owner: - --- - -CREATE TRIGGER after_update_on_entity_preview AFTER UPDATE ON war.entity_preview REFERENCING NEW TABLE AS new_table FOR EACH STATEMENT EXECUTE PROCEDURE war.entity_previews__notify_upsert(); - - --- --- Name: entity_preview last_modification_tmsp; Type: TRIGGER; Schema: war; Owner: - --- - -CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON war.entity_preview FOR EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification(); - -/** -* ADD SCHEMA WAR END -**/ - --- 2 -Drop Trigger after_epr_upsert On projects.info_proj_rel; - -Create Trigger after_epr_upsert - After Insert - Or Update On projects.info_proj_rel For Each STATEMENT - Execute Procedure war.after_info_proj_rel_upsert (); - --- 3 Triggers for notifying need for updating class labels -Create Trigger after_api_class_upsert - After Insert - Or Update On data_for_history.api_class For Each STATEMENT - Execute Procedure war.notify__need_to_check_class_labels (); - -Create Trigger after_update_or_insert_of_class_label - After Insert - Or Update On projects.text_property For Each Row - When (new.fk_dfh_class Is Not Null) - Execute Procedure war.notify__need_to_check_class_labels (); - - --- -- 3 create warehouse data --- SELECT war.warehouse_update_all(); diff --git a/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-down.sql b/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-down.sql deleted file mode 100644 index 29c7a20bb..000000000 --- a/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-down.sql +++ /dev/null @@ -1 +0,0 @@ --- NO WAY BACK diff --git a/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-up.sql b/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-up.sql deleted file mode 100644 index 04236af09..000000000 --- a/server/db-migrate/migrations/sqls/20191227215440-inf-d-migrate-has-type-to-role-up.sql +++ /dev/null @@ -1,35 +0,0 @@ --- create all the hasType roles, with former pk_entity of entity_association in notes -Insert Into information.role (fk_property, fk_temporal_entity, fk_entity, notes) -Select - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.pk_entity::text -From - information.entity_association t1, - system.class_has_type_property t2 -Where - t1.fk_property = t2.fk_property; - --- update all the info_proj_rels to point to new role -Update - projects.info_proj_rel t0 -Set - fk_entity = t1.pk_entity -From - information.role t1, - system.class_has_type_property t2 -Where - t0.fk_entity = t1.notes::int - And t1.fk_property = t2.fk_property; - --- delete the entity_associations -Delete From information.entity_association -Where pk_entity In ( - Select - t1.pk_entity - From - information.entity_association t1, - system.class_has_type_property t2 - Where - t1.fk_property = t2.fk_property) diff --git a/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-down.sql b/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-down.sql deleted file mode 100644 index f162e6322..000000000 --- a/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-down.sql +++ /dev/null @@ -1,3143 +0,0 @@ --- 1 --- 4 add schema warehouse -/** -* ADD SCHEMA WAREHOUSE START -**/ -SET check_function_bodies = false; - --- --- Name: warehouse; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA warehouse; - - --- --- Name: after_info_proj_rel_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.after_info_proj_rel_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - pg_notify('queue_updated', 'true'); - RETURN NEW; -END; -$$; - - --- --- Name: do_updates_for_time_after(timestamp without time zone); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.do_updates_for_time_after(tmsp timestamp without time zone) RETURNS void - LANGUAGE plpgsql - AS $$ -Declare - t_row record; -Begin - For t_row In ( - /********** - * Selects the pk_entities that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp), - -- select fk_entity and fk_project of all affected persistent_items and temporal_entities - tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_domain As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of entity_associations where info_proj_rel changed - Select - t1.fk_info_range As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.entity_association t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity), - tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project) - /******* - * Perform the updates on entity_preview_non_recursive - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - warehouse.entity_preview_non_recursive__upsert (t_row.pk_entities, - t_row.fk_project); - --RAISE INFO 'upserted entity_preview_non_recursive for fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - ELSEIF (t_row.is_in_project = False) Then - Perform - warehouse.entity_preview_non_recursive__delete (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; -End; -$$; - - --- --- Name: entity_preview__add_missing(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__add_missing() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, type_label, related_full_texts, full_text, ts_vector, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t1.related_full_texts, - t1.full_text, - t1.ts_vector, - TRUE -FROM - entity_preview_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__create_temporary(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__create_temporary() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - DROP TABLE IF EXISTS entity_preview_temporary; - CREATE TEMP TABLE entity_preview_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ---------- full text completion ------------ - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_temporary t1, - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - UPDATE - entity_preview_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__full_text__add_missing(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__full_text__add_missing() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_full_text_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, type_label, related_full_texts, full_text, ts_vector, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.own_full_text, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - t1.related_full_texts, - t1.full_text, - t1.ts_vector, - TRUE -FROM - entity_preview_full_text_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__full_text__create_temporary(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__full_text__create_temporary() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - DROP TABLE IF EXISTS entity_preview_full_text_temporary; - CREATE TEMP TABLE entity_preview_full_text_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label, - NULL::text full_text, - NULL::tsvector ts_vector - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_full_text_temporary ADD UNIQUE (pk_entity, fk_project); - - -- fill related full texts - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - related_full_texts, - jsonb_object_keys(related_full_texts)::integer fk_full_text - FROM - entity_preview_full_text_temporary -), -tw2 AS ( - SELECT - tw1.pk_entity, - tw1.fk_project, - tw1.related_full_texts, - tw1.fk_full_text, - t2.own_full_text AS related_full_text - FROM - tw1, - entity_preview_full_text_temporary t2 - WHERE - tw1.fk_full_text = t2.pk_entity - AND tw1.fk_project IS NOT DISTINCT FROM t2.fk_project -), -tw3 AS ( - SELECT - tw2.pk_entity, tw2.fk_project, json_object_agg(tw2.fk_full_text, tw2.related_full_text) related_full_texts - FROM - tw2 - GROUP BY - tw2.pk_entity, - tw2.fk_project -) -UPDATE - entity_preview_full_text_temporary t2 -SET - related_full_texts = tw3.related_full_texts -FROM - tw3 -WHERE - tw3.pk_entity = t2.pk_entity - AND tw3.fk_project IS NOT DISTINCT FROM t2.fk_project; - - ----------- create full text --------- - UPDATE - entity_preview_full_text_temporary t1 - SET - full_text = ( - SELECT - string_agg - FROM ( - SELECT - 1, - string_agg(txt, ', ' ORDER BY rank) - FROM ( - SELECT - rank, - txt - FROM ( - SELECT - 1 rank, - coalesce(t1.type_label, t1.class_label, '') AS txt - UNION - SELECT - 2 rank, - t1.own_full_text AS txt - UNION - SELECT - 3 rank, - value AS txt - FROM - jsonb_each_text(t1.related_full_texts)) AS all_strings - WHERE - txt != '') AS items - GROUP BY - 1) AS x); - ----------- create tsvector ---------- - UPDATE - entity_preview_full_text_temporary t1 - SET - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t1.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t1.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t1.full_text, '')), 'C')); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__full_text__remove_superfluous(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__full_text__remove_superfluous() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_full_text_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_full_text_temporary, to be deleted' AS note - FROM - entity_preview_full_text_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__full_text__update_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__full_text__update_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - warehouse.entity_preview__full_text__create_temporary (); - PERFORM - warehouse.entity_preview__full_text__add_missing (); - PERFORM - warehouse.entity_preview__full_text__remove_superfluous (); - PERFORM - warehouse.entity_preview__full_text__update_modified (); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__full_text__update_modified(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__full_text__update_modified() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - own_full_text, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_full_text_temporary, to be updated' AS note - FROM - entity_preview_full_text_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - own_full_text, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_full_text_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) -UPDATE - warehouse.entity_preview t1 -SET - own_full_text = tw1.own_full_text, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE -FROM - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__labels__add_missing(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__labels__add_missing() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - warehouse.entity_preview -) INSERT INTO warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_entity_label, fk_type, type_label, skip_triggers) -SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.entity_type, - t1.class_label, - t1.entity_label, - t1.time_span, - t1.fk_entity_label, - t1.fk_type, - t1.type_label, - TRUE -FROM - entity_preview_labels_temporary t1, - tw1 -WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -UPDATE warehouse.entity_preview -SET skip_triggers = false -WHERE skip_triggers = true; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__labels__create_temporary(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__labels__create_temporary() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - DROP TABLE IF EXISTS entity_preview_labels_temporary; - CREATE TEMP TABLE entity_preview_labels_temporary AS - SELECT - *, - COALESCE(fk_project, 0)::integer project, - CASE WHEN table_name = 'persistent_item' THEN 'peIt' - ELSE 'teEn' - END AS entity_type, - own_entity_label AS entity_label, - NULL::text type_label - FROM - warehouse.entity_preview_non_recursive; - - ALTER TABLE entity_preview_labels_temporary ADD UNIQUE (pk_entity, fk_project); - - ---------- entity label completion ------------ - WHILE - -- check if entity labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_labels_temporary t1, - entity_preview_labels_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill entity label - UPDATE - entity_preview_labels_temporary t1 - SET - entity_label = t2.entity_label - FROM - entity_preview_labels_temporary t2 - WHERE - t1.fk_entity_label IS NOT NULL - AND t1.fk_entity_label = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - - ---------- type label completion ------------ - WHILE - -- check if type labels still need update - ( - SELECT - count(t1.pk_entity) > 0 - FROM - entity_preview_labels_temporary t1, - entity_preview_labels_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.type_label IS DISTINCT FROM t2.entity_label) - LOOP - -- fill type label - UPDATE - entity_preview_labels_temporary t1 - SET - type_label = t2.entity_label - FROM - entity_preview_labels_temporary t2 - WHERE - t1.fk_type IS NOT NULL - AND t1.fk_type = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.entity_label IS DISTINCT FROM t2.entity_label; - END LOOP; - ----------- create full text --------- - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__labels__remove_superfluous(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__labels__remove_superfluous() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_labels_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_labels_temporary, to be deleted' AS note - FROM - entity_preview_labels_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__labels__update_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__labels__update_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - warehouse.entity_preview__labels__create_temporary (); - PERFORM - warehouse.entity_preview__labels__add_missing (); - PERFORM - warehouse.entity_preview__labels__remove_superfluous (); - PERFORM - warehouse.entity_preview__labels__update_modified (); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__labels__update_modified(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__labels__update_modified() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - entity_preview_labels_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - fk_entity_label, - fk_type, - type_label, - 'different from entity_preview_labels_temporary, to be updated' AS note - FROM - warehouse.entity_preview -) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__notify_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__notify_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - PERFORM pg_notify('entity_preview_updated'::text, json_build_object( - 'pk_entity', NEW.pk_entity, - 'fk_project', NEW.fk_project, - 'project', NEW.project, - 'fk_class', NEW.fk_class, - 'entity_type', NEW.entity_type, - 'class_label', NEW.class_label, - 'entity_label', NEW.entity_label, - 'time_span', NEW.time_span, - 'fk_type', NEW.fk_type, - 'type_label', NEW.type_label - )::text); - RETURN NEW; - END; - $$; - - --- --- Name: entity_preview__refresh_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__refresh_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ -Begin - -- performs a complete refresh of entity preview from scratch - Perform - warehouse.entity_preview_non_recursive__refresh (); - Perform - warehouse.entity_preview__update_all (); - Return True; -End; -$$; - - --- --- Name: entity_preview__remove_superfluous(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__remove_superfluous() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview_temporary, to be deleted' AS note - FROM - warehouse.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview_temporary, to be deleted' AS note - FROM - entity_preview_temporary -) DELETE FROM warehouse.entity_preview t1 USING tw1 -WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - -RETURN TRUE; - -END; -$$; - - --- --- Name: entity_preview__update_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_all() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - PERFORM - warehouse.entity_preview__create_temporary (); - PERFORM - warehouse.entity_preview__add_missing (); - PERFORM - warehouse.entity_preview__remove_superfluous (); - PERFORM - warehouse.entity_preview__update_modified (); - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview__update_dependent_class_labels(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_dependent_class_labels() RETURNS trigger - LANGUAGE plpgsql - AS $$ - BEGIN - - RAISE INFO 'Called TRIGGER FUNCTION entity_preview__update_dependent_class_labels; dfh_pk_class: % class_label: %', NEW.dfh_pk_class, NEW.class_label; - - PERFORM warehouse.entity_preview_non_recursive__update_class_labels(NEW.dfh_pk_class, NEW.class_label); - - RETURN NEW; - END; - $$; - - --- --- Name: entity_preview__update_modified(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview__update_modified() RETURNS boolean - LANGUAGE plpgsql - AS $$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - entity_preview_temporary - EXCEPT - SELECT - pk_entity, - fk_project, - project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - first_second, - last_second, - own_full_text, - fk_entity_label, - fk_type, - type_label, - related_full_texts, - full_text, - ts_vector, - 'different from entity_preview_temporary, to be updated' AS note - FROM - warehouse.entity_preview - ) - UPDATE - warehouse.entity_preview t1 - SET - fk_class = tw1.fk_class, - entity_type = tw1.entity_type, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second, - own_full_text = tw1.own_full_text, - fk_entity_label = tw1.fk_entity_label, - fk_type = tw1.fk_type, - type_label = tw1.type_label, - related_full_texts = tw1.related_full_texts, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - skip_triggers = TRUE - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - - UPDATE warehouse.entity_preview - SET skip_triggers = false - WHERE skip_triggers = true; - - RETURN TRUE; -END; -$$; - - --- --- Name: entity_preview_non_recursive; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.entity_preview_non_recursive ( - pk_entity integer, - fk_class integer, - fk_project integer, - table_name character varying, - class_label character varying, - own_full_text text, - own_entity_label text, - time_span jsonb, - related_full_texts jsonb, - fk_entity_label integer, - fk_type integer, - first_second bigint, - last_second bigint -); - - --- --- Name: entity_preview_non_recursive__create(integer[]); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__create(param_pk_entities integer[]) RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE sql - AS $$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t1.pk_entity = Any (param_pk_entities) - And t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Where - t1.pk_entity = Any (param_pk_entities) -), --- fields --- TODO: add fk_project for consideration of project-settings -/** - * Start of selecting ordered fields per class and project - */ --- all text_properties except comments -tw02 As ( - Select - Case t2.pk_entity - When 217 Then - - 9 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_class As fk_class, - t1.pk_class As fk_class_for_class_field, - null::int As fk_domain_class, - null::int As fk_range_class, - null::int As fk_property, - null::boolean As property_is_outgoing, - t2.pk_entity As fk_class_field, - t3.pk_entity As fk_project - From - tw2 t0, - data_for_history.v_class t1, - "system".class_field t2, - projects.project t3 - Where - pk_class != 365 - And t1.pk_class = t0.fk_class - And t2.used_table = 'information.text_property' - And t2.pk_entity != 3364 -), --- all outgoing property fields --- outgoing property fields -tw05 As ( - Select Distinct - t3.ord_num As field_order, - t2.has_domain As fk_class, - null::int As fk_class_for_class_field, - t2.has_domain As fk_domain_class, - null::int As fk_range_class, - t2.pk_property As fk_property, - True As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join ( Select Distinct - fk_class As pk_class - From - tw2) t1 On True --t1.pk_class IN (365) AND t0.pk_entity IN (375669, 24, 27) - Join data_for_history.v_property t2 On t1.pk_class = t2.has_domain - Left Join projects.class_field_config t3 On t2.has_domain = t3.fk_domain_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw06 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw05 t1 -), --- field order comes from project -tw07 As ( - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw05 t1, - tw06 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw05 t1 - Join tw06 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw05 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- ingoing property fields -tw08 As ( - Select Distinct - Case t2.pk_property - When 1111 Then - - 10::int - Else - t3.ord_num - End As field_order, - t2.has_range As fk_class, - null::int As fk_class_for_class_field, - null::int As fk_domain_class, - t2.has_range As fk_range_class, - t2.pk_property As fk_property, - False As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join ( Select Distinct - fk_class As pk_class - From - tw2) t1 On t1.pk_class != 365 - Join data_for_history.v_property t2 On t1.pk_class = t2.has_range - Left Join projects.class_field_config t3 On t2.has_range = t3.fk_range_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw09 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw08 t1 -), -tw010 As ( - -- field order comes from project - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw08 t1, - tw09 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw08 t1 - Join tw09 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw08 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- all fields for all projects and all classes -tw011 As ( - Select - * - From - tw02 - Union All - Select - * - From - tw07 - Union All - Select - * - From - tw010 -), -/* - * End of selecting ordered fields per class and project - **/ --- explode with all fields: join all entities with their fields -tw4 As ( - -- - Select - tw2.pk_entity, - tw2.fk_class, - tw2.fk_project, - tw2.table_name, - tw2.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2, - tw011 t2 -Where - tw2.fk_project = t2.fk_project - And tw2.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1 -Where (t1.fk_entity = Any (param_pk_entities) - Or t1.fk_temporal_entity = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) Filter (Where string Is Not Null) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- select roles with time primitive, first and last second -tw9 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - t2.calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t2.calendar) As last_second - From - information.role t1, - projects.info_proj_rel t2, - information.v_time_primitive t3 - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t3.pk_entity = t1.fk_entity - And t2.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t3.julian_day, - t3.duration, - commons.time_primitive__get_first_second (t3.julian_day) As first_second, - commons.time_primitive__get_last_second (t3.julian_day, t3.duration, t1.community_favorite_calendar) As last_second - From - information.v_role t1 - Join information.v_time_primitive t3 On t3.pk_entity = t1.fk_entity - Where - t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw10 As ( - Select - tw9.fk_project, - tw9.fk_temporal_entity, - min(tw9.first_second) first_second, - max(tw9.last_second) last_second, - jsonb_object_agg( - Case When tw9.fk_property = 71 Then - 'p81'::text - When tw9.fk_property = 72 Then - 'p82'::text - When tw9.fk_property = 150 Then - 'p81a'::text - When tw9.fk_property = 151 Then - 'p81b'::text - When tw9.fk_property = 152 Then - 'p82a'::text - When tw9.fk_property = 153 Then - 'p82b'::text - Else - tw9.fk_property::text - End, json_build_object('julianDay', tw9.julian_day, 'duration', tw9.duration, 'calendar', tw9.calendar)) As time_span - From - tw9 - Group By - tw9.fk_project, - tw9.fk_temporal_entity -), -tw11 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, '; ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw10 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw12 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw13 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw11 t1 - Left Join tw12 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw14 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t2.fk_entity = t1.pk_entity -And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) -And t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw15 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw14 t1, - system.class_has_type_property t2 - Where (t1.fk_info_domain = Any (param_pk_entities) - Or t1.fk_info_range = Any (param_pk_entities)) - And t1.fk_project Is Null - And t1.fk_property = t2.fk_property -Union -Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count -From - tw14 t3, - system.class_has_type_property t4 -Where (t3.fk_info_domain = Any (param_pk_entities) - Or t3.fk_info_range = Any (param_pk_entities)) -And t3.fk_project Is Not Null -And t3.fk_property = t4.fk_property -Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw16 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw13 t1 - Left Join tw15 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw16; - -$$; - - --- --- Name: entity_preview_non_recursive__create_all(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__create_all() RETURNS SETOF warehouse.entity_preview_non_recursive - LANGUAGE sql - AS $$ - -- 1 - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'persistent_item'::varchar As table_name, - t3.class_label - From - information.persistent_item t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'temporal_entity'::varchar As table_name, - t3.class_label - From - information.temporal_entity t1, - projects.info_proj_rel t2, - warehouse.class_preview t3 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - And t1.fk_class = t3.dfh_pk_class -), --- all entities per project and repo -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 - Union - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - NULL::integer As fk_project, - t1.table_name, - t1.class_label - From - tw1 t1 -), --- fields --- TODO: add fk_project for consideration of project-settings -/** - * Start of selecting ordered fields per class and project - */ --- all text_properties except comments -tw02 As ( - Select - Case t2.pk_entity - When 217 Then - - 9 - When 218 Then - - 8 - When 219 Then - - 7 - Else - null::int - End As field_order, - t1.pk_class As fk_class, - t1.pk_class As fk_class_for_class_field, - null::int As fk_domain_class, - null::int As fk_range_class, - null::int As fk_property, - null::boolean As property_is_outgoing, - t2.pk_entity As fk_class_field, - t3.pk_entity As fk_project - From - data_for_history.v_class t1, - "system".class_field t2, - projects.project t3 - Where - pk_class != 365 - And t2.used_table = 'information.text_property' - And t2.pk_entity != 3364 -), --- all outgoing property fields --- outgoing property fields -tw05 As ( - Select Distinct - t3.ord_num As field_order, - t2.has_domain As fk_class, - null::int As fk_class_for_class_field, - t2.has_domain As fk_domain_class, - null::int As fk_range_class, - t2.pk_property As fk_property, - True As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join data_for_history.v_class t1 On True --t1.pk_class IN (365) AND t0.pk_entity IN (375669, 24, 27) - Join data_for_history.v_property t2 On t1.pk_class = t2.has_domain - Left Join projects.class_field_config t3 On t2.has_domain = t3.fk_domain_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw06 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw05 t1 -), --- field order comes from project -tw07 As ( - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw05 t1, - tw06 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw05 t1 - Join tw06 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw05 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- ingoing property fields -tw08 As ( - Select Distinct - Case t2.pk_property - When 1111 Then - - 10::int - Else - t3.ord_num - End As field_order, - t2.has_range As fk_class, - null::int As fk_class_for_class_field, - null::int As fk_domain_class, - t2.has_range As fk_range_class, - t2.pk_property As fk_property, - False As property_is_outgoing, - null::int As fk_class_field, - t0.pk_entity As fk_project - From - projects.project t0 - Join data_for_history.v_class t1 On t1.pk_class != 365 - Join data_for_history.v_property t2 On t1.pk_class = t2.has_range - Left Join projects.class_field_config t3 On t2.has_range = t3.fk_range_class - And t2.pk_property = t3.fk_property - And t3.fk_project = t0.pk_entity - Order By - fk_project -), -tw09 As ( - Select Distinct On (fk_class, - fk_project) - field_order, - fk_class, - fk_project - From - tw08 t1 -), -tw010 As ( - -- field order comes from project - Select - t1.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project - From - tw08 t1, - tw09 t2 -Where - t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Not Null -Union All --- field order comes from default project or is null -Select - t3.field_order, - t1.fk_class, - t1.fk_class_for_class_field, - t1.fk_domain_class, - t1.fk_range_class, - t1.fk_property, - t1.property_is_outgoing, - t1.fk_class_field, - t1.fk_project -From - tw08 t1 - Join tw09 t2 On t2.fk_class = t1.fk_class - And t2.fk_project = t1.fk_project - And t2.field_order Is Null - Left Join tw08 t3 On t3.fk_class = t1.fk_class - And t3.fk_property = t1.fk_property - And t3.fk_project = 375669 - Order By - fk_project -), --- all fields for all projects and all classes -tw011 As ( - Select - * - From - tw02 - Union All - Select - * - From - tw07 - Union All - Select - * - From - tw010 -), -/* - * End of selecting ordered fields per class and project - **/ --- explode with all fields: join all entities with their fields -tw4 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t2.field_order, - t2.fk_class_field, - t2.fk_property, - t2.fk_range_class, - t2.fk_domain_class, - t2.property_is_outgoing - From - tw2 t1, - tw011 t2 -Where - t1.fk_project = t2.fk_project - And t1.fk_class = t2.fk_class -), --- select all roles per project with ord_num -tw5 As ( - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - NULL::integer As ord_num_of_domain, - NULL::integer As ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1 - Where - t1.is_in_project_count > 0 -), --- select all text_properties per project with ord_num -tw6 As ( - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True - Union - Select - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - NULL::integer As fk_project, - 0 As "coalesce", - NULL::integer As ord_num_of_text_property - From - information.v_text_property t1 - Where - t1.is_in_project_count > 0 -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - coalesce(t3.string, t4.notes, t7.string) As string, - coalesce(t5.pk_entity, t6.pk_entity, t9.pk_entity, t10.pk_entity) As fk_related_entity - From - tw4 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_property = t2.fk_property - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.property_is_outgoing = True - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join language with outgoing roles - Left Join information.language t4 On t2.fk_entity = t4.pk_entity - -- join persistent_item with outgoing roles - Left Join information.persistent_item t5 On t2.fk_entity = t5.pk_entity - -- join temporal_entity with outgoing roles - Left Join information.temporal_entity t6 On t2.fk_entity = t6.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_class_field = t7.fk_class_field - And t1.fk_project Is Not Distinct From t7.fk_project - -- join ingoing roles - Left Join tw5 t8 On t1.fk_property = t8.fk_property - And t1.fk_project Is Not Distinct From t8.fk_project - And t1.property_is_outgoing = False - And t8.fk_entity = t1.pk_entity - -- join persistent_item with ingoing roles - Left Join information.persistent_item t9 On t8.fk_temporal_entity = t9.pk_entity - -- join temporal_entity with ingoing roles - Left Join information.temporal_entity t10 On t8.fk_temporal_entity = t10.pk_entity -), --- group for ordered array of strings -tw8 As ( - Select - pk_entity, - fk_class, - fk_project, - table_name, - class_label, - array_agg(string Order By t1.field_order Asc, t1.ord_num Asc) Filter (Where string Is Not Null) string_array - From - tw7 t1 - Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), -tw9 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw10 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw9 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw9 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw11 As ( - Select - tw10.fk_project, - tw10.fk_temporal_entity, - min(tw10.first_second) first_second, - max(tw10.last_second) last_second, - jsonb_object_agg( - Case When tw10.fk_property = 71 Then - 'p81'::text - When tw10.fk_property = 72 Then - 'p82'::text - When tw10.fk_property = 150 Then - 'p81a'::text - When tw10.fk_property = 151 Then - 'p81b'::text - When tw10.fk_property = 152 Then - 'p82a'::text - When tw10.fk_property = 153 Then - 'p82b'::text - Else - tw10.fk_property::text - End, json_build_object('julianDay', tw10.julian_day, 'duration', tw10.duration, 'calendar', tw10.calendar)) As time_span - From - tw10 - Group By - tw10.fk_project, - tw10.fk_temporal_entity -), -tw12 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - array_to_string(t1.string_array, ', ') own_full_text, - t1.string_array[1] own_entity_label, - t2.time_span, - t2.first_second, - t2.last_second - From - tw8 t1 - Left Join tw11 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- group related things and create object with fk_related_entities -tw13 As ( - Select - t1.pk_entity, - t1.fk_project, - jsonb_object_agg(t1.fk_related_entity::text, NULL::unknown) As related_full_texts, - array_agg(t1.fk_related_entity Order By t1.field_order Asc, t1.ord_num Asc) As fk_entity_labels - From - tw7 t1 -Where - t1.fk_related_entity Is Not Null -Group By - pk_entity, - fk_class, - fk_project, - table_name, - class_label -), --- join fk_entity_label and related_full_texts -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second, - t2.related_full_texts, - Case When t1.own_entity_label Is Not Null Then - NULL::integer - Else - t2.fk_entity_labels[1] - End As fk_entity_label - From - tw12 t1 - Left Join tw13 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select all entity associations per project with ord_num -tw15 As ( - Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t1.is_in_project_count - From - information.v_entity_association t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select Distinct - t1.pk_entity, - t1.fk_info_domain, - t1.fk_info_range, - t1.fk_data_domain, - t1.fk_data_range, - t1.fk_property, - NULL::integer As fk_project, - 0 As project, - t1.is_in_project_count -From - information.v_entity_association t1 -Where - t1.is_in_project_count > 0 -), --- get type entity_associations (DEPRECATED) -tw16 As ( - Select Distinct On (t1.fk_project, - t1.fk_property, - t1.fk_info_domain) - t1.fk_project, - t1.fk_property, - t1.fk_info_domain, - t1.fk_info_range, - t1.is_in_project_count - From - tw15 t1, - system.class_has_type_property t2 - Where - t1.fk_project Is Null - And t1.fk_property = t2.fk_property - Union - Select - t3.fk_project, - t3.fk_property, - t3.fk_info_domain, - t3.fk_info_range, - t3.is_in_project_count - From - tw15 t3, - system.class_has_type_property t4 - Where - t3.fk_project Is Not Null - And t3.fk_property = t4.fk_property - Order By - 1, - 2, - 3, - 5 Desc -), --- join fk_type -tw17 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.table_name, - t1.class_label, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.related_full_texts, - t1.fk_entity_label, - t2.fk_info_range As fk_type, - t1.first_second, - t1.last_second - From - tw14 t1 - Left Join tw16 t2 On t1.pk_entity = t2.fk_info_domain - And t1.fk_project Is Not Distinct From t2.fk_project -) -Select - * -From - tw17; - -$$; - - --- --- Name: entity_preview_non_recursive__delete(integer[], integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__delete(param_pk_entities integer[], param_fk_project integer) RETURNS void - LANGUAGE sql - AS $$ - - /** - * Delete the entity previews of the entities with given param_pk_entities - * for the given param_fk_project - */ - DELETE FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - AND fk_project IS NOT DISTINCT FROM param_fk_project; - - /** - * Clean up the repo - * Delete repo entity_previews if the entity is removed from all projects - */ - DELETE FROM warehouse.entity_preview_non_recursive - WHERE pk_entity IN ( - -- find entities that are in no project anymore - SELECT pk_entity - FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - EXCEPT - SELECT pk_entity - FROM warehouse.entity_preview_non_recursive - WHERE pk_entity = ANY(param_pk_entities) - AND fk_project IS NOT NULL - ) - AND fk_project IS NULL; - - -$$; - - --- --- Name: entity_preview_non_recursive__refresh(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__refresh() RETURNS void - LANGUAGE sql - AS $$ - - DELETE FROM warehouse.entity_preview_non_recursive; - INSERT INTO warehouse.entity_preview_non_recursive - SELECT * FROM warehouse.entity_preview_non_recursive__create_all(); - -$$; - - --- --- Name: entity_preview_non_recursive__update_class_labels(integer, text); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__update_class_labels(pk_class integer, param_class_label text DEFAULT NULL::text) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - new_class_label TEXT; - BEGIN - - ---------------------- REPO & PROJECTS VERSIONS ---------------------- - - RAISE INFO 'entity_preview_non_recursive__update_class_labels of pk_class: %', pk_class; - - -- get new_class_label - IF (param_class_label IS NULL) THEN - SELECT class_label INTO new_class_label - FROM warehouse.class_preview - WHERE dfh_pk_class = pk_class; - ELSE - new_class_label = param_class_label; - END IF; - - RAISE INFO 'new_class_label: %', new_class_label; - - -- update all dependent entity_previews with new_class_label (if DISTINCT) - UPDATE warehouse.entity_preview_non_recursive - SET class_label = new_class_label - WHERE fk_class = pk_class - AND class_label IS DISTINCT FROM new_class_label; - - RETURN true; - END; - $$; - - --- --- Name: entity_preview_non_recursive__upsert(integer[], integer); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_non_recursive__upsert(param_pk_entities integer[], param_fk_project integer) RETURNS void - LANGUAGE sql - AS $$ - - /** - * UPSERT the entity previews of the entities with given param_pk_entities - * for the given param_fk_project and the repo version (fk_project = NULL) - */ - INSERT INTO - warehouse.entity_preview_non_recursive - ( - SELECT * FROM warehouse.entity_preview_non_recursive__create(param_pk_entities) - WHERE fk_project IS NULL OR fk_project = param_fk_project - ) - ON CONFLICT (pk_entity, COALESCE(fk_project, 0)) - DO UPDATE - SET - fk_class = EXCLUDED.fk_class, - table_name = EXCLUDED.table_name, - class_label = EXCLUDED.class_label, - own_full_text = EXCLUDED.own_full_text, - own_entity_label = EXCLUDED.own_entity_label, - time_span = EXCLUDED.time_span, - first_second = EXCLUDED.first_second, - last_second = EXCLUDED.last_second, - related_full_texts = EXCLUDED.related_full_texts, - fk_entity_label = EXCLUDED.fk_entity_label, - fk_type = EXCLUDED.fk_type; - -$$; - - --- --- Name: entity_preview_update_queue_worker(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.entity_preview_update_queue_worker() RETURNS boolean - LANGUAGE plpgsql - AS $$ -Declare - last_warehouse_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the last warehouse.entity_preview_non_recursive update - */ - Select - tmsp_update_begin Into last_warehouse_update - From - warehouse.entity_preview_non_recursive_updates - Order By - pk_entity Desc - Limit 1; - -- set very early default - If last_warehouse_update Is Null Then - last_warehouse_update = '1970-01-01 00:00:00.000000'::timestamp; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of warehouse - */ - If (last_project_modification > last_warehouse_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into warehouse.entity_preview_non_recursive_updates (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - warehouse.do_updates_for_time_after (last_warehouse_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - warehouse.entity_preview_non_recursive_updates - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$$; - - --- --- Name: needs_update(text, text[]); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.needs_update(fn_name text, fn_params text[]) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - fn_name_concat TEXT; - BEGIN - - fn_name_concat = array_to_string(ARRAY['warehouse.', fn_name],''); - - PERFORM warehouse.notify_fn_call('warehouse_update_request'::text, fn_name_concat, fn_params); - - RETURN TRUE; - - END; - $$; - - --- --- Name: notify_fn_call(text, text, text[]); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.notify_fn_call(channel text, fn_name text, fn_params text[]) RETURNS boolean - LANGUAGE plpgsql - AS $$ - DECLARE - fn_concat TEXT; - BEGIN - - fn_concat = fn_name || '(' || array_to_string(fn_params, ',', 'NULL'::text) || ')'; - - PERFORM pg_notify( - channel, - json_build_object('fn', fn_concat)::text - ); - - RETURN TRUE; - - END; - $$; - - --- --- Name: update_class_preview__on_class_profile_view_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_class_profile_view_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ - DECLARE - label text; - entity_type text; - BEGIN - - INSERT INTO warehouse.class_preview (dfh_pk_class, class_label, entity_type) - SELECT v.dfh_pk_class, v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ON CONFLICT ON CONSTRAINT dfh_pk_class_unique - DO - UPDATE - SET (class_label, entity_type) = ( - SELECT v.class_label, v.entity_type - FROM information.v_class_preview as v - WHERE v.dfh_pk_class = NEW.dfh_fk_class - ); - - RETURN NEW; - - END; - $$; - - --- --- Name: update_class_preview__on_label_delete(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_label_delete() RETURNS trigger - LANGUAGE plpgsql - AS $$ BEGIN - - -- If it is a geovistory class label - IF (OLD.dfh_fk_class IS NOT NULL AND OLD.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = ( - SELECT dfh_standard_label - FROM data_for_history.class - WHERE dfh_pk_class = OLD.dfh_fk_class - ) - WHERE dfh_pk_class = OLD.dfh_fk_class; - - END IF; - - RETURN OLD; - - END; - $$; - - --- --- Name: update_class_preview__on_label_upsert(); Type: FUNCTION; Schema: warehouse; Owner: - --- - -CREATE FUNCTION warehouse.update_class_preview__on_label_upsert() RETURNS trigger - LANGUAGE plpgsql - AS $$ BEGIN - - - -- If it is a geovistory class label - IF ( NEW.dfh_fk_class IS NOT NULL AND NEW.com_fk_system_type = 184) THEN - - UPDATE warehouse.class_preview - SET class_label = NEW.dfh_label - WHERE dfh_pk_class = NEW.dfh_fk_class; - - END IF; - - RETURN NEW; - - END; - $$; - - --- --- Name: class_preview; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.class_preview ( - class_label character varying, - entity_type text, - dfh_pk_class integer -); - - --- --- Name: entity_preview; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.entity_preview ( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - entity_type text, - class_label character varying, - entity_label text, - time_span jsonb, - own_full_text text, - fk_entity_label integer, - fk_type integer, - type_label text, - related_full_texts jsonb, - full_text text, - ts_vector tsvector, - skip_triggers boolean, - first_second bigint, - last_second bigint -); - - --- --- Name: entity_preview_non_recursive_updates; Type: TABLE; Schema: warehouse; Owner: - --- - -CREATE TABLE warehouse.entity_preview_non_recursive_updates ( - pk_entity integer NOT NULL, - tmsp_update_begin timestamp without time zone, - tmsp_update_end timestamp without time zone -); - - --- --- Name: entity_preview_non_recursive_updates_pk_entity_seq; Type: SEQUENCE; Schema: warehouse; Owner: - --- - -CREATE SEQUENCE warehouse.entity_preview_non_recursive_updates_pk_entity_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: entity_preview_non_recursive_updates_pk_entity_seq; Type: SEQUENCE OWNED BY; Schema: warehouse; Owner: - --- - -ALTER SEQUENCE warehouse.entity_preview_non_recursive_updates_pk_entity_seq OWNED BY warehouse.entity_preview_non_recursive_updates.pk_entity; - - --- --- Name: v_entity_association_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_entity_association_per_project_and_repo AS - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - COALESCE(epr.fk_project, 0) AS project, - ea.is_in_project_count - FROM information.v_entity_association ea, - projects.info_proj_rel epr - WHERE ((epr.fk_entity = ea.pk_entity) AND (epr.is_in_project = true)) -UNION - SELECT DISTINCT ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer AS fk_project, - 0 AS project, - ea.is_in_project_count - FROM information.v_entity_association ea - WHERE (ea.is_in_project_count > 0); - - --- --- Name: v_roles_per_project_and_repo; Type: VIEW; Schema: warehouse; Owner: - --- - -CREATE VIEW warehouse.v_roles_per_project_and_repo AS - WITH tw1 AS ( - SELECT t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - FROM (information.role t1 - LEFT JOIN LATERAL ( SELECT (count(info_proj_rel.pk_entity))::integer AS is_in_project_count - FROM projects.info_proj_rel - WHERE ((info_proj_rel.fk_entity = t1.pk_entity) AND (info_proj_rel.is_in_project = true)) - GROUP BY info_proj_rel.fk_entity) t2 ON (true)) - ) - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - COALESCE(t2.fk_project, 0) AS project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - FROM tw1 t1, - projects.info_proj_rel t2 - WHERE ((t2.fk_entity = t1.pk_entity) AND (t2.is_in_project = true)) -UNION - SELECT t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - NULL::integer AS fk_project, - 0 AS project, - NULL::integer AS ord_num_of_domain, - NULL::integer AS ord_num_of_range, - t1.is_in_project_count - FROM tw1 t1 - WHERE (t1.is_in_project_count > 0); - - --- --- Name: entity_preview_non_recursive_updates pk_entity; Type: DEFAULT; Schema: warehouse; Owner: - --- - -ALTER TABLE ONLY warehouse.entity_preview_non_recursive_updates ALTER COLUMN pk_entity SET DEFAULT nextval('warehouse.entity_preview_non_recursive_updates_pk_entity_seq'::regclass); - - --- --- Name: class_preview dfh_pk_class_unique; Type: CONSTRAINT; Schema: warehouse; Owner: - --- - -ALTER TABLE ONLY warehouse.class_preview - ADD CONSTRAINT dfh_pk_class_unique UNIQUE (dfh_pk_class); - - --- --- Name: entity_preview entity_preview_unique; Type: CONSTRAINT; Schema: warehouse; Owner: - --- - -ALTER TABLE ONLY warehouse.entity_preview - ADD CONSTRAINT entity_preview_unique UNIQUE (pk_entity, project); - - --- --- Name: entity_preview_first_second_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_first_second_idx ON warehouse.entity_preview USING hash (first_second); - - --- --- Name: entity_preview_fk_class_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_fk_class_idx ON warehouse.entity_preview USING btree (fk_class); - - --- --- Name: entity_preview_fk_project_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_fk_project_idx ON warehouse.entity_preview USING btree (fk_project); - - --- --- Name: entity_preview_last_second_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_last_second_idx ON warehouse.entity_preview USING hash (last_second); - - --- --- Name: entity_preview_pk_entity_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_pk_entity_idx ON warehouse.entity_preview USING btree (pk_entity); - - --- --- Name: entity_preview_project_idx; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE INDEX entity_preview_project_idx ON warehouse.entity_preview USING btree (project); - - --- --- Name: pk_entity_fk_project_unique; Type: INDEX; Schema: warehouse; Owner: - --- - -CREATE UNIQUE INDEX pk_entity_fk_project_unique ON warehouse.entity_preview_non_recursive USING btree (pk_entity, COALESCE(fk_project, 0)); - - --- --- Name: class_preview after_update_on_class_preview__class_label; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_update_on_class_preview__class_label AFTER UPDATE OF class_label ON warehouse.class_preview FOR EACH ROW EXECUTE PROCEDURE warehouse.entity_preview__update_dependent_class_labels(); - - --- --- Name: entity_preview after_upsert_on_entity_preview; Type: TRIGGER; Schema: warehouse; Owner: - --- - -CREATE TRIGGER after_upsert_on_entity_preview AFTER INSERT OR UPDATE OF entity_label, class_label, time_span, type_label ON warehouse.entity_preview FOR EACH ROW WHEN (((new.project IS NOT NULL) AND (new.fk_class IS NOT NULL) AND (new.entity_type IS NOT NULL))) EXECUTE PROCEDURE warehouse.entity_preview__notify_upsert(); - -ALTER TABLE warehouse.entity_preview DISABLE TRIGGER after_upsert_on_entity_preview; - -/** -* ADD SCHEMA WAREHOUSE END -**/ - - --- trigger after_insert_or_update on table data_for_history.class_profile_view depends on function warehouse.update_class_preview__on_class_profile_view_upsert() -CREATE TRIGGER after_insert_or_update - AFTER INSERT OR UPDATE - ON data_for_history.class_profile_view - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_class_profile_view_upsert(); - --- trigger after_delete on table data_for_history.label depends on function warehouse.update_class_preview__on_label_delete() -CREATE TRIGGER after_delete - AFTER DELETE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_label_delete(); - --- trigger after_insert_or_update on table data_for_history.label depends on function warehouse.update_class_preview__on_label_upsert() -CREATE TRIGGER after_insert_or_update - AFTER INSERT OR UPDATE - ON data_for_history.label - FOR EACH ROW - EXECUTE PROCEDURE warehouse.update_class_preview__on_label_upsert(); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-up.sql b/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-up.sql deleted file mode 100644 index 047dfa188..000000000 --- a/server/db-migrate/migrations/sqls/20191229104108-war-drop-old-warehouse-up.sql +++ /dev/null @@ -1,3 +0,0 @@ --- -- 2 -Drop Schema warehouse Cascade; - diff --git a/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-down.sql b/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-down.sql deleted file mode 100644 index d5ee659b0..000000000 --- a/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop View war.v_entity_association_per_project_and_repo; - diff --git a/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-up.sql b/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-up.sql deleted file mode 100644 index a147eda2b..000000000 --- a/server/db-migrate/migrations/sqls/20191229114550-war-v-ent-ass-per-proj-and-repo-up.sql +++ /dev/null @@ -1,32 +0,0 @@ -Create Or Replace View war.v_entity_association_per_project_and_repo As Select Distinct - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - coalesce(epr.fk_project, 0) As project, - ea.is_in_project_count -From - information.v_entity_association ea, - projects.info_proj_rel epr -Where - epr.fk_entity = ea.pk_entity - And epr.is_in_project = True -Union -Select Distinct - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - NULL::integer As fk_project, - 0 As project, - ea.is_in_project_count -From - information.v_entity_association ea -Where - ea.is_in_project_count > 0; - diff --git a/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-down.sql b/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-down.sql deleted file mode 100644 index 39cd7e9a3..000000000 --- a/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-down.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -Alter Table projects.dfh_class_proj_rel_vt Rename Column enabled_in_entities To is_in_project; - diff --git a/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-up.sql b/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-up.sql deleted file mode 100644 index 3bc6b37fe..000000000 --- a/server/db-migrate/migrations/sqls/20191229154824-pro-dfh-relations-cleanup-up.sql +++ /dev/null @@ -1,6 +0,0 @@ -/* Replace with your SQL commands */ -Delete From projects.dfh_profile_proj_rel -Where fk_profile Not In (4, 5, 8); - -Alter Table projects.dfh_class_proj_rel_vt Rename Column is_in_project To enabled_in_entities; - diff --git a/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-down.sql b/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-down.sql deleted file mode 100644 index 47ffa36d1..000000000 --- a/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop View war.v_property_preview; - diff --git a/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-up.sql b/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-up.sql deleted file mode 100644 index 0cf92d9ed..000000000 --- a/server/db-migrate/migrations/sqls/20191230141529-war-v-property-preview-up.sql +++ /dev/null @@ -1,94 +0,0 @@ -Create Or Replace View war.v_property_preview As With tw0 As ( - Select - project.pk_entity, - project.fk_language - From - projects.project - Union All - Select - NULL::integer As int4, - 18889 -), -tw1 As ( - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 1 As rank, - 'project label'::text As text - From - tw0 t1, - projects.text_property t2 - Where - t1.pk_entity = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 2 As rank, - 'default project label in default lang'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t3.fk_property, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in default lang'::text As text - From - tw0 t1, - information.language t2, - data_for_history.v_label t3 - Where - t3.fk_property Is Not Null - And t3.language::bpchar = t2.iso6391 - And t3.type = 'label'::text - Union All - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 4 As rank, - 'default project label in en'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = 18889 - Union All - Select - t3.fk_property, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in en'::text As text - From - tw0 t1, - data_for_history.v_label t3 - Where - t3.fk_property Is Not Null - And t3.language::text = 'en'::text - And t3.type = 'label'::text -) -Select Distinct On (tw1.fk_project, tw1.fk_property) - tw1.fk_property, - tw1.fk_project, - tw1.label -From - tw1 -Order By - tw1.fk_project, - tw1.fk_property, - tw1.rank; - diff --git a/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-down.sql b/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-down.sql deleted file mode 100644 index 0e5135b31..000000000 --- a/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop Function projects.deactivate_ontome_profile_for_geovistory_project; - diff --git a/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-up.sql b/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-up.sql deleted file mode 100644 index a465e084f..000000000 --- a/server/db-migrate/migrations/sqls/20191230163403-pro-f-deactivate-ontome-profile-up.sql +++ /dev/null @@ -1,95 +0,0 @@ -Create Or Replace Function projects.deactivate_ontome_profile_for_geovistory_project ( - profileId INT, - projectId INT -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Begin - /** - * Deactivate Profile - */ - Update - projects.dfh_profile_proj_rel - Set - enabled = False - Where - fk_profile = profileId - And fk_project = projectId; - - /** - * Deactivate Classes - * (only classes that are not part of another ontome profile - * activated by the geovistroy project) - */ - -- select class profile relations - With ctw1 As ( - Select Distinct - t1.dfh_pk_class fk_class, - t1.dfh_fk_profile fk_profile - From - data_for_history.api_class t1 -), --- select the classes of deactivation-profile -ctw2 As ( - Select - pk_class, - identifier_in_namespace - From - data_for_history.v_class t1, - ctw1 t2 - Where - t1.pk_class = t2.fk_class - And t2.fk_profile = profileId -), --- select the profiles the project has without deactivation-profile -ctw3 As ( - Select Distinct - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = projectId - And fk_profile != profileId - And enabled = True - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), --- select the classes of the profiles of the project except the deactivation-profile -ctw4 As ( - Select Distinct - pk_class, - identifier_in_namespace - From - data_for_history.v_class t1, - ctw1 t2, - ctw3 t3 - Where - t1.pk_class = t2.fk_class - And t2.fk_profile = t3.fk_profile -), --- select the classes to be deactivated -ctw5 As ( - Select - pk_class - From - ctw2 - Except - Select - pk_class - From - ctw4) -Update - projects.dfh_class_proj_rel t1 -Set - enabled_in_entities = False -From - ctw5 t2 -Where - t1.fk_class = t2.pk_class - And t1.fk_project = projectId; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-down.sql b/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-down.sql deleted file mode 100644 index 65e4f0b65..000000000 --- a/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-down.sql +++ /dev/null @@ -1,419 +0,0 @@ --- 5 -Drop Function information.relate_outgoing_roles_with_te_ens_to_project; - -Create Or Replace Function information.add_outgoing_roles_with_te_ens_to_project ( - param_pk_roles integer[], - param_pk_project integer, - param_account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Begin - With pe_it_roles As ( - Select - pk_entity, - fk_temporal_entity - From - information.v_role - Where - pk_entity In ( - Select - (unnest(param_pk_roles))) -), -te_ents As ( - Select - fk_temporal_entity As pk_entity - From - pe_it_roles -), --- Find all roles related to temporal entities mached by pe_it_roles -te_ent_roles As ( - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t2.pk_entity)) As ts2 -Union All -Select - ts2.* -From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_ingoing_roles_to_add (t2.pk_entity)) As ts2 -), --- Find all entity_associations of temporal entities -te_ent_entity_associations As ( - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_entity_associations_to_add (t2.pk_entity)) As ts2 - Union All - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_ingoing_entity_associations_to_add (t2.pk_entity)) As ts2 -), --- get a list of all pk_entities of repo version -pk_entities_of_repo As ( - Select - pk_entity, - null::calendar_type As calendar - From - pe_it_roles -Union -Select - pk_entity, - null::calendar_type As calendar -From - te_ents -Union -Select - pk_entity, - calendar -From - te_ent_roles -Union -Select - pk_entity, - null::calendar_type As calendar -From - te_ent_entity_associations) - Insert Into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) -Select - param_pk_project, - True, - pk_entity, - calendar, - param_account_id -From - pk_entities_of_repo; -End -$BODY$; - --- 4 -Create Or Replace Function information.add_pe_it_to_project ( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Begin - With pe_it_roles As ( - Select - * - From - information.get_ingoing_roles_to_add (param_pk_entity) -), --- find all entity associations that involve the pe_it -pe_it_entity_associations As ( - -- where pe_it is domain - Select - * - From - information.get_outgoing_entity_associations_to_add (param_pk_entity) - Union - -- where pe_it is range - Select - * - From - information.get_ingoing_entity_associations_to_add (param_pk_entity) -), --- Find all temporal entities related to pe_it_roles --- that are of an auto-add property -te_ents As ( - Select - fk_temporal_entity As pk_entity - From - pe_it_roles -), --- Find all roles related to temporal entities mached by pe_it_roles -te_ent_roles As ( - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t2.pk_entity)) As ts2 -Union All -Select - ts2.* -From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_ingoing_roles_to_add (t2.pk_entity)) As ts2 -), --- Find all entity_associations of temporal entities -te_ent_entity_associations As ( - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_entity_associations_to_add (t2.pk_entity)) As ts2 - Union All - Select - ts2.* - From - te_ents t2 - Cross Join Lateral ( - Select - * - From - information.get_ingoing_entity_associations_to_add (t2.pk_entity)) As ts2 -), --- get a list of all pk_entities of repo version -pk_entities_of_repo As ( - Select - param_pk_entity As pk_entity, - null::calendar_type As calendar -Union -Select - pk_entity, - null::calendar_type As calendar -From - pe_it_entity_associations -Union -Select - pk_entity, - calendar -From - pe_it_roles -Union -Select - pk_entity, - null::calendar_type As calendar -From - te_ents -Union -Select - pk_entity, - calendar -From - te_ent_roles -Union -Select - pk_entity, - null::calendar_type As calendar -From - te_ent_entity_associations -Union -Select - pk_entity, - null::calendar_type As calendar -From - information.get_accociated_text_properties (param_pk_entity)) - Insert Into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) -Select - param_pk_project, - True, - pk_entity, - calendar, - param_account_id -From - pk_entities_of_repo t1 On Conflict On Constraint entity_version_project_rel_fk_entity_fk_project_key Do - Update - Set - is_in_project = EXCLUDED.is_in_project, calendar = EXCLUDED.calendar, fk_last_modifier = EXCLUDED.fk_last_modifier; -End -$BODY$; - --- 3 -Drop Function information.get_outgoing_roles_to_add (entity_id integer, project_id integer); - -Create Or Replace Function information.get_outgoing_roles_to_add ( - param_pk_entity integer -) - Returns Table ( - pk_entity integer, - fk_class integer, - fk_temporal_entity integer, - fk_property integer, - fk_entity integer, - max_quantifier smallint, - calendar calendar_type -) - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Begin - Return QUERY With tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - 'persistent_item' table_name - From - information.persistent_item t1 - Where - t1.pk_entity = param_pk_entity - Union All - Select - t2.pk_entity, - t2.fk_class, - 'temporal_entity' table_name - From - information.temporal_entity t2 - Where - t2.pk_entity = param_pk_entity -) - Select Distinct - ts2.pk_entity, - ts1.fk_class, - ts2.fk_temporal_entity, - ts2.fk_property, - ts2.fk_entity, - ts1.max_quantifier, - ts2.calendar - From ( - Select - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - From - system.v_auto_add_properties t1, - tw1 - Where - t1.fk_class = tw1.fk_class) As ts1 - Cross Join Lateral ( - Select - t1.pk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t1.fk_entity, - t1.community_favorite_calendar As calendar - From - information.v_role t1, - tw1 - Where - t1.fk_temporal_entity = tw1.pk_entity - And t1.fk_property = ts1.dfh_pk_property - And t1.is_in_project_count Is Not Null - Order By - t1.is_in_project_count Desc, - t1.tmsp_creation Desc - Limit ( - Select - Case When ts1.max_quantifier = - 1 Then - Null - Else - ts1.max_quantifier - End)) As ts2; -End; -$BODY$; - --- 2 -Drop Function information.get_ingoing_roles_to_add (entity_id integer, project_id integer); - -Create Or Replace Function information.get_ingoing_roles_to_add ( - param_pk_entity integer -) - Returns Table ( - pk_entity integer, - fk_class integer, - fk_temporal_entity integer, - fk_property integer, - fk_entity integer, - max_quantifier smallint, - calendar calendar_type -) - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Begin - Return QUERY With tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - 'persistent_item' table_name - From - information.persistent_item t1 - Where - t1.pk_entity = param_pk_entity - Union All - Select - t2.pk_entity, - t2.fk_class, - 'temporal_entity' table_name - From - information.temporal_entity t2 - Where - t2.pk_entity = param_pk_entity -) - Select Distinct - ts2.pk_entity, - ts1.fk_class, - ts2.fk_temporal_entity, - ts2.fk_property, - ts2.fk_entity, - ts1.max_quantifier, - ts2.calendar - From ( - Select - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - From - system.v_auto_add_properties t1, - tw1 - Where - t1.fk_class = tw1.fk_class) As ts1 - Cross Join Lateral ( - Select - t1.pk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t1.fk_entity, - t1.community_favorite_calendar As calendar - From - information.v_role t1, - tw1 - Where - t1.fk_entity = tw1.pk_entity - And t1.fk_property = ts1.dfh_pk_property - And t1.is_in_project_count Is Not Null - Order By - t1.is_in_project_count Desc, - t1.tmsp_creation Desc - Limit ( - Select - Case When ts1.max_quantifier = - 1 Then - Null - Else - ts1.max_quantifier - End)) As ts2; -End; -$BODY$; - --- 1 -Drop View information.v_entity_class_map; - diff --git a/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-up.sql b/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-up.sql deleted file mode 100644 index 751ede929..000000000 --- a/server/db-migrate/migrations/sqls/20191231135724-inf-f-add-entity-functions-up.sql +++ /dev/null @@ -1,572 +0,0 @@ --- 1 -Create View information.v_entity_class_map As ( - Select - pk_entity, - fk_class, - 'appellation' table_name - From - information.appellation - Union All - Select - pk_entity, - fk_class, - 'language' table_name - From - information.language - Union All - Select - pk_entity, - fk_class, - 'persistent_item' table_name - From - information.persistent_item - Union All - Select - pk_entity, - fk_class, - 'place' table_name - From - information.place - Union All - Select - pk_entity, - fk_class, - 'temporal_entity' table_name - From - information.temporal_entity - Union All - Select - pk_entity, - fk_class, - 'time_primitive' table_name - From - information.time_primitive); - --- 2 f: get ingoing roles to add ---Drop Function information.get_ingoing_roles_to_add (param_pk_entity int); - -Create Or Replace Function information.get_ingoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language SQL - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - domain_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all ingoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.domain_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.domain_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.domain_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same range and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t2.fk_class = t4.has_domain - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - --- 3 f: get outgoing roles to add -Drop Function information.get_outgoing_roles_to_add (param_pk_entity int); - -Create Or Replace Function information.get_outgoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language SQL - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all outgoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.range_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.range_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.range_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_temporal_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t4.has_domain In (t2.fk_class, - 50 -- make every class to a timespan class -) - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - --- 4 -Create Or Replace Function information.add_pe_it_to_project ( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer -) - Returns void - Language 'sql' - As $BODY$ - /** - * Adds a persistent item to a project, with general properties: - * - * Appellations - * - incoming roles of property 'has appellation for language' and is_in_projects_count > 0 - * - temporal entities of class 'appellation use for language' - * - outgoing roles of those 'appellation use for languages', - * while in each group of property not more then the max quantifier allows - * - * Type - * - max. one outgoing role fullfilling those criteria - * - it is of a has-type subproperty - * - it is the role with highes is_in_projects_count - * - is_in_projects_count > 0 - * - * Text Properties - * - All related text_properties that are in at least one project - */ - With tw1 As ( - -- select roles 'has appellation for language' - Select - pk_entity, - fk_temporal_entity - From - information.v_role - Where - fk_entity = param_pk_entity - And fk_property = 1111 - And is_in_project_count > 0 -), -tw2 As ( - -- select temporal entities 'appellation use for language' - Select - fk_temporal_entity As pk_entity - From - tw1 -), -tw3 As ( - -- select outgoing roles of those 'appellation use for languages' - Select - t2.pk_entity, - calendar - From - tw2 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, - param_pk_project)) As t2 -), -tw4 As ( - -- select has type role - Select - t1.pk_entity - From - information.v_role t1, - data_for_history.v_property t2 - Where - t1.fk_temporal_entity = param_pk_entity - And t1.fK_property = t2.pk_property - And t2.is_has_type_subproperty - And t1.is_in_project_count > 0 - Order By - t1.is_in_project_count Desc - Limit 1 -), -tw5 As ( - -- select text properties - Select Distinct - t1.pk_entity - From - information.text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = param_pk_entity - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True -), -tw6 As ( - -- union all entities to add to project - Select - param_pk_entity pk_entity, - null::calendar_type calendar - Union - Select - pk_entity, - null::calendar_type calendar - From - tw1 - Union - Select - pk_entity, - null::calendar_type calendar - From - tw2 - Union - Select - pk_entity, - calendar calendar - From - tw3 - Union - Select - pk_entity, - null::calendar_type calendar - From - tw4 - Union - Select - pk_entity, - null::calendar_type calendar - From - tw5) - Insert Into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) -Select - param_pk_project, - True, - pk_entity, - calendar, - param_account_id -From - tw6 t1 On Conflict On Constraint entity_version_project_rel_fk_entity_fk_project_key Do - Update - Set - is_in_project = EXCLUDED.is_in_project, calendar = EXCLUDED.calendar, fk_last_modifier = EXCLUDED.fk_last_modifier; - -$BODY$; - --- 5 -Drop Function information.add_outgoing_roles_with_te_ens_to_project; - -Create Or Replace Function information.relate_outgoing_roles_with_te_ens_to_project ( - param_pk_roles integer[], - param_pk_project integer, - param_account_id integer, - param_is_in_project boolean -) - Returns Setof projects.info_proj_rel - Language SQL - Cost 100 Volatile - As $BODY$ - /** - * Changes relation of temporal entities to project that are domain of given roles. - * - * For each temporal entity, select: - * - * * General properties - * - * Appellations - * - incoming roles of property 'has appellation for language' and is_in_projects_count > 0 - * - temporal entities of class 'appellation use for language' - * - outgoing roles of those 'appellation use for languages', - * while in each group of property not more then the max quantifier allows - * - * Type - * - max. one outgoing role fullfilling those criteria - * - it is of a has-type subproperty - * - it is the role with highes is_in_projects_count - * - is_in_projects_count > 0 - * - * Text Properties - * - All related text_properties that are in at least one project - * - * * Specific properties - * - * Outgoing Roles - * - outgoing role of properties, fullfilling those criteria: - * - property is enabled by the given project - * - max number of roles per property is not bigger than max range quantifier - * - role is_in_projects_count > 0 - * - */ - /* - * - */ - With tw01 As ( - -- select the ingoing roles - Select - pk_entity, - fk_temporal_entity - From - information.v_role - Where - pk_entity In ( - Select - (unnest(param_pk_roles))) -), -tw02 As ( - -- select the ids of the temproal entities - Select - fk_temporal_entity As pk_entity - From - tw01 -), -/* - * General properties - */ -tw1 As ( - -- select roles 'has appellation for language' - Select - t1.pk_entity, - t1.fk_temporal_entity - From - information.v_role t1, - tw02 t2 - Where - t1.fk_entity = t2.pk_entity - And t1.fk_property = 1111 - And t1.is_in_project_count > 0 -), -tw2 As ( - -- select temporal entities 'appellation use for language' - Select - fk_temporal_entity As pk_entity - From - tw1 -), -tw3 As ( - -- select outgoing roles of those 'appellation use for languages' - Select - t2.pk_entity, - calendar - From - tw2 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, - param_pk_project)) As t2 -), -tw4 As ( - -- select has type role - Select - t1.pk_entity - From - information.v_role t1, - data_for_history.v_property t2, - tw02 t3 - Where - t1.fk_temporal_entity = t3.pk_entity - And t1.fK_property = t2.pk_property - And t2.is_has_type_subproperty - And t1.is_in_project_count > 0 - Order By - t1.is_in_project_count Desc - Limit 1 -), -tw5 As ( - -- select text properties - Select Distinct - t1.pk_entity - From - information.text_property t1, - projects.info_proj_rel t2, - tw02 t3 - Where - t1.fk_concerned_entity = t3.pk_entity - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True -), -/** - * Specific properties - */ -tw6 As ( - -- select outgoing roles of the temporal entities - Select - t2.pk_entity, - calendar - From - tw02 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, - param_pk_project)) As t2 -), -tw7 As ( - -- union all entities to add to project - Select - pk_entity, - null::calendar_type calendar - From - tw02 -Union -Select - pk_entity, - null::calendar_type calendar -From - tw1 -Union -Select - pk_entity, - null::calendar_type calendar -From - tw2 -Union -Select - pk_entity, - calendar calendar -From - tw3 -Union -Select - pk_entity, - null::calendar_type calendar -From - tw4 -Union -Select - pk_entity, - null::calendar_type calendar -From - tw5 -Union -Select - pk_entity, - calendar calendar -From - tw6) - Insert Into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) -Select - param_pk_project, - param_is_in_project, - pk_entity, - calendar, - param_account_id -From - tw7 t1 On Conflict On Constraint entity_version_project_rel_fk_entity_fk_project_key Do - Update - Set - is_in_project = EXCLUDED.is_in_project, calendar = EXCLUDED.calendar, fk_last_modifier = EXCLUDED.fk_last_modifier - Returning - *; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200101195804-war-again-down.sql b/server/db-migrate/migrations/sqls/20200101195804-war-again-down.sql deleted file mode 100644 index 5454a3ce9..000000000 --- a/server/db-migrate/migrations/sqls/20200101195804-war-again-down.sql +++ /dev/null @@ -1,612 +0,0 @@ --- 6 -Create Or Replace Function war.edges__create_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All Select Distinct - fk_source, - NULL::INT As fk_project, - fk_target, - target_provides, - is_in_project_count As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - --- 5 -Create Or Replace Function war.edges__create_all () - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All - Select - fk_source, - NULL::INT As fk_project, - fk_target, - target_provides, - is_in_project_count As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - --- 4 -Create Or Replace Function war.updater () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the begin of the last update - */ - Select - tmsp_update_begin Into last_war_update - From - war.update_log - Order By - pk_entity Desc - Limit 1; - -- if the update_log is empty - If last_war_update Is Null Then - -- update the whole warehouse (this will also add a record in update_log) - Perform - war.warehouse_update_all (); - --Return true for indicating that tehere has been an update - Return True; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - If (last_project_modification > last_war_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - war.do_updates_for_difference_since (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - --- 3 --- 2 --- no back --- 1 - -Create Or Replace Function war.enriched_nodes__enrich_entity_label () - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - needs_update boolean; -Begin - needs_update = True; - ---------- entity label completion ------------ - WHILE (needs_update = True) - Loop - -- fill entity label - With tw0 As ( - Select - t1.pk_entity, - t1.fk_project, - t1.entity_label old_l, - t3.entity_label, - t1.own_entity_label_field_order, - t2.field_order - From - war.enriched_node t1 - Join ( Select Distinct On (fk_source, - fk_project) - * - From - war.edge j1 - Order By - fk_source, - fk_project, - j1.field_order Asc, - j1.ord_num_within_field Asc) t2 On coalesce(t1.own_entity_label_field_order, 10000) > coalesce(t2.field_order, 10000) - And t1.pk_entity = t2.fk_source - And t1.fk_project Is Not Distinct From t2.fk_project - Join Lateral ( - -- join the target enriched_node, in project variant, else in repo variant - Select Distinct On (j2.pk_entity) - j2.entity_label --, j2.pk_entity, j2.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Union All - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null) j2) t3 On t1.entity_label Is Distinct From t3.entity_label -), -tw1 As ( - Update - war.enriched_node t1 - Set - entity_label = t2.entity_label - From - tw0 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - * -) -Select - count(*) > 0 Into needs_update -From - tw1; -End Loop; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200101195804-war-again-up.sql b/server/db-migrate/migrations/sqls/20200101195804-war-again-up.sql deleted file mode 100644 index 663ba2972..000000000 --- a/server/db-migrate/migrations/sqls/20200101195804-war-again-up.sql +++ /dev/null @@ -1,1099 +0,0 @@ --- 1 - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_entity_label( - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -Declare - needs_update boolean; -Begin - needs_update = True; - ---------- entity label completion ------------ - WHILE (needs_update = True) - Loop - -- fill entity label - With tw0 AS ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - -- t1.own_entity_label_field_order, - -- t2.field_order, - -- t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then t1.own_entity_label - WHEN t1.fk_project IS NOT NULL THEN - CASE - When t2.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t2.entity_label - END - ELSE - CASE - When t4.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t4.entity_label - END - End entity_label - From - war.enriched_node t1 - -- JOIN the project variants (here the ord_num in field is important) - LEFT JOIN LATERAL ( - SELECT Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t2 - left Join Lateral ( - Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity - , t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null - ) t6 - ) t3 On True - WHERE t1.pk_entity = t2.fk_source - AND t1.fk_project = t2.fk_project -- '=' (sic!) - ORDER BY t1.pk_entity, t2.field_order, t2.ord_num_within_field ASC - ) t2 ON TRUE - - -- JOIN the repo variants (here the frequency of entity_label is relevant) - LEFT JOIN LATERAL ( - SELECT - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t4 - LEFT JOIN LATERAL ( - SELECT * - FROM war.enriched_node t5 - WHERE t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null - ) t5 ON TRUE - WHERE t1.pk_entity = t4.fk_source - AND t1.fk_project IS NULL AND t4.fk_project IS NULL - GROUP BY t5.entity_label, t4.field_order - ORDER BY t4.field_order, count(t5.pk_entity) DESC - LIMIT 1 - ) t4 ON TRUE -), -tw1 As ( - Update - war.enriched_node t1 - Set - entity_label = t2.entity_label - From - tw0 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.entity_label Is Distinct From t2.entity_label - Returning - t1.entity_label, - t2.entity_label -) -Select - count(*) > 0 Into needs_update -From - tw1; -End Loop; -End; -$BODY$; - - --- 2 - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_some( - node_ids war.node_id[]) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - With tw1 As ( - Select - t1.* - From - war.enriched_node t1, - unnest(node_ids) t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select entity_label -tw2 AS ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - --t1.own_entity_label_field_order, - --t2.field_order, - --t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then t1.own_entity_label - WHEN t1.fk_project IS NOT NULL THEN - CASE - When t2.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t2.entity_label - END - ELSE - CASE - When t4.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t4.entity_label - END - End entity_label - From - tw1 t1 - -- JOIN the project variants (here the ord_num in field is important) - LEFT JOIN LATERAL ( - SELECT Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t2 - left Join Lateral ( - Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity - , t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null - ) t6 - ) t3 On True - WHERE t1.pk_entity = t2.fk_source - AND t1.fk_project = t2.fk_project -- '=' (sic!) - ORDER BY t1.pk_entity, t2.field_order, t2.ord_num_within_field ASC - ) t2 ON TRUE - - -- JOIN the repo variants (here the frequency of entity_label is relevant) - LEFT JOIN LATERAL ( - SELECT - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t4 - LEFT JOIN LATERAL ( - SELECT * - FROM war.enriched_node t5 - WHERE t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null - ) t5 ON TRUE - WHERE t1.pk_entity = t4.fk_source - AND t1.fk_project IS NULL AND t4.fk_project IS NULL - GROUP BY t5.entity_label, t4.field_order - ORDER BY t4.field_order, count(t5.pk_entity) DESC - LIMIT 1 - ) t4 ON TRUE -), --- select type_label -tw3 As ( - Select - t1.pk_entity, - t1.fk_project, - t3.entity_label type_label, - t3.pk_entity fk_type - From - tw1 t1 - Join Lateral ( - Select - * - From - war.edge j1 - Where - j1.target_provides = 'type' - And j1.fk_source = t1.pk_entity - And j1.fk_project Is Not Distinct From t1.fk_project - Order By - j1.field_order Asc, - j1.ord_num_within_field - Limit 1) t2 On True - Join Lateral ( - -- join the target enriched_node, in project variant, else in repo variant - Select Distinct On (j2.pk_entity) - j2.entity_label, - j2.pk_entity --, j2.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Union All - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null) j2) t3 On True -), --- select full_text -tw4 As ( - Select - t1.pk_entity, - t1.fk_project, - t4.entity_label, - t1.class_label, - t5.type_label, - array_to_string(array_remove(Array[t1.class_label, t5.type_label, t1.own_full_text, string_agg(t3.own_full_text, ', ' Order By t2.field_order Asc, t2.ord_num_within_field), t4.entity_label], Null), ', ') As full_text - From - tw1 t1 - Join war.edge t2 On t1.pk_entity = t2.fk_source - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.enriched_node t3 On t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Left Join tw2 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project - Left Join tw3 t5 On t1.pk_entity = t5.pk_entity - And t1.fk_project Is Not Distinct From t5.fk_project -Group By - t1.pk_entity, - t1.fk_project, - t1.class_label, - t5.type_label, - t4.entity_label, - t1.own_full_text -), --- left join entity_label, full_text, fk_type and type_label, where at least one needs update -tw5 As ( - Select - t1.pk_entity, - t1.fk_project, - t1.entity_label old_label, - t2.entity_label, - t1.fk_type old_fk_type, - t3.fk_type, - t1.type_label old_type_label, - t3.type_label, - t1.full_text old_full_text, - t4.full_text - From - tw1 t1 - Left Join tw2 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Left Join tw3 t3 On t1.pk_entity = t3.pk_entity - And t1.fk_project Is Not Distinct From t3.fk_project - Left Join tw4 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project -Where (t1.entity_label Is Distinct From t2.entity_label - Or t1.type_label Is Distinct From t3.type_label - Or t1.fk_type Is Distinct From t3.fk_type - Or t1.full_text Is Distinct From t4.full_text)) -Update - war.enriched_node t1 -Set - entity_label = t2.entity_label, - fk_type = t2.fk_type, - type_label = t2.type_label, - full_text = t2.full_text, - ts_vector = ( - Select - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t2.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t2.full_text, '')), 'C')) -From - tw5 t2 -Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -Returning - t1.*; - -$BODY$; - - - --- 3 -Create Or Replace Function war.do_updates_for_difference_since2 ( - tmsp timestamp without time zone -) - Returns Setof war.node_id - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Declare - t_row record; - node_ids war.node_id[]; -Begin - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - Drop Table If Exists temp_node_changes; - Create TEMP Table temp_node_changes As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification ::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification ::timestamp >= tmsp -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) -/********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ -Select - is_in_project, - fk_project, - array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, - is_in_project; - Drop Table If Exists temp_edge_changes; - Create TEMP Table temp_edge_changes As - /********** - * Selects the pk_roles of edges that need to be updated or deleted - ***********/ - Select - array_agg( t1.fk_entity - ) As fk_roles, - t1.fk_project, - t1.is_in_project - From - projects.info_proj_rel t1, - information.role t2 - Where - t1.tmsp_last_modification::timestamp >= tmsp - And t1.fk_entity = t2.pk_entity - Group By - t1.fk_project, - t1.is_in_project; - - /******* - * Perform the updates on nodes - *******/ - For t_row In ( - Select - * - From - temp_node_changes) - Loop - If (t_row.is_in_project = True) Then - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.nodes__upsert_some (t_row.pk_entities, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.nodes__delete_some (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; - - /******* - * Perform the updates on edges - *******/ - For t_row In ( - Select - * - From - temp_edge_changes) - Loop - If (t_row.is_in_project = True) Then - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_roles, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__delete_some (t_row.fk_roles, - t_row.fk_project); - End If; - End Loop; - Perform - pg_notify('test', 'here'); - - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - -- Step 1: get the keys of nodes that need enrichment: - -- - source node keys of updated, inserted or deleted edges - -- - keys of updated or inserted nodes - -- This is done above in the loops - /******* - * REMARK: THE FOLLOWING LOOP HAS UNEXPECTED SIDE EFFECTS! - * IT DELETES THE LABELS OF SOME ENTITIES - *******/ - -- start a loop that runs while to_enrich is not empty - WHILE ( - Select - count(*) > 0 - From - to_enrich) - Loop - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - RAISE NOTICE 'node_ids %', node_ids; - Perform - pg_notify('test', 'node_ids'); - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - /******* - * update the entity_preview, TODO - *******/ - -- Select - -- war.entity_preview__update_all (); - Return QUERY Select Distinct - * - From - to_enrich; -End; -$BODY$; - --- 4 -Create Or Replace Function war.updater () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the begin of the last update - */ - Select - tmsp_update_begin Into last_war_update - From - war.update_log - Order By - pk_entity Desc - Limit 1; - -- if the update_log is empty - If last_war_update Is Null Then - -- update the whole warehouse (this will also add a record in update_log) - Perform - war.warehouse_update_all (); - --Return true for indicating that tehere has been an update - Return True; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - If (last_project_modification > last_war_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - war.do_updates_for_difference_since2 (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - --- 5 -CREATE OR REPLACE FUNCTION war.edges__create_all( - ) - RETURNS SETOF war.edge - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - WITH tw1 AS ( - ---- outgoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_temporal_entity as fk_source, - t1.fk_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_range as ord_num_within_field, - t1.is_in_project_count, - CASE WHEN t5.is_has_type_subproperty THEN 'type'::war.edge_target_type - ELSE 'text'::war.edge_target_type - END as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_domain = t3.fk_class - AND t5.has_range = t4.fk_class - UNION ALL - ---- ingoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_entity as fk_source, - t1.fk_temporal_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_domain as ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity, fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_range = t3.fk_class - AND t5.has_domain = t4.fk_class - - ) - SELECT - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - WHEN project_has_own_field_order = true THEN field_order_of_project - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1 - UNION ALL - SELECT DISTINCT - fk_source, - NULL::INT AS fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - null::int as ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1; - -$BODY$; - - --- 6 -CREATE OR REPLACE FUNCTION war.edges__create_some( - param_pk_roles integer[], - param_fk_project integer) - RETURNS SETOF war.edge - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ -WITH tw1 AS ( - ---- outgoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_temporal_entity as fk_source, - t1.fk_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_range as ord_num_within_field, - t1.is_in_project_count, - CASE WHEN t5.is_has_type_subproperty THEN 'type'::war.edge_target_type - ELSE 'text'::war.edge_target_type - END as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_domain_class = t5.has_domain - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = ANY(param_pk_roles) - AND t2.fk_project = param_fk_project - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_domain = t3.fk_class - AND t5.has_range = t4.fk_class - UNION ALL - ---- ingoing edges of project - SELECT - t2.fk_project, - t1.pk_entity as fk_role, - t1.fk_entity as fk_source, - t1.fk_temporal_entity as fk_target, - t1.fk_property, - t6.field_order as field_order_of_project, - t7.field_order as field_order_of_default_project, - CASE WHEN ( - EXISTS ( - SELECT pk_entity - FROM projects.class_field_config j1 - WHERE j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) - ) - THEN true - ELSE false - END project_has_own_field_order, - t2.ord_num_of_domain as ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type as target_provides - FROM - information.v_role t1, - projects.info_proj_rel t2 - JOIN LATERAL ( - SELECT pk_entity, fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_entity - ) AS t3 ON TRUE - JOIN LATERAL ( - SELECT pk_entity,fk_class - FROM information.persistent_item - WHERE pk_entity = t1.fk_temporal_entity - UNION ALL - SELECT pk_entity,fk_class - FROM information.temporal_entity - WHERE pk_entity = t1.fk_temporal_entity - ) AS t4 ON TRUE, - data_for_history.v_property t5 - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = t2.fk_project - ) AS t6 ON true - LEFT JOIN LATERAL ( - SELECT j1.ord_num as field_order - FROM projects.class_field_config j1 - WHERE j1.fk_property = t5.pk_property - AND j1.fk_range_class = t5.has_range - AND j1.fk_project = 375669 -- Default config project - ) AS t7 ON true - WHERE - t1.pk_entity = ANY(param_pk_roles) - AND t2.fk_project = param_fk_project - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = true - AND t5.pk_property = t1.fk_property - AND t5.has_range = t3.fk_class - AND t5.has_domain = t4.fk_class - - ) - SELECT - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - WHEN project_has_own_field_order = true THEN field_order_of_project - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1 - UNION ALL - SELECT Distinct - fk_source, - NULL::INT AS fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - null::int as ord_num_within_field, - case - WHEN fk_property = 1111 THEN -9 - ELSE field_order_of_default_project - END AS field_order, - fk_role - from tw1; -$BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-down.sql b/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-down.sql deleted file mode 100644 index b351cc563..000000000 --- a/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-down.sql +++ /dev/null @@ -1,706 +0,0 @@ --- 3 -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) On Conflict Do NOTHING -Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_entity, string, fk_system_type, fk_language) - Values (pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_entity, string, fk_system_type, fk_language) - Values (pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_entity, enabled_in_entities) -Select - pk_new_project As fk_project, - fk_entity, - enabled_in_entities -From - projects.dfh_class_proj_rel -Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') -Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for entity_associations referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an entity_association associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.entity_association t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_cell_domain Is Not Null - Or t2.fk_cell_range Is Not Null - Or t2.fk_data_domain Is Not Null - Or t2.fk_data_range Is Not Null)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) -Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version -From - projects.info_proj_rel t1, - tw1 t2 -Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy entity_associations pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new digital's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - t4.entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And t3.entity_version = t2.fk_entity_version - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy entity_associations pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new chunk's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the entity_associations pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) -Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project -From - information.entity_association t1, - data.entity t2 -Where - t1.fk_data_domain = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_preview_non_recursive from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into warehouse.entity_preview_non_recursive (pk_entity, fk_class, fk_project, table_name, class_label, own_full_text, own_entity_label, time_span, related_full_texts, fk_entity_label, fk_type) -Select - pk_entity, - fk_class, - pk_new_project As fk_project, - table_name, - class_label, - own_full_text, - own_entity_label, - time_span, - related_full_texts, - fk_entity_label, - fk_type -From - warehouse.entity_preview_non_recursive -Where - fk_project = pk_sandbox_project On Conflict (pk_entity, coalesce(fk_project, 0)) - Do NOTHING; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into warehouse.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, own_full_text, fk_entity_label, fk_type, related_full_texts, full_text, ts_vector) -Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - own_full_text, - fk_entity_label, - fk_type, - related_full_texts, - full_text, - ts_vector -From - warehouse.entity_preview -Where - fk_project = pk_sandbox_project On Conflict On Constraint entity_preview_unique Do NOTHING; - - /* - * Clone query - */ - Insert Into projects.query (fk_last_modifier, name, description, query, fk_project, fk_cloned_from_query) -Select - account_id As fk_last_modifier, - name, - description, - query, - pk_new_project As fk_project, - pk_entity -From - projects.query -Where - fk_project = pk_sandbox_project; - - /* - * Clone visual - */ - Insert Into projects.visual (fk_last_modifier, name, description, visual, fk_project) - With tw1 As ( - -- unnest all queryLayers - Select - pk_entity, - visual, - jsonb_array_elements(visual -> 'settings' -> 'queryLayers') As layer - From - projects.visual - Where - fk_project = pk_sandbox_project), - tw2 As ( - -- replace the pk of original query with pk of new query and set queryVersion=1 - Select - t1.pk_entity, - t1.visual, - jsonb_set(jsonb_set(t1.layer, '{queryPk}', t2.pk_entity::text::jsonb), '{queryVersion}', '1'::jsonb) As modified_layer - From - tw1 t1, - projects.query t2 - Where - t2.fk_project = pk_new_project - And t2.fk_cloned_from_query = (t1.layer ->> 'queryPk')::integer), - tw3 As ( - -- aggregate modified query layers and insert them into the visuals object - Select - t1.pk_entity, - jsonb_set(t1.visual, '{settings,queryLayers}', jsonb_agg(t1.modified_layer)) As modified_visual - From - tw2 t1 - Group By - t1.pk_entity, - t1.visual -) - Select - account_id As fk_last_modifier, - t2.name, - t2.description, - t1.modified_visual As visual, - pk_new_project As fk_project - From - tw3 t1, - projects.visual t2 - Where - t1.pk_entity = t2.pk_entity; -End; -$BODY$; - --- 2 -Create Or Replace Function commons.analysis__time_chart_cont__czml_time_values ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - -- temporal entities - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601 (t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601 (t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) Filter (Where t2.pk_entity Is Not Null), '[]') As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - commons.julian_second__to_iso_8601 (x1 - 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - commons.julian_second__to_iso_8601 (x2 + 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - Select - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw7 - Order By - x, - 1 -), -tw9 As ( - Select - row_number() Over () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From tw8 -) -Select - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) Into res -From - tw9; - Return res; -End; -$BODY$; - --- 1 -Create Or Replace Function commons.analysis__create_temporal_distribution ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - Select - first_second, - last_second, - pk_entity - From - warehouse.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - json_strip_nulls (json_agg(t2.pk_entity)) As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - y, - data, - x1, - x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - Select - 1, - x2 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - y, - data, - x1, - x2 - From - tw7 - Order By - x, - 1 -) -Select - jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) Into res -From - tw8; - Return coalesce(res, '[]'::jsonb); -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-up.sql b/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-up.sql deleted file mode 100644 index fe65fd18a..000000000 --- a/server/db-migrate/migrations/sqls/20200102163813-com-f-rename-warehouse-to-war-up.sql +++ /dev/null @@ -1,648 +0,0 @@ --- 1 -Create Or Replace Function commons.analysis__create_temporal_distribution ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - Select - first_second, - last_second, - pk_entity - From - war.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - json_strip_nulls (json_agg(t2.pk_entity)) As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - 0 y, - '[]'::json As data, - x1, - x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - y, - data, - x1, - x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - Select - 1, - x2 x, - count y, - data, - x1, - x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - y, - data, - x1, - x2 - From - tw7 - Order By - x, - 1 -) -Select - jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) Into res -From - tw8; - Return coalesce(res, '[]'::jsonb); -End; -$BODY$; - --- 2 -Create Or Replace Function commons.analysis__time_chart_cont__czml_time_values ( - param_pk_entities integer[], - param_project integer -) - Returns jsonb - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - res jsonb; -Begin - With tw0 As ( - -- temporal entities - Select - first_second, - last_second, - pk_entity - From - war.entity_preview - Where - pk_entity = Any (param_pk_entities) - And project = param_project - And first_second Is Not Null - And last_second Is Not Null -), -tw1 As ( - Select - first_second julian_second, - pk_entity - From - tw0 - Union - Select - last_second julian_second, - pk_entity - From - tw0 - Order By - 1 -), -tw2 As ( - Select Distinct On (julian_second) - julian_second - From - tw1 -), -tw3 As ( - Select - julian_second, - row_number() Over () pk, - (row_number() Over () + 1) fk_next -From tw2 -), -tw4 As ( - Select - t1.julian_second x1, - t2.julian_second x2 - From - tw3 t1, - tw3 t2 - Where - t1.fk_next = t2.pk -), -tw5 As ( - Select - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601 (t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601 (t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) Filter (Where t2.pk_entity Is Not Null), '[]') As data, - count(t2.pk_entity) - From - tw4 t1 - Left Join tw0 t2 On t2.first_second < t1.x2 - And t2.last_second > t1.x1 -Group By - t1.x1, - t1.x2 -Order By - t1.x1 -), -tw6 As ( - -- select the very first point - Select - x1 x, - commons.julian_second__to_iso_8601 (x1 - 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 - Limit 1 -), -tw7 As ( - -- select the very last point - Select - x2 x, - commons.julian_second__to_iso_8601 (x2 + 1) iso_x, - 0 y, - '[]'::json As data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Order By - x1 Desc - Limit 1 -), -tw8 As ( - -- first point - Select - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw6 - Union All - -- all other points - Select - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - Select - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw5 - Union All - -- last point - Select - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From - tw7 - Order By - x, - 1 -), -tw9 As ( - Select - row_number() Over () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - From tw8 -) -Select - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) Into res -From - tw9; - Return res; -End; -$BODY$; - --- 3 -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) On Conflict Do NOTHING -Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) -Select - pk_new_project As fk_project, - fk_profile, - enabled -From - projects.dfh_profile_proj_rel -Where - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) -Select - pk_new_project As fk_project, - fk_class, - enabled_in_entities -From - projects.dfh_class_proj_rel -Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') -Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for entity_associations referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an entity_association associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.entity_association t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_cell_domain Is Not Null - Or t2.fk_cell_range Is Not Null - Or t2.fk_data_domain Is Not Null - Or t2.fk_data_range Is Not Null)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) -Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version -From - projects.info_proj_rel t1, - tw1 t2 -Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy entity_associations pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new digital's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - t4.entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And t3.entity_version = t2.fk_entity_version - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy entity_associations pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new chunk's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the entity_associations pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) -Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project -From - information.entity_association t1, - data.entity t2 -Where - t1.fk_data_domain = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) -Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification -From - war.entity_preview -Where - fk_project = pk_sandbox_project On Conflict On Constraint war_entity_preview_unique Do NOTHING; - - /* - * Clone analysis - */ - Insert Into projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) -Select - account_id As fk_last_modifier, - pk_new_project As fk_project, - fk_analysis_type, - name, - description, - analysis_definition -From - projects.analysis -Where - fk_project = pk_sandbox_project; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-down.sql b/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-down.sql deleted file mode 100644 index 5f6837c0d..000000000 --- a/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back because we delete the data! diff --git a/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-up.sql b/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-up.sql deleted file mode 100644 index c0c6a3d12..000000000 --- a/server/db-migrate/migrations/sqls/20200103153746-inf-change-class-constraint-up.sql +++ /dev/null @@ -1,4 +0,0 @@ -Drop Table If Exists data_for_history.class Cascade; - -Drop Table If Exists data_for_history.class_vt Cascade; - diff --git a/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-down.sql b/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-down.sql deleted file mode 100644 index c06807b4d..000000000 --- a/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-down.sql +++ /dev/null @@ -1,435 +0,0 @@ --- 3 --- No way back --- 2 - -Create Or Replace Function information.get_ingoing_entity_associations_to_add ( - param_pk_entity integer -) - Returns Table ( - pk_entity integer, - fk_class integer, - fk_info_domain integer, - fk_property integer, - fk_info_range integer, - max_quantifier smallint -) - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Begin - Return QUERY With tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - 'persistent_item' table_name - From - information.persistent_item t1 - Where - t1.pk_entity = param_pk_entity - Union All - Select - t2.pk_entity, - t2.fk_class, - 'temporal_entity' table_name - From - information.temporal_entity t2 - Where - t2.pk_entity = param_pk_entity -) - Select Distinct - ts2.pk_entity, - ts1.fk_class, - ts2.fk_info_domain, - ts2.fk_property, - ts2.fk_info_range, - ts1.max_quantifier - From ( - Select - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - From - system.v_auto_add_properties t1, - tw1 - Where - t1.fk_class = tw1.fk_class) As ts1 - Cross Join Lateral ( - Select - t1.pk_entity, - t1.fk_info_domain, - t1.fk_property, - t1.fk_info_range - From - information.v_entity_association t1, - tw1 - Where - t1.fk_info_range = tw1.pk_entity - And t1.fk_property = ts1.dfh_pk_property - And t1.is_in_project_count Is Not Null - Order By - t1.is_in_project_count Desc, - t1.tmsp_creation Desc - Limit ( - Select - Case When ts1.max_quantifier = - 1 Then - Null - Else - ts1.max_quantifier - End)) As ts2; -End; -$BODY$; - -Create Or Replace Function information.get_outgoing_entity_associations_to_add ( - param_pk_entity integer -) - Returns Table ( - pk_entity integer, - fk_class integer, - fk_info_domain integer, - fk_property integer, - fk_info_range integer, - max_quantifier smallint -) - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Begin - Return QUERY With tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - 'persistent_item' table_name - From - information.persistent_item t1 - Where - t1.pk_entity = param_pk_entity - Union All - Select - t2.pk_entity, - t2.fk_class, - 'temporal_entity' table_name - From - information.temporal_entity t2 - Where - t2.pk_entity = param_pk_entity -) - Select Distinct - ts2.pk_entity, - ts1.fk_class, - ts2.fk_info_domain, - ts2.fk_property, - ts2.fk_info_range, - ts1.max_quantifier - From ( - Select - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - From - system.v_auto_add_properties t1, - tw1 - Where - t1.fk_class = tw1.fk_class) As ts1 - Cross Join Lateral ( - Select - t1.pk_entity, - t1.fk_info_domain, - t1.fk_property, - t1.fk_info_range - From - information.v_entity_association t1, - tw1 - Where - t1.fk_info_domain = tw1.pk_entity - And t1.fk_property = ts1.dfh_pk_property - And t1.is_in_project_count Is Not Null - Order By - t1.is_in_project_count Desc, - t1.tmsp_creation Desc - Limit ( - Select - Case When ts1.max_quantifier = - 1 Then - Null - Else - ts1.max_quantifier - End)) As ts2; -End; -$BODY$; - -Create Or Replace Function information.get_ingoing_roles_to_add ( - param_pk_entity integer -) - Returns Table ( - pk_entity integer, - fk_class integer, - fk_temporal_entity integer, - fk_property integer, - fk_entity integer, - max_quantifier smallint, - calendar calendar_type -) - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Begin - Return QUERY With tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - 'persistent_item' table_name - From - information.persistent_item t1 - Where - t1.pk_entity = param_pk_entity - Union All - Select - t2.pk_entity, - t2.fk_class, - 'temporal_entity' table_name - From - information.temporal_entity t2 - Where - t2.pk_entity = param_pk_entity -) - Select Distinct - ts2.pk_entity, - ts1.fk_class, - ts2.fk_temporal_entity, - ts2.fk_property, - ts2.fk_entity, - ts1.max_quantifier, - ts2.calendar - From ( - Select - t1.dfh_pk_property, - t1.fk_class, - t1.max_quantifier - From - system.v_auto_add_properties t1, - tw1 - Where - t1.fk_class = tw1.fk_class) As ts1 - Cross Join Lateral ( - Select - t1.pk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t1.fk_entity, - t1.community_favorite_calendar As calendar - From - information.v_role t1, - tw1 - Where - t1.fk_entity = tw1.pk_entity - And t1.fk_property = ts1.dfh_pk_property - And t1.is_in_project_count Is Not Null - Order By - t1.is_in_project_count Desc, - t1.tmsp_creation Desc - Limit ( - Select - Case When ts1.max_quantifier = - 1 Then - Null - Else - ts1.max_quantifier - End)) As ts2; -End; -$BODY$; - -Create Or Replace Function information.get_ingoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - domain_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all ingoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.domain_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.domain_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.domain_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same range and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t2.fk_class = t4.has_domain - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - -Create Or Replace Function information.add_te_en_to_project ( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Begin - -- Find all roles related to temporal entity - With te_ent_roles As ( - Select - * - From - information.get_outgoing_roles_to_add (param_pk_entity) - Union All - Select - * - From - information.get_ingoing_roles_to_add (param_pk_entity) -), --- Find all entity_associations of temporal entities -te_ent_entity_associations As ( - Select - * - From - information.get_outgoing_entity_associations_to_add (param_pk_entity) - Union All - Select - * - From - information.get_ingoing_entity_associations_to_add (param_pk_entity) -), --- get a list of all pk_entities of repo version -pk_entities_of_repo As ( - Select - param_pk_entity As pk_entity, - null::calendar_type As calendar - Union - Select - pk_entity, - calendar - From - te_ent_roles - Union - Select - pk_entity, - null::calendar_type As calendar - From - te_ent_entity_associations) - Insert Into projects.v_info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) -Select - param_pk_project, - True, - pk_entity, - calendar, - param_account_id -From - pk_entities_of_repo; -End -$BODY$; - --- 1 -Create Or Replace View information.v_entity_association As With ea_project_count As ( - Select - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - coalesce(count(*) Filter (Where epr.is_in_project = True), 0::bigint)::integer As is_in_project_count - From - information.entity_association ea_1 - Left Join projects.info_proj_rel epr On epr.fk_entity = ea_1.pk_entity -Group By - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period -) -Select - ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.dfh_range_instances_max_quantifier As range_max_quantifier, - p.dfh_domain_instances_max_quantifier As domain_max_quantifier -From - ea_project_count ea - Left Join data_for_history.property p On ea.fk_property = p.dfh_pk_property; - diff --git a/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-up.sql b/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-up.sql deleted file mode 100644 index 485879317..000000000 --- a/server/db-migrate/migrations/sqls/20200103160115-inf-change-property-constraint-up.sql +++ /dev/null @@ -1,63 +0,0 @@ --- 1 -Create Or Replace View information.v_entity_association As With ea_project_count As ( - Select - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - coalesce(count(*) Filter (Where epr.is_in_project = True), 0::bigint)::integer As is_in_project_count - From - information.entity_association ea_1 - Left Join projects.info_proj_rel epr On epr.fk_entity = ea_1.pk_entity -Group By - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period -) -Select - ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.range_instances_max_quantifier::smallint As range_max_quantifier, - p.domain_instances_max_quantifier::smallint As domain_max_quantifier -From - ea_project_count ea - Left Join data_for_history.v_property p On ea.fk_property = p.pk_property; - --- 2 -Drop Function information.get_ingoing_entity_associations_to_add; - -Drop Function information.get_outgoing_entity_associations_to_add; - -Drop Function information.get_ingoing_roles_to_add (integer, integer); - -Drop Function information.get_ingoing_roles_to_add (integer); - -Drop Function information.add_te_en_to_project; - --- 3 -Drop Table If Exists data_for_history.property Cascade; - -Drop Table If Exists data_for_history.property_vt; - diff --git a/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-down.sql deleted file mode 100644 index 7f8019335..000000000 --- a/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-down.sql +++ /dev/null @@ -1,64 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - With existing_te_ens As ( - Select - fk_temporal_entity, - array_agg(jsonb_build_object('fk_property', fk_property, 'fk_entity', fk_entity)) identity_defining_roles - From - information.role As r - Join data_for_history.property As p On p.dfh_pk_property = r.fk_property - And p.identity_defining = True - Group By - fk_temporal_entity -), -new_te_en As ( - Select - array_agg(a.elements::jsonb) roles - From ( - Select - 1 x, - jsonb_array_elements_text(param_roles) elements) As a - Group By - a.x -) -Select - teEn.* -From - Into resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity -Where - teEn.fk_class = param_fk_class; - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-up.sql deleted file mode 100644 index da94d6e0a..000000000 --- a/server/db-migrate/migrations/sqls/20200104103447-inf-f-temporal-entity-find-or-create-up.sql +++ /dev/null @@ -1,64 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - With existing_te_ens As ( - Select - fk_temporal_entity, - array_agg(jsonb_build_object('fk_property', fk_property, 'fk_entity', fk_entity)) identity_defining_roles - From - information.role As r - Join data_for_history.v_property As p On p.pk_property = r.fk_property - And p.identity_defining = True - Group By - fk_temporal_entity -), -new_te_en As ( - Select - array_agg(a.elements::jsonb) roles - From ( - Select - 1 x, - jsonb_array_elements_text(param_roles) elements) As a - Group By - a.x -) -Select - teEn.* -From - Into resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity -Where - teEn.fk_class = param_fk_class; - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-down.sql b/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-down.sql deleted file mode 100644 index 5bb4de830..000000000 --- a/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-down.sql +++ /dev/null @@ -1,391 +0,0 @@ --- 2 - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_some( - node_ids war.node_id[]) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 -AS $BODY$ - With tw1 As ( - Select - t1.* - From - war.enriched_node t1, - unnest(node_ids) t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select entity_label -tw2 AS ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - --t1.own_entity_label_field_order, - --t2.field_order, - --t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then t1.own_entity_label - WHEN t1.fk_project IS NOT NULL THEN - CASE - When t2.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t2.entity_label - END - ELSE - CASE - When t4.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t4.entity_label - END - End entity_label - From - tw1 t1 - -- JOIN the project variants (here the ord_num in field is important) - LEFT JOIN LATERAL ( - SELECT Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t2 - left Join Lateral ( - Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity - , t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null - ) t6 - ) t3 On True - WHERE t1.pk_entity = t2.fk_source - AND t1.fk_project = t2.fk_project -- '=' (sic!) - ORDER BY t1.pk_entity, t2.field_order, t2.ord_num_within_field ASC - ) t2 ON TRUE - - -- JOIN the repo variants (here the frequency of entity_label is relevant) - LEFT JOIN LATERAL ( - SELECT - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t4 - LEFT JOIN LATERAL ( - SELECT * - FROM war.enriched_node t5 - WHERE t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null - ) t5 ON TRUE - WHERE t1.pk_entity = t4.fk_source - AND t1.fk_project IS NULL AND t4.fk_project IS NULL - GROUP BY t5.entity_label, t4.field_order - ORDER BY t4.field_order, count(t5.pk_entity) DESC - LIMIT 1 - ) t4 ON TRUE -), --- select type_label -tw3 As ( - Select - t1.pk_entity, - t1.fk_project, - t3.entity_label type_label, - t3.pk_entity fk_type - From - tw1 t1 - Join Lateral ( - Select - * - From - war.edge j1 - Where - j1.target_provides = 'type' - And j1.fk_source = t1.pk_entity - And j1.fk_project Is Not Distinct From t1.fk_project - Order By - j1.field_order Asc, - j1.ord_num_within_field - Limit 1) t2 On True - Join Lateral ( - -- join the target enriched_node, in project variant, else in repo variant - Select Distinct On (j2.pk_entity) - j2.entity_label, - j2.pk_entity --, j2.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Union All - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null) j2) t3 On True -), --- select full_text -tw4 As ( - Select - t1.pk_entity, - t1.fk_project, - t4.entity_label, - t1.class_label, - t5.type_label, - array_to_string(array_remove(Array[t1.class_label, t5.type_label, t1.own_full_text, string_agg(t3.own_full_text, ', ' Order By t2.field_order Asc, t2.ord_num_within_field), t4.entity_label], Null), ', ') As full_text - From - tw1 t1 - Join war.edge t2 On t1.pk_entity = t2.fk_source - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.enriched_node t3 On t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Left Join tw2 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project - Left Join tw3 t5 On t1.pk_entity = t5.pk_entity - And t1.fk_project Is Not Distinct From t5.fk_project -Group By - t1.pk_entity, - t1.fk_project, - t1.class_label, - t5.type_label, - t4.entity_label, - t1.own_full_text -), --- left join entity_label, full_text, fk_type and type_label, where at least one needs update -tw5 As ( - Select - t1.pk_entity, - t1.fk_project, - t1.entity_label old_label, - t2.entity_label, - t1.fk_type old_fk_type, - t3.fk_type, - t1.type_label old_type_label, - t3.type_label, - t1.full_text old_full_text, - t4.full_text - From - tw1 t1 - Left Join tw2 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Left Join tw3 t3 On t1.pk_entity = t3.pk_entity - And t1.fk_project Is Not Distinct From t3.fk_project - Left Join tw4 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project -Where (t1.entity_label Is Distinct From t2.entity_label - Or t1.type_label Is Distinct From t3.type_label - Or t1.fk_type Is Distinct From t3.fk_type - Or t1.full_text Is Distinct From t4.full_text)) -Update - war.enriched_node t1 -Set - entity_label = t2.entity_label, - fk_type = t2.fk_type, - type_label = t2.type_label, - full_text = t2.full_text, - ts_vector = ( - Select - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t2.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t2.full_text, '')), 'C')) -From - tw5 t2 -Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -Returning - t1.*; - -$BODY$; --- 1 - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_entity_label( - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE -AS $BODY$ -Declare - needs_update boolean; -Begin - needs_update = True; - ---------- entity label completion ------------ - WHILE (needs_update = True) - Loop - -- fill entity label - With tw0 AS ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - -- t1.own_entity_label_field_order, - -- t2.field_order, - -- t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then t1.own_entity_label - WHEN t1.fk_project IS NOT NULL THEN - CASE - When t2.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t2.entity_label - END - ELSE - CASE - When t4.target_field_overrides_own_label = false Then - t1.own_entity_label - Else - t4.entity_label - END - End entity_label - From - war.enriched_node t1 - -- JOIN the project variants (here the ord_num in field is important) - LEFT JOIN LATERAL ( - SELECT Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t2 - left Join Lateral ( - Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity - , t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null - ) t6 - ) t3 On True - WHERE t1.pk_entity = t2.fk_source - AND t1.fk_project = t2.fk_project -- '=' (sic!) - ORDER BY t1.pk_entity, t2.field_order, t2.ord_num_within_field ASC - ) t2 ON TRUE - - -- JOIN the repo variants (here the frequency of entity_label is relevant) - LEFT JOIN LATERAL ( - SELECT - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - ( - t1.own_entity_label_field_order IS NULL - OR - t1.own_entity_label_field_order > coalesce(t2.field_order, 10000) - ) target_field_overrides_own_label - FROM war.edge t4 - LEFT JOIN LATERAL ( - SELECT * - FROM war.enriched_node t5 - WHERE t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null - ) t5 ON TRUE - WHERE t1.pk_entity = t4.fk_source - AND t1.fk_project IS NULL AND t4.fk_project IS NULL - GROUP BY t5.entity_label, t4.field_order - ORDER BY t4.field_order, count(t5.pk_entity) DESC - LIMIT 1 - ) t4 ON TRUE -), -tw1 As ( - Update - war.enriched_node t1 - Set - entity_label = t2.entity_label - From - tw0 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.entity_label Is Distinct From t2.entity_label - Returning - t1.entity_label, - t2.entity_label -) -Select - count(*) > 0 Into needs_update -From - tw1; -End Loop; -End; -$BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-up.sql b/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-up.sql deleted file mode 100644 index 8b37063a2..000000000 --- a/server/db-migrate/migrations/sqls/20200104131225-war-f-entity-label-up.sql +++ /dev/null @@ -1,392 +0,0 @@ --- 1 -Create Or Replace Function war.enriched_nodes__enrich_entity_label () - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - needs_update boolean; -Begin - needs_update = True; - ---------- entity label completion ------------ - WHILE (needs_update = True) - Loop - -- fill entity label - With tw0 As ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - -- t1.own_entity_label_field_order, - -- t2.field_order, - -- t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then - t1.own_entity_label - When t1.fk_project Is Not Null Then - Case When t2.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t2.entity_label - End - Else - Case When t4.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t4.entity_label - End - End entity_label - From - war.enriched_node t1 - -- JOIN the project variants (here the ord_num in field is important) - Left Join Lateral ( Select Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t2.field_order, 10000)) target_field_overrides_own_label - From - war.edge t2 - Left Join Lateral ( Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity, - t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null) t6) t3 On True - Where - t1.pk_entity = t2.fk_source - And t1.fk_project = t2.fk_project -- '=' (sic!) - Order By - t1.pk_entity, - t2.field_order, - t2.ord_num_within_field Asc) t2 On True - -- JOIN the repo variants (here the frequency of entity_label is relevant) - Left Join Lateral ( - Select - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t4.field_order, 10000)) target_field_overrides_own_label - From - war.edge t4 - Left Join Lateral ( - Select - * - From - war.enriched_node t5 - Where - t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null) t5 On True - Where - t1.pk_entity = t4.fk_source - And t1.fk_project Is Null - And t4.fk_project Is Null - Group By - t5.entity_label, - t4.field_order - Order By - t4.field_order, - count(t5.pk_entity) - Desc - Limit 1) t4 On True -), -tw1 As ( - Update - war.enriched_node t1 - Set - entity_label = t2.entity_label - From - tw0 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.entity_label Is Distinct From t2.entity_label - Returning - t1.entity_label, - t2.entity_label -) -Select - count(*) > 0 Into needs_update -From - tw1; -End Loop; -End; -$BODY$; - --- 2 -Create Or Replace Function war.enriched_nodes__enrich_some ( - node_ids war.node_id[] -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - Select - t1.* - From - war.enriched_node t1, - unnest(node_ids) t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select entity_label -tw2 As ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - --t1.own_entity_label_field_order, - --t2.field_order, - --t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then - t1.own_entity_label - When t1.fk_project Is Not Null Then - Case When t2.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t2.entity_label - End - Else - Case When t4.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t4.entity_label - End - End entity_label - From - tw1 t1 - -- JOIN the project variants (here the ord_num in field is important) - Left Join Lateral ( Select Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t2.field_order, 10000)) target_field_overrides_own_label - From - war.edge t2 - Left Join Lateral ( Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity, - t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null) t6) t3 On True - Where - t1.pk_entity = t2.fk_source - And t1.fk_project = t2.fk_project -- '=' (sic!) - Order By - t1.pk_entity, - t2.field_order, - t2.ord_num_within_field Asc) t2 On True - -- JOIN the repo variants (here the frequency of entity_label is relevant) - Left Join Lateral ( - Select - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t4.field_order, 10000)) target_field_overrides_own_label - From - war.edge t4 - Left Join Lateral ( - Select - * - From - war.enriched_node t5 - Where - t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null) t5 On True - Where - t1.pk_entity = t4.fk_source - And t1.fk_project Is Null - And t4.fk_project Is Null - Group By - t5.entity_label, - t4.field_order - Order By - t4.field_order, - count(t5.pk_entity) - Desc - Limit 1) t4 On True -), --- select type_label -tw3 As ( - Select - t1.pk_entity, - t1.fk_project, - t3.entity_label type_label, - t3.pk_entity fk_type - From - tw1 t1 - Join Lateral ( - Select - * - From - war.edge j1 - Where - j1.target_provides = 'type' - And j1.fk_source = t1.pk_entity - And j1.fk_project Is Not Distinct From t1.fk_project - Order By - j1.field_order Asc, - j1.ord_num_within_field - Limit 1) t2 On True - Join Lateral ( - -- join the target enriched_node, in project variant, else in repo variant - Select Distinct On (j2.pk_entity) - j2.entity_label, - j2.pk_entity --, j2.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Union All - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null) j2) t3 On True -), --- select full_text -tw4 As ( - Select - t1.pk_entity, - t1.fk_project, - t4.entity_label, - t1.class_label, - t5.type_label, - array_to_string(array_remove(Array[t1.class_label, t5.type_label, t1.own_full_text, string_agg(t3.own_full_text, ', ' Order By t2.field_order Asc, t2.ord_num_within_field), t4.entity_label], Null), ', ') As full_text - From - tw1 t1 - Join war.edge t2 On t1.pk_entity = t2.fk_source - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.enriched_node t3 On t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Left Join tw2 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project - Left Join tw3 t5 On t1.pk_entity = t5.pk_entity - And t1.fk_project Is Not Distinct From t5.fk_project -Group By - t1.pk_entity, - t1.fk_project, - t1.class_label, - t5.type_label, - t4.entity_label, - t1.own_full_text -), --- left join entity_label, full_text, fk_type and type_label, where at least one needs update -tw5 As ( - Select - t1.pk_entity, - t1.fk_project, - t1.entity_label old_label, - t2.entity_label, - t1.fk_type old_fk_type, - t3.fk_type, - t1.type_label old_type_label, - t3.type_label, - t1.full_text old_full_text, - t4.full_text - From - tw1 t1 - Left Join tw2 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Left Join tw3 t3 On t1.pk_entity = t3.pk_entity - And t1.fk_project Is Not Distinct From t3.fk_project - Left Join tw4 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project -Where (t1.entity_label Is Distinct From t2.entity_label - Or t1.type_label Is Distinct From t3.type_label - Or t1.fk_type Is Distinct From t3.fk_type - Or t1.full_text Is Distinct From t4.full_text)) -Update - war.enriched_node t1 -Set - entity_label = t2.entity_label, - fk_type = t2.fk_type, - type_label = t2.type_label, - full_text = t2.full_text, - ts_vector = ( - Select - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t2.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t2.full_text, '')), 'C')) -From - tw5 t2 -Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -Returning - t1.*; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-down.sql deleted file mode 100644 index 536659b08..000000000 --- a/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-down.sql +++ /dev/null @@ -1,66 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - With existing_te_ens As ( - Select - fk_temporal_entity, - array_agg(jsonb_build_object('fk_property', fk_property, 'fk_entity', fk_entity)) identity_defining_roles - From - information.role As r, - data_for_history.api_property p - Where - p.dfh_pk_property = r.fk_property - And p.dfh_identity_defining = True - Group By - fk_temporal_entity -), -new_te_en As ( - Select - array_agg(a.elements::jsonb) roles - From ( - Select - 1 x, - jsonb_array_elements_text(param_roles) elements) As a - Group By - a.x -) -Select - teEn.* -From - Into resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity -Where - teEn.fk_class = param_fk_class; - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-up.sql deleted file mode 100644 index 3d823dc36..000000000 --- a/server/db-migrate/migrations/sqls/20200104190944-inf-f-temporal-entity-find-or-create-up.sql +++ /dev/null @@ -1,91 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - With tw1 As ( - -- select the fk_entities of the outgoing roles - Select - * - From - jsonb_to_recordset(param_roles) As x (fk_entity int, - fk_property int) -), -tw2 As ( - -- select all temporal entities, being domain of a role and as such a candidate - Select - fk_temporal_entity - From - information.role t1, - tw1 t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_property = t2.fk_property -), -existing_te_ens As ( - Select - t2.fk_temporal_entity, - array_agg(jsonb_build_object('fk_property', t2.fk_property, 'fk_entity', t2.fk_entity)) identity_defining_roles - From - tw2 t1, - information.role t2, - ( Select Distinct On (dfh_pk_property) - dfh_pk_property, - dfh_identity_defining - From - data_for_history.api_property) t3 - Where - t1.fk_temporal_entity = t2.fk_temporal_entity - And t3.dfh_pk_property = t2.fk_property - And t3.dfh_identity_defining = True - Group By - t2.fk_temporal_entity -), -new_te_en As ( - Select - array_agg(a.elements::jsonb) roles - From ( - Select - 1 x, - jsonb_array_elements_text(param_roles) elements) As a - Group By - a.x -) -Select - teEn.* -From - Into resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity -Where - teEn.fk_class = param_fk_class; - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-down.sql b/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-down.sql deleted file mode 100644 index 3d823dc36..000000000 --- a/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-down.sql +++ /dev/null @@ -1,91 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - With tw1 As ( - -- select the fk_entities of the outgoing roles - Select - * - From - jsonb_to_recordset(param_roles) As x (fk_entity int, - fk_property int) -), -tw2 As ( - -- select all temporal entities, being domain of a role and as such a candidate - Select - fk_temporal_entity - From - information.role t1, - tw1 t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_property = t2.fk_property -), -existing_te_ens As ( - Select - t2.fk_temporal_entity, - array_agg(jsonb_build_object('fk_property', t2.fk_property, 'fk_entity', t2.fk_entity)) identity_defining_roles - From - tw2 t1, - information.role t2, - ( Select Distinct On (dfh_pk_property) - dfh_pk_property, - dfh_identity_defining - From - data_for_history.api_property) t3 - Where - t1.fk_temporal_entity = t2.fk_temporal_entity - And t3.dfh_pk_property = t2.fk_property - And t3.dfh_identity_defining = True - Group By - t2.fk_temporal_entity -), -new_te_en As ( - Select - array_agg(a.elements::jsonb) roles - From ( - Select - 1 x, - jsonb_array_elements_text(param_roles) elements) As a - Group By - a.x -) -Select - teEn.* -From - Into resulting_row existing_te_ens - -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity -Where - teEn.fk_class = param_fk_class; - -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-up.sql b/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-up.sql deleted file mode 100644 index a2c28a99c..000000000 --- a/server/db-migrate/migrations/sqls/20200108171858-inf-entity-find-or-create-up.sql +++ /dev/null @@ -1,91 +0,0 @@ -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- -- RAISE INFO 'input values: %', NEW; - -- ------ if existing, store in result ----- - -- With tw1 As ( - -- -- select the fk_entities of the outgoing roles - -- Select - -- * - -- From - -- jsonb_to_recordset(param_roles) As x (fk_entity int, - -- fk_property int) - -- ), - -- tw2 As ( - -- -- select all temporal entities, being domain of a role and as such a candidate - -- Select - -- fk_temporal_entity - -- From - -- information.role t1, - -- tw1 t2 - -- Where - -- t1.fk_entity = t2.fk_entity - -- And t1.fk_property = t2.fk_property - -- ), - -- existing_te_ens As ( - -- Select - -- t2.fk_temporal_entity, - -- array_agg(jsonb_build_object('fk_property', t2.fk_property, 'fk_entity', t2.fk_entity)) identity_defining_roles - -- From - -- tw2 t1, - -- information.role t2, - -- ( Select Distinct On (dfh_pk_property) - -- dfh_pk_property, - -- dfh_identity_defining - -- From - -- data_for_history.api_property) t3 - -- Where - -- t1.fk_temporal_entity = t2.fk_temporal_entity - -- And t3.dfh_pk_property = t2.fk_property - -- And t3.dfh_identity_defining = True - -- Group By - -- t2.fk_temporal_entity - -- ), - -- new_te_en As ( - -- Select - -- array_agg(a.elements::jsonb) roles - -- From ( - -- Select - -- 1 x, - -- jsonb_array_elements_text(param_roles) elements) As a - -- Group By - -- a.x - -- ) - -- Select - -- teEn.* - -- From - -- Into resulting_row existing_te_ens - -- -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - -- Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - -- Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity - -- Where - -- teEn.fk_class = param_fk_class; - -- -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- -- RAISE INFO 'result of select: %', resulting_row; - -- ------- if not existing, insert and store in result ----- - -- If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) -Select - * -From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - -- End If; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-down.sql b/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-down.sql deleted file mode 100644 index 6fea13e21..000000000 --- a/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-down.sql +++ /dev/null @@ -1,50 +0,0 @@ -Create Or Replace View data_for_history.v_property As With tw1 As ( - Select - t1_1.dfh_pk_property As pk_property, - t1_1.dfh_is_inherited As is_inherited, - t1_1.dfh_property_domain As has_domain, - t1_1.dfh_domain_instances_min_quantifier As domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier As domain_instances_max_quantifier, - t1_1.dfh_property_range As has_range, - t1_1.dfh_range_instances_min_quantifier As range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier As range_instances_max_quantifier, - t1_1.dfh_identity_defining As identity_defining, - t1_1.dfh_is_has_type_subproperty As is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) As profiles - From - data_for_history.api_property t1_1 - Group By - t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_identity_defining, - t1_1.dfh_is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace -) -Select - t1.pk_property, - t1.is_inherited, - t1.has_domain, - t1.domain_instances_min_quantifier, - t1.domain_instances_max_quantifier, - t1.has_range, - t1.range_instances_min_quantifier, - t1.range_instances_max_quantifier, - t1.identity_defining, - Case When t2.pk_entity Is Not Null Then - True - Else - t1.is_has_type_subproperty - End As is_has_type_subproperty, - t1.identifier_in_namespace, - t1.profiles -From - tw1 t1 - Left Join system.class_has_type_property t2 On t1.pk_property = t2.fk_property; - diff --git a/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-up.sql b/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-up.sql deleted file mode 100644 index c81967d9a..000000000 --- a/server/db-migrate/migrations/sqls/20200121163602-dfh-v-property-add-generic-prop-1111-up.sql +++ /dev/null @@ -1,74 +0,0 @@ -Create Or Replace View data_for_history.v_property As With tw1 As ( - Select - t1_1.dfh_pk_property As pk_property, - t1_1.dfh_is_inherited As is_inherited, - t1_1.dfh_property_domain As has_domain, - t1_1.dfh_domain_instances_min_quantifier As domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier As domain_instances_max_quantifier, - t1_1.dfh_property_range As has_range, - t1_1.dfh_range_instances_min_quantifier As range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier As range_instances_max_quantifier, - t1_1.dfh_identity_defining As identity_defining, - t1_1.dfh_is_has_type_subproperty As is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) As profiles - From - data_for_history.api_property t1_1 - Group By - t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_identity_defining, - t1_1.dfh_is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace - Union - -- Create a property 1111 for each classes except 365 - Select - 1111 As pk_property, - True As is_inherited, - 365 As has_domain, - 0 As domain_instances_min_quantifier, - - 1 As domain_instances_max_quantifier, - t1.dfh_pk_class As has_range, - 1 As range_instances_min_quantifier, - 1 As range_instances_max_quantifier, - True As identity_defining, - False As is_has_type_subproperty, - 'histP9' As identifier_in_namespace, - jsonb_agg(Distinct jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) As profiles - From - data_for_history.api_class t1 - Where - t1.dfh_pk_class != 365 - Group By - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_basic_type, - t1.dfh_basic_type_label -) -Select - t1.pk_property, - t1.is_inherited, - t1.has_domain, - t1.domain_instances_min_quantifier, - t1.domain_instances_max_quantifier, - t1.has_range, - t1.range_instances_min_quantifier, - t1.range_instances_max_quantifier, - t1.identity_defining, - Case When t2.pk_entity Is Not Null Then - True - Else - t1.is_has_type_subproperty - End As is_has_type_subproperty, - t1.identifier_in_namespace, - t1.profiles -From - tw1 t1 - Left Join system.class_has_type_property t2 On t1.pk_property = t2.fk_property; - diff --git a/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-down.sql b/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-down.sql deleted file mode 100644 index a7fbf725f..000000000 --- a/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-down.sql +++ /dev/null @@ -1,5 +0,0 @@ -Drop Trigger last_modification_tmsp On war.enriched_node; - -Alter Table war.enriched_node - Drop Column tmsp_last_modification; - diff --git a/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-up.sql b/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-up.sql deleted file mode 100644 index 227f54088..000000000 --- a/server/db-migrate/migrations/sqls/20200224145951-war-t-enriched-node-add-tmsp-up.sql +++ /dev/null @@ -1,8 +0,0 @@ -Alter Table war.enriched_node - Add Column tmsp_last_modification timestamp With time zone; - -Create Trigger last_modification_tmsp - Before Insert Or Update On war.enriched_node - For Each Row - Execute Procedure commons.tmsp_last_modification (); - diff --git a/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-down.sql b/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-down.sql deleted file mode 100644 index 9255f20b9..000000000 --- a/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-down.sql +++ /dev/null @@ -1,37 +0,0 @@ -Create Or Replace Function war.enriched_nodes__create_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t2.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t1.time_span, - t1.first_second, - t1.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification - From - war.nodes__create_some (param_pk_entities, - param_fk_project) t1, - war.v_class_preview t2 - Where - t1.fk_class = t2.fk_class - And t1.fk_project Is Not Distinct From t2.fk_project; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-up.sql b/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-up.sql deleted file mode 100644 index 4c0eca4bd..000000000 --- a/server/db-migrate/migrations/sqls/20200224150459-war-f-enriched-nodes--create-some-up.sql +++ /dev/null @@ -1,395 +0,0 @@ -Create Or Replace Function war.enriched_nodes__create_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t1.fk_temporal_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string - From - tw1 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 -Where - string Is Not Null -Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text - From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - And t2.fk_project = param_fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project - And t3.fk_project = param_fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), -t1.fk_class, -t3.label As class_label, -t1.entity_type, -t1.own_entity_label, -t1.own_full_text, -t2.time_span, -t2.first_second, -t2.last_second, -t1.own_entity_label_field_order, -t1.own_entity_label As entity_label, -Null::integer fk_type, -Null::text type_label, -Null::text full_text, -Null::tsvector ts_vector, -Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-down.sql b/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-down.sql deleted file mode 100644 index 0abd07a7b..000000000 --- a/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -Drop Function war.enriched_nodes__upsert_some; - diff --git a/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-up.sql b/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-up.sql deleted file mode 100644 index 13a675f16..000000000 --- a/server/db-migrate/migrations/sqls/20200224152248-war-f-enriched-nodes--upsert-some-up.sql +++ /dev/null @@ -1,100 +0,0 @@ -Create Or Replace Function war.enriched_nodes__upsert_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- Create enriched_nodes on the fly - Select - * - From - war.enriched_nodes__create_some (param_pk_entities, - param_fk_project) -), -tw2 As ( - -- Select the enriched_nodes that are different in one of the non recursive columns - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.class_label, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.class_label, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second - From - war.enriched_node t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the enriched_nodes that are different in one of the non recursive columns - Update - war.enriched_node t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_type = t2.entity_type, - own_full_text = t2.own_full_text, - own_entity_label = t2.own_entity_label, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - tw2 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created enriched_nodes that do not yet exist - Insert Into war.enriched_node - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-down.sql b/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-down.sql deleted file mode 100644 index 5d2b11e57..000000000 --- a/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-down.sql +++ /dev/null @@ -1,95 +0,0 @@ -Create Or Replace View war.v_class_preview As -With tw0 As ( - Select - project.pk_entity, - project.fk_language - From - projects.project - Union All - Select - Null::integer As int4, - 18889 -), -tw1 As ( - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 1 As rank, - 'project label'::text As text - From - tw0 t1, - projects.text_property t2 - Where - t1.pk_entity = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 2 As rank, - 'default project label in default lang'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in default lang'::text As text - From - tw0 t1, - information.language t2, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t3.language::bpchar = t2.iso6391 - And t3.type = 'label'::text - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 4 As rank, - 'default project label in en'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = 18889 - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in en'::text As text - From - tw0 t1, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t3.language::text = 'en'::text - And t3.type = 'label'::text -) -Select Distinct On (tw1.fk_project, tw1.fk_class) - tw1.fk_class, - tw1.fk_project, - tw1.label -From - tw1 -Order By - tw1.fk_project, - tw1.fk_class, - tw1.rank; - diff --git a/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-up.sql b/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-up.sql deleted file mode 100644 index be299200b..000000000 --- a/server/db-migrate/migrations/sqls/20200224161046-war-v-class-label-up.sql +++ /dev/null @@ -1,96 +0,0 @@ -Create Or Replace View war.v_class_preview As -With tw0 As ( - Select - project.pk_entity, - project.fk_language - From - projects.project - Union All - Select - Null::integer As int4, - 18889 -), -tw1 As ( - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 1 As rank, - 'project label'::text As text - From - tw0 t1, - projects.text_property t2 - Where - t1.pk_entity = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 2 As rank, - 'default project label in default lang'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in default lang'::text As text - From - tw0 t1, - information.language t2, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t1.fk_language = t2.pk_entity - And t3.language::bpchar = t2.iso6391 - And t3.type = 'label'::text - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 4 As rank, - 'default project label in en'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = 18889 - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 5 As rank, - 'ontome label in en'::text As text - From - tw0 t1, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t3.language::text = 'en'::text - And t3.type = 'label'::text -) -Select Distinct On (tw1.fk_project, tw1.fk_class) - tw1.fk_class, - tw1.fk_project, - tw1.label -From - tw1 -Order By - tw1.fk_project, - tw1.fk_class, - tw1.rank; - diff --git a/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-down.sql b/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-down.sql deleted file mode 100644 index 161ae635b..000000000 --- a/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-down.sql +++ /dev/null @@ -1,470 +0,0 @@ --- 4 -Create Or Replace Function war.edges__upsert_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - Select - war.edges__delete_some (param_pk_roles, - param_fk_project); - -Insert Into war.edge -Select - * -From - war.edges__create_some (param_pk_roles, - param_fk_project) -Returning - *; - -$BODY$; - --- 3 -Drop Index war.edge_unique_project; - -Drop Index war.edge_unique_repo; - --- 2 -Create Or Replace Function war.edges__create_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - --- 1 -Create Or Replace Function war.edges__create_all () - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-up.sql b/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-up.sql deleted file mode 100644 index 0381a3350..000000000 --- a/server/db-migrate/migrations/sqls/20200224162153-war-f-edges--upsert-some-up.sql +++ /dev/null @@ -1,533 +0,0 @@ --- 1 fix edges__create_all to make only one edge per role, project, source and target -Create Or Replace Function war.edges__create_all () - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_role) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - --- 2 Fix -Create Or Replace Function war.edges__create_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_role) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1 - Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role - From - tw1; - -$BODY$; - --- 3 -Truncate war.edge; - -Create Unique Index edge_unique_project On war.edge (fk_source, fk_project, fk_target, fk_role) -Where - fk_project Is Not Null; - -Create Unique Index edge_unique_repo On war.edge (fk_source, fk_target, fk_role) -Where - fk_project Is Null; - --- 4 -Create Or Replace Function war.edges__upsert_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- Create edges on the fly - Select - * - From - war.edges__create_some (param_pk_roles, - param_fk_project) -), -tw2 As ( - -- Select the edges that are different in one of the non recursive columns - Select - * - From - tw1 t1 - Except - Select - t1.* - From - war.edge t1, - tw1 t2 - Where - t1.fk_role = t2.fk_role - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the edges that are different in one of the non recursive columns - Update - war.edge t1 - Set - fk_source = t2.fk_source, - fk_project = t2.fk_project, - fk_target = t2.fk_target, - target_provides = t2.target_provides, - ord_num_within_field = t2.ord_num_within_field, - field_order = t2.field_order, - fk_role = t2.fk_role - From - tw2 t2 - Where - t1.fk_role = t2.fk_role - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created edges that do not yet exist - Insert Into war.edge - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-down.sql b/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-down.sql deleted file mode 100644 index 4267d6348..000000000 --- a/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-down.sql +++ /dev/null @@ -1,524 +0,0 @@ --- 4 -Create Or Replace Function war.do_updates_for_difference_since ( - tmsp timestamp without time zone -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - t_row record; -Begin - For t_row In ( - /********** - * Selects the pk_entities of nodes that need to be updated. - * - * takes only the latest item for each pk_entity and project. - * this helps to skip unneeded intermediate updates. For example: - * Those update requests: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 24, is_in_project false - * - entity 207386, project 82, is_in_project true - * - entity 207386, project 24, is_in_project true - * - * is reduced to the latest ones per project and entity: - * - entity 207386, project 24, is_in_project true - * - entity 207386, project 82, is_in_project true - * - * also takes only pk_entity of persistent_item or temporal_entity - * by joining a union of information.persistent_item and information.temporal_entity - * - * also takes only pk_entity of items that have a info_proj_rel. - * this excludes entities that are related by project's properties (roles) but are not in project - * themselfes. - ***********/ - With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp), - -- select fk_entity and fk_project of all affected persistent_items and temporal_entities - tw2 As ( - -- persistent_items where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity), - tw3 As ( - Select Distinct On (t1.fk_project, - t1.fk_entity) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification - From - tw2 t1, - projects.info_proj_rel t2 - Where - t1.fk_entity = t2.fk_entity - And t1.fk_project = t2.fk_project - Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, - fk_project, - array_agg(fk_entity) pk_entities --, count(pk_entity) - From - tw3 - Group By - fk_project, - is_in_project) - /******* - * Perform the updates on nodes - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - war.nodes__upsert_some (t_row.pk_entities, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.nodes__delete_some (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; - For t_row In ( - /********** - * Selects the pk_roles of edges that need to be updated. - * - ***********/ - Select - array_agg(t1.fk_entity) As fk_roles, - t1.fk_project, - t1.is_in_project - From - projects.info_proj_rel t1, - information.role t2 - Where - t1.tmsp_last_modification::timestamp >= tmsp - And t1.fk_entity = t2.pk_entity - Group By - t1.fk_project, - t1.is_in_project) - /******* - * Perform the updates on nodes - *******/ - Loop - If (t_row.is_in_project = True) Then - Perform - war.edges__upsert_some (t_row.fk_roles, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.edges__delete_some (t_row.fk_roles, - t_row.fk_project); - End If; - End Loop; -End; -$BODY$; - --- 3 -Drop Index projects.info_proj_rel_is_in_project_idx; - -Drop Index projects.info_proj_rel_tmsp_last_modification_idx; - --- 2 -Create Or Replace Function war.updater () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the begin of the last update - */ - Select - tmsp_update_begin Into last_war_update - From - war.update_log - Order By - pk_entity Desc - Limit 1; - -- if the update_log is empty - If last_war_update Is Null Then - -- update the whole warehouse (this will also add a record in update_log) - Perform - war.warehouse_update_all (); - --Return true for indicating that tehere has been an update - Return True; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - If (last_project_modification > last_war_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - war.do_updates_for_difference_since2 (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - --- 1 -Create Or Replace Function war.do_updates_for_difference_since2 ( - tmsp timestamp without time zone -) - Returns Setof war.node_id - Language 'plpgsql' - Cost 100 Volatile Rows 1000 - As $BODY$ -Declare - t_row record; - node_ids war.node_id[]; -Begin - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - Drop Table If Exists temp_node_changes; - Create TEMP Table temp_node_changes As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.tmsp_last_modification ::timestamp - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification ::timestamp >= tmsp -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( --- persistent_items where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification -From - information.persistent_item t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- temporal_entities where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification -From - information.temporal_entity t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- domain entities of roles where info_proj_rel changed -Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification -From - information.role t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- range entities of roles where info_proj_rel changed -Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification -From - information.role t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- concerned entities of text_properties where info_proj_rel changed -Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification -From - information.text_property t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( -Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t2.is_in_project, - t1.tmsp_last_modification -From - tw2 t1, - projects.info_proj_rel t2 -Where - t1.fk_entity = t2.fk_entity And t1.fk_project = t2.fk_project -Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) -/********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ -Select - is_in_project, fk_project, array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, is_in_project; - Drop Table If Exists temp_edge_changes; - Create TEMP Table temp_edge_changes As - /********** - * Selects the pk_roles of edges that need to be updated or deleted - ***********/ - Select - array_agg( t1.fk_entity - ) As fk_roles, - t1.fk_project, - t1.is_in_project -From - projects.info_proj_rel t1, - information.role t2 -Where - t1.tmsp_last_modification::timestamp >= tmsp - And t1.fk_entity = t2.pk_entity -Group By - t1.fk_project, - t1.is_in_project; - - /******* - * Perform the updates on nodes - *******/ - For t_row In ( - Select - * - From - temp_node_changes) - Loop - If (t_row.is_in_project = True) Then - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.nodes__upsert_some (t_row.pk_entities, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Perform - war.nodes__delete_some (t_row.pk_entities, - t_row.fk_project); - End If; - End Loop; - - /******* - * Perform the updates on edges - *******/ - For t_row In ( - Select - * - From - temp_edge_changes) - Loop - If (t_row.is_in_project = True) Then - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_roles, - t_row.fk_project); - ELSEIF (t_row.is_in_project = False) Then - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__delete_some (t_row.fk_roles, - t_row.fk_project); - End If; - End Loop; - Perform - pg_notify('test', 'here'); - - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - -- Step 1: get the keys of nodes that need enrichment: - -- - source node keys of updated, inserted or deleted edges - -- - keys of updated or inserted nodes - -- This is done above in the loops - /******* - * REMARK: THE FOLLOWING LOOP HAS UNEXPECTED SIDE EFFECTS! - * IT DELETES THE LABELS OF SOME ENTITIES - *******/ - -- start a loop that runs while to_enrich is not empty - WHILE ( - Select - count(*) > 0 - From - to_enrich) - Loop - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - Raise NOTICE 'node_ids %', node_ids; - Perform - pg_notify('test', 'node_ids'); - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - - /******* - * update the entity_preview, TODO - *******/ - -- Select - -- war.entity_preview__update_all (); - Return QUERY Select Distinct - * - From - to_enrich; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-up.sql b/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-up.sql deleted file mode 100644 index 1899b5ad5..000000000 --- a/server/db-migrate/migrations/sqls/20200224174424-war-f-do-updates-for-difference-since-up.sql +++ /dev/null @@ -1,610 +0,0 @@ --- 1 -Drop Function war.do_updates_for_difference_since2 (timestamp without time zone); - --- 2 -Create Or Replace Function war.updater () - Returns boolean - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -Begin - /* - * Get the timestamp of the begin of the last update - */ - Select - tmsp_update_begin Into last_war_update - From - war.update_log - Order By - pk_entity Desc - Limit 1; - -- if the update_log is empty - If last_war_update Is Null Then - -- update the whole warehouse (this will also add a record in update_log) - Perform - war.warehouse_update_all (); - --Return true for indicating that tehere has been an update - Return True; - End If; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - Select - tmsp_last_modification::timestamp Into last_project_modification - From - projects.info_proj_rel - Order By - tmsp_last_modification Desc - Limit 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - If (last_project_modification > last_war_update) Then - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - Insert Into war.update_log (tmsp_update_begin) - Values (now()::timestamp) - Returning - pk_entity Into pk_update; - - /***** - * Perform the updates - ******/ - Perform - war.do_updates_for_difference_since (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - Update - war.update_log - Set - tmsp_update_end = clock_timestamp()::timestamp - Where - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - Return True; - Else - /* - * Return false for indicating that there has been no update - */ - Return False; - End If; -End; -$BODY$; - --- 3 -Create Index On projects.info_proj_rel (is_in_project); - -Create Index On projects.info_proj_rel (tmsp_last_modification); - --- 4 -Drop Function war.do_updates_for_difference_since; - -Create Or Replace Function war.do_updates_for_difference_since ( - tmsp timestamp without time zone -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - t_row record; - node_ids war.node_id[]; - t timestamptz := clock_timestamp(); - -- used for DEBUGGING - enrich_loop_count int := 0; -Begin - Create TEMP Table changed_info_proj_rel On Commit Drop As - -- select recently modified info_proj_rels - Select - t1.fk_entity, t1.fk_project, t1.is_in_project, t1.tmsp_last_modification - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp; - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - - /* - * 1. Delete enriched_nodes and entity previews - * - * Delete the enriched_nodes and entity_previews of PeIt’s or TeEn’s that have a - * recently been removed from their project (modified info_proj_rel where - * is_in_project = false) - * - * Read this about temp tables on commit drop: - * https://stackoverflow.com/questions/10596896/postgresql-thread-safety-for-temporary-tables - */ - -- DEBUG - Raise notice '#1.a querying removed_crm_entities...'; - Create TEMP Table removed_crm_entities On Commit Drop As - With tw1 As ( - -- select recent info_proj_rel where is_in_project = false - Select - t1.fk_entity, - t1.fk_project - From - changed_info_proj_rel t1 - Where - t1.is_in_project = False -), -tw2 As ( --- join persistent_items -Select - t2.fk_entity, - t2.fk_project -From - information.persistent_item t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- join temporal_entities -Select - t2.fk_entity, - t2.fk_project -From - information.temporal_entity t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity - ) -Select - fk_entity, fk_project -From - tw2; - -- DEBUG TIME - Raise notice '...#1.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#1.b deleting enriched_nodes and entity_previews...'; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_crm_entities) - Loop - Raise NOTICE 'Node to delete fk_project: %, fk_entity: %', t_row.fk_project, t_row.fk_entity; - End Loop; - -- END DEBUG - -- delete enriched_nodes - Delete From war.enriched_node t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- delete entity_previews - Delete From war.entity_preview t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- DEBUG TIME - Raise notice '...#1.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.a querying affected_nodes'; - - /* - * 2. Update enriched_node table - * - * all enriched_nodes that are possibly affected by the modifications since last update, - * need to be updated or inserted. Enriched_nodes are possibly affected, if a PeIt or - * TeEn is added to project, if a role or text_property related to that PeIt or TeEn - * is changed in its relation to the project. - */ - Create TEMP Table affected_nodes On Commit Drop As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.is_in_project, - t1.tmsp_last_modification - From - changed_info_proj_rel t1 -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( --- persistent_items where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.persistent_item t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True -Union All --- temporal_entities where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.temporal_entity t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True -Union All --- domain entities of roles where info_proj_rel changed -Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.role t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- range entities of roles where info_proj_rel changed -Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.role t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -Union All --- concerned entities of text_properties where info_proj_rel changed -Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.text_property t1, - tw1 t2 -Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( -Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification -From - tw2 t1 -Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) -/********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ -Select - is_in_project, fk_project, array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, is_in_project; - -- DEBUG TIME - Raise notice '...#2.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.b upserting affected_nodes...'; - - /** - * Loop over the affected nodes per project and upsert the enriched nodes - * (the not recursive columns) - */ - For t_row In ( - Select - * - From - affected_nodes) - Loop - -- START DEBUG - -- Show affected_nodes - Raise NOTICE 'Nodes to upsert fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - -- END DEBUG - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.enriched_nodes__upsert_some (t_row.pk_entities, - t_row.fk_project); - End Loop; - -- DEBUG TIME - Raise notice '...#2.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.a query removed_roles...'; - - /* - * 3. Delete edges - * - * Delete the edges of roles that have a recently been removed from their project - * (modified info_proj_rel where is_in_project = false) - */ - Create TEMP Table removed_roles On Commit Drop As - -- select recent info_proj_rel to roles where is_in_project = false - Select - t1.fk_entity As fk_role, t1.fk_project, t2.fk_entity, t2.fk_temporal_entity - From - changed_info_proj_rel t1, information.role t2 - Where - t1.is_in_project = False - And t1.fk_entity = t2.pk_entity; - -- Add the entities, related to removed roles, to to_enrich - Insert Into to_enrich - -- select domain persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_temporal_entity - Union All - -- select range persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- select domain temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_temporal_entity - Union All - -- select range temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_entity; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_roles) - Loop - Raise NOTICE 'Edges to delete fk_project: %, fk_role: %', t_row.fk_project, t_row.fk_role; - End Loop; - -- END DEBUG - Raise notice '...#3.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.b delete edges...'; - Delete From war.edge t1 Using removed_roles t2 - Where t1.fk_project Is Not Distinct From t2.fk_project - And t1.fk_role = t2.fk_role; - -- DEBUG TIME - Raise notice '...#3.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.a query affected roles...'; - - /* - * 4. Update edges - * - * All edges that are affected by the modifications since last update need to be updated or inserted. - */ - Create TEMP Table updated_roles On Commit Drop As - -- select recent info_proj_rel to roles where is_in_project = false - Select - array_agg( t1.fk_entity - ) As fk_roles, t1.fk_project -From - changed_info_proj_rel t1, information.role t2 -Where - t1.fk_entity = t2.pk_entity - And t1.is_in_project = True -Group By - t1.fk_project; - Raise notice '...#4.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.b update edges...'; - -- Update the edges - For t_row In ( - Select - * - From - updated_roles) - Loop - -- DEBUG - -- show the updated roles - Raise NOTICE 'Updated roles fk_project: %, fk_roles: %', t_row.fk_project, t_row.fk_roles; - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_roles, - t_row.fk_project); - End Loop; - Raise notice '...#4.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - - /* - * 5. Enrich nodes - * - * Fill all recursive colums of all enriched_nodes that are not up to date. - * After this step, the table enriched_node should be in a final state - * so that the changes can be brought to the table entity_previews - */ - -- START DEBUG - Raise notice '#5 enrich nodes...'; - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - to_enrich) - Loop - Raise NOTICE 'Initial nodes to_enrich (before loop): fk_project%, pk_entity: %', t_row.fk_project, t_row.pk_entity; - End Loop; - -- END DEBUG - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - WHILE ( - Select - (count(*) > 0 - And enrich_loop_count <= 50) - From - to_enrich) - Loop - -- breac - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - -- DEBUG - -- Show node_ids to enrich - Raise NOTICE 'node_ids from to_enrich %', node_ids; - -- show number of iterations - Raise NOTICE 'enrich_loop_count %', enrich_loop_count; - enrich_loop_count = enrich_loop_count + 1; - If enrich_loop_count = 50 Then - Raise WARNING 'enrich_loop_count = 50. node_ids from to_enrich %', node_ids; - End If; - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - Raise notice '...#5 time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#6 update entity_previews...'; - - /* - * 6. Update entity_previews - * - * Update all entity_previews with all enriched_nodes where tmsp_last_modification - * is more recent than last update_log.tmsp_update_end. - */ - Create TEMP Table modified_enriched_node On Commit Drop As - With tw1 As ( - -- select the modified enriched_node - Select - * - From - war.enriched_node t1 - Where - t1.tmsp_last_modification > tmsp ) - -- Select the entity_previews that are different in one of the columns - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - war.entity_preview t1, tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Update the edges that are different in one of the non recursive columns - Update - war.entity_preview t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - entity_type = t2.entity_type, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_label = t2.entity_label, - full_text = t2.full_text, - ts_vector = t2.ts_vector, - type_label = t2.type_label, - fk_type = t2.fk_type, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - modified_enriched_node t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Insert the created edges that do not yet exist - Insert Into war.entity_preview - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - From - modified_enriched_node t1 - On Conflict - Do Nothing; - Raise notice '...#6 time spent=%', clock_timestamp() - t; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-down.sql b/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-down.sql deleted file mode 100644 index dda2d9917..000000000 --- a/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-down.sql +++ /dev/null @@ -1,33 +0,0 @@ -Create Or Replace Function war.enriched_nodes__create_all () - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t2.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t1.time_span, - t1.first_second, - t1.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification - From - war.node t1, - war.v_class_preview t2 - Where - t1.fk_class = t2.fk_class - And t1.fk_project Is Not Distinct From t2.fk_project; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-up.sql b/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-up.sql deleted file mode 100644 index 1725db6b8..000000000 --- a/server/db-migrate/migrations/sqls/20200225122737-war-f-enriched-nodes--create-all-up.sql +++ /dev/null @@ -1,373 +0,0 @@ -Create Or Replace Function war.enriched_nodes__create_all () - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string - From - tw2 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 -Where - string Is Not Null -Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text - From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw15 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity) - /* - * time spans and class label added - **/ - Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), - t1.fk_class, - t3.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification - From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-down.sql b/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-down.sql deleted file mode 100644 index bd82e72c2..000000000 --- a/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-down.sql +++ /dev/null @@ -1,31 +0,0 @@ -Create Or Replace Function war.nodes_and_edges__update_all () - Returns void - Language 'sql' - Cost 100 Volatile - As $BODY$ - Delete From war.node; - -Delete From war.edge; - -Delete From war.enriched_node; - -Insert Into war.node -Select - * -From - war.nodes__create_all (); - -Insert Into war.edge -Select - * -From - war.edges__create_all (); - -Insert Into war.enriched_node -Select - * -From - war.enriched_nodes__create_all (); - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-up.sql b/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-up.sql deleted file mode 100644 index 16cc32b39..000000000 --- a/server/db-migrate/migrations/sqls/20200225123546-war-f-nodes-and-edges--update-all-up.sql +++ /dev/null @@ -1,23 +0,0 @@ -Create Or Replace Function war.nodes_and_edges__update_all () - Returns void - Language 'sql' - Cost 100 Volatile - As $BODY$ - Truncate war.edge; - -Insert Into war.edge -Select - * -From - war.edges__create_all (); - -Truncate war.enriched_node; - -Insert Into war.enriched_node -Select - * -From - war.enriched_nodes__create_all (); - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-down.sql b/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-down.sql deleted file mode 100644 index 009f38736..000000000 --- a/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-down.sql +++ /dev/null @@ -1,12 +0,0 @@ --- enriched node -Create Index enriched_node_full_text_idx On war.enriched_node Using btree (full_text Collate pg_catalog. "default" Asc NULLS Last) Tablespace pg_default; - -Create Index enriched_node_own_entity_label_idx1 On war.enriched_node Using btree (own_entity_label Collate pg_catalog. "default" Asc NULLS Last) Tablespace pg_default; - -Create Index enriched_node_own_entity_label_idx On war.enriched_node Using btree (own_entity_label Collate pg_catalog. "default" Asc NULLS Last) Tablespace pg_default; - -Create Index enriched_node_own_full_text_idx On war.enriched_node Using btree (own_full_text Collate pg_catalog. "default" Asc NULLS Last) Tablespace pg_default; - --- entity preview -Create Index entity_preview_full_text_idx On war.entity_preview Using btree (full_text Collate pg_catalog. "default" Asc NULLS Last) Tablespace pg_default; - diff --git a/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-up.sql b/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-up.sql deleted file mode 100644 index df6f86b49..000000000 --- a/server/db-migrate/migrations/sqls/20200225132753-war-fix-small-indexes-up.sql +++ /dev/null @@ -1,12 +0,0 @@ --- enriched node -Drop Index war.enriched_node_full_text_idx; - -Drop Index war.enriched_node_own_entity_label_idx; - -Drop Index war.enriched_node_own_entity_label_idx1; - -Drop Index war.enriched_node_own_full_text_idx; - --- entity preview -Drop Index war.entity_preview_full_text_idx; - diff --git a/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-down.sql b/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-down.sql deleted file mode 100644 index aaf56573d..000000000 --- a/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-down.sql +++ /dev/null @@ -1,834 +0,0 @@ --- 5 -Create Or Replace Function war.edges__delete_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - Delete From war.edge - Where fk_role = Any (param_pk_roles) - And (fk_project Is Null - Or fk_project = param_fk_project) - Returning - *; - -$BODY$; - --- 4 -Create Or Replace Function war.nodes__delete_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - /** - * Delete the enriched_nodes with param_pk_entities and - * fk_project is param_fk_project or null (repo) - */ - Delete From war.enriched_node - Where pk_entity = Any (param_pk_entities) - And (fk_project Is Not Distinct From param_fk_project - Or fk_project Is Null); - - -/** - * Delete the nodes with param_pk_entities and - * fk_project is param_fk_project or null (repo) - */ -Delete From war.node -Where pk_entity = Any (param_pk_entities) - And (fk_project Is Not Distinct From param_fk_project - Or fk_project Is Null) -Returning - *; - -$BODY$; - --- 2 -Create Or Replace Function war.nodes__create_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t1.fk_temporal_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string - From - tw1 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 -Where - string Is Not Null -Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text - From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - And t2.fk_project = param_fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project - And t3.fk_project = param_fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity) -/* - * time spans added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), -t1.fk_class, -t1.entity_type, -t1.own_entity_label, -t1.own_full_text, -t2.time_span, -t2.first_second, -t2.last_second, -t1.own_entity_label_field_order -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -$BODY$; - --- 1 -Create Or Replace Function war.nodes__create_all () - Returns Setof war.node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string - From - tw2 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 -Where - string Is Not Null -Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text - From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian - From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw15 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity) - /* - * time spans added - **/ - Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), - t1.fk_class, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order - From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project -$BODY$; - --- 3 -Create Or Replace Function war.nodes__upsert_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - -- delete nodes and enriched_nodes - Select - war.nodes__delete_some (param_pk_entities, - param_fk_project); - -Insert Into war.enriched_node -Select - * -From - war.enriched_nodes__create_some (param_pk_entities, - param_fk_project); - -Insert Into war.node -Select - * -From - war.nodes__create_some (param_pk_entities, - param_fk_project) -Returning - *; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-up.sql b/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-up.sql deleted file mode 100644 index 0f73a7015..000000000 --- a/server/db-migrate/migrations/sqls/20200225134631-war-cleanup-up.sql +++ /dev/null @@ -1,19 +0,0 @@ --- 1 -Drop Function war.nodes__create_all (); - --- 2 -Drop Function war.nodes__create_some (integer[], integer); - --- 3 -Drop Function war.nodes__upsert_some (integer[], integer); - --- 4 -Drop Function war.nodes__delete_some (integer[], integer); - --- 5 -Drop Function war.edges__delete_some (integer[], integer); - --- 6 -Select - war.warehouse_update_all (); - diff --git a/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-down.sql b/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-down.sql deleted file mode 100644 index 4bf967e68..000000000 --- a/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-down.sql +++ /dev/null @@ -1,30 +0,0 @@ - --- 4 -ALTER TABLE projects.class_field_config_vt - ADD CONSTRAINT class_field_config_vt_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - - --- 3 -ALTER TABLE public.account_project_rel_vt - ADD CONSTRAINT account_project_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - --- 2 -ALTER TABLE projects.info_proj_rel_vt - ADD CONSTRAINT info_proj_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - - --- 1 -ALTER TABLE projects.dfh_class_proj_rel_vt - ADD CONSTRAINT dfh_class_proj_rel_vt_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; diff --git a/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-up.sql b/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-up.sql deleted file mode 100644 index e1d2b45a5..000000000 --- a/server/db-migrate/migrations/sqls/20200226163610-pro-delete-constraint-up.sql +++ /dev/null @@ -1,12 +0,0 @@ - --- 1 -ALTER TABLE projects.dfh_class_proj_rel_vt DROP CONSTRAINT dfh_class_proj_rel_vt_fk_project_fkey; - --- 2 -ALTER TABLE projects.info_proj_rel_vt DROP CONSTRAINT info_proj_rel_vt_fk_project_fkey; - --- 3 -ALTER TABLE public.account_project_rel_vt DROP CONSTRAINT account_project_rel_vt_fk_project_fkey; - --- 4 -ALTER TABLE projects.class_field_config_vt DROP CONSTRAINT class_field_config_vt_fk_project_fkey; diff --git a/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-down.sql b/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-down.sql deleted file mode 100644 index 939cf60c4..000000000 --- a/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-down.sql +++ /dev/null @@ -1,6 +0,0 @@ -Alter Table data_for_history.property_of_property_vt - Add Column dfh_fk_property_of_property_of_origin int; - -Alter Table data_for_history.property_of_property - Add Column dfh_fk_property_of_property_of_origin int; - diff --git a/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-up.sql b/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-up.sql deleted file mode 100644 index 613d009a3..000000000 --- a/server/db-migrate/migrations/sqls/20200305122338-dfh-t-property-of-property-up.sql +++ /dev/null @@ -1,6 +0,0 @@ -Alter Table data_for_history.property_of_property - Drop Column dfh_fk_property_of_property_of_origin; - -Alter Table data_for_history.property_of_property_vt - Drop Column dfh_fk_property_of_property_of_origin; - diff --git a/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-down.sql b/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-down.sql deleted file mode 100644 index 2f0ad4a12..000000000 --- a/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-down.sql +++ /dev/null @@ -1,268 +0,0 @@ --- 8 -Drop Function information.v_statement_of_statement_find_or_create (); - --- 7 -Drop View information.v_statement_of_statement; - --- 5 -Drop Table information.statement_of_statement_vt; - --- 4 -Create Or Replace Function commons.init_entity_child_table ( - schema_and_table_name character varying -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - unique_constraint_name varchar; -Begin - -- Create the name of the unique constraint that will be applied to the new table's pk_entity - Select - Into unique_constraint_name replace(schema_and_table_name, '.', '_') _pk_entity_unique; - -- Do the Magic: - Execute format( ' - - -- Add unique constraint to pk_entity of the new table, so that it can be referenced by foreign keys - - ALTER TABLE %1$s ADD CONSTRAINT %2$s_pk_entity_unique UNIQUE (pk_entity); - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - ); - - -- Trigger: create_entity_version_key - - CREATE TRIGGER create_entity_version_key - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key(); - - -- Trigger: update_entity_version_key - - CREATE TRIGGER update_entity_version_key - BEFORE UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key();', schema_and_table_name, unique_constraint_name); -End -$BODY$; - --- 3 -Drop Table information.statement_of_statement; - --- 2 -Create Table information.property_of_property_vt ( - pk_entity integer Not Null, - schema_name character varying Collate pg_catalog. "default" Not Null, - table_name character varying Collate pg_catalog. "default" Not Null, - notes text Collate pg_catalog. "default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property integer, - provisional_property character varying Collate pg_catalog. "default", - fk_role integer, - fk_entity_association integer, - fk_range_entity integer Not Null, - entity_version integer -) -With ( - Oids = False) -Tablespace pg_default; - --- 1 -Create Table information.property_of_property ( - -- Inherited from table information.entity: pk_entity integer NOT NULL DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - -- Inherited from table information.entity: schema_name character varying COLLATE pg_catalog."default" NOT NULL, - -- Inherited from table information.entity: table_name character varying COLLATE pg_catalog."default" NOT NULL, - -- Inherited from table information.entity: notes text COLLATE pg_catalog."default", - -- Inherited from table information.entity: fk_creator integer, - -- Inherited from table information.entity: fk_last_modifier integer, - -- Inherited from table information.entity: tmsp_creation timestamp with time zone DEFAULT now(), - -- Inherited from table information.entity: tmsp_last_modification timestamp with time zone, - -- Inherited from table information.entity: sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - -- Inherited from table information.entity: metadata jsonb, - - fk_property integer, - provisional_property character varying Collate pg_catalog. "default", - fk_role integer, - fk_entity_association integer, - fk_range_entity integer Not Null, - entity_version integer, - Constraint information_property_of_property_pk_entity_unique Unique (pk_entity), - Constraint property_of_property_fk_entity_association_fkey Foreign Key (fk_entity_association) References information.entity_association (pk_entity) Match SIMPLE On Update No ACTION On Delete No ACTION, - Constraint property_of_property_fk_role_fkey Foreign Key (fk_role) References information.role (pk_entity) Match SIMPLE On Update No ACTION On Delete No ACTION -) -Inherits ( - information.entity -) -With ( - Oids = False) -Tablespace pg_default; - --- Index: property_of_property_pk_entity_idx --- DROP INDEX information.property_of_property_pk_entity_idx; - -Create Index property_of_property_pk_entity_idx On information.property_of_property Using btree (pk_entity Asc NULLS Last) Tablespace pg_default; - --- Trigger: create_entity_version_key --- DROP TRIGGER create_entity_version_key ON information.property_of_property; - -Create Trigger create_entity_version_key - Before Insert On information.property_of_property For Each Row - Execute Procedure commons.create_entity_version_key (); - --- Trigger: creation_tmsp --- DROP TRIGGER creation_tmsp ON information.property_of_property; - -Create Trigger creation_tmsp - Before Insert On information.property_of_property For Each Row - Execute Procedure commons.tmsp_creation (); - --- Trigger: insert_schema_table_name --- DROP TRIGGER insert_schema_table_name ON information.property_of_property; - -Create Trigger insert_schema_table_name - Before Insert On information.property_of_property For Each Row - Execute Procedure commons.insert_schema_table_name (); - --- Trigger: last_modification_tmsp --- DROP TRIGGER last_modification_tmsp ON information.property_of_property; - -Create Trigger last_modification_tmsp - Before Insert Or Update On information.property_of_property For Each Row - Execute Procedure commons.tmsp_last_modification (); - --- Trigger: update_entity_version_key --- DROP TRIGGER update_entity_version_key ON information.property_of_property; - -Create Trigger update_entity_version_key - Before Update On information.property_of_property For Each Row - Execute Procedure commons.update_entity_version_key (); - --- Trigger: versioning_trigger --- DROP TRIGGER versioning_trigger ON information.property_of_property; - -Create Trigger versioning_trigger - Before Insert Or Delete Or Update On information.property_of_property For Each Row - Execute Procedure public.versioning ('sys_period', 'information.property_of_property_vt', 'true'); - --- 0.1 -Create Or Replace View information.v_property_of_property As -Select - property_of_property.pk_entity, - property_of_property.schema_name, - property_of_property.table_name, - property_of_property.notes, - property_of_property.fk_creator, - property_of_property.fk_last_modifier, - property_of_property.tmsp_creation, - property_of_property.tmsp_last_modification, - property_of_property.sys_period, - property_of_property.metadata, - property_of_property.fk_property, - property_of_property.provisional_property, - property_of_property.fk_role, - property_of_property.fk_entity_association, - property_of_property.fk_range_entity, - property_of_property.entity_version -From - information.property_of_property; - --- 6 -Create Function information.v_property_of_property_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_property_of_property; -Begin - Raise INFO ' input values - NEW.fk_property: %, - NEW.provisional_property: % - NEW.fk_role: % - NEW.fk_entity_association: % - NEW.fk_range_entity: % - ', NEW.fk_property, NEW.provisional_property, NEW.fk_role, NEW.fk_entity_association, NEW.fk_range_entity; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.property_of_property - Where - fk_property Is Not Distinct From NEW.fk_property - And provisional_property Is Not Distinct From NEW.provisional_property - And fk_role Is Not Distinct From NEW.fk_role - And fk_entity_association Is Not Distinct From NEW.fk_entity_association - And fk_range_entity Is Not Distinct From NEW.fk_range_entity; - Raise INFO 'resulting_pk: %', resulting_pk; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - Raise INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.property_of_property (fk_property, provisional_property, fk_role, fk_entity_association, fk_range_entity) - Values (NEW.fk_property, NEW.provisional_property, NEW.fk_role, NEW.fk_entity_association, NEW.fk_range_entity) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_property_of_property - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - --- 0.2 -Create Trigger on_insert - Instead Of INSERT On information.v_property_of_property For Each Row - Execute Procedure information.v_property_of_property_find_or_create (); - diff --git a/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-up.sql b/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-up.sql deleted file mode 100644 index 1b9daee87..000000000 --- a/server/db-migrate/migrations/sqls/20200305125536-inf-t-statement-of-statement-up.sql +++ /dev/null @@ -1,138 +0,0 @@ --- 0 -Drop View information.v_property_of_property; - --- 1 -Drop Table information.property_of_property; - --- 2 -Drop Table information.property_of_property_vt; - --- 3 -Create Table information.statement_of_statement ( - fk_property_of_property integer, - fk_subject integer, - fk_object integer Not Null, - Foreign Key (fk_subject) References information.role (pk_entity) -) -Inherits ( - information.entity -); - --- 4 -Create Or Replace Function commons.init_entity_child_table ( - schema_and_table_name character varying -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - unique_constraint_name varchar; -Begin - -- Create the name of the unique constraint that will be applied to the new table's pk_entity - Select - Into unique_constraint_name replace(schema_and_table_name, '.', '_') _pk_entity_unique; - -- Do the Magic: - Execute format( ' - - -- Add unique constraint to pk_entity of the new table, so that it can be referenced by foreign keys - - ALTER TABLE %1$s ADD CONSTRAINT %2$s_pk_entity_unique UNIQUE (pk_entity); - - -- Trigger: creation_tmsp - - CREATE TRIGGER creation_tmsp - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation(); - - -- Trigger: insert_schema_table_name - - CREATE TRIGGER insert_schema_table_name - BEFORE INSERT - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.insert_schema_table_name(); - - -- Trigger: last_modification_tmsp - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - - -- Table: _vt - - CREATE TABLE %1$s_vt (LIKE %1$s); - - -- Trigger: versioning_trigger - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR UPDATE OR DELETE ON %1$s - FOR EACH ROW EXECUTE PROCEDURE versioning( - "sys_period", ''%1$s_vt'', true - );', schema_and_table_name, unique_constraint_name); -End -$BODY$; - --- 5 -Select - commons.init_entity_child_table ('information.statement_of_statement'); - --- 6 -Drop Function information.v_property_of_property_find_or_create (); - --- 7 -Create View information.v_statement_of_statement As -Select - * -From - information.statement_of_statement; - --- 8 -Create Function information.v_statement_of_statement_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_statement_of_statement; -Begin - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.statement_of_statement - Where - fk_property_of_property Is Not Distinct From NEW.fk_property_of_property - And fk_subject Is Not Distinct From NEW.fk_subject - And fk_object Is Not Distinct From NEW.fk_object; - -- RAISE INFO 'resulting_pk: %', resulting_pk; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - --RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.statement_of_statement (fk_property_of_property, fk_subject, fk_object) - Values (NEW.fk_property_of_property, NEW.fk_subject, NEW.fk_object) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_statement_of_statement - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-down.sql b/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-down.sql deleted file mode 100644 index cca9a8a25..000000000 --- a/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-down.sql +++ /dev/null @@ -1,22 +0,0 @@ --- 3 -Alter Table data. "column" - Drop Column fk_column_relationship_type; - -Alter Table data. "column_vt" - Drop Column fk_column_relationship_type; - --- 2 -Update - system.system_type -Set - st_column_name = 'fk_column_type' -Where - st_column_name = 'fk_column_content_type' - And st_table_name = 'column' - And st_schema_name = 'data'; - --- 1 -Alter Table data.column Rename Column fk_column_content_type To fk_column_type; - -Alter Table data.column_vt Rename Column fk_column_content_type To fk_column_type; - diff --git a/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-up.sql b/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-up.sql deleted file mode 100644 index 9e1156f31..000000000 --- a/server/db-migrate/migrations/sqls/20200309143420-dat-t-column-rework-up.sql +++ /dev/null @@ -1,22 +0,0 @@ --- 1 rename column fk_column_type --> fk_column_content_type -Alter Table data.column Rename Column fk_column_type To fk_column_content_type; - -Alter Table data.column_vt Rename Column fk_column_type To fk_column_content_type; - --- 2 update system_types where st_column_name was 'fk_column_type' -Update - system.system_type -Set - st_column_name = 'fk_column_content_type' -Where - st_column_name = 'fk_column_type' - And st_table_name = 'column' - And st_schema_name = 'data'; - --- 3 add column fk_column_relationship_type -Alter Table data. "column" - Add Column fk_column_relationship_type integer Not Null Default 3367; - -Alter Table data. "column_vt" - Add Column fk_column_relationship_type integer; - diff --git a/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-down.sql b/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-down.sql deleted file mode 100644 index 9e8456799..000000000 --- a/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back diff --git a/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-up.sql b/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-up.sql deleted file mode 100644 index 7f8c9e099..000000000 --- a/server/db-migrate/migrations/sqls/20200309151359-dat-t-cell-and-row-up.sql +++ /dev/null @@ -1,16 +0,0 @@ -Alter Table data.values_association - Drop Constraint If Exists values_association_fk_domain_cell_fkey; - -Alter Table data.values_association - Drop Constraint If Exists values_association_fk_range_cell_fkey; - -Drop Table If Exists data.cell; - -Drop Table If Exists data.cell_vt; - -Drop Materialized View If Exists importer.huygens_data_table_json_prospect; - -Drop Table If Exists data.row; - -Drop Table If Exists data.row_vt; - diff --git a/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-down.sql b/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-down.sql deleted file mode 100644 index 18b63aca9..000000000 --- a/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-down.sql +++ /dev/null @@ -1,124 +0,0 @@ --- 3 -Create Or Replace Function information.v_role_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_role; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.role - Where - fk_entity = NEW.fk_entity - And fk_temporal_entity = NEW.fk_temporal_entity - And fk_property = NEW.fk_property; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.role (fk_entity, fk_temporal_entity, fk_property) - Values (NEW.fk_entity, NEW.fk_temporal_entity, NEW.fk_property) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_role - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - --- 2 -Drop View information.v_role; - -Create View information.v_role As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - -Create Trigger on_insert - Instead Of INSERT On information.v_role For Each Row - Execute Procedure information.v_role_find_or_create (); - --- 1.1 -Alter Table information.role - Alter Column fk_property Drop Not Null; - -Alter Table information.role - Alter Column fk_temporal_entity Drop Not Null; - -Alter Table information.role - Alter Column fk_entity Drop Not Null; - -Alter Table information.role - Alter Column fk_property Drop Default; - -Alter Table information.role - Alter Column fk_temporal_entity Drop Default; - -Alter Table information.role - Alter Column fk_entity Drop Default; - --- 1 -Alter Table information.role - Drop Column fk_data_subject; - -Alter Table information.role - Drop Column fk_data_object; - -Alter Table information.role - Drop Column fk_tables_subject; - -Alter Table information.role - Drop Column fk_tables_object; - -Alter Table information.role_vt - Drop Column fk_data_subject; - -Alter Table information.role_vt - Drop Column fk_data_object; - -Alter Table information.role_vt - Drop Column fk_tables_subject; - -Alter Table information.role_vt - Drop Column fk_tables_object; - diff --git a/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-up.sql b/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-up.sql deleted file mode 100644 index 981369c5e..000000000 --- a/server/db-migrate/migrations/sqls/20200318131855-inf-t-merge-ea-to-role-up.sql +++ /dev/null @@ -1,156 +0,0 @@ --- 1 alter table inf.role add the columns for data schema and tables schema -Alter Table information.role - Add Column fk_property_of_property int Not Null Default 0; - -Alter Table information.role - Add Column fk_subject_data int Not Null Default 0; - -Alter Table information.role - Add Column fk_subject_tables_row bigint Not Null Default 0; - -Alter Table information.role - Add Column fk_subject_tables_cell bigint Not Null Default 0; - -Alter Table information.role - Add Column fk_object_data int Not Null Default 0; - -Alter Table information.role - Add Column fk_object_tables_row bigint Not Null Default 0; - -Alter Table information.role - Add Column fk_object_tables_cell bigint Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_property_of_property int Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_subject_data int Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_subject_tables_row bigint Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_subject_tables_cell bigint Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_object_data int Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_object_tables_row bigint Not Null Default 0; - -Alter Table information.role_vt - Add Column fk_object_tables_cell bigint Not Null Default 0; - --- 1.1 -Alter Table information.role - Alter Column fk_property Set Not Null; - -Alter Table information.role - Alter Column fk_temporal_entity Set Not Null; - -Alter Table information.role - Alter Column fk_entity Set Not Null; - -Alter Table information.role - Alter Column fk_property Set Default 0; - -Alter Table information.role - Alter Column fk_temporal_entity Set Default 0; - -Alter Table information.role - Alter Column fk_entity Set Default 0; - --- 2 alter inf.v_role -Drop View information.v_role; - -Create View information.v_role As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_property_of_property, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_subject_data, - t1.fk_subject_tables_row, - t1.fk_subject_tables_cell, - t1.fk_object_data, - t1.fk_object_tables_row, - t1.fk_object_tables_cell, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - -Create Trigger on_insert - Instead Of INSERT On information.v_role For Each Row - Execute Procedure information.v_role_find_or_create (); - --- 3 alter function create or find inf.v_role -Create Or Replace Function information.v_role_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_role; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.role - Where - fk_property = NEW.fk_property - And fk_property_of_property = NEW.fk_property_of_property - And fk_temporal_entity = NEW.fk_temporal_entity - And fk_subject_data = NEW.fk_subject_data - And fk_subject_tables_row = NEW.fk_subject_tables_row - And fk_subject_tables_cell = NEW.fk_subject_tables_cell - And fk_entity = NEW.fk_entity - And fk_object_data = NEW.fk_object_data - And fk_object_tables_row = NEW.fk_object_tables_row - And fk_object_tables_cell = NEW.fk_object_tables_cell; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.role (fk_property, fk_property_of_property, fk_temporal_entity, fk_subject_data, fk_subject_tables_row, fk_subject_tables_cell, fk_entity, fk_object_data, fk_object_tables_row, fk_object_tables_cell) - Values (NEW.fk_property, NEW.fk_property_of_property, NEW.fk_temporal_entity, NEW.fk_subject_data, NEW.fk_subject_tables_row, NEW.fk_subject_tables_cell, NEW.fk_entity, NEW.fk_object_data, NEW.fk_object_tables_row, NEW.fk_object_tables_cell) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_role - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-down.sql b/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-down.sql deleted file mode 100644 index d605ac65b..000000000 --- a/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-down.sql +++ /dev/null @@ -1,18 +0,0 @@ --- 3 -Drop Trigger creation_tmsp On information.role; - -Drop Trigger last_modification_tmsp On information.role; - --- 2 -Delete From information.role -Where metadata ->> 'from_entity_association' Is Not Null; - --- 1 -Create Trigger creation_tmsp - Before Insert On information.role For Each Row - Execute Procedure commons.tmsp_creation (); - -Create Trigger last_modification_tmsp - Before Insert Or Update On information.role For Each Row - Execute Procedure commons.tmsp_last_modification (); - diff --git a/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-up.sql b/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-up.sql deleted file mode 100644 index 72b0fc24b..000000000 --- a/server/db-migrate/migrations/sqls/20200318133353-inf-d-copy-ea-to-role-up.sql +++ /dev/null @@ -1,29 +0,0 @@ --- 1 disable triggers for timestamps -Drop Trigger creation_tmsp On information.role; - -Drop Trigger last_modification_tmsp On information.role; - --- 2 insert the data -Insert Into information.role (fk_property, fk_temporal_entity, fk_entity, fk_subject_data, fk_object_data, tmsp_creation, tmsp_last_modification, sys_period, metadata) -Select - fk_property, - coalesce(fk_info_domain, 0), - coalesce(fk_info_range, 0), - coalesce(fk_data_domain, 0), - coalesce(fk_data_range, 0), - tmsp_creation, - tmsp_last_modification, - sys_period, - json_build_object('from_entity_association', pk_entity) -From - information.entity_association; - --- 3 enable triggers for timestamps -Create Trigger creation_tmsp - Before Insert On information.role For Each Row - Execute Procedure commons.tmsp_creation (); - -Create Trigger last_modification_tmsp - Before Insert Or Update On information.role For Each Row - Execute Procedure commons.tmsp_last_modification (); - diff --git a/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-down.sql b/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-down.sql deleted file mode 100644 index 6eccb2759..000000000 --- a/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-down.sql +++ /dev/null @@ -1,25 +0,0 @@ --- 2 -Update - projects.info_proj_rel_vt t1 -Set - fk_entity = (t2.metadata ->> 'from_entity_association')::integer -From - information.role t2 -Where - t2.metadata ->> 'from_entity_association' Is Not Null - And t1.fk_entity = t2.pk_entity -Returning - *; - -Update - projects.info_proj_rel t1 -Set - fk_entity = (t2.metadata ->> 'from_entity_association')::integer -From - information.role t2 -Where - t2.metadata ->> 'from_entity_association' Is Not Null - And t1.fk_entity = t2.pk_entity -Returning - *; - diff --git a/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-up.sql b/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-up.sql deleted file mode 100644 index a1f9dd47d..000000000 --- a/server/db-migrate/migrations/sqls/20200318141137-pro-d-change-inf-proj-rel-from-ea-to-role-up.sql +++ /dev/null @@ -1,49 +0,0 @@ --- 1 disable triggers for timestamps and versionsioning (to keep history clean) -Drop Trigger last_modification_tmsp On projects.info_proj_rel; - -Drop Trigger on_upsert On projects.info_proj_rel; - -Drop Trigger update_entity_version_key On projects.info_proj_rel; - -Drop Trigger versioning_trigger On projects.info_proj_rel; - --- 2 update data -Update - projects.info_proj_rel_vt t1 -Set - fk_entity = t2.pk_entity -From - information.role t2 -Where - t1.fk_entity = (t2.metadata ->> 'from_entity_association')::integer -Returning - *; - -Update - projects.info_proj_rel t1 -Set - fk_entity = t2.pk_entity -From - information.role t2 -Where - t1.fk_entity = (t2.metadata ->> 'from_entity_association')::integer -Returning - *; - --- 3 add triggers again -Create Trigger last_modification_tmsp - Before Insert Or Update On projects.info_proj_rel For Each Row - Execute Procedure commons.tmsp_last_modification (); - -Create Trigger on_upsert - Before Insert Or Update On projects.info_proj_rel For Each Row - Execute Procedure commons.evpr_fk_entity_fk_entity_version (); - -Create Trigger update_entity_version_key - Before Update On projects.info_proj_rel For Each Row - Execute Procedure commons.update_entity_version_key (); - -Create Trigger versioning_trigger - Before Insert Or Delete Or Update On projects.info_proj_rel For Each Row - Execute Procedure public.versioning ('sys_period', 'projects.info_proj_rel_vt', 'true'); - diff --git a/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-down.sql b/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-down.sql deleted file mode 100644 index 639dbb479..000000000 --- a/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-down.sql +++ /dev/null @@ -1,291 +0,0 @@ -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) - On Conflict - Do Nothing - Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - Select - pk_new_project As fk_project, - fk_profile, - enabled - From - projects.dfh_profile_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - Select - pk_new_project As fk_project, - fk_class, - enabled_in_entities - From - projects.dfh_class_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') - Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for entity_associations referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an entity_association associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.entity_association t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_cell_domain Is Not Null - Or t2.fk_cell_range Is Not Null - Or t2.fk_data_domain Is Not Null - Or t2.fk_data_range Is Not Null)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - From - projects.info_proj_rel t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy entity_associations pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new digital's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - t4.entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And t3.entity_version = t2.fk_entity_version - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy entity_associations pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.entity_association (fk_data_domain, fk_data_range, fk_info_domain, fk_info_range, fk_property, fk_cell_domain, fk_cell_range, metadata) - -- select entity_associations pointing to the new chunk's fk_cloned_from - Select - t3.pk_entity As fk_data_domain, -- pk of new digital - t2.fk_data_range, - t2.fk_info_domain, - t2.fk_info_range, - t2.fk_property, - t2.fk_cell_domain, - t2.fk_cell_range, - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.entity_association t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_data_domain = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the entity_associations pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) - Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project - From - information.entity_association t1, - data.entity t2 - Where - t1.fk_data_domain = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - From - war.entity_preview - Where - fk_project = pk_sandbox_project - On Conflict On Constraint war_entity_preview_unique - Do Nothing; - - /* - * Clone analysis - */ - Insert Into projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - Select - account_id As fk_last_modifier, - pk_new_project As fk_project, - fk_analysis_type, - name, - description, - analysis_definition - From - projects.analysis - Where - fk_project = pk_sandbox_project; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-up.sql b/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-up.sql deleted file mode 100644 index 766357c27..000000000 --- a/server/db-migrate/migrations/sqls/20200320105024-com-f-clone-sandbox-ea-to-role-up.sql +++ /dev/null @@ -1,298 +0,0 @@ -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) - On Conflict - Do Nothing - Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - Select - pk_new_project As fk_project, - fk_profile, - enabled - From - projects.dfh_profile_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - Select - pk_new_project As fk_project, - fk_class, - enabled_in_entities - From - projects.dfh_class_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') - Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for roles referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an role associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.role t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_subject_tables_cell != 0 - Or t2.fk_object_tables_cell != 0 - Or t2.fk_subject_tables_row != 0 - Or t2.fk_object_tables_row != 0 - Or t2.fk_subject_data != 0 - Or t2.fk_object_data != 0)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - From - projects.info_proj_rel t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy roles pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.role (fk_temporal_entity, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_entity, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select roles pointing to the new digital's fk_cloned_from - Select - coalesce(t2.fk_temporal_entity, 0), - t3.pk_entity As fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_entity, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.role t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 As fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy roles pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.role (fk_temporal_entity, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_entity, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select roles pointing to the new chunk's fk_cloned_from - Select - coalesce(t2.fk_temporal_entity, 0), - t3.pk_entity As fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_entity, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.role t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the roles pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) - Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project - From - information.role t1, - data.entity t2 - Where - t1.fk_subject_data = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - From - war.entity_preview - Where - fk_project = pk_sandbox_project - On Conflict On Constraint war_entity_preview_unique - Do Nothing; - - /* - * Clone analysis - */ - Insert Into projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - Select - account_id As fk_last_modifier, - pk_new_project As fk_project, - fk_analysis_type, - name, - description, - analysis_definition - From - projects.analysis - Where - fk_project = pk_sandbox_project; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-down.sql b/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-down.sql deleted file mode 100644 index be3db8cb8..000000000 --- a/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-down.sql +++ /dev/null @@ -1,141 +0,0 @@ --- 7 -Alter Table information._backup_entity_association Rename To entity_association; - --- 6 -Create View information.v_entity_association As -With ea_project_count As ( - Select - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period, - coalesce(count(*) Filter (Where epr.is_in_project = True), 0::bigint)::integer As is_in_project_count - From - information.entity_association ea_1 - Left Join projects.info_proj_rel epr On epr.fk_entity = ea_1.pk_entity -Group By - ea_1.pk_entity, - ea_1.fk_property, - ea_1.fk_info_domain, - ea_1.fk_info_range, - ea_1.fk_data_domain, - ea_1.fk_data_range, - ea_1.notes, - ea_1.tmsp_creation, - ea_1.tmsp_last_modification, - ea_1.sys_period -) -Select - ea.pk_entity, - ea.fk_property, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.notes, - ea.tmsp_creation, - ea.tmsp_last_modification, - ea.sys_period, - ea.is_in_project_count, - p.range_instances_max_quantifier::smallint As range_max_quantifier, - p.domain_instances_max_quantifier::smallint As domain_max_quantifier -From - ea_project_count ea - Left Join data_for_history.v_property p On ea.fk_property = p.pk_property; - --- 5 -Create Or Replace View war.v_entity_association_per_project_and_repo As Select Distinct - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - epr.fk_project, - coalesce(epr.fk_project, 0) As project, - ea.is_in_project_count -From - information.v_entity_association ea, - projects.info_proj_rel epr -Where - epr.fk_entity = ea.pk_entity - And epr.is_in_project = True -Union -Select Distinct - ea.pk_entity, - ea.fk_info_domain, - ea.fk_info_range, - ea.fk_data_domain, - ea.fk_data_range, - ea.fk_property, - Null::integer As fk_project, - 0 As project, - ea.is_in_project_count -From - information.v_entity_association ea -Where - ea.is_in_project_count > 0; - --- 4 -Create Function information.v_entity_association_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_entity_association; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.entity_association - Where - fk_property = NEW.fk_property - And fk_info_domain Is Not Distinct From NEW.fk_info_domain - And fk_info_range Is Not Distinct From NEW.fk_info_range - And fk_data_domain Is Not Distinct From NEW.fk_data_domain - And fk_data_range Is Not Distinct From NEW.fk_data_range; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.entity_association (fk_property, fk_info_domain, fk_info_range, fk_data_domain, fk_data_range) - Values (NEW.fk_property, NEW.fk_info_domain, NEW.fk_info_range, NEW.fk_data_domain, NEW.fk_data_range) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_entity_association - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - --- 3 -Create Trigger on_insert - Instead Of INSERT On information.v_entity_association For Each Row - Execute Procedure information.v_entity_association_find_or_create (); - --- 2 --- no way back --- 1 --- no way back diff --git a/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-up.sql b/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-up.sql deleted file mode 100644 index 79a29c9f6..000000000 --- a/server/db-migrate/migrations/sqls/20200320134917-inf-ea-to-role-cleanup-up.sql +++ /dev/null @@ -1,21 +0,0 @@ --- 1 -Drop Table If Exists information._backup_role; - --- 2 -Drop Table If Exists information.entity_association_vt; - --- 3 -Drop Trigger on_insert On information.v_entity_association; - --- 4 -Drop Function information.v_entity_association_find_or_create (); - --- 5 -Drop View war.v_entity_association_per_project_and_repo; - --- 6 -Drop View information.v_entity_association; - --- 7 -Alter Table information.entity_association Rename To _backup_entity_association; - diff --git a/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-down.sql b/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-down.sql deleted file mode 100644 index 3b2726974..000000000 --- a/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-down.sql +++ /dev/null @@ -1,15 +0,0 @@ --- 3 and 2 --- no way back --- 1 - -Alter Table data.digital DISABLE Trigger versioning_trigger; - -Update - data.digital -Set - fk_system_type = Null -Where - fk_system_type = 3286; - -Alter Table data.digital ENABLE Trigger versioning_trigger; - diff --git a/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-up.sql b/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-up.sql deleted file mode 100644 index 1bace4916..000000000 --- a/server/db-migrate/migrations/sqls/20200323141313-cleanup-data-related-to-digitals-up.sql +++ /dev/null @@ -1,32 +0,0 @@ --- 1 -Alter Table data.digital DISABLE Trigger versioning_trigger; - -Update - data.digital -Set - fk_system_type = 3286 -Where - fk_system_type Is Null; - -Alter Table data.digital ENABLE Trigger versioning_trigger; - --- 2 --- remove inherited fk_property for 'is part of – geovP6' - -Update - information.role -Set - fk_property = 1317 -Where - fk_property = 1328; - --- 3 --- remove inherited fk_property for 'is reproduction of – geovP1' - -Update - information.role -Set - fk_property = 1216 -Where - fk_property = 1329; - diff --git a/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-down.sql b/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-down.sql deleted file mode 100644 index a57e8204e..000000000 --- a/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-down.sql +++ /dev/null @@ -1,15 +0,0 @@ --- 7 -Drop Trigger on_insert On information.v_lang_string; - --- 6 -Drop Function information.v_lang_string_find_or_create (); - --- 5 -Drop View information.v_lang_string; - --- 3 -Drop Table information.lang_string_vt; - --- 1 -Drop Table information.lang_string; - diff --git a/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-up.sql b/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-up.sql deleted file mode 100644 index f631487b4..000000000 --- a/server/db-migrate/migrations/sqls/20200326064159-inf-t-lang-string-up.sql +++ /dev/null @@ -1,92 +0,0 @@ --- 1 (Inherits all for the string from table commons.text) -Create Table information.lang_string ( - fk_language integer Not Null, - fk_class integer Not Null, - entity_version integer Default 1, - Foreign Key (fk_language) References information.language (pk_entity) -) -Inherits ( - information.entity, - commons.text -); - --- 2 -Create Index On information.lang_string (pk_entity); - -Create Index On information.lang_string (fk_language); - -Create Trigger update_entity_version_key - Before Update On information.lang_string For Each Row - Execute Procedure commons.update_entity_version_key (); - -Create Trigger sync_quill_doc_and_string - Before Insert Or Update On information.lang_string For Each Row - Execute Procedure commons.text__sync_quill_doc_and_string (); - -Alter Table information.lang_string - Add Constraint unique__fk_language__fk_class__string Unique (fk_language, fk_class, string); - --- 3 -Select - commons.init_entity_child_table ('information.lang_string'); - --- 4 -Alter Table information.lang_string_vt INHERIT commons.text_vt; - --- 5 -Create View information.v_lang_string As -Select - * -From - information.lang_string; - --- 6 -Create Function information.v_lang_string_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_lang_string; -Begin - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.lang_string - Where - fk_class Is Not Distinct From NEW.fk_class - And fk_language Is Not Distinct From NEW.fk_language - And string = coalesce(NEW.string, commons.quill_doc_to_string (NEW.quill_doc)); - -- RAISE INFO 'resulting_pk: %', resulting_pk; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - --RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.lang_string (fk_class, fk_language, string, quill_doc) - Values (NEW.fk_class, NEW.fk_language, NEW.string, NEW.quill_doc) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_lang_string - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - --- 7 -Create Trigger on_insert - Instead Of INSERT On information.v_lang_string For Each Row - Execute Procedure information.v_lang_string_find_or_create (); - diff --git a/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-down.sql b/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-down.sql deleted file mode 100644 index 0761990e5..000000000 --- a/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-down.sql +++ /dev/null @@ -1,137 +0,0 @@ --- 4 -Create Table information.statement_of_statement_vt ( - pk_entity integer Not Null, - schema_name character varying Collate pg_catalog. "default" Not Null, - table_name character varying Collate pg_catalog. "default" Not Null, - notes text Collate pg_catalog. "default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - fk_property_of_property integer, - fk_subject integer, - fk_object integer Not Null -); - --- 3 -Create Table information.statement_of_statement ( - -- Inherited from table information.entity: pk_entity integer NOT NULL DEFAULT nextval('information.entity_pk_entity_seq'::regclass), - -- Inherited from table information.entity: schema_name character varying COLLATE pg_catalog."default" NOT NULL, - -- Inherited from table information.entity: table_name character varying COLLATE pg_catalog."default" NOT NULL, - -- Inherited from table information.entity: notes text COLLATE pg_catalog."default", - -- Inherited from table information.entity: fk_creator integer, - -- Inherited from table information.entity: fk_last_modifier integer, - -- Inherited from table information.entity: tmsp_creation timestamp with time zone DEFAULT now(), - -- Inherited from table information.entity: tmsp_last_modification timestamp with time zone, - -- Inherited from table information.entity: sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - -- Inherited from table information.entity: metadata jsonb, - - fk_property_of_property integer, - fk_subject integer, - fk_object integer Not Null, - Constraint information_statement_of_statement_pk_entity_unique Unique (pk_entity), - Constraint statement_of_statement_fk_subject_fkey Foreign Key (fk_subject) References information.role (pk_entity) Match SIMPLE On Update No ACTION On Delete No ACTION -) -Inherits ( - information.entity -) -With ( - Oids = False) -Tablespace pg_default; - -Alter Table information.statement_of_statement Owner To postgres; - --- Trigger: creation_tmsp --- DROP TRIGGER creation_tmsp ON information.statement_of_statement; - -Create Trigger creation_tmsp - Before Insert On information.statement_of_statement For Each Row - Execute Procedure commons.tmsp_creation (); - --- Trigger: insert_schema_table_name --- DROP TRIGGER insert_schema_table_name ON information.statement_of_statement; - -Create Trigger insert_schema_table_name - Before Insert On information.statement_of_statement For Each Row - Execute Procedure commons.insert_schema_table_name (); - --- Trigger: last_modification_tmsp --- DROP TRIGGER last_modification_tmsp ON information.statement_of_statement; - -Create Trigger last_modification_tmsp - Before Insert Or Update On information.statement_of_statement For Each Row - Execute Procedure commons.tmsp_last_modification (); - --- Trigger: versioning_trigger --- DROP TRIGGER versioning_trigger ON information.statement_of_statement; - -Create Trigger versioning_trigger - Before Insert Or Delete Or Update On information.statement_of_statement For Each Row - Execute Procedure public.versioning ('sys_period', 'information.statement_of_statement_vt', 'true'); - --- 2 -Create Or Replace View information.v_statement_of_statement As -Select - statement_of_statement.pk_entity, - statement_of_statement.schema_name, - statement_of_statement.table_name, - statement_of_statement.notes, - statement_of_statement.fk_creator, - statement_of_statement.fk_last_modifier, - statement_of_statement.tmsp_creation, - statement_of_statement.tmsp_last_modification, - statement_of_statement.sys_period, - statement_of_statement.metadata, - statement_of_statement.fk_property_of_property, - statement_of_statement.fk_subject, - statement_of_statement.fk_object -From - information.statement_of_statement; - --- 1 -Create Function information.v_statement_of_statement_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_statement_of_statement; -Begin - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.statement_of_statement - Where - fk_property_of_property Is Not Distinct From NEW.fk_property_of_property - And fk_subject Is Not Distinct From NEW.fk_subject - And fk_object Is Not Distinct From NEW.fk_object; - -- RAISE INFO 'resulting_pk: %', resulting_pk; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - --RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.statement_of_statement (fk_property_of_property, fk_subject, fk_object) - Values (NEW.fk_property_of_property, NEW.fk_subject, NEW.fk_object) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_statement_of_statement - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-up.sql b/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-up.sql deleted file mode 100644 index fcb706209..000000000 --- a/server/db-migrate/migrations/sqls/20200326120045-inf-t-drop-statement-of-statement-up.sql +++ /dev/null @@ -1,12 +0,0 @@ --- 1 -Drop Function information.v_statement_of_statement_find_or_create (); - --- 2 -Drop View information.v_statement_of_statement; - --- 3 -Drop Table information.statement_of_statement; - --- 4 -Drop Table information.statement_of_statement_vt; - diff --git a/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-down.sql b/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-down.sql deleted file mode 100644 index 6ff38d7d8..000000000 --- a/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-down.sql +++ /dev/null @@ -1,403 +0,0 @@ --- 5 -Drop View war.v_property_preview; - -Drop View war.v_class_preview; - -Drop View data_for_history.v_label; - -Create Or Replace View data_for_history.v_label As Select Distinct On (t1.dfh_profile_label, t1.dfh_profile_label_language) - 'label'::text As Type, - t1.dfh_profile_label As label, - t1.dfh_profile_label_language As - Language, - t1.dfh_pk_profile As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_profile_definition, t1.dfh_profile_definition_language) - 'definition'::text As Type, - t1.dfh_profile_definition As label, - t1.dfh_profile_definition_language As - Language, - t1.dfh_pk_profile As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_project_label, t1.dfh_project_label_language) - 'label'::text As Type, - t1.dfh_project_label As label, - t1.dfh_project_label_language As - Language, - Null::integer As fk_profile, - t1.dfh_owned_by_project As fk_project, - Null::integer As fk_property, - Null::integer As fk_class -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_property_label, t1.dfh_property_label_language) - 'label'::text As Type, - t1.dfh_property_label As label, - t1.dfh_property_label_language As - Language, - Null::integer As fk_profile, - Null::integer As fk_project, - t1.dfh_pk_property As fk_property, - Null::integer As fk_class -From - data_for_history.api_property t1 -Union -Select Distinct On (t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) - 'scope_note'::text As Type, - t1.dfh_property_scope_note As label, - t1.dfh_property_scope_note_language As - Language, - Null::integer As fk_profile, - Null::integer As fk_project, - t1.dfh_pk_property As fk_property, - Null::integer As fk_class -From - data_for_history.api_property t1 -Union -Select Distinct On (t1.dfh_class_label, t1.dfh_class_label_language) - 'label'::text As Type, - t1.dfh_class_label As label, - t1.dfh_class_label_language As - Language, - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - t1.dfh_pk_class As fk_class -From - data_for_history.api_class t1 -Union -Select Distinct On (t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) - 'scope_note'::text As Type, - t1.dfh_class_scope_note As label, - t1.dfh_class_scope_note_language As - Language, - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - t1.dfh_pk_class As fk_class -From - data_for_history.api_class t1; - -Create Or Replace View war.v_property_preview As -With tw0 As ( - Select - project.pk_entity, - project.fk_language - From - projects.project - Union All - Select - Null::integer As int4, - 18889 -), -tw1 As ( - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 1 As rank, - 'project label'::text As text - From - tw0 t1, - projects.text_property t2 - Where - t1.pk_entity = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 2 As rank, - 'default project label in default lang'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t3.fk_property, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in default lang'::text As text - From - tw0 t1, - information.language t2, - data_for_history.v_label t3 - Where - t3.fk_property Is Not Null - And t3.language::bpchar = t2.iso6391 - And t3.type = 'label'::text - Union All - Select - t2.fk_dfh_property As fk_property, - t1.pk_entity As fk_project, - t2.string As label, - 4 As rank, - 'default project label in en'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_property Is Not Null - And t2.fk_language = 18889 - Union All - Select - t3.fk_property, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in en'::text As text - From - tw0 t1, - data_for_history.v_label t3 - Where - t3.fk_property Is Not Null - And t3.language::text = 'en'::text - And t3.type = 'label'::text -) -Select Distinct On (tw1.fk_project, tw1.fk_property) - tw1.fk_property, - tw1.fk_project, - tw1.label -From - tw1 -Order By - tw1.fk_project, - tw1.fk_property, - tw1.rank; - -Create Or Replace View war.v_class_preview As -With tw0 As ( - Select - project.pk_entity, - project.fk_language - From - projects.project - Union All - Select - Null::integer As int4, - 18889 -), -tw1 As ( - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 1 As rank, - 'project label'::text As text - From - tw0 t1, - projects.text_property t2 - Where - t1.pk_entity = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 2 As rank, - 'default project label in default lang'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = t1.fk_language - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 3 As rank, - 'ontome label in default lang'::text As text - From - tw0 t1, - information.language t2, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t1.fk_language = t2.pk_entity - And t3.language::bpchar = t2.iso6391 - And t3.type = 'label'::text - Union All - Select - t2.fk_dfh_class As fk_class, - t1.pk_entity As fk_project, - t2.string As label, - 4 As rank, - 'default project label in en'::text As text - From - tw0 t1, - projects.text_property t2 - Where - 375669 = t2.fk_project - And t2.fk_dfh_class Is Not Null - And t2.fk_language = 18889 - Union All - Select - t3.fk_class, - t1.pk_entity As fk_project, - t3.label, - 5 As rank, - 'ontome label in en'::text As text - From - tw0 t1, - data_for_history.v_label t3 - Where - t3.fk_class Is Not Null - And t3.language::text = 'en'::text - And t3.type = 'label'::text -) -Select Distinct On (tw1.fk_project, tw1.fk_class) - tw1.fk_class, - tw1.fk_project, - tw1.label -From - tw1 -Order By - tw1.fk_project, - tw1.fk_class, - tw1.rank; - --- 4 -Drop Table data_for_history.property_of_property_vt; - --- 3 -Drop Table data_for_history.property_of_property; - --- 2 -Create Table data_for_history.property_of_property_vt ( - pk_entity integer Not Null, - schema_name character varying Collate pg_catalog. "default", - table_name character varying Collate pg_catalog. "default", - entity_version integer, - notes text Collate pg_catalog. "default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - tmsp_last_dfh_update timestamp with time zone, - is_enabled_in_profile boolean, - removed_from_api boolean, - dfh_pk_property_of_property integer Not Null, - dfh_identifier_in_namespace text Collate pg_catalog. "default", - dfh_has_property_domain integer, - dfh_has_class_range integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_standard_label character varying(500) Collate pg_catalog. "default", - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint -) -With ( - Oids = False) -Tablespace pg_default; - --- 1 -Create Table data_for_history.property_of_property ( - -- Inherited from table data_for_history.entity: pk_entity integer NOT NULL DEFAULT nextval('data_for_history.entity_pk_entity_seq'::regclass), - -- Inherited from table data_for_history.entity: schema_name character varying COLLATE pg_catalog."default", - -- Inherited from table data_for_history.entity: table_name character varying COLLATE pg_catalog."default", - -- Inherited from table data_for_history.entity: entity_version integer, - -- Inherited from table data_for_history.entity: notes text COLLATE pg_catalog."default", - -- Inherited from table data_for_history.entity: fk_creator integer, - -- Inherited from table data_for_history.entity: fk_last_modifier integer, - -- Inherited from table data_for_history.entity: tmsp_creation timestamp with time zone DEFAULT now(), - -- Inherited from table data_for_history.entity: tmsp_last_modification timestamp with time zone, - -- Inherited from table data_for_history.entity: sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - -- Inherited from table data_for_history.entity: tmsp_last_dfh_update timestamp with time zone, - -- Inherited from table data_for_history.entity: is_enabled_in_profile boolean, - -- Inherited from table data_for_history.entity: removed_from_api boolean DEFAULT false, - - dfh_pk_property_of_property integer Not Null, - dfh_identifier_in_namespace text Collate pg_catalog. "default", - dfh_has_property_domain integer, - dfh_has_class_range integer, - dfh_creation_time timestamp without time zone, - dfh_modification_time timestamp without time zone, - dfh_standard_label character varying(500) Collate pg_catalog. "default", - dfh_domain_instances_min_quantifier smallint, - dfh_domain_instances_max_quantifier smallint, - dfh_range_instances_min_quantifier smallint, - dfh_range_instances_max_quantifier smallint, - Constraint data_for_history_property_of_property_pk_entity_unique Unique (pk_entity), - Constraint unique_dfh_pk_property_of_property Unique (dfh_pk_property_of_property) -) -Inherits ( - data_for_history.entity -) -With ( - Oids = False) -Tablespace pg_default; - --- Index: property_of_property_pk_entity_idx --- DROP INDEX data_for_history.property_of_property_pk_entity_idx; - -Create Index property_of_property_pk_entity_idx On data_for_history.property_of_property Using btree (pk_entity Asc NULLS Last) Tablespace pg_default; - --- Trigger: create_entity_version_key --- DROP TRIGGER create_entity_version_key ON data_for_history.property_of_property; - -Create Trigger create_entity_version_key - Before Insert On data_for_history.property_of_property For Each Row - Execute Procedure commons.create_entity_version_key (); - --- Trigger: creation_tmsp --- DROP TRIGGER creation_tmsp ON data_for_history.property_of_property; - -Create Trigger creation_tmsp - Before Insert On data_for_history.property_of_property For Each Row - Execute Procedure commons.tmsp_creation (); - --- Trigger: insert_schema_table_name --- DROP TRIGGER insert_schema_table_name ON data_for_history.property_of_property; - -Create Trigger insert_schema_table_name - Before Insert On data_for_history.property_of_property For Each Row - Execute Procedure commons.insert_schema_table_name (); - --- Trigger: last_modification_tmsp --- DROP TRIGGER last_modification_tmsp ON data_for_history.property_of_property; - -Create Trigger last_modification_tmsp - Before Insert Or Update On data_for_history.property_of_property For Each Row - Execute Procedure commons.tmsp_last_modification (); - --- Trigger: update_entity_version_key --- DROP TRIGGER update_entity_version_key ON data_for_history.property_of_property; - -Create Trigger update_entity_version_key - Before Update On data_for_history.property_of_property For Each Row - Execute Procedure commons.update_entity_version_key (); - --- Trigger: versioning_trigger --- DROP TRIGGER versioning_trigger ON data_for_history.property_of_property; - -Create Trigger versioning_trigger - Before Insert Or Delete Or Update On data_for_history.property_of_property For Each Row - Execute Procedure public.versioning ('sys_period', 'data_for_history.property_of_property_vt', 'true'); - diff --git a/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-up.sql b/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-up.sql deleted file mode 100644 index aabef5faf..000000000 --- a/server/db-migrate/migrations/sqls/20200403122139-dfh-property-of-property-up.sql +++ /dev/null @@ -1,157 +0,0 @@ --- 1 -Alter Table data.property_of_property - Drop Constraint If Exists property_of_property_fk_property_of_property_fkey; - -Alter Table data.property_of_property_mapping - Drop Constraint If Exists property_of_property_mapping_fk_property_of_property_fkey; - -Drop Table data_for_history.property_of_property; - --- 2 -Drop Table data_for_history.property_of_property_vt; - --- 3 -Create Table data_for_history.property_of_property ( - pk_property_of_property integer Not Null, - label text, - label_language character varying, - scope_note text, - scope_note_language character varying, - is_inherited boolean, - has_domain integer, - dfh_domain_instances_min_quantifier integer, - dfh_domain_instances_max_quantifier integer, - has_range integer, - dfh_range_instances_min_quantifier integer, - dfh_range_instances_max_quantifier integer, - identifier_in_namespace character varying, - fk_profile integer, - Unique (pk_entity), - Unique (has_domain, pk_property_of_property, has_range) -) -Inherits ( - data_for_history.entity -); - --- 4 -Select - commons.init_entity_child_table ('data_for_history.property_of_property'); - --- 5 -Create Or Replace View data_for_history.v_label As Select Distinct On (t1.dfh_profile_label, t1.dfh_profile_label_language) - 'label'::text As "type", - t1.dfh_profile_label As "label", - t1.dfh_profile_label_language As "language", - t1.dfh_pk_profile As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_profile_definition, t1.dfh_profile_definition_language) - 'definition'::text As "type", - t1.dfh_profile_definition As "label", - t1.dfh_profile_definition_language As "language", - t1.dfh_pk_profile As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_project_label, t1.dfh_project_label_language) - 'label'::text As "type", - t1.dfh_project_label As "label", - t1.dfh_project_label_language As "language", - Null::integer As fk_profile, - t1.dfh_owned_by_project As fk_project, - Null::integer As fk_property, - Null::integer As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_profile t1 -Union -Select Distinct On (t1.dfh_property_label, t1.dfh_property_label_language) - 'label'::text As "type", - t1.dfh_property_label As "label", - t1.dfh_property_label_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - t1.dfh_pk_property As fk_property, - Null::integer As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_property t1 -Union -Select Distinct On (t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) - 'scope_note'::text As "type", - t1.dfh_property_scope_note As "label", - t1.dfh_property_scope_note_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - t1.dfh_pk_property As fk_property, - Null::integer As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_property t1 -Union -Select Distinct On (t1.dfh_class_label, t1.dfh_class_label_language) - 'label'::text As "type", - t1.dfh_class_label As "label", - t1.dfh_class_label_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - t1.dfh_pk_class As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_class t1 -Union -Select Distinct On (t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) - 'scope_note'::text As "type", - t1.dfh_class_scope_note As "label", - t1.dfh_class_scope_note_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - t1.dfh_pk_class As fk_class, - Null::integer As fk_property_of_property -From - data_for_history.api_class t1 -Union -Select Distinct On (t1.label, t1.label_language) - 'label'::text As "type", - t1.label As "label", - t1.label_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class, - t1.pk_property_of_property As fk_property_of_property -From - data_for_history.property_of_property t1 -Union -Select Distinct On (t1.scope_note, t1.scope_note_language) - 'scope_note'::text As "type", - t1.scope_note As "label", - t1.scope_note_language As "language", - Null::integer As fk_profile, - Null::integer As fk_project, - Null::integer As fk_property, - Null::integer As fk_class, - t1.pk_property_of_property As fk_property_of_property -From - data_for_history.property_of_property t1; - --- 6 -Insert Into data_for_history.property_of_property (pk_property_of_property, label, label_language, scope_note, scope_note_language, is_inherited, has_domain, dfh_domain_instances_min_quantifier, dfh_domain_instances_max_quantifier, has_range, dfh_range_instances_min_quantifier, dfh_range_instances_max_quantifier, identifier_in_namespace, fk_profile) - Values (1, 'has reference', 'en', 'Description of a location within an Information Object, like the reference to a page in a book, written in free text.', 'en', False, 1218, -- mentions – geovP2 - 1, 1, 657, -- Reference – geovC13 - 0, 1, 'geov?', 5 -- Geovistory Basics -) -On Conflict - Do Nothing; - diff --git a/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-down.sql b/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-down.sql deleted file mode 100644 index 9a13367c4..000000000 --- a/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-down.sql +++ /dev/null @@ -1,88 +0,0 @@ -Create Or Replace Function information.get_outgoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all outgoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.range_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.range_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.range_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_temporal_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t4.has_domain In (t2.fk_class, 50 -- make every class to a timespan class -) - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-up.sql b/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-up.sql deleted file mode 100644 index 2db8ed0d2..000000000 --- a/server/db-migrate/migrations/sqls/20200421133152-inf-f-add-te-en-up.sql +++ /dev/null @@ -1,89 +0,0 @@ -Create Or Replace Function information.get_outgoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all outgoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.range_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.range_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.range_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_temporal_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t1.is_in_project_count > 0 - And t4.has_domain In (t2.fk_class, 50 -- make every class to a timespan class -) - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-down.sql b/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-down.sql deleted file mode 100644 index d0aacdeb0..000000000 --- a/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-down.sql +++ /dev/null @@ -1,2882 +0,0 @@ --- 1 rename information.statement -> role -Alter Table information.statement Rename To Role; - --- 2 rename information.statement_vt -> role_vt -Alter Table information.statement_vt Rename To role_vt; - --- 3 rename column information.role (fk_subject_info) -> (fk_temporal_entity) -Alter Table information.role Rename Column fk_subject_info To fk_temporal_entity; - --- 4 rename column information.role_vt (fk_subject_info) -> (fk_temporal_entity) -Alter Table information.role_vt Rename Column fk_subject_info To fk_temporal_entity; - --- 5 rename column information.role (fk_object_info) -> (fk_entity) -Alter Table information.role Rename Column fk_object_info To fk_entity; - --- 6 rename column information.role_vt (fk_object_info) -> (fk_entity) -Alter Table information.role_vt Rename Column fk_object_info To fk_entity; - --- 7 drop view information.v_statement -Drop View information.v_statement; - --- 8 create view information.v_role -Create Or Replace View information.v_role As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_property_of_property, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_subject_data, - t1.fk_subject_tables_row, - t1.fk_subject_tables_cell, - t1.fk_object_data, - t1.fk_object_tables_row, - t1.fk_object_tables_cell, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - --- 9 rename trigger function v_statement_find_or_create() -> v_role_find_or_create -Alter Function information.v_statement_find_or_create Rename To v_role_find_or_create; - --- fn-1 refactor function commons.get_entity_appellation -Create Or Replace Function commons.get_entity_appellation ( - pk_entity integer -) - Returns character varying - Language 'sql' - Cost 100 Volatile - As $BODY$ - Select - t3.string - From - information.role t1, - information.role t2, - information.appellation t3 - Where - t1.fk_entity = $1 - And t2.fk_temporal_entity = t1.fk_temporal_entity - And t2.fk_property = 1113 - And t2.fk_entity = t3.pk_entity; - -$BODY$; - --- fn-2 refactor function information.get_outgoing_roles_to_add -Drop Function information.get_outgoing_statements_to_add; - -Create Or Replace Function information.get_outgoing_roles_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_entity integer, - fk_temporal_entity integer, - calendar calendar_type -) - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all outgoing roles, joined with range and domain class - Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t3.fk_class range_class, - t1.fk_property, - Case When t4.range_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.range_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.range_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_role t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_temporal_entity = entity_id - And t1.fk_temporal_entity = t2.pk_entity - And t1.fk_entity = t3.pk_entity - And t1.fk_property = t4.pk_property - And t1.is_in_project_count > 0 - And t4.has_domain In (t2.fk_class, 50 -- make every class to a timespan class -) - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_entity, - fk_temporal_entity, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - --- fn-3 ADD function information.relate_outgoing_roles_with_te_ens_to_project -Create Or Replace Function information.relate_outgoing_roles_with_te_ens_to_project ( - param_pk_roles integer[], - param_pk_project integer, - param_account_id integer, - param_is_in_project boolean -) - Returns Setof projects.info_proj_rel - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - /** - * Changes relation of temporal entities to project that are domain of given roles. - * - * For each temporal entity, select: - * - * * General properties - * - * Appellations - * - incoming roles of property 'has appellation for language' and is_in_projects_count > 0 - * - temporal entities of class 'appellation use for language' - * - outgoing roles of those 'appellation use for languages', - * while in each group of property not more then the max quantifier allows - * - * Type - * - max. one outgoing role fullfilling those criteria - * - it is of a has-type subproperty - * - it is the role with highes is_in_projects_count - * - is_in_projects_count > 0 - * - * Text Properties - * - All related text_properties that are in at least one project - * - * * Specific properties - * - * Outgoing Roles - * - outgoing role of properties, fullfilling those criteria: - * - property is enabled by the given project - * - max number of roles per property is not bigger than max range quantifier - * - role is_in_projects_count > 0 - * - */ - /* - * - */ - With tw01 As ( - -- select the ingoing roles - Select - pk_entity, - fk_temporal_entity - From - information.v_role - Where - pk_entity In ( - Select - (unnest(param_pk_roles))) -), -tw02 As ( - -- select the ids of the temproal entities - Select - fk_temporal_entity As pk_entity - From - tw01 -), -/* - * General properties - */ -tw1 As ( - -- select roles 'has appellation for language' - Select - t1.pk_entity, - t1.fk_temporal_entity - From - information.v_role t1, - tw02 t2 - Where - t1.fk_entity = t2.pk_entity - And t1.fk_property = 1111 - And t1.is_in_project_count > 0 -), -tw2 As ( - -- select temporal entities 'appellation use for language' - Select - fk_temporal_entity As pk_entity - From - tw1 -), -tw3 As ( - -- select outgoing roles of those 'appellation use for languages' - Select - t2.pk_entity, - calendar - From - tw2 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, param_pk_project)) As t2 -), -tw4 As ( - -- select has type role - Select - t1.pk_entity - From - information.v_role t1, - data_for_history.v_property t2, - tw02 t3 - Where - t1.fk_temporal_entity = t3.pk_entity - And t1.fK_property = t2.pk_property - And t2.is_has_type_subproperty - And t1.is_in_project_count > 0 - Order By - t1.is_in_project_count Desc - Limit 1 -), -tw5 As ( - -- select text properties - Select Distinct - t1.pk_entity - From - information.text_property t1, - projects.info_proj_rel t2, - tw02 t3 - Where - t1.fk_concerned_entity = t3.pk_entity - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True -), -/** - * Specific properties - */ -tw6 As ( - -- select outgoing roles of the temporal entities - Select - t2.pk_entity, - calendar - From - tw02 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, param_pk_project)) As t2 -), -tw7 As ( - -- union all entities to add to project - Select - pk_entity, - Null::calendar_type calendar - From - tw02 -Union -Select - pk_entity, - Null::calendar_type calendar -From - tw1 -Union -Select - pk_entity, - Null::calendar_type calendar -From - tw2 -Union -Select - pk_entity, - calendar calendar -From - tw3 -Union -Select - pk_entity, - Null::calendar_type calendar -From - tw4 -Union -Select - pk_entity, - Null::calendar_type calendar -From - tw5 -Union -Select - pk_entity, - calendar calendar -From - tw6) - Insert Into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - Select - param_pk_project, - param_is_in_project, - pk_entity, - calendar, - param_account_id - From - tw7 t1 - On Conflict On Constraint entity_version_project_rel_fk_entity_fk_project_key - Do Update Set - is_in_project = EXCLUDED.is_in_project, - calendar = EXCLUDED.calendar, - fk_last_modifier = EXCLUDED.fk_last_modifier - Returning - *; - -$BODY$; - --- fn-4 ADD function information.add_pe_it_to_project -Create Or Replace Function information.add_pe_it_to_project ( - param_pk_entity integer, - param_pk_project integer, - param_account_id integer -) - Returns void - Language 'sql' - Cost 100 Volatile - As $BODY$ - /** - * Adds a persistent item to a project, with general properties: - * - * Appellations - * - incoming roles of property 'has appellation for language' and is_in_projects_count > 0 - * - temporal entities of class 'appellation use for language' - * - outgoing roles of those 'appellation use for languages', - * while in each group of property not more then the max quantifier allows - * - * Type - * - max. one outgoing role fullfilling those criteria - * - it is of a has-type subproperty - * - it is the role with highes is_in_projects_count - * - is_in_projects_count > 0 - * - * Text Properties - * - All related text_properties that are in at least one project - */ - With tw1 As ( - -- select roles 'has appellation for language' - Select - pk_entity, - fk_temporal_entity - From - information.v_role - Where - fk_entity = param_pk_entity - And fk_property = 1111 - And is_in_project_count > 0 -), -tw2 As ( - -- select temporal entities 'appellation use for language' - Select - fk_temporal_entity As pk_entity - From - tw1 -), -tw3 As ( - -- select outgoing roles of those 'appellation use for languages' - Select - t2.pk_entity, - calendar - From - tw2 t1 - Cross Join Lateral ( - Select - * - From - information.get_outgoing_roles_to_add (t1.pk_entity, param_pk_project)) As t2 -), -tw4 As ( - -- select has type role - Select - t1.pk_entity - From - information.v_role t1, - data_for_history.v_property t2 - Where - t1.fk_temporal_entity = param_pk_entity - And t1.fK_property = t2.pk_property - And t2.is_has_type_subproperty - And t1.is_in_project_count > 0 - Order By - t1.is_in_project_count Desc - Limit 1 -), -tw5 As ( - -- select text properties - Select Distinct - t1.pk_entity - From - information.text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = param_pk_entity - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True -), -tw6 As ( - -- union all entities to add to project - Select - param_pk_entity pk_entity, - Null::calendar_type calendar - Union - Select - pk_entity, - Null::calendar_type calendar - From - tw1 - Union - Select - pk_entity, - Null::calendar_type calendar - From - tw2 - Union - Select - pk_entity, - calendar calendar - From - tw3 - Union - Select - pk_entity, - Null::calendar_type calendar - From - tw4 - Union - Select - pk_entity, - Null::calendar_type calendar - From - tw5) - Insert Into projects.info_proj_rel (fk_project, is_in_project, fk_entity, calendar, fk_last_modifier) - Select - param_pk_project, - True, - pk_entity, - calendar, - param_account_id - From - tw6 t1 - On Conflict On Constraint entity_version_project_rel_fk_entity_fk_project_key - Do Update Set - is_in_project = EXCLUDED.is_in_project, - calendar = EXCLUDED.calendar, - fk_last_modifier = EXCLUDED.fk_last_modifier; - -$BODY$; - --- fn-5 ADD function information.add_pe_its_to_project -Create Or Replace Function information.add_pe_its_to_projects ( - entity_pks integer[], - project_pks integer[], - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_entity int; - pk_project int; -Begin - FOREACH pk_entity In Array entity_pks Loop - FOREACH pk_project In Array project_pks Loop - Perform - information.add_pe_it_to_project (pk_entity, pk_project, account_id); - End Loop; - End Loop; -End -$BODY$; - --- fn-6 ADD function information.temporal_entity_find_or_create -Create Or Replace Function information.temporal_entity_find_or_create ( - param_fk_class integer, - param_roles jsonb -) - Returns information.temporal_entity - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - resulting_row information.temporal_entity; -Begin - -- -- RAISE INFO 'input values: %', NEW; - -- ------ if existing, store in result ----- - -- With tw1 As ( - -- -- select the fk_entities of the outgoing roles - -- Select - -- * - -- From - -- jsonb_to_recordset(param_roles) As x (fk_entity int, - -- fk_property int) - -- ), - -- tw2 As ( - -- -- select all temporal entities, being domain of a role and as such a candidate - -- Select - -- fk_temporal_entity - -- From - -- information.role t1, - -- tw1 t2 - -- Where - -- t1.fk_entity = t2.fk_entity - -- And t1.fk_property = t2.fk_property - -- ), - -- existing_te_ens As ( - -- Select - -- t2.fk_temporal_entity, - -- array_agg(jsonb_build_object('fk_property', t2.fk_property, 'fk_entity', t2.fk_entity)) identity_defining_roles - -- From - -- tw2 t1, - -- information.role t2, - -- ( Select Distinct On (dfh_pk_property) - -- dfh_pk_property, - -- dfh_identity_defining - -- From - -- data_for_history.api_property) t3 - -- Where - -- t1.fk_temporal_entity = t2.fk_temporal_entity - -- And t3.dfh_pk_property = t2.fk_property - -- And t3.dfh_identity_defining = True - -- Group By - -- t2.fk_temporal_entity - -- ), - -- new_te_en As ( - -- Select - -- array_agg(a.elements::jsonb) roles - -- From ( - -- Select - -- 1 x, - -- jsonb_array_elements_text(param_roles) elements) As a - -- Group By - -- a.x - -- ) - -- Select - -- teEn.* - -- From - -- Into resulting_row existing_te_ens - -- -- Here we check if the roles for the new TeEn do completele contain all the identity defining roles of an existing TeEn - -- Join new_te_en On new_te_en.roles @> existing_te_ens.identity_defining_roles - -- Join information.temporal_entity As teEn On teEn.pk_entity = existing_te_ens.fk_temporal_entity - -- Where - -- teEn.fk_class = param_fk_class; - -- -- RAISE EXCEPTION 'resulting_row: %', resulting_row; - -- -- RAISE INFO 'result of select: %', resulting_row; - -- ------- if not existing, insert and store in result ----- - -- If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.temporal_entity (fk_class) - Values (param_fk_class) - -- return all fields of the new row - Returning - *) - Select - * - From - Into resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row -- ; - -- End If; - Return resulting_row; -End; -$BODY$; - --- fn-7 refactor function information.v_role_find_or_create -Create Or Replace Function information.v_role_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_role; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.role - Where - fk_property = NEW.fk_property - And fk_property_of_property = NEW.fk_property_of_property - And fk_temporal_entity = NEW.fk_temporal_entity - And fk_subject_data = NEW.fk_subject_data - And fk_subject_tables_row = NEW.fk_subject_tables_row - And fk_subject_tables_cell = NEW.fk_subject_tables_cell - And fk_entity = NEW.fk_entity - And fk_object_data = NEW.fk_object_data - And fk_object_tables_row = NEW.fk_object_tables_row - And fk_object_tables_cell = NEW.fk_object_tables_cell; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.role (fk_property, fk_property_of_property, fk_temporal_entity, fk_subject_data, fk_subject_tables_row, fk_subject_tables_cell, fk_entity, fk_object_data, fk_object_tables_row, fk_object_tables_cell) - Values (NEW.fk_property, NEW.fk_property_of_property, NEW.fk_temporal_entity, NEW.fk_subject_data, NEW.fk_subject_tables_row, NEW.fk_subject_tables_cell, NEW.fk_entity, NEW.fk_object_data, NEW.fk_object_tables_row, NEW.fk_object_tables_cell) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_role - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - -Create Trigger on_insert - Instead Of INSERT On information.v_role For Each Row - Execute Procedure information.v_role_find_or_create (); - --- fn-8 refactor function commons.clone_sandbox_project -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) - On Conflict - Do Nothing - Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - Select - pk_new_project As fk_project, - fk_profile, - enabled - From - projects.dfh_profile_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - Select - pk_new_project As fk_project, - fk_class, - enabled_in_entities - From - projects.dfh_class_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') - Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for roles referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an role associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.role t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_subject_tables_cell != 0 - Or t2.fk_object_tables_cell != 0 - Or t2.fk_subject_tables_row != 0 - Or t2.fk_object_tables_row != 0 - Or t2.fk_subject_data != 0 - Or t2.fk_object_data != 0)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - From - projects.info_proj_rel t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy roles pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.role (fk_temporal_entity, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_entity, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select roles pointing to the new digital's fk_cloned_from - Select - coalesce(t2.fk_temporal_entity, 0), - t3.pk_entity As fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_entity, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.role t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 As fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy roles pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.role (fk_temporal_entity, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_entity, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select roles pointing to the new chunk's fk_cloned_from - Select - coalesce(t2.fk_temporal_entity, 0), - t3.pk_entity As fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_entity, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.role t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the roles pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) - Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project - From - information.role t1, - data.entity t2 - Where - t1.fk_subject_data = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - From - war.entity_preview - Where - fk_project = pk_sandbox_project - On Conflict On Constraint war_entity_preview_unique - Do Nothing; - - /* - * Clone analysis - */ - Insert Into projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - Select - account_id As fk_last_modifier, - pk_new_project As fk_project, - fk_analysis_type, - name, - description, - analysis_definition - From - projects.analysis - Where - fk_project = pk_sandbox_project; -End; -$BODY$; - --- 10 rename column war.edge (fk_statement) -> (fk_role) -Alter Table war.edge Rename Column fk_statement To fk_role; - --- fn-9 refactor function war.do_updates_for_difference_since -Create Or Replace Function war.do_updates_for_difference_since ( - tmsp timestamp Without time zone -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - t_row record; - node_ids war.node_id[]; - t timestamptz := clock_timestamp(); - -- used for DEBUGGING - enrich_loop_count int := 0; -Begin - Create TEMP Table changed_info_proj_rel On Commit Drop As - -- select recently modified info_proj_rels - Select - t1.fk_entity, t1.fk_project, t1.is_in_project, t1.tmsp_last_modification - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp; - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - - /* - * 1. Delete enriched_nodes and entity previews - * - * Delete the enriched_nodes and entity_previews of PeIt’s or TeEn’s that have a - * recently been removed from their project (modified info_proj_rel where - * is_in_project = false) - * - * Read this about temp tables on commit drop: - * https://stackoverflow.com/questions/10596896/postgresql-thread-safety-for-temporary-tables - */ - -- DEBUG - Raise notice '#1.a querying removed_crm_entities...'; - Create TEMP Table removed_crm_entities On Commit Drop As - With tw1 As ( - -- select recent info_proj_rel where is_in_project = false - Select - t1.fk_entity, - t1.fk_project - From - changed_info_proj_rel t1 - Where - t1.is_in_project = False -), -tw2 As ( --- join persistent_items -Select - t2.fk_entity, - t2.fk_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- join temporal_entities - Select - t2.fk_entity, - t2.fk_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - ) - Select - fk_entity, fk_project - From - tw2; - -- DEBUG TIME - Raise notice '...#1.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#1.b deleting enriched_nodes and entity_previews...'; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_crm_entities) - Loop - Raise NOTICE 'Node to delete fk_project: %, fk_entity: %', t_row.fk_project, t_row.fk_entity; - End Loop; - -- END DEBUG - -- delete enriched_nodes - Delete From war.enriched_node t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- delete entity_previews - Delete From war.entity_preview t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- DEBUG TIME - Raise notice '...#1.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.a querying affected_nodes'; - - /* - * 2. Update enriched_node table - * - * all enriched_nodes that are possibly affected by the modifications since last update, - * need to be updated or inserted. Enriched_nodes are possibly affected, if a PeIt or - * TeEn is added to project, if a role or text_property related to that PeIt or TeEn - * is changed in its relation to the project. - */ - Create TEMP Table affected_nodes On Commit Drop As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.is_in_project, - t1.tmsp_last_modification - From - changed_info_proj_rel t1 -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( --- persistent_items where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- domain entities of roles where info_proj_rel changed - Select - t1.fk_temporal_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of roles where info_proj_rel changed - Select - t1.fk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.role t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( -Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification -From - tw2 t1 -Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, fk_project, array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, is_in_project; - -- DEBUG TIME - Raise notice '...#2.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.b upserting affected_nodes...'; - - /** - * Loop over the affected nodes per project and upsert the enriched nodes - * (the not recursive columns) - */ - For t_row In ( - Select - * - From - affected_nodes) - Loop - -- START DEBUG - -- Show affected_nodes - Raise NOTICE 'Nodes to upsert fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - -- END DEBUG - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.enriched_nodes__upsert_some (t_row.pk_entities, t_row.fk_project); - End Loop; - -- DEBUG TIME - Raise notice '...#2.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.a query removed_roles...'; - - /* - * 3. Delete edges - * - * Delete the edges of roles that have a recently been removed from their project - * (modified info_proj_rel where is_in_project = false) - */ - Create TEMP Table removed_roles On Commit Drop As - -- select recent info_proj_rel to roles where is_in_project = false - Select - t1.fk_entity As fk_role, t1.fk_project, t2.fk_entity, t2.fk_temporal_entity - From - changed_info_proj_rel t1, information.role t2 - Where - t1.is_in_project = False - And t1.fk_entity = t2.pk_entity; - -- Add the entities, related to removed roles, to to_enrich - Insert Into to_enrich - -- select domain persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_temporal_entity - Union All - -- select range persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- select domain temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_temporal_entity - Union All - -- select range temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_roles t2 - Where - t1.pk_entity = t2.fk_entity; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_roles) - Loop - Raise NOTICE 'Edges to delete fk_project: %, fk_role: %', t_row.fk_project, t_row.fk_role; - End Loop; - -- END DEBUG - Raise notice '...#3.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.b delete edges...'; - Delete From war.edge t1 Using removed_roles t2 - Where t1.fk_project Is Not Distinct From t2.fk_project - And t1.fk_role = t2.fk_role; - -- DEBUG TIME - Raise notice '...#3.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.a query affected roles...'; - - /* - * 4. Update edges - * - * All edges that are affected by the modifications since last update need to be updated or inserted. - */ - Create TEMP Table updated_roles On Commit Drop As - -- select recent info_proj_rel to roles where is_in_project = false - Select - array_agg( t1.fk_entity - ) As fk_roles, t1.fk_project -From - changed_info_proj_rel t1, information.role t2 -Where - t1.fk_entity = t2.pk_entity - And t1.is_in_project = True -Group By - t1.fk_project; - Raise notice '...#4.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.b update edges...'; - -- Update the edges - For t_row In ( - Select - * - From - updated_roles) - Loop - -- DEBUG - -- show the updated roles - Raise NOTICE 'Updated roles fk_project: %, fk_roles: %', t_row.fk_project, t_row.fk_roles; - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_roles, t_row.fk_project); - End Loop; - Raise notice '...#4.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - - /* - * 5. Enrich nodes - * - * Fill all recursive colums of all enriched_nodes that are not up to date. - * After this step, the table enriched_node should be in a final state - * so that the changes can be brought to the table entity_previews - */ - -- START DEBUG - Raise notice '#5 enrich nodes...'; - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - to_enrich) - Loop - Raise NOTICE 'Initial nodes to_enrich (before loop): fk_project%, pk_entity: %', t_row.fk_project, t_row.pk_entity; - End Loop; - -- END DEBUG - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - WHILE ( - Select - (count(*) > 0 - And enrich_loop_count <= 50) - From to_enrich) - Loop - -- breac - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - -- DEBUG - -- Show node_ids to enrich - Raise NOTICE 'node_ids from to_enrich %', node_ids; - -- show number of iterations - Raise NOTICE 'enrich_loop_count %', enrich_loop_count; - enrich_loop_count = enrich_loop_count + 1; - If enrich_loop_count = 50 Then - Raise WARNING 'enrich_loop_count = 50. node_ids from to_enrich %', node_ids; - End If; - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - Raise notice '...#5 time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#6 update entity_previews...'; - - /* - * 6. Update entity_previews - * - * Update all entity_previews with all enriched_nodes where tmsp_last_modification - * is more recent than last update_log.tmsp_update_end. - */ - Create TEMP Table modified_enriched_node On Commit Drop As - With tw1 As ( - -- select the modified enriched_node - Select - * - From - war.enriched_node t1 - Where - t1.tmsp_last_modification > tmsp ) - -- Select the entity_previews that are different in one of the columns - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - war.entity_preview t1, tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Update the edges that are different in one of the non recursive columns - Update - war.entity_preview t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - entity_type = t2.entity_type, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_label = t2.entity_label, - full_text = t2.full_text, - ts_vector = t2.ts_vector, - type_label = t2.type_label, - fk_type = t2.fk_type, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - modified_enriched_node t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Insert the created edges that do not yet exist - Insert Into war.entity_preview - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - From - modified_enriched_node t1 - On Conflict - Do Nothing; - Raise notice '...#6 time spent=%', clock_timestamp() - t; -End; -$BODY$; - --- fn-10 refactor function war.edges__create_all -Create Or Replace Function war.edges__create_all () - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_role) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role -From - tw1; - -$BODY$; - --- fn-11 refactor function war.edges__create_some -Drop Function war.edges__create_some (integer[], integer); - -Create Or Replace Function war.edges__create_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_temporal_entity As fk_source, - t1.fk_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_role, - t1.fk_entity As fk_source, - t1.fk_temporal_entity As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_role t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_entity) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_temporal_entity - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_temporal_entity) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_roles) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_role) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_role -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_role -From - tw1; - -$BODY$; - --- fn-12 refactor function war.edges__upsert_some -Drop Function war.edges__upsert_some (integer[], integer); - -Create Or Replace Function war.edges__upsert_some ( - param_pk_roles integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- Create edges on the fly - Select - * - From - war.edges__create_some (param_pk_roles, param_fk_project) -), -tw2 As ( - -- Select the edges that are different in one of the non recursive columns - Select - * - From - tw1 t1 - Except - Select - t1.* - From - war.edge t1, - tw1 t2 - Where - t1.fk_role = t2.fk_role - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the edges that are different in one of the non recursive columns - Update - war.edge t1 - Set - fk_source = t2.fk_source, - fk_project = t2.fk_project, - fk_target = t2.fk_target, - target_provides = t2.target_provides, - ord_num_within_field = t2.ord_num_within_field, - field_order = t2.field_order, - fk_role = t2.fk_role - From - tw2 t2 - Where - t1.fk_role = t2.fk_role - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created edges that do not yet exist - Insert Into war.edge - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - ---Alter Function war.edges__upsert_some (integer[], integer) Owner To postgres; - --- fn-13 refactor function war.enriched_nodes__create_all -Create Or Replace Function war.enriched_nodes__create_all () - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw2 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join tw15 t2 On t2.pk_entity = t1.fk_entity - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span -From - tw16 -Group By - tw16.fk_project, - tw16.fk_temporal_entity) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), - t1.fk_class, - t3.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - --- fn-14 refactor function war.enriched_nodes__create_some -Create Or Replace Function war.enriched_nodes__create_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' roles -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_role t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t1.fk_temporal_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property -From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw1 t1 - -- join outgoing roles - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_temporal_entity = t1.pk_entity - -- join appellation with outgoing roles - Left Join information.appellation t3 On t2.fk_entity = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - And t2.fk_project = param_fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project - And t3.fk_project = param_fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select roles with time primitive, first and last second -tw16 As ( - Select - t1.fk_temporal_entity, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_entity, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_temporal_entity, - t1.fk_property) - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_role t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_entity) t2 On t1.fk_temporal_entity = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_temporal_entity, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_temporal_entity, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_temporal_entity) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), -t1.fk_class, -t3.label As class_label, -t1.entity_type, -t1.own_entity_label, -t1.own_full_text, -t2.time_span, -t2.first_second, -t2.last_second, -t1.own_entity_label_field_order, -t1.own_entity_label As entity_label, -Null::integer fk_type, -Null::text type_label, -Null::text full_text, -Null::tsvector ts_vector, -Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_temporal_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - --- 11 rename indexes and constraints -Alter Index information.statement_pk_entity_idx Rename To role_pk_entity_idx; - -Alter Index information.statement_fk_object_info_idx Rename To role_fk_entity_idx; - -Alter Index information.statement_fk_subject_info_idx Rename To role_fk_temporal_entity_idx; - -Alter Table information.role Rename Constraint information_statement_pk_entity_unique To information_role_pk_entity_unique; - --- 12 recreate vm_statement -Drop Materialized View war.vm_statement; - -Create Materialized View war.vm_statement Tablespace pg_default As -With tw1 As ( - Select - t1.pk_entity, - t1.fk_property, - t1.fk_entity, - t1.fk_temporal_entity, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - From - information.role t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True - Group By - info_proj_rel.fk_entity) t2 On True -) -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - tw1 t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_entity, - t1.fk_temporal_entity, - t1.fk_property, - Null::integer As fk_project, - 0 As project, - Null::integer As ord_num_of_domain, - Null::integer As ord_num_of_range, - t1.is_in_project_count -From - tw1 t1 -Where - t1.is_in_project_count > 0 With DATA; - -Create Index vm_statement_fk_entity_idx On war.vm_statement Using btree (fk_entity) Tablespace pg_default; - -Create Index vm_statement_fk_project_idx On war.vm_statement Using btree (fk_project) Tablespace pg_default; - -Create Index vm_statement_fk_property_idx On war.vm_statement Using btree (fk_property) Tablespace pg_default; - -Create Index vm_statement_fk_temporal_entity_idx On war.vm_statement Using btree (fk_temporal_entity) Tablespace pg_default; - -Create Index vm_statement_pk_entity_idx On war.vm_statement Using btree (pk_entity) Tablespace pg_default; - -Create Unique Index vm_statement_pk_entity_project_idx On war.vm_statement Using btree (pk_entity, project) Tablespace pg_default; - diff --git a/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-up.sql b/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-up.sql deleted file mode 100644 index 448b9dc97..000000000 --- a/server/db-migrate/migrations/sqls/20200512124546-inf-t-role-renaming-up.sql +++ /dev/null @@ -1,2429 +0,0 @@ --- 1 rename information.role -> statement -Alter Table information.role Rename To statement; - --- 2 rename information.role_vt -> statement_vt -Alter Table information.role_vt Rename To statement_vt; - --- 3 rename column information.statement (fk_temporal_entity) -> (fk_subject_info) -Alter Table information.statement Rename Column fk_temporal_entity To fk_subject_info; - --- 4 rename column information.statement_vt (fk_temporal_entity) -> (fk_subject_info) -Alter Table information.statement_vt Rename Column fk_temporal_entity To fk_subject_info; - --- 5 rename column information.statement (fk_entity) -> (fk_object_info) -Alter Table information.statement Rename Column fk_entity To fk_object_info; - --- 6 rename column information.statement_vt (fk_entity) -> (fk_object_info) -Alter Table information.statement_vt Rename Column fk_entity To fk_object_info; - --- 7 drop view information.v_role -Drop View information.v_role; - --- 8 create view information.v_statement -Create Or Replace View information.v_statement As -Select - t1.pk_entity, - t1.fk_property, - t1.fk_property_of_property, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_subject_data, - t1.fk_subject_tables_row, - t1.fk_subject_tables_cell, - t1.fk_object_data, - t1.fk_object_tables_row, - t1.fk_object_tables_cell, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -From - information.statement t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count, - coalesce(count(*) Filter (Where info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer As is_standard_in_project_count, - mode() Within Group (Order By info_proj_rel.calendar) As community_favorite_calendar - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True Group By - info_proj_rel.fk_entity) t2 On True; - --- 9 rename trigger function v_role_find_or_create -> v_statement_find_or_create() -Alter Function information.v_role_find_or_create Rename To v_statement_find_or_create; - --- fn-1 refactor function commons.get_entity_appellation -Create Or Replace Function commons.get_entity_appellation ( - pk_entity integer -) - Returns character varying - Language 'sql' - Cost 100 Volatile - As $BODY$ - Select - t3.string - From - information.statement t1, - information.statement t2, - information.appellation t3 - Where - t1.fk_object_info = $1 - And t2.fk_subject_info = t1.fk_subject_info - And t2.fk_property = 1113 - And t2.fk_object_info = t3.pk_entity; - -$BODY$; - --- fn-2 refactor function information.get_outgoing_roles_to_add -Drop Function information.get_outgoing_roles_to_add; - -Create Or Replace Function information.get_outgoing_statements_to_add ( - entity_id integer, - project_id integer -) - Returns Table ( - pk_entity integer, - fk_object_info integer, - fk_subject_info integer, - calendar calendar_type -) - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- select profiles the project - Select - fk_profile - From - projects.dfh_profile_proj_rel - Where - fk_project = project_id - Union - Select - 5 As fk_profile -- GEOVISTORY BASICS -), -tw2 As ( - -- select properties of the project - Select Distinct On (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - From - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - Where - t1.fk_profile = t2.dfh_fk_profile - And t3.pk_property = t2.dfh_pk_property -), -tw3 As ( - -- select all outgoing statements, joined with range and domain class - Select - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t3.fk_class range_class, - t1.fk_property, - Case When t4.range_instances_max_quantifier = - 1 Then - FLOAT8 '+infinity' - When t4.range_instances_max_quantifier Is Null Then - FLOAT8 '+infinity' - Else - t4.range_instances_max_quantifier - End target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() Over (Partition By t3.fk_class, - t1.fk_property Order By is_in_project_count Desc) As rank, - t1.community_favorite_calendar calendar - From - information.v_statement t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - Where - fk_subject_info = entity_id - And t1.fk_subject_info = t2.pk_entity - And t1.fk_object_info = t3.pk_entity - And t1.fk_property = t4.pk_property - And t1.is_in_project_count > 0 - And t4.has_domain In (t2.fk_class, 50 -- make every class to a timespan class -) - And t3.fk_class = t4.has_range -) -Select - pk_entity, - fk_object_info, - fk_subject_info, - calendar -From - tw3 -Where - target_max_quantifier >= rank; - -$BODY$; - --- fn-3 DROP function information.relate_outgoing_roles_with_te_ens_to_project -Drop Function information.relate_outgoing_roles_with_te_ens_to_project; - --- fn-4 DROP function information.add_pe_it_to_project -Drop Function information.add_pe_it_to_project; - --- fn-5 DROP function information.add_pe_its_to_projects -Drop Function information.add_pe_its_to_projects; - --- fn-6 DROP function information.temporal_entity_find_or_create -Drop Function information.temporal_entity_find_or_create; - --- fn-7 refactor function information.v_statement_find_or_create -Create Or Replace Function information.v_statement_find_or_create () - Returns Trigger - Language 'plpgsql' - Cost 100 Volatile Not Leakproof - As $BODY$ -Declare - resulting_pk integer; - resulting_row information.v_statement; -Begin - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - Select - pk_entity - From - Into resulting_pk information.statement - Where - fk_property = NEW.fk_property - And fk_property_of_property = NEW.fk_property_of_property - And fk_subject_info = NEW.fk_subject_info - And fk_subject_data = NEW.fk_subject_data - And fk_subject_tables_row = NEW.fk_subject_tables_row - And fk_subject_tables_cell = NEW.fk_subject_tables_cell - And fk_object_info = NEW.fk_object_info - And fk_object_data = NEW.fk_object_data - And fk_object_tables_row = NEW.fk_object_tables_row - And fk_object_tables_cell = NEW.fk_object_tables_cell; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - If Not FOUND Then - -- RAISE INFO 'Not found, creating new...'; - With _insert As ( -Insert Into information.statement (fk_property, fk_property_of_property, fk_subject_info, fk_subject_data, fk_subject_tables_row, fk_subject_tables_cell, fk_object_info, fk_object_data, fk_object_tables_row, fk_object_tables_cell) - Values (NEW.fk_property, NEW.fk_property_of_property, NEW.fk_subject_info, NEW.fk_subject_data, NEW.fk_subject_tables_row, NEW.fk_subject_tables_cell, NEW.fk_object_info, NEW.fk_object_data, NEW.fk_object_tables_row, NEW.fk_object_tables_cell) - -- return all fields of the new row - Returning - *) - Select - pk_entity - From - Into resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - End If; - Select - * - From - Into resulting_row information.v_statement - Where - pk_entity = resulting_pk; - Return resulting_row; -End; -$BODY$; - -Create Trigger on_insert - Instead Of INSERT On information.v_statement For Each Row - Execute Procedure information.v_statement_find_or_create (); - --- fn-8 refactor function commons.clone_sandbox_project -Create Or Replace Function commons.clone_sandbox_project ( - account_id integer -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -Begin - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - Insert Into projects.project (fk_language, fk_cloned_from_project) - Values (fk_project_default_language, pk_sandbox_project) - On Conflict - Do Nothing - Returning - pk_entity Into pk_new_project; - - /* - * add label of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - Insert Into projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - Values (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - Insert Into projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - Select - pk_new_project As fk_project, - fk_profile, - enabled - From - projects.dfh_profile_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - Insert Into projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - Select - pk_new_project As fk_project, - fk_class, - enabled_in_entities - From - projects.dfh_class_proj_rel - Where - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - Insert Into data.namespace (fk_project, standard_label) - Values (pk_new_project, 'Default Namespace') - Returning - pk_entity Into pk_new_default_namespace; - - /* - * add account to project - */ - Insert Into public.account_project_rel (fk_project, account_id, Role) - Values (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for statements referencing to data - */ - With tw1 As ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - Select - t1.pk_entity - From - projects.info_proj_rel t1 - Where - fk_project = pk_sandbox_project - Except - Select - t1.pk_entity - From - projects.info_proj_rel t1, - information.statement t2 - Where - fk_project = pk_sandbox_project - And t1.fk_entity = t2.pk_entity - And (t2.fk_subject_tables_cell != 0 - Or t2.fk_object_tables_cell != 0 - Or t2.fk_subject_tables_row != 0 - Or t2.fk_object_tables_row != 0 - Or t2.fk_subject_data != 0 - Or t2.fk_object_data != 0)) - Insert Into projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - Select - pk_new_project As fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - From - projects.info_proj_rel t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.digital t2 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace; - - /* - * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new digital's fk_cloned_from - Select - coalesce(t2.fk_subject_info, 0), - t3.pk_entity As fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.statement t2, - data.digital t3 - Where - fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - Insert Into data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - Select - pk_new_default_namespace As fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 As fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - From - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - Where - t1.fk_project = pk_sandbox_project - And t1.pk_entity = t2.fk_namespace - And t3.pk_text = t2.fk_text - And (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - Insert Into information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new chunk's fk_cloned_from - Select - coalesce(t2.fk_subject_info, 0), - t3.pk_entity As fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - From - projects.info_proj_rel t1, - information.statement t2, - data.chunk t3 - Where - t1.fk_project = pk_sandbox_project - And t1.is_in_project = True - And t1.fk_entity = t2.pk_entity - And t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - And t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the statements pointing to data to the new project - */ - Insert Into projects.info_proj_rel (fk_entity, fk_project, is_in_project) - Select - t1.pk_entity As fk_entity, - pk_new_project As fk_project, - True As is_in_project - From - information.statement t1, - data.entity t2 - Where - t1.fk_subject_data = t2.pk_entity - And t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - Insert Into war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - Select - pk_entity, - pk_new_project As fk_project, - pk_new_project As project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - From - war.entity_preview - Where - fk_project = pk_sandbox_project - On Conflict On Constraint war_entity_preview_unique - Do Nothing; - - /* - * Clone analysis - */ - Insert Into projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - Select - account_id As fk_last_modifier, - pk_new_project As fk_project, - fk_analysis_type, - name, - description, - analysis_definition - From - projects.analysis - Where - fk_project = pk_sandbox_project; -End; -$BODY$; - --- 10 rename column war.edge (fk_role) -> (fk_statement) -Alter Table war.edge Rename Column fk_role To fk_statement; - --- fn-9 refactor function war.do_updates_for_difference_since -Create Or Replace Function war.do_updates_for_difference_since ( - tmsp timestamp Without time zone -) - Returns void - Language 'plpgsql' - Cost 100 Volatile - As $BODY$ -Declare - t_row record; - node_ids war.node_id[]; - t timestamptz := clock_timestamp(); - -- used for DEBUGGING - enrich_loop_count int := 0; -Begin - Create TEMP Table changed_info_proj_rel On Commit Drop As - -- select recently modified info_proj_rels - Select - t1.fk_entity, t1.fk_project, t1.is_in_project, t1.tmsp_last_modification - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp; - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - - /* - * 1. Delete enriched_nodes and entity previews - * - * Delete the enriched_nodes and entity_previews of PeIt’s or TeEn’s that have a - * recently been removed from their project (modified info_proj_rel where - * is_in_project = false) - * - * Read this about temp tables on commit drop: - * https://stackoverflow.com/questions/10596896/postgresql-thread-safety-for-temporary-tables - */ - -- DEBUG - Raise notice '#1.a querying removed_crm_entities...'; - Create TEMP Table removed_crm_entities On Commit Drop As - With tw1 As ( - -- select recent info_proj_rel where is_in_project = false - Select - t1.fk_entity, - t1.fk_project - From - changed_info_proj_rel t1 - Where - t1.is_in_project = False -), -tw2 As ( --- join persistent_items -Select - t2.fk_entity, - t2.fk_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- join temporal_entities - Select - t2.fk_entity, - t2.fk_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - ) - Select - fk_entity, fk_project - From - tw2; - -- DEBUG TIME - Raise notice '...#1.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#1.b deleting enriched_nodes and entity_previews...'; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_crm_entities) - Loop - Raise NOTICE 'Node to delete fk_project: %, fk_entity: %', t_row.fk_project, t_row.fk_entity; - End Loop; - -- END DEBUG - -- delete enriched_nodes - Delete From war.enriched_node t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- delete entity_previews - Delete From war.entity_preview t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- DEBUG TIME - Raise notice '...#1.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.a querying affected_nodes'; - - /* - * 2. Update enriched_node table - * - * all enriched_nodes that are possibly affected by the modifications since last update, - * need to be updated or inserted. Enriched_nodes are possibly affected, if a PeIt or - * TeEn is added to project, if a statement or text_property related to that PeIt or TeEn - * is changed in its relation to the project. - */ - Create TEMP Table affected_nodes On Commit Drop As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.is_in_project, - t1.tmsp_last_modification - From - changed_info_proj_rel t1 -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( --- persistent_items where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- domain entities of statements where info_proj_rel changed - Select - t1.fk_subject_info As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.statement t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of statements where info_proj_rel changed - Select - t1.fk_object_info As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.statement t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( -Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification -From - tw2 t1 -Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, fk_project, array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, is_in_project; - -- DEBUG TIME - Raise notice '...#2.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.b upserting affected_nodes...'; - - /** - * Loop over the affected nodes per project and upsert the enriched nodes - * (the not recursive columns) - */ - For t_row In ( - Select - * - From - affected_nodes) - Loop - -- START DEBUG - -- Show affected_nodes - Raise NOTICE 'Nodes to upsert fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - -- END DEBUG - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.enriched_nodes__upsert_some (t_row.pk_entities, t_row.fk_project); - End Loop; - -- DEBUG TIME - Raise notice '...#2.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.a query removed_statements...'; - - /* - * 3. Delete edges - * - * Delete the edges of statements that have a recently been removed from their project - * (modified info_proj_rel where is_in_project = false) - */ - Create TEMP Table removed_statements On Commit Drop As - -- select recent info_proj_rel to statements where is_in_project = false - Select - t1.fk_entity As fk_statement, t1.fk_project, t2.fk_object_info, t2.fk_subject_info - From - changed_info_proj_rel t1, information.statement t2 - Where - t1.is_in_project = False - And t1.fk_entity = t2.pk_entity; - -- Add the entities, related to removed statements, to to_enrich - Insert Into to_enrich - -- select domain persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_subject_info - Union All - -- select range persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_object_info - Union All - -- select domain temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_subject_info - Union All - -- select range temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_object_info; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_statements) - Loop - Raise NOTICE 'Edges to delete fk_project: %, fk_statement: %', t_row.fk_project, t_row.fk_statement; - End Loop; - -- END DEBUG - Raise notice '...#3.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.b delete edges...'; - Delete From war.edge t1 Using removed_statements t2 - Where t1.fk_project Is Not Distinct From t2.fk_project - And t1.fk_statement = t2.fk_statement; - -- DEBUG TIME - Raise notice '...#3.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.a query affected statements...'; - - /* - * 4. Update edges - * - * All edges that are affected by the modifications since last update need to be updated or inserted. - */ - Create TEMP Table updated_statements On Commit Drop As - -- select recent info_proj_rel to statements where is_in_project = false - Select - array_agg( t1.fk_entity - ) As fk_statements, t1.fk_project -From - changed_info_proj_rel t1, information.statement t2 -Where - t1.fk_entity = t2.pk_entity - And t1.is_in_project = True -Group By - t1.fk_project; - Raise notice '...#4.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.b update edges...'; - -- Update the edges - For t_row In ( - Select - * - From - updated_statements) - Loop - -- DEBUG - -- show the updated statements - Raise NOTICE 'Updated statements fk_project: %, fk_statements: %', t_row.fk_project, t_row.fk_statements; - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_statements, t_row.fk_project); - End Loop; - Raise notice '...#4.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - - /* - * 5. Enrich nodes - * - * Fill all recursive colums of all enriched_nodes that are not up to date. - * After this step, the table enriched_node should be in a final state - * so that the changes can be brought to the table entity_previews - */ - -- START DEBUG - Raise notice '#5 enrich nodes...'; - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - to_enrich) - Loop - Raise NOTICE 'Initial nodes to_enrich (before loop): fk_project%, pk_entity: %', t_row.fk_project, t_row.pk_entity; - End Loop; - -- END DEBUG - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - WHILE ( - Select - (count(*) > 0 - And enrich_loop_count <= 50) - From to_enrich) - Loop - -- breac - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - -- DEBUG - -- Show node_ids to enrich - Raise NOTICE 'node_ids from to_enrich %', node_ids; - -- show number of iterations - Raise NOTICE 'enrich_loop_count %', enrich_loop_count; - enrich_loop_count = enrich_loop_count + 1; - If enrich_loop_count = 50 Then - Raise WARNING 'enrich_loop_count = 50. node_ids from to_enrich %', node_ids; - End If; - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - Raise notice '...#5 time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#6 update entity_previews...'; - - /* - * 6. Update entity_previews - * - * Update all entity_previews with all enriched_nodes where tmsp_last_modification - * is more recent than last update_log.tmsp_update_end. - */ - Create TEMP Table modified_enriched_node On Commit Drop As - With tw1 As ( - -- select the modified enriched_node - Select - * - From - war.enriched_node t1 - Where - t1.tmsp_last_modification > tmsp ) - -- Select the entity_previews that are different in one of the columns - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - war.entity_preview t1, tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Update the edges that are different in one of the non recursive columns - Update - war.entity_preview t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - entity_type = t2.entity_type, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_label = t2.entity_label, - full_text = t2.full_text, - ts_vector = t2.ts_vector, - type_label = t2.type_label, - fk_type = t2.fk_type, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - modified_enriched_node t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Insert the created edges that do not yet exist - Insert Into war.entity_preview - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - From - modified_enriched_node t1 - On Conflict - Do Nothing; - Raise notice '...#6 time spent=%', clock_timestamp() - t; -End; -$BODY$; - --- fn-10 refactor function war.edges__create_all -Create Or Replace Function war.edges__create_all () - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_subject_info As fk_source, - t1.fk_object_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_object_info As fk_source, - t1.fk_subject_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_statement) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1; - -$BODY$; - --- fn-11 refactor function war.edges__create_some -Drop Function war.edges__create_some (integer[], integer); - -Create Or Replace Function war.edges__create_some ( - param_pk_statements integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_subject_info As fk_source, - t1.fk_object_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_statements) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_object_info As fk_source, - t1.fk_subject_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_statements) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_statement) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1; - -$BODY$; - --- fn-12 refactor function war.edges__upsert_some -Drop Function war.edges__upsert_some (integer[], integer); - -Create Or Replace Function war.edges__upsert_some ( - param_pk_statements integer[], - param_fk_project integer -) - Returns Setof war.edge - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With tw1 As ( - -- Create edges on the fly - Select - * - From - war.edges__create_some (param_pk_statements, param_fk_project) -), -tw2 As ( - -- Select the edges that are different in one of the non recursive columns - Select - * - From - tw1 t1 - Except - Select - t1.* - From - war.edge t1, - tw1 t2 - Where - t1.fk_statement = t2.fk_statement - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the edges that are different in one of the non recursive columns - Update - war.edge t1 - Set - fk_source = t2.fk_source, - fk_project = t2.fk_project, - fk_target = t2.fk_target, - target_provides = t2.target_provides, - ord_num_within_field = t2.ord_num_within_field, - field_order = t2.field_order, - fk_statement = t2.fk_statement - From - tw2 t2 - Where - t1.fk_statement = t2.fk_statement - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created edges that do not yet exist - Insert Into war.edge - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - --- fn-13 refactor function war.enriched_nodes__create_all -Create Or Replace Function war.enriched_nodes__create_all () - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' statements -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_statement t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw2 t1 - -- join outgoing statements - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_subject_info = t1.pk_entity - -- join appellation with outgoing statements - Left Join information.appellation t3 On t2.fk_object_info = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select statements with time primitive, first and last second -tw16 As ( - Select - t1.fk_subject_info, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.statement t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_object_info - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_subject_info, - t1.fk_property) - t1.fk_subject_info, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_statement t1 - Join tw15 t2 On t2.pk_entity = t1.fk_object_info - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_subject_info, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_subject_info, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span -From - tw16 -Group By - tw16.fk_project, - tw16.fk_subject_info) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), - t1.fk_class, - t3.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_subject_info - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - --- fn-14 refactor function war.enriched_nodes__create_some -Create Or Replace Function war.enriched_nodes__create_some ( - param_pk_entities integer[], - param_fk_project integer -) - Returns Setof war.enriched_node - Language 'sql' - Cost 100 Volatile Rows 1000 - As $BODY$ - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' statements -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_statement t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t1.fk_subject_info = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property -From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw1 t1 - -- join outgoing statements - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_subject_info = t1.pk_entity - -- join appellation with outgoing statements - Left Join information.appellation t3 On t2.fk_object_info = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - And t2.fk_project = param_fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project - And t3.fk_project = param_fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select statements with time primitive, first and last second -tw16 As ( - Select - t1.fk_subject_info, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.statement t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_object_info) t2 On t1.fk_subject_info = Any (param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_object_info, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_subject_info, - t1.fk_property) - t1.fk_subject_info, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_statement t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_object_info) t2 On t1.fk_subject_info = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_subject_info, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_subject_info, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_subject_info) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), -t1.fk_class, -t3.label As class_label, -t1.entity_type, -t1.own_entity_label, -t1.own_full_text, -t2.time_span, -t2.first_second, -t2.last_second, -t1.own_entity_label_field_order, -t1.own_entity_label As entity_label, -Null::integer fk_type, -Null::text type_label, -Null::text full_text, -Null::tsvector ts_vector, -Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_subject_info - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - --- 11 rename indexes and constraints -Alter Index information.role_pk_entity_idx Rename To statement_pk_entity_idx; - -Alter Index information.role_fk_entity_idx Rename To statement_fk_object_info_idx; - -Alter Index information.role_fk_temporal_entity_idx Rename To statement_fk_subject_info_idx; - -Alter Table information.statement Rename Constraint information_role_pk_entity_unique To information_statement_pk_entity_unique; - --- 12 recreate vm_statement -Drop Materialized View war.vm_statement; - -Create Materialized View war.vm_statement Tablespace pg_default As -With tw1 As ( - Select - t1.pk_entity, - t1.fk_property, - t1.fk_object_info, - t1.fk_subject_info, - t2.is_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period - From - information.statement t1 - Left Join Lateral ( - Select - count(info_proj_rel.pk_entity)::integer As is_in_project_count - From - projects.info_proj_rel - Where - info_proj_rel.fk_entity = t1.pk_entity - And info_proj_rel.is_in_project = True - Group By - info_proj_rel.fk_entity) t2 On True -) -Select - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - tw1 t1, - projects.info_proj_rel t2 -Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -Union -Select - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - Null::integer As fk_project, - 0 As project, - Null::integer As ord_num_of_domain, - Null::integer As ord_num_of_range, - t1.is_in_project_count -From - tw1 t1 -Where - t1.is_in_project_count > 0 With DATA; - -Create Index vm_statement_fk_object_info_idx On war.vm_statement Using btree (fk_object_info) Tablespace pg_default; - -Create Index vm_statement_fk_project_idx On war.vm_statement Using btree (fk_project) Tablespace pg_default; - -Create Index vm_statement_fk_property_idx On war.vm_statement Using btree (fk_property) Tablespace pg_default; - -Create Index vm_statement_fk_subject_info_idx On war.vm_statement Using btree (fk_subject_info) Tablespace pg_default; - -Create Index vm_statement_pk_entity_idx On war.vm_statement Using btree (pk_entity) Tablespace pg_default; - -Create Unique Index vm_statement_pk_entity_project_idx On war.vm_statement Using btree (pk_entity, project) Tablespace pg_default; - diff --git a/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-down.sql b/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-down.sql deleted file mode 100644 index 7715b8e25..000000000 --- a/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-down.sql +++ /dev/null @@ -1,17 +0,0 @@ --- UPDATE ACCOUNT (back - 1) -ALTER TABLE public.account -ADD COLUMN password text; - --- MIGRATE PASSWORDS (back) -UPDATE public.account - SET password = public.credential.password - FROM public.credential - WHERE public.account.id = public.credential.accountId; - --- UPDATE ACCOUNT (back - 2) -ALTER TABLE public.account -ALTER COLUMN password SET NOT NULL; - - --- CREATE THE NEW TABLE (back) -DROP TABLE public.credential; diff --git a/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-up.sql b/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-up.sql deleted file mode 100644 index 93b12e35c..000000000 --- a/server/db-migrate/migrations/sqls/20200701063201-lb3-account-to-lb4-accountCredentials-up.sql +++ /dev/null @@ -1,16 +0,0 @@ --- CREATE THE NEW TABLE -CREATE TABLE public.credential -( - id serial PRIMARY KEY, - accountId integer NOT NULL, - password text NOT NULL, - CONSTRAINT account_credential_fkey FOREIGN KEY (accountId) REFERENCES public.account (id) -); - --- MIGRATE PASSWORDS -INSERT INTO public.credential (accountId, password) - SELECT id, password FROM public.account; - --- UPDATE ACCOUNT -ALTER TABLE public.account -DROP COLUMN password; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-down.sql b/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-down.sql deleted file mode 100644 index cec2c9fbf..000000000 --- a/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-down.sql +++ /dev/null @@ -1,31 +0,0 @@ -CREATE OR REPLACE VIEW information.v_entity_class_map - AS - SELECT appellation.pk_entity, - appellation.fk_class, - 'appellation'::text AS table_name - FROM information.appellation -UNION ALL - SELECT language.pk_entity, - language.fk_class, - 'language'::text AS table_name - FROM information.language -UNION ALL - SELECT persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::text AS table_name - FROM information.persistent_item -UNION ALL - SELECT place.pk_entity, - place.fk_class, - 'place'::text AS table_name - FROM information.place -UNION ALL - SELECT temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::text AS table_name - FROM information.temporal_entity -UNION ALL - SELECT time_primitive.pk_entity, - time_primitive.fk_class, - 'time_primitive'::text AS table_name - FROM information.time_primitive; diff --git a/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-up.sql b/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-up.sql deleted file mode 100644 index 04b867cf9..000000000 --- a/server/db-migrate/migrations/sqls/20200709093513-inf-v-entity-class-map-up.sql +++ /dev/null @@ -1,41 +0,0 @@ -CREATE OR REPLACE VIEW information.v_entity_class_map - AS - SELECT appellation.pk_entity, - appellation.fk_class, - 'appellation'::text AS table_name - FROM information.appellation -UNION ALL - SELECT language.pk_entity, - language.fk_class, - 'language'::text AS table_name - FROM information.language -UNION ALL - SELECT persistent_item.pk_entity, - persistent_item.fk_class, - 'persistent_item'::text AS table_name - FROM information.persistent_item -UNION ALL - SELECT place.pk_entity, - place.fk_class, - 'place'::text AS table_name - FROM information.place -UNION ALL - SELECT dimension.pk_entity, - dimension.fk_class, - 'dimension'::text AS table_name - FROM information.dimension -UNION ALL - SELECT lang_string.pk_entity, - lang_string.fk_class, - 'lang_string'::text AS table_name - FROM information.lang_string -UNION ALL - SELECT temporal_entity.pk_entity, - temporal_entity.fk_class, - 'temporal_entity'::text AS table_name - FROM information.temporal_entity -UNION ALL - SELECT time_primitive.pk_entity, - time_primitive.fk_class, - 'time_primitive'::text AS table_name - FROM information.time_primitive; diff --git a/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-down.sql b/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-down.sql deleted file mode 100644 index 1ffaf44f6..000000000 --- a/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-down.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -DROP table system.config; -DROP table system.config_vt; diff --git a/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-up.sql b/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-up.sql deleted file mode 100644 index 767eeb9ee..000000000 --- a/server/db-migrate/migrations/sqls/20200713203022-sys-t-config-up.sql +++ /dev/null @@ -1,54 +0,0 @@ --- 1 (Inherits all for the string from table commons.text) -Create Table system.config ( - key varchar, - config jsonb, - entity_version integer Default 1 -) -Inherits ( - system.entity -); - --- 2 -Select - commons.init_entity_child_table ('system.config'); - --- 3 -INSERT INTO system.config (key, config) VALUES ( - 'SYS_CONFIG', - '{ - "classes": { - "40": { - "mapsToListType": { - "appellation": "true" - } - }, - "51": { - "mapsToListType": { - "place": "true" - } - }, - "52": { - "mapsToListType": { - "dimension": { - "measurementUnitClass": 56 - } - } - }, - "54": { - "mapsToListType": { - "language": "true" - } - }, - "335": { - "mapsToListType": { - "timePrimitive": "true" - } - }, - "657": { - "mapsToListType": { - "langString": "true" - } - } - } - }' -) diff --git a/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-down.sql b/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-down.sql deleted file mode 100644 index f97660354..000000000 --- a/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-down.sql +++ /dev/null @@ -1,57 +0,0 @@ -CREATE OR REPLACE FUNCTION information.v_language_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_row information.language; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.language - WHERE - fk_class = NEW.fk_class - AND lang_type = NEW.lang_type - AND scope = NEW.scope - AND iso6392b = NEW.iso6392b - AND iso6392t = NEW.iso6392t - AND iso6391 = NEW.iso6391; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.language ( - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391 - ) - VALUES ( - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391 - ) - -- return all fields of the new row - RETURNING * - ) - SELECT * FROM INTO resulting_row _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - RETURN resulting_row; - END; - $BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-up.sql b/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-up.sql deleted file mode 100644 index fc8583ed8..000000000 --- a/server/db-migrate/migrations/sqls/20200722072503-inf-f-find-or-create-language-up.sql +++ /dev/null @@ -1,66 +0,0 @@ -CREATE OR REPLACE FUNCTION information.v_language_find_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row information.v_language; - BEGIN - - -- RAISE INFO 'input values: %', NEW; - - ------ if existing, store in result ----- - SELECT * FROM INTO resulting_row information.v_language - WHERE - fk_class = NEW.fk_class - AND lang_type = NEW.lang_type - AND scope = NEW.scope - AND iso6392b = NEW.iso6392b - AND iso6392t = NEW.iso6392t - AND iso6391 = NEW.iso6391 - AND pk_language = NEW.pk_language; - - -- RAISE INFO 'result of select: %', resulting_row; - - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO information.language ( - fk_class, - lang_type, - scope, - iso6392b, - iso6392t, - iso6391, - pk_language - ) - VALUES ( - NEW.fk_class, - NEW.lang_type, - NEW.scope, - NEW.iso6392b, - NEW.iso6392t, - NEW.iso6391, - NEW.pk_language - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - - - SELECT * FROM INTO resulting_row information.v_language - WHERE pk_entity = resulting_pk; - - RETURN resulting_row; - END; - $BODY$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-down.sql b/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-down.sql deleted file mode 100644 index 1521b1a69..000000000 --- a/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-down.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Replace with your SQL commands */ -/* Replace with your SQL commands */ -DROP TRIGGER versioning_trigger ON information.statement; - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON information.statement - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'information.role_vt', 'true'); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-up.sql b/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-up.sql deleted file mode 100644 index b462c37c7..000000000 --- a/server/db-migrate/migrations/sqls/20200813120000-hotfix-statement-vt-trigger-up.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* Replace with your SQL commands */ -DROP TRIGGER versioning_trigger ON information.statement; - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON information.statement - FOR EACH ROW - EXECUTE PROCEDURE public.versioning('sys_period', 'information.statement_vt', 'true'); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-down.sql b/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-down.sql deleted file mode 100644 index debb166c6..000000000 --- a/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-down.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE projects.text_property_vt -DROP COLUMN fk_project ; - -ALTER TABLE projects.text_property_vt -DROP COLUMN fk_pro_project ; - -ALTER TABLE projects.text_property_vt -ADD COLUMN fk_entity INT; diff --git a/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-up.sql b/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-up.sql deleted file mode 100644 index 450a31440..000000000 --- a/server/db-migrate/migrations/sqls/20200819090548-pro-t-text-property-vt-up.sql +++ /dev/null @@ -1,15 +0,0 @@ -ALTER TABLE projects.text_property_vt -ADD COLUMN fk_project INT; - -ALTER TABLE projects.text_property_vt -ADD COLUMN fk_pro_project INT; - -ALTER TABLE projects.text_property_vt -drop COLUMN fk_entity; - --- update version history of added columns -UPDATE projects.text_property_vt t0 -SET fk_pro_project = t1.fk_pro_project, -fk_project = t1.fk_project -FROM projects.text_property t1 -WHERE t0.pk_entity = t1.pk_entity; diff --git a/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-down.sql b/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-down.sql deleted file mode 100644 index 34d715263..000000000 --- a/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-down.sql +++ /dev/null @@ -1,32 +0,0 @@ --- 11 -DROP TRIGGER notify_modification ON projects.class_field_config; - --- 10 -DROP TRIGGER notify_modification ON data_for_history.api_property; - --- 9 -DROP TRIGGER notify_modification ON projects.dfh_profile_proj_rel; - --- 8 -DROP TRIGGER notify_modification ON data_for_history.api_class; - --- 7 -DROP TRIGGER notify_modification ON projects.info_proj_rel; - --- 6 -DROP TRIGGER notify_modification ON information.temporal_entity; - --- 5 -DROP TRIGGER notify_modification ON information.persistent_item; - --- 4 -DROP TRIGGER notify_modification ON information.statement; - --- 3 -DROP TRIGGER notify_modification ON projects.text_property; - --- 2 -DROP TRIGGER notify_modification ON projects.project; - --- 1 -DROP FUNCTION commons.notify_modification_trigger(); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-up.sql b/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-up.sql deleted file mode 100644 index 0ecb6c464..000000000 --- a/server/db-migrate/migrations/sqls/20200820140830-com-f-update-notification-up.sql +++ /dev/null @@ -1,63 +0,0 @@ --- 1 -Create Or Replace Function commons.notify_modification_trigger () - Returns Trigger - As $trigger$ -Begin - -- Notify the channel, e.g.: "modified_projects_text_property" - Perform - pg_notify('modified_' || TG_TABLE_SCHEMA || '_' || TG_TABLE_NAME, now()::text); - Return NEW; -End; -$trigger$ -Language plpgsql; - --- 2 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.project For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 3 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.text_property For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 4 -Create Trigger notify_modification - After Insert Or Update Or Delete On information.statement For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 5 -Create Trigger notify_modification - After Insert Or Update Or Delete On information.persistent_item For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 6 -Create Trigger notify_modification - After Insert Or Update Or Delete On information.temporal_entity For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 7 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.info_proj_rel For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 8 -Create Trigger notify_modification - After Insert Or Update Or Delete On data_for_history.api_class For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 9 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.dfh_profile_proj_rel For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 10 -Create Trigger notify_modification - After Insert Or Update Or Delete On data_for_history.api_property For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - --- 11 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.class_field_config For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - diff --git a/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-down.sql b/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-down.sql deleted file mode 100644 index 31f6ef6eb..000000000 --- a/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-down.sql +++ /dev/null @@ -1,2 +0,0 @@ - -DROP TABLE war.class_preview; diff --git a/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-up.sql b/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-up.sql deleted file mode 100644 index 235b7e527..000000000 --- a/server/db-migrate/migrations/sqls/20200824104247-war-t-class-label-up.sql +++ /dev/null @@ -1,20 +0,0 @@ - -CREATE TABLE war.class_preview -( - fk_class integer, - fk_project integer, - label text COLLATE pg_catalog."default", - tmsp_last_modification timestamp with time zone, - CONSTRAINT war_class_preview_unique UNIQUE (fk_class, fk_project) -); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON war.class_preview - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); - -Create Trigger notify_modification - After Insert Or Update Or Delete On war.class_preview - For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); diff --git a/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-down.sql b/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-down.sql deleted file mode 100644 index b41d2f294..000000000 --- a/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-down.sql +++ /dev/null @@ -1,3 +0,0 @@ -/* Replace with your SQL commands */ -DROP table projects.entity_label_config; -DROP table projects.entity_label_config_vt; diff --git a/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-up.sql b/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-up.sql deleted file mode 100644 index 5753d5c7d..000000000 --- a/server/db-migrate/migrations/sqls/20200831161624-pro-t-entity-label-config-up.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 1 (Inherits all for the string from table commons.text) -CREATE TABLE projects.entity_label_config ( - fk_project int, - fk_class int, - config jsonb, - entity_version integer DEFAULT 1 -) -INHERITS ( - projects.entity -); - --- 2 -SELECT - commons.init_entity_child_table ('projects.entity_label_config'); - --- 3 -Create Trigger notify_modification - After Insert Or Update Or Delete On projects.entity_label_config For Each STATEMENT - Execute Procedure commons.notify_modification_trigger (); - diff --git a/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-down.sql b/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-down.sql deleted file mode 100644 index cbe2a9f46..000000000 --- a/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM projects.entity_label_config -WHERE fk_project = 375669; diff --git a/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-up.sql b/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-up.sql deleted file mode 100644 index 60dec7c60..000000000 --- a/server/db-migrate/migrations/sqls/20200916124242-add-entity-label-config-up.sql +++ /dev/null @@ -1,70 +0,0 @@ -DELETE FROM projects.entity_label_config -WHERE fk_project = 375669; - -INSERT INTO projects.entity_label_config (fk_project, fk_class, config) -VALUES -(375669,525, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,526, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,503, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,522, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,529, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,502, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,68, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,218, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,457, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,220, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,363, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,221, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,455, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,456, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,521, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,518, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,657, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,21, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,53, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,441, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,40, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,60, '{"labelParts": [{"field": {"fkProperty": 83, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,61, '{"labelParts": [{"field": {"fkProperty": 86, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,62, '{"labelParts": [{"field": {"fkProperty": 87, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,63, '{"labelParts": [{"field": {"fkProperty": 88, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,528, '{"labelParts": [{"field": {"fkProperty": 1339, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,533, '{"labelParts": [{"field": {"fkProperty": 1341, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,535, '{"labelParts": [{"field": {"fkProperty": 1345, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,631, '{"labelParts": [{"field": {"fkProperty": 1431, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,633, '{"labelParts": [{"field": {"fkProperty": 1436, "isOutgoing": true, "nrOfStatementsInLabel": 2}, "ordNum": 0}]}' ), -(375669,78, '{"labelParts": [{"field": {"fkProperty": 132, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 131, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,79, '{"labelParts": [{"field": {"fkProperty": 134, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 133, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,244, '{"labelParts": [{"field": {"fkProperty": 991, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 992, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,212, '{"labelParts": [{"field": {"fkProperty": 1177, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1178, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,442, '{"labelParts": [{"field": {"fkProperty": 1189, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1188, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,523, '{"labelParts": [{"field": {"fkProperty": 1335, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1336, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,527, '{"labelParts": [{"field": {"fkProperty": 1358, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1343, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,637, '{"labelParts": [{"field": {"fkProperty": 1441, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1442, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}]}' ), -(375669,334, '{"labelParts": [{"field": {"fkProperty": 1445, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 0}, {"field": {"fkProperty": 1446, "isOutgoing": true, "nrOfStatementsInLabel": 1}, "ordNum": 1}, {"field": {"fkProperty": 1409, "isOutgoing": true, "nrOfStatementsInLabel": 2}, "ordNum": 2}]}' ), -(375669,635, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,54, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,56, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,219, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,332, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,364, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,443, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,444, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,449, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,450, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,451, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,452, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,454, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,459, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,516, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,519, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,520, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,524, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,607, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,608, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,629, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,630, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,632, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,634, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,636, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ), -(375669,638, '{"labelParts": [{"field": {"fkProperty": 1111, "isOutgoing": false, "nrOfStatementsInLabel": 1}, "ordNum": 0}]}' ); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-down.sql b/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-down.sql deleted file mode 100644 index 8268de057..000000000 --- a/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-down.sql +++ /dev/null @@ -1,52 +0,0 @@ - -CREATE OR REPLACE VIEW data_for_history.v_property - AS - WITH tw1 AS ( - SELECT t1_1.dfh_pk_property AS pk_property, - t1_1.dfh_is_inherited AS is_inherited, - t1_1.dfh_property_domain AS has_domain, - t1_1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1_1.dfh_property_range AS has_range, - t1_1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1_1.dfh_identity_defining AS identity_defining, - t1_1.dfh_is_has_type_subproperty AS is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles - FROM data_for_history.api_property t1_1 - GROUP BY t1_1.dfh_pk_property, t1_1.dfh_is_inherited, t1_1.dfh_property_domain, t1_1.dfh_domain_instances_min_quantifier, t1_1.dfh_domain_instances_max_quantifier, t1_1.dfh_property_range, t1_1.dfh_range_instances_min_quantifier, t1_1.dfh_range_instances_max_quantifier, t1_1.dfh_identity_defining, t1_1.dfh_is_has_type_subproperty, t1_1.dfh_property_identifier_in_namespace - UNION - SELECT 1111 AS pk_property, - true AS is_inherited, - 365 AS has_domain, - 0 AS domain_instances_min_quantifier, - '-1'::integer AS domain_instances_max_quantifier, - t1_1.dfh_pk_class AS has_range, - 1 AS range_instances_min_quantifier, - 1 AS range_instances_max_quantifier, - true AS identity_defining, - false AS is_has_type_subproperty, - 'histP9'::character varying AS identifier_in_namespace, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles - FROM data_for_history.api_class t1_1 - WHERE t1_1.dfh_pk_class <> 365 - GROUP BY t1_1.dfh_pk_class, t1_1.dfh_class_identifier_in_namespace, t1_1.dfh_basic_type, t1_1.dfh_basic_type_label - ) - SELECT t1.pk_property, - t1.is_inherited, - t1.has_domain, - t1.domain_instances_min_quantifier, - t1.domain_instances_max_quantifier, - t1.has_range, - t1.range_instances_min_quantifier, - t1.range_instances_max_quantifier, - t1.identity_defining, - CASE - WHEN t2.pk_entity IS NOT NULL THEN true - ELSE t1.is_has_type_subproperty - END AS is_has_type_subproperty, - t1.identifier_in_namespace, - t1.profiles - FROM tw1 t1 - LEFT JOIN system.class_has_type_property t2 ON t1.pk_property = t2.fk_property; diff --git a/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-up.sql b/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-up.sql deleted file mode 100644 index 064206abc..000000000 --- a/server/db-migrate/migrations/sqls/20201029150441-dfh-v-property-up.sql +++ /dev/null @@ -1,85 +0,0 @@ - -CREATE OR REPLACE VIEW data_for_history.v_property - AS - WITH tw0 AS ( - SELECT - t1.dfh_pk_property, - t1.dfh_is_inherited , - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier , - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_fk_profile, - t1.removed_from_api - FROM data_for_history.api_property t1 - - -- add property 1111 to all classes - UNION - SELECT - 1111 AS dfh_pk_property, - true AS dfh_is_inherited, - 365 AS dfh_property_domain, - 0 AS dfh_domain_instances_min_quantifier, - '-1'::integer AS dfh_domain_instances_max_quantifier, - t1_1.dfh_pk_class AS dfh_property_range, - 1 AS dfh_range_instances_min_quantifier, - 1 AS dfh_range_instances_max_quantifier, - true AS dfh_identity_defining, - false AS dfh_is_has_type_subproperty, - 'histP9'::character varying AS dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM data_for_history.api_class t1_1 - WHERE t1_1.dfh_pk_class <> 365 - GROUP BY t1_1.dfh_fk_profile, t1_1.removed_from_api, t1_1.dfh_pk_class, t1_1.dfh_class_identifier_in_namespace, t1_1.dfh_basic_type, t1_1.dfh_basic_type_label -) - --- aggtegates the profiles and removed_from_api per property -, tw1 AS ( - SELECT - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles - FROM - tw0 t1_1 - GROUP BY - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range -) --- select list of unique properties (see distinct on) --- joining the profiles --- note: the important thing is that properties not removed from api --- are given precedence over properties removed from api (see order by) -SELECT DISTINCT ON (t1.dfh_pk_property,t1.dfh_property_domain,t1.dfh_property_range) - t1.dfh_pk_property AS pk_property, - t1.dfh_is_inherited AS is_inherited, - t1.dfh_property_domain AS has_domain, - t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1.dfh_property_range AS has_range, - t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1.dfh_identity_defining AS identity_defining, - t1.dfh_is_has_type_subproperty AS is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - t2.profiles -- joins the profiles -FROM - tw0 t1, - tw1 t2 -WHERE - t1.dfh_pk_property=t2.dfh_pk_property -AND t1.dfh_property_domain=t2.dfh_property_domain -AND t1.dfh_property_range=t2.dfh_property_range -ORDER BY - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.removed_from_api ASC -- make sure the select distinct gives prio to removed_from_api=false - diff --git a/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-down.sql b/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-down.sql deleted file mode 100644 index 4277efb2a..000000000 --- a/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-down.sql +++ /dev/null @@ -1,14 +0,0 @@ --- table data.factoid_role_mapping -ALTER TABLE data.factoid_property_mapping RENAME TO factoid_role_mapping; -ALTER TABLE data.factoid_property_mapping_vt RENAME TO factoid_role_mapping_vt; - --- table data.property_of_property -ALTER TABLE data.property_of_property RENAME COLUMN fk_domain_factoid_property TO fk_domain_factoid_role; -ALTER TABLE data.property_of_property_vt RENAME COLUMN fk_domain_factoid_property_vt TO fk_domain_factoid_role; - --- table data.property_of_property_mapping -ALTER TABLE data.property_of_property_mapping RENAME COLUMN fk_domain_factoid_property_mapping TO fk_domain_factoid_role_mapping; -ALTER TABLE data.property_of_property_mapping_vt RENAME COLUMN fk_domain_factoid_property_mapping_vt TO fk_domain_factoid_role_mapping; - --- table data.factoid_role_mapping new column is_outgoing -ALTER TABLE data.factoid_role_mapping DROP COLUMN is_outgoing; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-up.sql b/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-up.sql deleted file mode 100644 index c9701f585..000000000 --- a/server/db-migrate/migrations/sqls/20201119144352-factoid-role-into-property-up.sql +++ /dev/null @@ -1,14 +0,0 @@ --- table data.factoid_role_mapping -ALTER TABLE data.factoid_role_mapping RENAME TO factoid_property_mapping; -ALTER TABLE data.factoid_role_mapping_vt RENAME TO factoid_property_mapping_vt; - --- table data.property_of_property -ALTER TABLE data.property_of_property RENAME COLUMN fk_domain_factoid_role TO fk_domain_factoid_property; -ALTER TABLE data.property_of_property_vt RENAME COLUMN fk_domain_factoid_role TO fk_domain_factoid_property_vt; - --- table data.property_of_property_mapping -ALTER TABLE data.property_of_property_mapping RENAME COLUMN fk_domain_factoid_role_mapping TO fk_domain_factoid_property_mapping; -ALTER TABLE data.property_of_property_mapping_vt RENAME COLUMN fk_domain_factoid_role_mapping TO fk_domain_factoid_property_mapping_vt; - --- table data.factoid_property_mapping new column is_outgoing -ALTER TABLE data.factoid_property_mapping ADD COLUMN is_outgoing BOOLEAN NOT NULL DEFAULT TRUE; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-down.sql b/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-down.sql deleted file mode 100644 index c815fc912..000000000 --- a/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-down.sql +++ /dev/null @@ -1,4 +0,0 @@ --- 2 -DROP TRIGGER ts_vector ON war.entity_preview; --- 1 -DROP FUNCTION war.entity_preview_ts_vector; diff --git a/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-up.sql b/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-up.sql deleted file mode 100644 index 614ce6c9d..000000000 --- a/server/db-migrate/migrations/sqls/20201120133344-war-t-entity-preview-trigger-up.sql +++ /dev/null @@ -1,25 +0,0 @@ --- 1 -CREATE OR REPLACE FUNCTION war.entity_preview_ts_vector() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF - AS $BODY$ - BEGIN NEW.ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(NEW.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(NEW.type_label, '')), 'B') || - setweight(to_tsvector(coalesce(NEW.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(NEW.full_text, '')), 'C') - ); - RETURN NEW; - END; - $BODY$; - --- 2 - -CREATE TRIGGER ts_vector - BEFORE INSERT OR UPDATE - ON war.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE war.entity_preview_ts_vector(); diff --git a/server/db-migrate/migrations/sqls/20201120145612-cleanup-down.sql b/server/db-migrate/migrations/sqls/20201120145612-cleanup-down.sql deleted file mode 100644 index 542dabc43..000000000 --- a/server/db-migrate/migrations/sqls/20201120145612-cleanup-down.sql +++ /dev/null @@ -1,4 +0,0 @@ - -ALTER TABLE projects.text_property DROP CONSTRAINT uniq_outgoing_property_label; - -ALTER TABLE projects.text_property DROP CONSTRAINT uniq_incoming_property_label diff --git a/server/db-migrate/migrations/sqls/20201120145612-cleanup-up.sql b/server/db-migrate/migrations/sqls/20201120145612-cleanup-up.sql deleted file mode 100644 index bb589ab3f..000000000 --- a/server/db-migrate/migrations/sqls/20201120145612-cleanup-up.sql +++ /dev/null @@ -1,48 +0,0 @@ - - --- delete duplicates of outgoing property labels -DELETE FROM projects.text_property -WHERE pk_entity IN - ( - SELECT pk_entity - FROM - ( - SELECT pk_entity, string, - ROW_NUMBER() OVER( PARTITION BY (fk_project,fk_dfh_property,fk_dfh_property_domain,fk_language) - ORDER BY pk_entity ) AS row_num - FROM projects.text_property - WHERE fk_system_type = 639 - AND fk_project IS NOT NULL - AND fk_dfh_property IS NOT NULL - AND fk_dfh_property_domain IS NOT NULL - AND fk_language IS NOT NULL - ) t - WHERE t.row_num > 1 - ); - --- create uniq constraint for outgoing property labels -ALTER TABLE projects.text_property ADD CONSTRAINT uniq_outgoing_property_label UNIQUE (fk_project,fk_dfh_property,fk_dfh_property_domain,fk_language); - - --- delete duplicates of incoming property labels -DELETE FROM projects.text_property -WHERE pk_entity IN - ( - SELECT pk_entity - FROM - ( - SELECT pk_entity, string, - ROW_NUMBER() OVER( PARTITION BY (fk_project,fk_dfh_property,fk_dfh_property_range,fk_language) - ORDER BY pk_entity ) AS row_num - FROM projects.text_property - WHERE fk_system_type = 639 - AND fk_project IS NOT NULL - AND fk_dfh_property IS NOT NULL - AND fk_dfh_property_range IS NOT NULL - AND fk_language IS NOT NULL - ) t - WHERE t.row_num > 1 - ); - --- create uniq constraint for incoming property labels -ALTER TABLE projects.text_property ADD CONSTRAINT uniq_incoming_property_label UNIQUE (fk_project,fk_dfh_property,fk_dfh_property_range,fk_language) diff --git a/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-down.sql b/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-down.sql deleted file mode 100644 index 9263ec7ef..000000000 --- a/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-down.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE war.entity_preview - ALTER COLUMN project DROP DEFAULT; - -ALTER TABLE war.entity_preview - ALTER COLUMN project drop NOT NULL; - diff --git a/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-up.sql b/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-up.sql deleted file mode 100644 index ef371a4d0..000000000 --- a/server/db-migrate/migrations/sqls/20201209105833-war-t-entity-preview-column-project-up.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE war.entity_preview - ALTER COLUMN project SET DEFAULT 0; - -ALTER TABLE war.entity_preview - ALTER COLUMN project SET NOT NULL; - diff --git a/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-down.sql b/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-down.sql deleted file mode 100644 index 972e0fc96..000000000 --- a/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-down.sql +++ /dev/null @@ -1,7 +0,0 @@ -/* Replace with your SQL commands */-- factoid_property_mapping -DROP TRIGGER versioning_trigger ON data.factoid_property_mapping ; -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON data.factoid_property_mapping - FOR EACH ROW - EXECUTE PROCEDURE versioning('sys_period', 'data.factoid_role_mapping_vt', 'true'); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-up.sql b/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-up.sql deleted file mode 100644 index e6306a93b..000000000 --- a/server/db-migrate/migrations/sqls/20210106102327-update-vt-trigger-for-factoids-up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- factoid_property_mapping -DROP TRIGGER versioning_trigger ON data.factoid_property_mapping ; -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON data.factoid_property_mapping - FOR EACH ROW - EXECUTE PROCEDURE versioning('sys_period', 'data.factoid_property_mapping_vt', 'true'); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-down.sql b/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-down.sql deleted file mode 100644 index 0ab57737f..000000000 --- a/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-down.sql +++ /dev/null @@ -1,859 +0,0 @@ --- 9 - -CREATE OR REPLACE FUNCTION war.do_updates_for_difference_since( - tmsp timestamp without time zone) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -Declare - t_row record; - node_ids war.node_id[]; - t timestamptz := clock_timestamp(); - -- used for DEBUGGING - enrich_loop_count int := 0; -Begin - Create TEMP Table changed_info_proj_rel On Commit Drop As - -- select recently modified info_proj_rels - Select - t1.fk_entity, t1.fk_project, t1.is_in_project, t1.tmsp_last_modification - From - projects.info_proj_rel t1 - Where - t1.tmsp_last_modification::timestamp >= tmsp; - Drop Table If Exists to_enrich; - Create TEMP Table to_enrich ( - pk_entity int, - fk_project int - ); - - /* - * 1. Delete enriched_nodes and entity previews - * - * Delete the enriched_nodes and entity_previews of PeIt’s or TeEn’s that have a - * recently been removed from their project (modified info_proj_rel where - * is_in_project = false) - * - * Read this about temp tables on commit drop: - * https://stackoverflow.com/questions/10596896/postgresql-thread-safety-for-temporary-tables - */ - -- DEBUG - Raise notice '#1.a querying removed_crm_entities...'; - Create TEMP Table removed_crm_entities On Commit Drop As - With tw1 As ( - -- select recent info_proj_rel where is_in_project = false - Select - t1.fk_entity, - t1.fk_project - From - changed_info_proj_rel t1 - Where - t1.is_in_project = False -), -tw2 As ( --- join persistent_items -Select - t2.fk_entity, - t2.fk_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- join temporal_entities - Select - t2.fk_entity, - t2.fk_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - ) - Select - fk_entity, fk_project - From - tw2; - -- DEBUG TIME - Raise notice '...#1.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#1.b deleting enriched_nodes and entity_previews...'; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_crm_entities) - Loop - Raise NOTICE 'Node to delete fk_project: %, fk_entity: %', t_row.fk_project, t_row.fk_entity; - End Loop; - -- END DEBUG - -- delete enriched_nodes - Delete From war.enriched_node t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- delete entity_previews - Delete From war.entity_preview t1 Using removed_crm_entities t2 - Where t1.pk_entity = t2.fk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- DEBUG TIME - Raise notice '...#1.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.a querying affected_nodes'; - - /* - * 2. Update enriched_node table - * - * all enriched_nodes that are possibly affected by the modifications since last update, - * need to be updated or inserted. Enriched_nodes are possibly affected, if a PeIt or - * TeEn is added to project, if a statement or text_property related to that PeIt or TeEn - * is changed in its relation to the project. - */ - Create TEMP Table affected_nodes On Commit Drop As - /********** - * Selects the pk_entities of nodes that need to be updated or deleted - ***********/ With tw1 As ( - Select - t1.fk_entity, - t1.fk_project, - t1.is_in_project, - t1.tmsp_last_modification - From - changed_info_proj_rel t1 -), --- select fk_entity and fk_project of all affected persistent_items and temporal_entities -tw2 As ( --- persistent_items where info_proj_rel changed -Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project -From - information.persistent_item t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- temporal_entities where info_proj_rel changed - Select - t1.pk_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.temporal_entity t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity And t2.is_in_project = True - Union All - -- domain entities of statements where info_proj_rel changed - Select - t1.fk_subject_info As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.statement t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- range entities of statements where info_proj_rel changed - Select - t1.fk_object_info As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.statement t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity - Union All - -- concerned entities of text_properties where info_proj_rel changed - Select - t1.fk_concerned_entity As fk_entity, - t2.fk_project, - t2.tmsp_last_modification, - t2.is_in_project - From - information.text_property t1, - tw1 t2 - Where - t1.pk_entity = t2.fk_entity -), -tw3 As ( -Select Distinct On (t1.fk_project, - t1.fk_entity ) - t1.fk_project, - t1.fk_entity, - t1.is_in_project, - t1.tmsp_last_modification -From - tw2 t1 -Order By - t1.fk_project, - t1.fk_entity, - t1.tmsp_last_modification Desc ) - /********** - * Group the remaining update request by is_in_project and fk_projects - ***********/ - Select - is_in_project, fk_project, array_agg(fk_entity ) pk_entities --, count(pk_entity) -From - tw3 -Group By - fk_project, is_in_project; - -- DEBUG TIME - Raise notice '...#2.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#2.b upserting affected_nodes...'; - - /** - * Loop over the affected nodes per project and upsert the enriched nodes - * (the not recursive columns) - */ - For t_row In ( - Select - * - From - affected_nodes) - Loop - -- START DEBUG - -- Show affected_nodes - Raise NOTICE 'Nodes to upsert fk_project: %, pk_entities: %', t_row.fk_project, t_row.pk_entities; - -- END DEBUG - Insert Into to_enrich - Select - pk_entity, - fk_project - From - war.enriched_nodes__upsert_some (t_row.pk_entities, t_row.fk_project); - End Loop; - -- DEBUG TIME - Raise notice '...#2.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.a query removed_statements...'; - - /* - * 3. Delete edges - * - * Delete the edges of statements that have a recently been removed from their project - * (modified info_proj_rel where is_in_project = false) - */ - Create TEMP Table removed_statements On Commit Drop As - -- select recent info_proj_rel to statements where is_in_project = false - Select - t1.fk_entity As fk_statement, t1.fk_project, t2.fk_object_info, t2.fk_subject_info - From - changed_info_proj_rel t1, information.statement t2 - Where - t1.is_in_project = False - And t1.fk_entity = t2.pk_entity; - -- Add the entities, related to removed statements, to to_enrich - Insert Into to_enrich - -- select domain persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_subject_info - Union All - -- select range persistent_items - Select - t1.pk_entity, - t2.fk_project - From - information.persistent_item t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_object_info - Union All - -- select domain temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_subject_info - Union All - -- select range temporal_entities - Select - t1.pk_entity, - t2.fk_project - From - information.temporal_entity t1, - removed_statements t2 - Where - t1.pk_entity = t2.fk_object_info; - -- START DEBUG - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - removed_statements) - Loop - Raise NOTICE 'Edges to delete fk_project: %, fk_statement: %', t_row.fk_project, t_row.fk_statement; - End Loop; - -- END DEBUG - Raise notice '...#3.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#3.b delete edges...'; - Delete From war.edge t1 Using removed_statements t2 - Where t1.fk_project Is Not Distinct From t2.fk_project - And t1.fk_statement = t2.fk_statement; - -- DEBUG TIME - Raise notice '...#3.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.a query affected statements...'; - - /* - * 4. Update edges - * - * All edges that are affected by the modifications since last update need to be updated or inserted. - */ - Create TEMP Table updated_statements On Commit Drop As - -- select recent info_proj_rel to statements where is_in_project = false - Select - array_agg( t1.fk_entity - ) As fk_statements, t1.fk_project -From - changed_info_proj_rel t1, information.statement t2 -Where - t1.fk_entity = t2.pk_entity - And t1.is_in_project = True -Group By - t1.fk_project; - Raise notice '...#4.a time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#4.b update edges...'; - -- Update the edges - For t_row In ( - Select - * - From - updated_statements) - Loop - -- DEBUG - -- show the updated statements - Raise NOTICE 'Updated statements fk_project: %, fk_statements: %', t_row.fk_project, t_row.fk_statements; - Insert Into to_enrich - Select - fk_source, - fk_project - From - war.edges__upsert_some (t_row.fk_statements, t_row.fk_project); - End Loop; - Raise notice '...#4.b time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - - /* - * 5. Enrich nodes - * - * Fill all recursive colums of all enriched_nodes that are not up to date. - * After this step, the table enriched_node should be in a final state - * so that the changes can be brought to the table entity_previews - */ - -- START DEBUG - Raise notice '#5 enrich nodes...'; - -- show removed_crm_entities (PeIt's and TeEn's) - For t_row In ( - Select - * - From - to_enrich) - Loop - Raise NOTICE 'Initial nodes to_enrich (before loop): fk_project%, pk_entity: %', t_row.fk_project, t_row.pk_entity; - End Loop; - -- END DEBUG - /******* - * enrich the enriched_nodes - * Theory: - * We have a tree of dependencies. The edges relate source to target nodes. - * source (dependent) nodes depend on target (dependency) nodes. - * Whenever an edge or a target node change, the source node needs to be (re-)enriched. - *******/ - WHILE ( - Select - (count(*) > 0 - And enrich_loop_count <= 50) - From to_enrich) - Loop - -- breac - -- get the war.node_id[] from to_enrich - Select - array_agg(Row (pk_entity, fk_project)::war.node_id) Into node_ids - From ( Select Distinct - pk_entity, - fk_project - From - to_enrich) x; - -- DEBUG - -- Show node_ids to enrich - Raise NOTICE 'node_ids from to_enrich %', node_ids; - -- show number of iterations - Raise NOTICE 'enrich_loop_count %', enrich_loop_count; - enrich_loop_count = enrich_loop_count + 1; - If enrich_loop_count = 50 Then - Raise WARNING 'enrich_loop_count = 50. node_ids from to_enrich %', node_ids; - End If; - -- empty table to_enrich - Delete From to_enrich; - -- enrich the nodes and - -- query keys of nodes that depend on changed nodes - -- put those source nodes in to_enrich - Insert Into to_enrich Select Distinct - t1.fk_source, - t1.fk_project - From - war.edge t1, - ( - -- enrich the nodes - Select - pk_entity, - fk_project - From - war.enriched_nodes__enrich_some (node_ids)) t2 - Where - t1.fk_target = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - End Loop; - Raise notice '...#5 time spent=%', clock_timestamp() - t; - t = clock_timestamp(); - Raise notice '#6 update entity_previews...'; - - /* - * 6. Update entity_previews - * - * Update all entity_previews with all enriched_nodes where tmsp_last_modification - * is more recent than last update_log.tmsp_update_end. - */ - Create TEMP Table modified_enriched_node On Commit Drop As - With tw1 As ( - -- select the modified enriched_node - Select - * - From - war.enriched_node t1 - Where - t1.tmsp_last_modification > tmsp ) - -- Select the entity_previews that are different in one of the columns - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, t1.fk_project, t1.project, t1.entity_type, t1.fk_class, t1.class_label, t1.entity_label, t1.full_text, t1.ts_vector, t1.type_label, t1.fk_type, t1.time_span, t1.first_second, t1.last_second - From - war.entity_preview t1, tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Update the edges that are different in one of the non recursive columns - Update - war.entity_preview t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - entity_type = t2.entity_type, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_label = t2.entity_label, - full_text = t2.full_text, - ts_vector = t2.ts_vector, - type_label = t2.type_label, - fk_type = t2.fk_type, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - modified_enriched_node t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project; - -- Insert the created edges that do not yet exist - Insert Into war.entity_preview - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - From - modified_enriched_node t1 - On Conflict - Do Nothing; - Raise notice '...#6 time spent=%', clock_timestamp() - t; -End; -$BODY$; --- 8 -CREATE OR REPLACE FUNCTION war.warehouse_update_all () - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - pk_update bigint; -BEGIN - INSERT INTO war.update_log (tmsp_update_begin) - VALUES (now()::timestamp) - RETURNING - pk_entity INTO pk_update; - PERFORM - war.nodes_and_edges__update_all (); - PERFORM - war.enriched_nodes__enrich (); - PERFORM - war.entity_preview__update_all (); - UPDATE - war.update_log - SET - tmsp_update_end = clock_timestamp()::timestamp - WHERE - pk_entity = pk_update; -END; -$BODY$; - --- 7 -CREATE OR REPLACE FUNCTION war.updater () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - last_war_update timestamp without time zone; - last_project_modification timestamp without time zone; - pk_update bigint; - -- pk_entity of the update done by this function -BEGIN - /* - * Get the timestamp of the begin of the last update - */ - SELECT - tmsp_update_begin INTO last_war_update - FROM - war.update_log - ORDER BY - pk_entity DESC - LIMIT 1; - -- if the update_log is empty - IF last_war_update IS NULL THEN - -- update the whole warehouse (this will also add a record in update_log) - PERFORM - war.warehouse_update_all (); - --Return true for indicating that tehere has been an update - RETURN TRUE; - END IF; - - /* - * Get the timestamp of the last rojects.info_proj_rel modification - */ - SELECT - tmsp_last_modification::timestamp INTO last_project_modification - FROM - projects.info_proj_rel - ORDER BY - tmsp_last_modification DESC - LIMIT 1; - - /* - * Check if we need an update, i.e: - * if last modification is newer than last update of war - */ - IF (last_project_modification > last_war_update) THEN - /* - * Create a new record for this update. - * the function now() is equivalent to transaction_timestamp() and - * returns the start time of the current transaction. - */ - INSERT INTO war.update_log (tmsp_update_begin) - VALUES (now()::timestamp) - RETURNING - pk_entity INTO pk_update; - - /***** - * Perform the updates - ******/ - PERFORM - war.do_updates_for_difference_since (last_war_update); - - /********** - * Store the timestamp of after the update so that we have a log of the execution time - * clock_timestamp() returns the actual current time, - * and therefore its value changes even within a single SQL command. - **********/ - UPDATE - war.update_log - SET - tmsp_update_end = clock_timestamp()::timestamp - WHERE - pk_entity = pk_update; - - /****** - * Return true for indicating that tehere has been an update - *******/ - RETURN TRUE; - ELSE - /* - * Return false for indicating that there has been no update - */ - RETURN FALSE; - END IF; -END; -$BODY$; - --- 6 -CREATE OR REPLACE FUNCTION war.nodes_and_edges__update_all () - RETURNS void - LANGUAGE 'sql' - COST 100 VOLATILE - AS $BODY$ - TRUNCATE war.edge; - -INSERT INTO war.edge -SELECT - * -FROM - war.edges__create_all (); - -TRUNCATE war.enriched_node; - -INSERT INTO war.enriched_node -SELECT - * -FROM - war.enriched_nodes__create_all (); - -$BODY$; - --- 5 -CREATE OR REPLACE FUNCTION war.entity_preview__update_class_labels () - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - WITH tw1 AS ( - SELECT - fk_class, - fk_project, - class_label - FROM - war.enriched_node t1 - GROUP BY - fk_class, - fk_project, - class_label -), -tw2 AS ( - SELECT - t2.* - FROM - tw1 t1, - war.v_class_preview t2 - WHERE - t1.fk_class = t2.fk_class - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t1.class_label IS DISTINCT FROM t2.label) -UPDATE - war.enriched_node t1 -SET - class_label = t2.label -FROM - tw2 t2 -WHERE - t1.fk_class = t2.fk_class - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project; - PERFORM - war.enriched_nodes__enrich_full_text (); - PERFORM - war.entity_preview__update_modified (); -END; -$BODY$; - --- 4 -CREATE OR REPLACE FUNCTION war.entity_preview__update_all () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - PERFORM - war.entity_preview__add_missing (); - PERFORM - war.entity_preview__remove_superfluous (); - PERFORM - war.entity_preview__update_modified (); - RETURN TRUE; -END; -$BODY$; - --- 3 -CREATE OR REPLACE FUNCTION war.entity_preview__update_modified () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- update modified entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - project, - entity_type, - fk_class, - class_label, - entity_label, - full_text, - ts_vector, - type_label, - fk_type, - time_span, - first_second, - last_second, - 'different from war.enriched_node, to be updated' AS note - FROM - war.enriched_node - EXCEPT - SELECT - pk_entity, - fk_project, - project, - entity_type, - fk_class, - class_label, - entity_label, - full_text, - ts_vector, - type_label, - fk_type, - time_span, - first_second, - last_second, - 'different from war.enriched_node, to be updated' AS note - FROM - war.entity_preview) - UPDATE - war.entity_preview t1 - SET - entity_type = tw1.entity_type, - fk_class = tw1.fk_class, - class_label = tw1.class_label, - entity_label = tw1.entity_label, - full_text = tw1.full_text, - ts_vector = tw1.ts_vector, - type_label = tw1.type_label, - fk_type = tw1.fk_type, - time_span = tw1.time_span, - first_second = tw1.first_second, - last_second = tw1.last_second - FROM - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - RETURN TRUE; -END; -$BODY$; - --- 2 -CREATE OR REPLACE FUNCTION war.entity_preview__remove_superfluous () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- remove superfluous entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in enriched_node, to be deleted' AS note - FROM - war.entity_preview - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in enriched_node, to be deleted' AS note - FROM - war.enriched_node) - DELETE FROM war.entity_preview t1 USING tw1 - WHERE t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - RETURN TRUE; -END; -$BODY$; - --- 1 -CREATE OR REPLACE FUNCTION war.entity_preview__add_missing () - RETURNS boolean - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -BEGIN - -- Add missing entity previews - WITH tw1 AS ( - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - war.enriched_node - EXCEPT - SELECT - pk_entity, - fk_project, - 'not in entity_preview, to be added' AS note - FROM - war.entity_preview) - INSERT INTO war.entity_preview (pk_entity, fk_project, project, entity_type, fk_class, class_label, entity_label, full_text, ts_vector, type_label, fk_type, time_span, first_second, last_second) - SELECT - t1.pk_entity, - t1.fk_project, - t1.project, - t1.entity_type, - t1.fk_class, - t1.class_label, - t1.entity_label, - t1.full_text, - t1.ts_vector, - t1.type_label, - t1.fk_type, - t1.time_span, - t1.first_second, - t1.last_second - FROM - war.enriched_node t1, - tw1 - WHERE - t1.pk_entity = tw1.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM tw1.fk_project; - RETURN TRUE; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-up.sql b/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-up.sql deleted file mode 100644 index 30005e677..000000000 --- a/server/db-migrate/migrations/sqls/20210108143510-war-f-drop-up.sql +++ /dev/null @@ -1,26 +0,0 @@ --- 1 -DROP FUNCTION war.entity_preview__add_missing (); - --- 2 -DROP FUNCTION war.entity_preview__remove_superfluous (); - --- 3 -DROP FUNCTION war.entity_preview__update_modified (); - --- 4 -DROP FUNCTION war.entity_preview__update_all (); - --- 5 -DROP FUNCTION war.entity_preview__update_class_labels (); - --- 6 -DROP FUNCTION war.nodes_and_edges__update_all (); - --- 7 -DROP FUNCTION war.updater (); - --- 8 -DROP FUNCTION war.warehouse_update_all (); - --- 9 -DROP FUNCTION war.do_updates_for_difference_since(timestamp without time zone); diff --git a/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-down.sql b/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-down.sql deleted file mode 100644 index a87650527..000000000 --- a/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- 1 -DROP TABLE war.statement; diff --git a/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-up.sql b/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-up.sql deleted file mode 100644 index 7cf9c4452..000000000 --- a/server/db-migrate/migrations/sqls/20210108143515-war-t-statements-up.sql +++ /dev/null @@ -1,38 +0,0 @@ --- 1 -CREATE TABLE war.statement -( - pk_entity integer, - fk_project integer, - project integer NOT NULL DEFAULT 0, - fk_property integer, - fk_object_info integer, - fk_subject_info integer, - ord_num_of_domain integer, - ord_num_of_range integer, - is_in_project_count integer -); - - -CREATE INDEX statement_fk_object_info_idx - ON war.statement USING btree - (fk_object_info); - -CREATE INDEX statement_fk_project_idx - ON war.statement USING btree - (fk_project); - -CREATE INDEX statement_fk_property_idx - ON war.statement USING btree - (fk_property); - -CREATE INDEX statement_fk_subject_info_idx - ON war.statement USING btree - (fk_subject_info); - -CREATE INDEX statement_pk_entity_idx - ON war.statement USING btree - (pk_entity); - -CREATE UNIQUE INDEX statement_pk_entity_project_idx - ON war.statement USING btree - (pk_entity, project); diff --git a/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-down.sql b/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-down.sql deleted file mode 100644 index b13a25520..000000000 --- a/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-down.sql +++ /dev/null @@ -1,1548 +0,0 @@ - -CREATE TABLE war.enriched_node -( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - class_label character varying COLLATE pg_catalog."default", - entity_type text COLLATE pg_catalog."default", - own_entity_label text COLLATE pg_catalog."default", - own_full_text text COLLATE pg_catalog."default", - time_span jsonb, - first_second bigint, - last_second bigint, - own_entity_label_field_order integer, - entity_label text COLLATE pg_catalog."default", - fk_type integer, - type_label text COLLATE pg_catalog."default", - full_text text COLLATE pg_catalog."default", - ts_vector tsvector, - tmsp_last_modification timestamp with time zone, - CONSTRAINT enriched_node_unique UNIQUE (pk_entity, project) -); - - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__create_all( - ) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With - -- all entities per project with class label - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = t2.fk_entity -), --- all entities -tw2 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type - From - tw1 t1 -), --- select all 'histP11 refers to name' statements -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count - From - information.v_statement t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property - From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw2 t1 - -- join outgoing statements - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_subject_info = t1.pk_entity - -- join appellation with outgoing statements - Left Join information.appellation t3 On t2.fk_object_info = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select statements with time primitive, first and last second -tw16 As ( - Select - t1.fk_subject_info, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.statement t1, - tw15 t2, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_object_info - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_subject_info, - t1.fk_property) - t1.fk_subject_info, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_statement t1 - Join tw15 t2 On t2.pk_entity = t1.fk_object_info - Where - t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_subject_info, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_subject_info, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span -From - tw16 -Group By - tw16.fk_project, - tw16.fk_subject_info) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), - t1.fk_class, - t3.label As class_label, - t1.entity_type, - t1.own_entity_label, - t1.own_full_text, - t2.time_span, - t2.first_second, - t2.last_second, - t1.own_entity_label_field_order, - t1.own_entity_label As entity_label, - Null::integer fk_type, - Null::text type_label, - Null::text full_text, - Null::tsvector ts_vector, - Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_subject_info - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__create_some( - param_pk_entities integer[], - param_fk_project integer) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With - -- all entities per project - tw1 As ( - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'peIt'::varchar As entity_type - From - information.persistent_item t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project - Union - Select - t1.pk_entity, - t1.fk_class, - t2.fk_project, - 'teEn'::varchar As entity_type - From - information.temporal_entity t1, - projects.info_proj_rel t2 - Where - t2.is_in_project = True - And t1.pk_entity = Any (param_pk_entities) - And t1.pk_entity = t2.fk_entity - And t2.fk_project = param_fk_project -), --- select all 'histP11 refers to name' statements -tw5 As ( - Select - - 10 As field_order, - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_property, - t2.fk_project, - coalesce(t2.fk_project, 0) As project, - t2.ord_num_of_domain, - t2.ord_num_of_range, - t1.is_in_project_count -From - information.v_statement t1, - projects.info_proj_rel t2 - Where - t1.fk_property = 1113 - And t1.fk_subject_info = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- select all text_properties per project with ord_num -tw6 As ( - Select - Case t1.fk_class_field - When 217 Then - - 10 - When 218 Then - - 8 - When 219 Then - - 7 - Else - Null::int - End As field_order, - t1.pk_entity, - t1.fk_concerned_entity, - t1.fk_language, - t1.fk_class_field, - t1.quill_doc, - t1.string, - t1.is_in_project_count, - t2.fk_project, - coalesce(t2.fk_project, 0) As "coalesce", - t2.ord_num_of_text_property -From - information.v_text_property t1, - projects.info_proj_rel t2 - Where - t1.fk_concerned_entity = Any (param_pk_entities) - And t2.fk_entity = t1.pk_entity - And t2.is_in_project = True -), --- join directly related things and create string -tw7 As ( - Select - t1.*, - coalesce(t2.field_order, t7.field_order) As field_order, - coalesce(t2.is_in_project_count, t7.is_in_project_count) As is_in_project_count, - coalesce(t2.ord_num_of_range, t7.ord_num_of_text_property) As ord_num, - regexp_replace(coalesce(t3.string, t7.string), E'[\\n\\r]+', '', 'g') As string -From - tw1 t1 - -- join outgoing statements - Left Join tw5 t2 On t1.fk_project Is Not Distinct From t2.fk_project - And t2.fk_subject_info = t1.pk_entity - -- join appellation with outgoing statements - Left Join information.appellation t3 On t2.fk_object_info = t3.pk_entity - -- join text properties - Left Join tw6 t7 On t1.pk_entity = t7.fk_concerned_entity - And t1.fk_project Is Not Distinct From t7.fk_project -), --- own_entity_label per project -tw8 As ( - Select Distinct On (fk_project, - pk_entity) - fk_project, - pk_entity, - string As own_entity_label, - field_order As own_entity_label_field_order - From - tw7 - Where - string Is Not Null - Order By - fk_project, - pk_entity, - field_order Asc, - ord_num Asc -), --- own_full_text per project -tw9 As ( - Select - fk_project, - pk_entity, - string_agg(string, '; ') As own_full_text -From - tw7 - Where - string Is Not Null - Group By - fk_project, - pk_entity - --ORDER BY field_order, ord_num -), --- own_entity_label per repo -tw10 As ( - Select Distinct On (pk_entity) - Null::int As fk_project, - pk_entity, - own_entity_label, - own_entity_label_field_order - From - tw8 - Group By - pk_entity, - own_entity_label, - own_entity_label_field_order - Order By - pk_entity, - count(fk_project) Desc -), --- own_full_text per repo -tw11 As ( - Select - Null::int As fk_project, - t1.pk_entity, - string_agg(t1.string, '; ') As own_full_text - From ( - Select - pk_entity, - string - From - tw7 - Where - string Is Not Null - Group By - pk_entity, - string - Order By - count(pk_entity) Desc) As t1 - Group By - t1.pk_entity -), --- project variant -tw12 As ( - Select Distinct On (t1.pk_entity, - t1.fk_project) - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw7 t1 - Left Join tw8 t2 On t2.pk_entity = t1.pk_entity - And t2.fk_project = t1.fk_project - And t2.fk_project = param_fk_project - Left Join tw9 t3 On t3.pk_entity = t1.pk_entity - And t3.fk_project = t1.fk_project - And t3.fk_project = param_fk_project -), --- repo variant -tw13 As ( - Select Distinct On (pk_entity) - t1.pk_entity, - t1.fk_class, - Null::integer As fk_project, - t1.entity_type, - t2.own_entity_label, - t2.own_entity_label_field_order, - t3.own_full_text - From - tw1 t1 - Left Join tw10 t2 On t2.pk_entity = t1.pk_entity - Left Join tw11 t3 On t3.pk_entity = t1.pk_entity -), -tw14 As ( - Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order - From - tw12 t1 -Union All -Select - t1.pk_entity, - t1.fk_class, - t1.fk_project, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.own_entity_label_field_order -From - tw13 t1 -), -/** - * Add time spans - */ -tw15 As ( - -- get first and last second of all time primitives - Select - t1.pk_entity, - t1.julian_day, - t1.duration, - commons.time_primitive__get_first_second (t1.julian_day) As first_second, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (t1.julian_day, t1.duration, 'julian') As last_second_julian -From - information.time_primitive t1 -), --- select statements with time primitive, first and last second -tw16 As ( - Select - t1.fk_subject_info, - t1.fk_property, - t3.fk_project, - t3.calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t3.calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.statement t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_object_info) t2 On t1.fk_subject_info = Any (param_pk_entities) - And (t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153])) - And t2.pk_entity = t1.fk_object_info, - projects.info_proj_rel t3 - Where - t1.pk_entity = t3.fk_entity - And t3.is_in_project = True - Union All ( Select Distinct On (t1.fk_subject_info, - t1.fk_property) - t1.fk_subject_info, - t1.fk_property, - Null::integer As fk_project, - t1.community_favorite_calendar, - t2.julian_day, - t2.duration, - t2.first_second, - Case When t1.community_favorite_calendar = 'gregorian' Then - t2.last_second_gregorian - Else - t2.last_second_julian - End last_second - From - information.v_statement t1 - Join Lateral ( - Select - j1.pk_entity, - j1.julian_day, - j1.duration, - commons.time_primitive__get_first_second (j1.julian_day) As first_second, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'gregorian') As last_second_gregorian, - commons.time_primitive__get_last_second (j1.julian_day, j1.duration, 'julian') As last_second_julian - From - information.time_primitive j1 - Where - j1.pk_entity = t1.fk_object_info) t2 On t1.fk_subject_info = Any (param_pk_entities) - And t1.fk_property = Any (Array[71, - 72, - 150, - 151, - 152, - 153]) - And t1.is_in_project_count > 0 - Order By - t1.fk_subject_info, - t1.fk_property, - t1.is_in_project_count Desc, - t1.tmsp_creation Desc) -), --- create time spans, first_second and last_second -tw17 As ( - Select - tw16.fk_project, - tw16.fk_subject_info, - min(tw16.first_second) first_second, - max(tw16.last_second) last_second, - jsonb_object_agg( - Case When tw16.fk_property = 71 Then - 'p81'::text - When tw16.fk_property = 72 Then - 'p82'::text - When tw16.fk_property = 150 Then - 'p81a'::text - When tw16.fk_property = 151 Then - 'p81b'::text - When tw16.fk_property = 152 Then - 'p82a'::text - When tw16.fk_property = 153 Then - 'p82b'::text - Else - tw16.fk_property::text - End, json_build_object('julianDay', tw16.julian_day, 'duration', tw16.duration, 'calendar', tw16.calendar)) As time_span - From - tw16 - Group By - tw16.fk_project, - tw16.fk_subject_info) -/* - * time spans and class label added - **/ -Select - t1.pk_entity, - t1.fk_project, - coalesce(t1.fk_project, 0), -t1.fk_class, -t3.label As class_label, -t1.entity_type, -t1.own_entity_label, -t1.own_full_text, -t2.time_span, -t2.first_second, -t2.last_second, -t1.own_entity_label_field_order, -t1.own_entity_label As entity_label, -Null::integer fk_type, -Null::text type_label, -Null::text full_text, -Null::tsvector ts_vector, -Null::timestamp With time zone tmsp_last_modification -From - tw14 t1 - Left Join tw17 t2 On t1.pk_entity = t2.fk_subject_info - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.v_class_preview t3 On t1.fk_class = t3.fk_class - And t1.fk_project Is Not Distinct From t3.fk_project -$BODY$; - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich( - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -BEGIN - - perform war.enriched_nodes__enrich_entity_label(); - perform war.enriched_nodes__enrich_full_text(); - perform war.enriched_nodes__enrich_type_label(); - -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_entity_label( - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -Declare - needs_update boolean; -Begin - needs_update = True; - ---------- entity label completion ------------ - WHILE (needs_update = True) - Loop - -- fill entity label - With tw0 As ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - -- t1.own_entity_label_field_order, - -- t2.field_order, - -- t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then - t1.own_entity_label - When t1.fk_project Is Not Null Then - Case When t2.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t2.entity_label - End - Else - Case When t4.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t4.entity_label - End - End entity_label - From - war.enriched_node t1 - -- JOIN the project variants (here the ord_num in field is important) - Left Join Lateral ( Select Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t2.field_order, 10000)) target_field_overrides_own_label - From - war.edge t2 - Left Join Lateral ( Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity, - t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null) t6) t3 On True - Where - t1.pk_entity = t2.fk_source - And t1.fk_project = t2.fk_project -- '=' (sic!) - Order By - t1.pk_entity, - t2.field_order, - t2.ord_num_within_field Asc) t2 On True - -- JOIN the repo variants (here the frequency of entity_label is relevant) - Left Join Lateral ( - Select - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t4.field_order, 10000)) target_field_overrides_own_label - From - war.edge t4 - Left Join Lateral ( - Select - * - From - war.enriched_node t5 - Where - t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null) t5 On True - Where - t1.pk_entity = t4.fk_source - And t1.fk_project Is Null - And t4.fk_project Is Null - Group By - t5.entity_label, - t4.field_order - Order By - t4.field_order, - count(t5.pk_entity) - Desc - Limit 1) t4 On True -), -tw1 As ( - Update - war.enriched_node t1 - Set - entity_label = t2.entity_label - From - tw0 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - And t1.entity_label Is Distinct From t2.entity_label - Returning - t1.entity_label, - t2.entity_label -) -Select - count(*) > 0 Into needs_update -From - tw1; -End Loop; -End; -$BODY$; - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_full_text( - ) - RETURNS boolean - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -BEGIN ------------ create full text --------- -WITH tw1 AS ( - SELECT - t1.pk_entity, - t1.fk_project, - t1.entity_label, - t1.class_label, - t1.type_label, - array_to_string(array_remove(ARRAY[ - t1.class_label, - t1.type_label, - t1.own_full_text, - string_agg(t3.own_full_text, ', ' ORDER BY t2.field_order asc, t2.ord_num_within_field), - t1.entity_label - ], null), ', ') as full_text - FROM - war.enriched_node t1, - war.edge t2, - war.enriched_node t3 - WHERE - t1.pk_entity = t2.fk_source AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - AND t2.fk_target = t3.pk_entity AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - -- todo: join target nodes of repo too, order by fk_project, select distinct on fk_source, fk_property?, fk_target - GROUP BY - t1.pk_entity - , t1.fk_project - , t1.class_label - , t1.type_label - , t1.entity_label - , t1.own_full_text -) -UPDATE - war.enriched_node t1 -SET - full_text = t2.full_text, - ----------- create tsvector ---------- - ts_vector = ( - SELECT - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || - setweight(to_tsvector(coalesce(t2.type_label, t2.class_label, '')), 'B') || - setweight(to_tsvector(coalesce(t2.full_text, '')), 'C') - ) -FROM - tw1 t2 -WHERE - t1.pk_entity = t2.pk_entity -AND - t1.fk_project IS NOT DISTINCT FROM t2.fk_project -AND - t1.full_text IS DISTINCT FROM t2.full_text; - - RETURN TRUE; -END; -$BODY$; - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_some( - node_ids war.node_id[]) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With tw1 As ( - Select - t1.* - From - war.enriched_node t1, - unnest(node_ids) t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), --- select entity_label -tw2 As ( - Select - t1.pk_entity, - t1.fk_project, - --t1.fk_class, - --CASE WHEN t1.fk_project IS NOT NULL THEN - -- t2.target_field_overrides_own_label - --ELSE - -- t4.target_field_overrides_own_label - --END target_field_overrides_own_label, - --t1.own_entity_label, - --t1.own_entity_label_field_order, - --t2.field_order, - --t2.ord_num_within_field, - --t4.field_order field_order_in_repo, - Case - -- never override entity_label of 'appellation use for lang' entity - When t1.fk_class = 365 Then - t1.own_entity_label - When t1.fk_project Is Not Null Then - Case When t2.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t2.entity_label - End - Else - Case When t4.target_field_overrides_own_label = False Then - t1.own_entity_label - Else - t4.entity_label - End - End entity_label - From - tw1 t1 - -- JOIN the project variants (here the ord_num in field is important) - Left Join Lateral ( Select Distinct On (t1.pk_entity) - t3.pk_entity, - t3.entity_label, - t2.field_order, - t2.ord_num_within_field, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t2.field_order, 10000)) target_field_overrides_own_label - From - war.edge t2 - Left Join Lateral ( Select Distinct On (t6.pk_entity) - t6.entity_label, - t6.pk_entity, - t6.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project = t3.fk_project - And t3.entity_label Is Not Null - Union All - Select - t3.entity_label, - t3.pk_entity, - t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null - And t3.entity_label Is Not Null) t6) t3 On True - Where - t1.pk_entity = t2.fk_source - And t1.fk_project = t2.fk_project -- '=' (sic!) - Order By - t1.pk_entity, - t2.field_order, - t2.ord_num_within_field Asc) t2 On True - -- JOIN the repo variants (here the frequency of entity_label is relevant) - Left Join Lateral ( - Select - count(t5.pk_entity), - t5.entity_label, - t4.field_order, - (t1.own_entity_label_field_order Is Null - Or t1.own_entity_label_field_order > coalesce(t4.field_order, 10000)) target_field_overrides_own_label - From - war.edge t4 - Left Join Lateral ( - Select - * - From - war.enriched_node t5 - Where - t4.fk_target = t5.pk_entity - And t5.fk_project Is Null - And t5.entity_label Is Not Null) t5 On True - Where - t1.pk_entity = t4.fk_source - And t1.fk_project Is Null - And t4.fk_project Is Null - Group By - t5.entity_label, - t4.field_order - Order By - t4.field_order, - count(t5.pk_entity) - Desc - Limit 1) t4 On True -), --- select type_label -tw3 As ( - Select - t1.pk_entity, - t1.fk_project, - t3.entity_label type_label, - t3.pk_entity fk_type - From - tw1 t1 - Join Lateral ( - Select - * - From - war.edge j1 - Where - j1.target_provides = 'type' - And j1.fk_source = t1.pk_entity - And j1.fk_project Is Not Distinct From t1.fk_project - Order By - j1.field_order Asc, - j1.ord_num_within_field - Limit 1) t2 On True - Join Lateral ( - -- join the target enriched_node, in project variant, else in repo variant - Select Distinct On (j2.pk_entity) - j2.entity_label, - j2.pk_entity --, j2.fk_project - From ( - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Union All - Select - t3.entity_label, - t3.pk_entity --, t3.fk_project - From - war.enriched_node t3 - Where - t2.fk_target = t3.pk_entity - And t3.fk_project Is Null) j2) t3 On True -), --- select full_text -tw4 As ( - Select - t1.pk_entity, - t1.fk_project, - t4.entity_label, - t1.class_label, - t5.type_label, - array_to_string(array_remove(Array[t1.class_label, t5.type_label, t1.own_full_text, string_agg(t3.own_full_text, ', ' Order By t2.field_order Asc, t2.ord_num_within_field), t4.entity_label], Null), ', ') As full_text - From - tw1 t1 - Join war.edge t2 On t1.pk_entity = t2.fk_source - And t1.fk_project Is Not Distinct From t2.fk_project - Join war.enriched_node t3 On t2.fk_target = t3.pk_entity - And t2.fk_project Is Not Distinct From t3.fk_project - Left Join tw2 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project - Left Join tw3 t5 On t1.pk_entity = t5.pk_entity - And t1.fk_project Is Not Distinct From t5.fk_project -Group By - t1.pk_entity, - t1.fk_project, - t1.class_label, - t5.type_label, - t4.entity_label, - t1.own_full_text -), --- left join entity_label, full_text, fk_type and type_label, where at least one needs update -tw5 As ( - Select - t1.pk_entity, - t1.fk_project, - t1.entity_label old_label, - t2.entity_label, - t1.fk_type old_fk_type, - t3.fk_type, - t1.type_label old_type_label, - t3.type_label, - t1.full_text old_full_text, - t4.full_text - From - tw1 t1 - Left Join tw2 t2 On t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Left Join tw3 t3 On t1.pk_entity = t3.pk_entity - And t1.fk_project Is Not Distinct From t3.fk_project - Left Join tw4 t4 On t1.pk_entity = t4.pk_entity - And t1.fk_project Is Not Distinct From t4.fk_project -Where (t1.entity_label Is Distinct From t2.entity_label - Or t1.type_label Is Distinct From t3.type_label - Or t1.fk_type Is Distinct From t3.fk_type - Or t1.full_text Is Distinct From t4.full_text)) -Update - war.enriched_node t1 -Set - entity_label = t2.entity_label, - fk_type = t2.fk_type, - type_label = t2.type_label, - full_text = t2.full_text, - ts_vector = ( - Select - setweight(to_tsvector(coalesce(t2.entity_label, '')), 'A') || setweight(to_tsvector(coalesce(t2.type_label, t1.class_label, '')), 'B') || setweight(to_tsvector(coalesce(t2.full_text, '')), 'C')) -From - tw5 t2 -Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -Returning - t1.*; - -$BODY$; - -CREATE OR REPLACE FUNCTION war.enriched_nodes__enrich_type_label( - ) - RETURNS void - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -DECLARE - needs_update boolean; -BEGIN - needs_update = true; - - ---------- type label completion ------------ - WHILE ( needs_update = true) - LOOP - -- fill type label - WITH tw0 AS ( - SELECT t1.pk_entity, t1.fk_project, t3.entity_label type_label, t3.pk_entity fk_type - FROM - war.enriched_node t1 - JOIN LATERAL ( - SELECT * - FROM war.edge j1 - WHERE j1.target_provides = 'type' - AND j1.fk_source = t1.pk_entity - AND j1.fk_project IS NOT DISTINCT FROM t1.fk_project - ORDER BY j1.field_order asc, j1.ord_num_within_field - LIMIT 1 - ) t2 ON TRUE - JOIN LATERAL ( - -- join the target enriched_node, in project variant, else in repo variant - SELECT DISTINCT ON (j2.pk_entity) - j2.entity_label, j2.pk_entity--, j2.fk_project - FROM - ( - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t2.fk_project IS NOT DISTINCT FROM t3.fk_project - UNION ALL - SELECT t3.entity_label, t3.pk_entity--, t3.fk_project - FROM - war.enriched_node t3 - WHERE - t2.fk_target = t3.pk_entity - AND t3.fk_project IS NULL - ) j2 - ) t3 ON - ( - t1.type_label IS DISTINCT FROM t3.entity_label - OR - t1.fk_type IS DISTINCT FROM t3.pk_entity - ) - - ), - tw1 AS ( - UPDATE - war.enriched_node t1 - SET - type_label = t2.type_label, - fk_type = t2.fk_type - FROM - tw0 t2 - WHERE t1.pk_entity = t2.pk_entity - AND t1.fk_project IS NOT DISTINCT FROM t2.fk_project - RETURNING t1.*, t2.type_label - ) - SELECT count(*) > 0 into needs_update - FROM tw1; - END LOOP; - -END; -$BODY$; - - -CREATE OR REPLACE FUNCTION war.enriched_nodes__upsert_some( - param_pk_entities integer[], - param_fk_project integer) - RETURNS SETOF war.enriched_node - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With tw1 As ( - -- Create enriched_nodes on the fly - Select - * - From - war.enriched_nodes__create_some (param_pk_entities, - param_fk_project) -), -tw2 As ( - -- Select the enriched_nodes that are different in one of the non recursive columns - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.class_label, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second - From - tw1 t1 - Except - Select - t1.pk_entity, - t1.fk_project, - t1.project, - t1.fk_class, - t1.class_label, - t1.entity_type, - t1.own_full_text, - t1.own_entity_label, - t1.time_span, - t1.first_second, - t1.last_second - From - war.enriched_node t1, - tw1 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the enriched_nodes that are different in one of the non recursive columns - Update - war.enriched_node t1 - Set - pk_entity = t2.pk_entity, - fk_project = t2.fk_project, - project = t2.project, - fk_class = t2.fk_class, - class_label = t2.class_label, - entity_type = t2.entity_type, - own_full_text = t2.own_full_text, - own_entity_label = t2.own_entity_label, - time_span = t2.time_span, - first_second = t2.first_second, - last_second = t2.last_second - From - tw2 t2 - Where - t1.pk_entity = t2.pk_entity - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created enriched_nodes that do not yet exist - Insert Into war.enriched_node - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - --- Index: enriched_node_class_label_idx - --- DROP INDEX war.enriched_node_class_label_idx; - -CREATE INDEX enriched_node_class_label_idx - ON war.enriched_node USING btree - (class_label COLLATE pg_catalog."default" ASC NULLS LAST); - - --- Index: enriched_node_entity_label_idx - --- DROP INDEX war.enriched_node_entity_label_idx; - -CREATE INDEX enriched_node_entity_label_idx - ON war.enriched_node USING btree - (entity_label COLLATE pg_catalog."default" ASC NULLS LAST); - - --- Index: enriched_node_entity_type_idx - --- DROP INDEX war.enriched_node_entity_type_idx; - -CREATE INDEX enriched_node_entity_type_idx - ON war.enriched_node USING btree - (entity_type COLLATE pg_catalog."default" ASC NULLS LAST); - - --- Index: enriched_node_fk_class_idx - --- DROP INDEX war.enriched_node_fk_class_idx; - -CREATE INDEX enriched_node_fk_class_idx - ON war.enriched_node USING btree - (fk_class ASC NULLS LAST); - - --- Index: enriched_node_fk_project_idx - --- DROP INDEX war.enriched_node_fk_project_idx; - -CREATE INDEX enriched_node_fk_project_idx - ON war.enriched_node USING btree - (fk_project ASC NULLS LAST); - - --- Index: enriched_node_fk_type_idx - --- DROP INDEX war.enriched_node_fk_type_idx; - -CREATE INDEX enriched_node_fk_type_idx - ON war.enriched_node USING btree - (fk_type ASC NULLS LAST); - - --- Index: enriched_node_pk_entity_idx - --- DROP INDEX war.enriched_node_pk_entity_idx; - -CREATE INDEX enriched_node_pk_entity_idx - ON war.enriched_node USING btree - (pk_entity ASC NULLS LAST); - - --- Index: enriched_node_type_label_idx - --- DROP INDEX war.enriched_node_type_label_idx; - -CREATE INDEX enriched_node_type_label_idx - ON war.enriched_node USING btree - (type_label COLLATE pg_catalog."default" ASC NULLS LAST); - - --- Trigger: last_modification_tmsp - --- DROP TRIGGER last_modification_tmsp ON war.enriched_node; - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON war.enriched_node - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification(); diff --git a/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-up.sql b/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-up.sql deleted file mode 100644 index 6acf04032..000000000 --- a/server/db-migrate/migrations/sqls/20210108144400-war-t-enriched-node-drop-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -DROP FUNCTION war.enriched_nodes__create_all (); - -DROP FUNCTION war.enriched_nodes__create_some (integer[], integer); - -DROP FUNCTION war.enriched_nodes__enrich (); -DROP FUNCTION war.enriched_nodes__enrich_entity_label(); - DROP FUNCTION war.enriched_nodes__enrich_full_text(); - DROP FUNCTION war.enriched_nodes__enrich_some(war.node_id[]); -DROP FUNCTION war.enriched_nodes__enrich_type_label(); -DROP FUNCTION war.enriched_nodes__upsert_some(integer[], integer); -DROP TABLE war.enriched_node; - diff --git a/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-down.sql b/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-down.sql deleted file mode 100644 index 8f13c986b..000000000 --- a/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-down.sql +++ /dev/null @@ -1,578 +0,0 @@ --- 1 - - -CREATE TABLE war.edge -( - fk_source integer, - fk_project integer, - fk_target integer, - target_provides war.edge_target_type, - ord_num_within_field integer, - field_order integer, - fk_statement integer -); - -CREATE OR REPLACE FUNCTION war.edges__create_all( - ) - RETURNS SETOF war.edge - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_subject_info As fk_source, - t1.fk_object_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_object_info As fk_source, - t1.fk_subject_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_statement) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1; - -$BODY$; - - - -CREATE OR REPLACE FUNCTION war.edges__create_some( - param_pk_statements integer[], - param_fk_project integer) - RETURNS SETOF war.edge - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With tw1 As ( - ---- outgoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_subject_info As fk_source, - t1.fk_object_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_range As ord_num_within_field, - t1.is_in_project_count, - Case When t5.is_has_type_subproperty Then - 'type'::war.edge_target_type - Else - 'text'::war.edge_target_type - End As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_domain_class = t5.has_domain - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_statements) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_domain = t3.fk_class - And t5.has_range = t4.fk_class - Union All - ---- ingoing edges of project - Select - t2.fk_project, - t1.pk_entity As fk_statement, - t1.fk_object_info As fk_source, - t1.fk_subject_info As fk_target, - t1.fk_property, - t6.field_order As field_order_of_project, - t7.field_order As field_order_of_default_project, - Case When (Exists ( - Select - pk_entity - From - projects.class_field_config j1 - Where - j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project)) Then - True - Else - False - End project_has_own_field_order, - t2.ord_num_of_domain As ord_num_within_field, - t1.is_in_project_count, - 'text'::war.edge_target_type As target_provides - From - information.v_statement t1, - projects.info_proj_rel t2 - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_object_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_object_info) As t3 On True - Join Lateral ( - Select - pk_entity, - fk_class - From - information.persistent_item - Where - pk_entity = t1.fk_subject_info - Union All - Select - pk_entity, - fk_class - From - information.temporal_entity - Where - pk_entity = t1.fk_subject_info) As t4 On True, - data_for_history.v_property t5 - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = t2.fk_project) As t6 On True - Left Join Lateral ( - Select - j1.ord_num As field_order - From - projects.class_field_config j1 - Where - j1.fk_property = t5.pk_property - And j1.fk_range_class = t5.has_range - And j1.fk_project = 375669 -- Default config project -) As t7 On True - Where - t1.pk_entity = Any (param_pk_statements) - And t2.fk_project = param_fk_project - And t1.pk_entity = t2.fk_entity - And t2.is_in_project = True - And t5.pk_property = t1.fk_property - And t5.has_range = t3.fk_class - And t5.has_domain = t4.fk_class -) - Select Distinct On (fk_source, fk_project, fk_target, fk_statement) - fk_source, - fk_project, - fk_target, - target_provides, - ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - When project_has_own_field_order = True Then - field_order_of_project - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1 -Union All Select Distinct - fk_source, - Null::int As fk_project, - fk_target, - target_provides, - --is_in_project_count as ord_num_within_field, - Null::int As ord_num_within_field, - Case When fk_property = 1111 Then - - 9 - Else - field_order_of_default_project - End As field_order, - fk_statement -From - tw1; - -$BODY$; - - -CREATE OR REPLACE FUNCTION war.edges__upsert_some( - param_pk_statements integer[], - param_fk_project integer) - RETURNS SETOF war.edge - LANGUAGE 'sql' - - COST 100 - VOLATILE - ROWS 1000 - -AS $BODY$ - With tw1 As ( - -- Create edges on the fly - Select - * - From - war.edges__create_some (param_pk_statements, param_fk_project) -), -tw2 As ( - -- Select the edges that are different in one of the non recursive columns - Select - * - From - tw1 t1 - Except - Select - t1.* - From - war.edge t1, - tw1 t2 - Where - t1.fk_statement = t2.fk_statement - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project -), -tw3 As ( - -- Update the edges that are different in one of the non recursive columns - Update - war.edge t1 - Set - fk_source = t2.fk_source, - fk_project = t2.fk_project, - fk_target = t2.fk_target, - target_provides = t2.target_provides, - ord_num_within_field = t2.ord_num_within_field, - field_order = t2.field_order, - fk_statement = t2.fk_statement - From - tw2 t2 - Where - t1.fk_statement = t2.fk_statement - And t1.fk_source = t2.fk_source - And t1.fk_target = t2.fk_target - And t1.fk_project Is Not Distinct From t2.fk_project - Returning - t1.* -), -tw4 As ( - -- Insert the created edges that do not yet exist - Insert Into war.edge - Select - * - From - tw1 - On Conflict - Do Nothing - Returning - * -) -Select - * -From - tw3 -Union -Select - * -From - tw4; - -$BODY$; - - - -CREATE INDEX edge_fk_project_idx - ON war.edge USING btree - (fk_project ASC NULLS LAST); - - -CREATE INDEX edge_fk_source_idx - ON war.edge USING btree - (fk_source ASC NULLS LAST); - - -CREATE INDEX edge_fk_target_idx - ON war.edge USING btree - (fk_target ASC NULLS LAST); - - -CREATE INDEX edge_priority_of_text_idx - ON war.edge USING btree - (ord_num_within_field ASC NULLS LAST); - -CREATE UNIQUE INDEX edge_unique_project - ON war.edge USING btree - (fk_source ASC NULLS LAST, fk_project ASC NULLS LAST, fk_target ASC NULLS LAST, fk_statement ASC NULLS LAST) - TABLESPACE pg_default - WHERE fk_project IS NOT NULL; - -CREATE UNIQUE INDEX edge_unique_repo - ON war.edge USING btree - (fk_source ASC NULLS LAST, fk_target ASC NULLS LAST, fk_statement ASC NULLS LAST) - TABLESPACE pg_default - WHERE fk_project IS NULL; diff --git a/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-up.sql b/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-up.sql deleted file mode 100644 index ef3cb99c0..000000000 --- a/server/db-migrate/migrations/sqls/20210108144402-war-t-edge-drop-up.sql +++ /dev/null @@ -1,8 +0,0 @@ -DROP FUNCTION war.edges__create_all (); - -DROP FUNCTION war.edges__create_some (integer[], integer); - -DROP FUNCTION war.edges__upsert_some (integer[], integer); - -DROP TABLE war.edge; - diff --git a/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-down.sql b/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-down.sql deleted file mode 100644 index 0c012bd69..000000000 --- a/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-down.sql +++ /dev/null @@ -1,17 +0,0 @@ - - -CREATE TABLE war.node -( - pk_entity integer, - fk_project integer, - project integer, - fk_class integer, - entity_type text COLLATE pg_catalog."default", - own_entity_label text COLLATE pg_catalog."default", - own_full_text text COLLATE pg_catalog."default", - time_span jsonb, - first_second bigint, - last_second bigint, - own_entity_label_field_order integer, - CONSTRAINT entity_preview_unique UNIQUE (pk_entity, project) -) diff --git a/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-up.sql b/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-up.sql deleted file mode 100644 index 12b196162..000000000 --- a/server/db-migrate/migrations/sqls/20210108150147-war-t-node-drop-up.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE war.node; diff --git a/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-down.sql b/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-down.sql deleted file mode 100644 index 982376c8b..000000000 --- a/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-down.sql +++ /dev/null @@ -1,7 +0,0 @@ - -CREATE TABLE war.update_log -( - pk_entity serial, - tmsp_update_begin timestamp without time zone, - tmsp_update_end timestamp without time zone -) diff --git a/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-up.sql b/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-up.sql deleted file mode 100644 index 29f661adc..000000000 --- a/server/db-migrate/migrations/sqls/20210108150318-war-t-update-log-drop-up.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE war.update_log; diff --git a/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-down.sql b/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-down.sql deleted file mode 100644 index cb2842c97..000000000 --- a/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-down.sql +++ /dev/null @@ -1,14 +0,0 @@ --- 3 unmark table as deprecated -ALTER TABLE system.analysis_type_deprecated RENAME TO analysis_type; -ALTER TABLE system.analysis_type_vt_deprecated RENAME TO analysis_type_vt; - --- 2 redirect foreign key to use system types -ALTER TABLE projects.analysis DROP CONSTRAINT analysis_fk_analysis_type_fkey; - -ALTER TABLE projects.analysis - ADD CONSTRAINT analysis_fk_analysis_type_fkey FOREIGN KEY (fk_analysis_type) - REFERENCES system.analysis_type (pk_entity); - - --- 1 drop system types for analysis types -DELETE FROM system.system_type WHERE pk_entity IN (3331,3332,3333) diff --git a/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-up.sql b/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-up.sql deleted file mode 100644 index e8c2b1891..000000000 --- a/server/db-migrate/migrations/sqls/20210112201048-sys-t-analysis-type-drop-up.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 1 create system types for analysis types -SELECT setval('system.entity_pk_entity_seq', 3330, true); -INSERT INTO System.system_type (st_schema_name, st_table_name, st_column_name, definition) -VALUES -('projects', 'analysis', 'fk_analysis_type', 'time-chart'), -('projects', 'analysis', 'fk_analysis_type', 'table'), -('projects', 'analysis', 'fk_analysis_type', 'map-and-time-cont'); -SELECT setval('system.entity_pk_entity_seq', max(pk_entity), true)from system.entity; - --- 2 redirect foreign key to use system types -ALTER TABLE projects.analysis DROP CONSTRAINT analysis_fk_analysis_type_fkey; - -ALTER TABLE projects.analysis - ADD CONSTRAINT analysis_fk_analysis_type_fkey FOREIGN KEY (fk_analysis_type) - REFERENCES system.system_type (pk_entity); - --- 3 mark table as deprecated -ALTER TABLE system.analysis_type RENAME TO analysis_type_deprecated; - -ALTER TABLE system.analysis_type_vt RENAME TO analysis_type_vt_deprecated; diff --git a/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-down.sql b/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-down.sql deleted file mode 100644 index 27b8f043c..000000000 --- a/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE war.statement DROP CONSTRAINT statement_pk_entity_project_key; diff --git a/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-up.sql b/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-up.sql deleted file mode 100644 index d38f03633..000000000 --- a/server/db-migrate/migrations/sqls/20210115115621-war-t-statement-uniq-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE war.statement - ADD CONSTRAINT statement_pk_entity_project_key UNIQUE (pk_entity, project); diff --git a/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-down.sql b/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-down.sql deleted file mode 100644 index 266ecb4eb..000000000 --- a/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP FUNCTION commons.time_primitive__get_to_day; -DROP FUNCTION commons.time_primitive__pretty_json; diff --git a/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-up.sql b/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-up.sql deleted file mode 100644 index fd0fd6ef4..000000000 --- a/server/db-migrate/migrations/sqls/20210115172750-com-f-time-primitive-pretty-up.sql +++ /dev/null @@ -1,122 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.time_primitive__get_to_day( - julian_day integer, - duration calendar_granularities, - calendar calendar_type) - RETURNS int - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ - DECLARE - day_after_added_duration int; - BEGIN - - IF(calendar IS NULL) THEN - RAISE WARNING 'No calendar provided'; - IF(julian_day < 2299161) THEN - calendar = 'julian'; - ELSE - calendar = 'gregorian'; - END IF; - END IF; - - IF(calendar = 'gregorian') THEN - IF(duration = '1 day') THEN - SELECT julian_day + 1 INTO day_after_added_duration; - ELSIF(duration = '1 month') THEN - SELECT to_char((('J' || julian_day::text)::DATE + INTERVAL '1 month'), 'J') INTO day_after_added_duration; - ELSIF(duration = '1 year') THEN - SELECT to_char((('J' || julian_day::text)::DATE + INTERVAL '1 year'), 'J') INTO day_after_added_duration; - ELSE - RAISE EXCEPTION 'duration not supported --> %', duration - USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; - END IF; - - ELSIF (calendar = 'julian') THEN - - IF(duration = '1 day') THEN - SELECT julian_day + 1 INTO day_after_added_duration; - ELSIF(duration = '1 month') THEN - SELECT commons.julian_cal__add_1_month(julian_day) INTO day_after_added_duration; - ELSIF(duration = '1 year') THEN - SELECT commons.julian_cal__add_1_year(julian_day) INTO day_after_added_duration; - ELSE - RAISE EXCEPTION 'duration not supported --> %', duration - USING HINT = 'Supported durations: "1 day", "1 month", "1 year"'; - END IF; - - ELSE - RAISE EXCEPTION 'calendar not supported --> %', calendar - USING HINT = 'Supported calendars: "gregorian", "julian"'; - END IF; - - RETURN day_after_added_duration; - END; - $BODY$; -CREATE OR REPLACE FUNCTION commons.time_primitive__pretty_json(time_primitive information.time_primitive, calendar calendar_type) - RETURNS jsonb - LANGUAGE 'plpgsql' - AS $BODY$ - DECLARE - from_day int; - from_second bigint; - from_julian_cal varchar; - from_gregorian_cal varchar; - from_gregorian_cal_iso8601 varchar; - - to_day int; - to_second bigint; - to_julian_cal varchar; - to_gregorian_cal varchar; - to_gregorian_cal_iso8601 varchar; - - label varchar; - - BEGIN - from_day = time_primitive.julian_day; - SELECT commons.time_primitive__get_first_second(from_day) INTO from_second; - SELECT concat(to_char(t.year, 'fm0000'),'-',to_char(t.month, 'fm00') , '-',to_char(t.day, 'fm00')) INTO from_julian_cal - FROM commons.julian_cal__year_month_day( from_day ) t; - SELECT to_char((('J' || from_day)::timestamp ), 'YYYY-MM-DD') into from_gregorian_cal; - SELECT commons.julian_second__to_iso_8601(from_second) into from_gregorian_cal_iso8601; - - SELECT commons.time_primitive__get_to_day(from_day, time_primitive.duration, calendar) INTO to_day; - SELECT commons.time_primitive__get_first_second(to_day) INTO to_second; - SELECT concat(to_char(t.year, 'fm0000'),'-',to_char(t.month, 'fm00') , '-',to_char(t.day, 'fm00')) INTO to_julian_cal - FROM commons.julian_cal__year_month_day( to_day ) t; - SELECT to_char((('J' || to_day)::timestamp ), 'YYYY-MM-DD') into to_gregorian_cal; - SELECT commons.julian_second__to_iso_8601(to_second) into to_gregorian_cal_iso8601; - SELECT - CASE WHEN calendar = 'gregorian' THEN - concat(from_gregorian_cal, ' (', time_primitive.duration, ')') - ELSE - concat(from_julian_cal, ' (', time_primitive.duration, ')') - END - INTO label; - - RETURN jsonb_build_object( - 'pkEntity', time_primitive.pk_entity, - 'fkClass', time_primitive.fk_class, - 'julianDay', time_primitive.julian_day, - 'duration', time_primitive.duration, - 'calendar', calendar::text, - 'label', label, - 'from', jsonb_build_object( - 'julianDay', from_day, - 'julianSecond', from_second, - 'calGregorian', from_gregorian_cal, - 'calGregorianIso8601', from_gregorian_cal_iso8601, - 'calJulian', from_julian_cal - ), - 'to', jsonb_build_object( - 'julianDay', to_day, - 'julianSecond', to_second, - 'calGregorian', to_gregorian_cal, - 'calGregorianIso8601', to_gregorian_cal_iso8601, - 'calJulian', to_julian_cal - ) - ); - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-down.sql b/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-down.sql deleted file mode 100644 index b5a3ed222..000000000 --- a/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE war.statement -DROP COLUMN object_info_value; diff --git a/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-up.sql b/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-up.sql deleted file mode 100644 index 3dcbace34..000000000 --- a/server/db-migrate/migrations/sqls/20210115201042-war-t-statement-add-object-value-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE war.statement -ADD COLUMN object_info_value jsonb; diff --git a/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-down.sql b/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-down.sql deleted file mode 100644 index 1a1156934..000000000 --- a/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-down.sql +++ /dev/null @@ -1 +0,0 @@ ---no way back diff --git a/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-up.sql b/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-up.sql deleted file mode 100644 index 834206f91..000000000 --- a/server/db-migrate/migrations/sqls/20210121134436-inf-data-add-missing-calendar-up.sql +++ /dev/null @@ -1,79 +0,0 @@ -BEGIN; -WITH tw1 AS ( - SELECT - array_agg(distinct t3.account_id) accounts, - array_agg(distinct t3.fk_project) projects, - t1.fk_subject_info, - t2.pk_entity pk_rel, - t2.fk_project, - t2.calendar, - t0.duration, - t0.julian_day, - (to_json(commons.julian_cal__year_month_day(t0.julian_day))->>'day')::int day_according_to_jul, - to_char((('J' || t0.julian_day)::timestamp ), 'DD')::int day_according_to_greg - FROM information.time_primitive t0, - information."statement" t1, - projects.info_proj_rel t2, - account_project_rel t3 - - WHERE t0.pk_entity=t1.fk_object_info - AND t1.pk_entity=t2.fk_entity - AND t2.fk_project = t3.fk_project - GROUP BY - t2.pk_entity, - t2.fk_project, - t2.calendar, - t1.fk_subject_info, - t0.duration, - t0.julian_day -), -tw2 AS ( - SELECT - t1.accounts, - t1.projects, - t1.fk_subject_info, - t1.pk_rel, - to_char((('J' || t1.julian_day)::timestamp ), 'YYYY-MM-DD') greg_proleptic, - t1.calendar, - t1.duration, - CASE WHEN (t1.julian_day < 2299161) THEN - 'julian' - ELSE - 'gregorian' - END cal_according_to_threshold, - CASE WHEN t1.duration IN ('1 month','1 year') THEN - CASE WHEN day_according_to_jul = 1 THEN - 'julian' - WHEN day_according_to_greg = 1 THEN - 'gregorian' - ELSE - 'error: no cal gives first day' - END - - END cal_according_to_day_in_month - FROM tw1 t1 -), -tw3 AS ( - SELECT - t1.*, - COALESCE(t1.cal_according_to_day_in_month, t1.cal_according_to_threshold)::calendar_type new_calendar, - t1.calendar::text = cal_according_to_day_in_month cal_day_in_month_match, - t1.calendar::text = cal_according_to_threshold cal_threshold_match, - CASE WHEN t1.calendar IS NOT NULL THEN - 'calendar provided' - WHEN t1.cal_according_to_day_in_month IS NOT NULL THEN - 'calendar deducable' - ELSE - 'calendar guessable' - END quality - FROM tw2 t1 -) -UPDATE projects.info_proj_rel t1 -SET calendar = t2.new_calendar -FROM tw3 t2 -WHERE t1.pk_entity = t2.pk_rel -AND t1.calendar IS NULL ---SELECT count(*), t1.quality ---FROM tw3 t1 ---GROUP BY ---t1.quality diff --git a/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-down.sql b/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-down.sql deleted file mode 100644 index bd40e7062..000000000 --- a/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-down.sql +++ /dev/null @@ -1,9 +0,0 @@ -UPDATE - system.config t1 -SET - config = replace(t2.config::text, 'valueObjectType', 'mapsToListType')::jsonb -FROM - system.config t2 -WHERE - t1.pk_entity = t2.pk_entity; - diff --git a/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-up.sql b/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-up.sql deleted file mode 100644 index af15d1750..000000000 --- a/server/db-migrate/migrations/sqls/20210129140325-sys-config-change-up.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE system.config t1 -SET config = '{"classes":{"40":{"valueObjectType":{"appellation":"true"}},"51":{"valueObjectType":{"place":"true"}},"52":{"valueObjectType":{"dimension":{"measurementUnitClass":56}}},"54":{"valueObjectType":{"language":"true"}},"335":{"valueObjectType":{"timePrimitive":"true"}},"657":{"valueObjectType":{"langString":"true"}},"689":{"valueObjectType":{"dimension":{"measurementUnitClass":690}}},"784":{"valueObjectType":{"langString":"true"}},"785":{"valueObjectType":{"langString":"true"}}},"specialFields":{"incomingProperties":{"1111":{"comment":"has appellation for language","displayInBasicFields":{"position":2}}},"outgoingProperties":{"4":{"comment":"has time-span (When)","displayInBasicFields":{"position":1000}},"1760":{"comment":"has web address (is web addess of) – P16","displayInBasicFields":{"position":5}},"1761":{"comment":"has short title","displayInBasicFields":{"position":1}},"1762":{"comment":"P18 has definition (is definition of)","displayInBasicFields":{"position":4}},"1763":{"comment":"P19 has comment (is comment about)","displayInBasicFields":{"position":6}}},"hasTypeSubproperties":{"comment":"all subproperties of has type (dfh.api_property.is_has_type_subproperty=true)","displayInBasicFields":{"position":3}}}}'::json -FROM system.config t2 -WHERE t1.pk_entity = t2.pk_entity; diff --git a/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-down.sql b/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-down.sql deleted file mode 100644 index de8e90bf4..000000000 --- a/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE projects.table_config; -DROP table projects.table_config_vt; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-up.sql b/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-up.sql deleted file mode 100644 index 154fa7521..000000000 --- a/server/db-migrate/migrations/sqls/20210210153312-creation-of-tables-config-up.sql +++ /dev/null @@ -1,28 +0,0 @@ -Create Table projects.table_config ( - fk_project integer NOT NULL, - account_id integer, - fk_digital integer NOT NULL, - config jsonb, - - CONSTRAINT tables_config_fk_project_fkey FOREIGN KEY (fk_project) - REFERENCES projects.project (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - - CONSTRAINT tables_config_account_id_fkey FOREIGN KEY (account_id) - REFERENCES public.account (id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - - CONSTRAINT tables_config_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION -) -Inherits ( - projects.entity -); - --- 2 -Select - commons.init_entity_child_table ('projects.table_config'); \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-down.sql b/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-down.sql deleted file mode 100644 index 275ea8998..000000000 --- a/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-down.sql +++ /dev/null @@ -1,59 +0,0 @@ - -CREATE OR REPLACE VIEW data_for_history.v_property - AS - WITH tw0 AS ( - SELECT t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_identity_defining, - t1_1.dfh_is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM data_for_history.api_property t1_1 - UNION - SELECT 1111 AS dfh_pk_property, - true AS dfh_is_inherited, - 365 AS dfh_property_domain, - 0 AS dfh_domain_instances_min_quantifier, - '-1'::integer AS dfh_domain_instances_max_quantifier, - t1_1.dfh_pk_class AS dfh_property_range, - 1 AS dfh_range_instances_min_quantifier, - 1 AS dfh_range_instances_max_quantifier, - true AS dfh_identity_defining, - false AS dfh_is_has_type_subproperty, - 'histP9'::character varying AS dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM data_for_history.api_class t1_1 - WHERE t1_1.dfh_pk_class <> 365 - GROUP BY t1_1.dfh_fk_profile, t1_1.removed_from_api, t1_1.dfh_pk_class, t1_1.dfh_class_identifier_in_namespace, t1_1.dfh_basic_type, t1_1.dfh_basic_type_label - ), tw1 AS ( - SELECT t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles - FROM tw0 t1_1 - GROUP BY t1_1.dfh_pk_property, t1_1.dfh_property_domain, t1_1.dfh_property_range - ) - SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range) t1.dfh_pk_property AS pk_property, - t1.dfh_is_inherited AS is_inherited, - t1.dfh_property_domain AS has_domain, - t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1.dfh_property_range AS has_range, - t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1.dfh_identity_defining AS identity_defining, - t1.dfh_is_has_type_subproperty AS is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - t2.profiles - FROM tw0 t1, - tw1 t2 - WHERE t1.dfh_pk_property = t2.dfh_pk_property AND t1.dfh_property_domain = t2.dfh_property_domain AND t1.dfh_property_range = t2.dfh_property_range - ORDER BY t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range, t1.removed_from_api; diff --git a/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-up.sql b/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-up.sql deleted file mode 100644 index ec3d9b642..000000000 --- a/server/db-migrate/migrations/sqls/20210304071020-dfh-v-property-improvement-up.sql +++ /dev/null @@ -1,60 +0,0 @@ - -CREATE OR REPLACE VIEW data_for_history.v_property - AS - WITH tw0 AS ( - SELECT t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_identity_defining, - t1_1.dfh_is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM data_for_history.api_property t1_1 - UNION - SELECT 1111 AS dfh_pk_property, - true AS dfh_is_inherited, - 365 AS dfh_property_domain, - 0 AS dfh_domain_instances_min_quantifier, - '-1'::integer AS dfh_domain_instances_max_quantifier, - t1_1.dfh_pk_class AS dfh_property_range, - 1 AS dfh_range_instances_min_quantifier, - 1 AS dfh_range_instances_max_quantifier, - true AS dfh_identity_defining, - false AS dfh_is_has_type_subproperty, - 'histP9'::character varying AS dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM data_for_history.api_class t1_1 - WHERE t1_1.dfh_pk_class <> 365 - AND t1_1.dfh_basic_type IN (8,9,30) - GROUP BY t1_1.dfh_fk_profile, t1_1.removed_from_api, t1_1.dfh_pk_class, t1_1.dfh_class_identifier_in_namespace, t1_1.dfh_basic_type, t1_1.dfh_basic_type_label - ), tw1 AS ( - SELECT t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles - FROM tw0 t1_1 - GROUP BY t1_1.dfh_pk_property, t1_1.dfh_property_domain, t1_1.dfh_property_range - ) - SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range) t1.dfh_pk_property AS pk_property, - t1.dfh_is_inherited AS is_inherited, - t1.dfh_property_domain AS has_domain, - t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1.dfh_property_range AS has_range, - t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1.dfh_identity_defining AS identity_defining, - t1.dfh_is_has_type_subproperty AS is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - t2.profiles - FROM tw0 t1, - tw1 t2 - WHERE t1.dfh_pk_property = t2.dfh_pk_property AND t1.dfh_property_domain = t2.dfh_property_domain AND t1.dfh_property_range = t2.dfh_property_range - ORDER BY t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range, t1.removed_from_api; diff --git a/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-down.sql b/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-up.sql b/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-up.sql deleted file mode 100644 index 095aeefc7..000000000 --- a/server/db-migrate/migrations/sqls/20210316190319-inf-text-prop-to-lang-string-up.sql +++ /dev/null @@ -1,66 +0,0 @@ --- create lang-strings -insert into information.lang_string (string,fk_language,fk_class,metadata) -WITH tw1 AS ( - select - pk_entity, - string, - fk_language, - case - when fk_class_field = 217 then 784 -- has short title -> Short title – C15 - when fk_class_field = 218 then 783 -- has web address -> Uniform Resource Locator (URL) – C14 - when fk_class_field = 219 then 785 -- has definition -> Text – C16 - when fk_class_field = 3364 then 785 -- has comment -> Text – C16 - else null - end as fk_class - from information.text_property -) -select - string, - fk_language, - fk_class, - json_build_object( - 'from_text_properties', json_agg(pk_entity) - ) as metadata -from tw1 -group by string, fk_language, fk_class -on conflict on constraint unique__fk_language__fk_class__string do update -set metadata = excluded.metadata; - - --- create statements -insert into information.statement (fk_subject_info,fk_property,fk_object_info,metadata) -select - t1.fk_concerned_entity as fk_subject_info, - case - when t1.fk_class_field = 217 then 1761 -- has short title – P17 - when t1.fk_class_field = 218 then 1760 -- has web address – P16 - when t1.fk_class_field = 219 then 1762 -- has definition – P18 - when t1.fk_class_field = 3364 then 1763 -- has comment – P19 - else null - end as fk_property, - t2.pk_entity as fk_object_info, - json_build_object( - 'from_text_property', t1.pk_entity - ) -from - information.text_property t1, - information.lang_string t2 -where - t2.metadata::jsonb->'from_text_properties' @> jsonb_build_array(t1.pk_entity); - --- update info-proj-rels -WITH tw1 AS ( - select - t1.pk_entity, - t1.fk_entity as old_fk_entity, - t2.pk_entity as new_fk_entity - from - projects.info_proj_rel t1, - information.statement t2 - where - t1.fk_entity = (t2.metadata->>'from_text_property')::int -) -update projects.info_proj_rel t1 -set fk_entity = t2.new_fk_entity -from tw1 t2 -where t1.pk_entity=t2.pk_entity; diff --git a/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-down.sql b/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-up.sql b/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-up.sql deleted file mode 100644 index 41b55d1c9..000000000 --- a/server/db-migrate/migrations/sqls/20210325224809-sys-config-update-up.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE system.config t1 -SET config = '{ "classes": { "40": { "excludedFromEntities": true, "valueObjectType": { "appellation": "true" } }, "51": { "excludedFromEntities": true, "valueObjectType": { "place": "true" } }, "52": { "excludedFromEntities": true, "valueObjectType": { "dimension": { "measurementUnitClass": 56 } } }, "54": { "excludedFromEntities": true, "valueObjectType": { "language": "true" } }, "335": { "excludedFromEntities": true, "valueObjectType": { "timePrimitive": "true" } }, "657": { "excludedFromEntities": true, "valueObjectType": { "langString": "true" } }, "689": { "excludedFromEntities": true, "valueObjectType": { "dimension": { "measurementUnitClass": 690 } } }, "784": { "excludedFromEntities": true, "valueObjectType": { "langString": "true" } }, "785": { "excludedFromEntities": true, "valueObjectType": { "langString": "true" } }, "521": { "excludedFromEntities": true }, "454": { "excludedFromEntities": true }, "445": { "excludedFromEntities": true }, "455": { "excludedFromEntities": true }, "456": { "excludedFromEntities": true }, "457": { "excludedFromEntities": true }, "1": { "excludedFromEntities": true }, "518": { "excludedFromEntities": true }, "70": { "excludedFromEntities": true }, "50": { "excludedFromEntities": true }, "218": { "excludedFromEntities": true }, "717": { "excludedFromEntities": true }, "709": { "excludedFromEntities": true }, "707": { "excludedFromEntities": true }, "716": { "excludedFromEntities": true }, "713": { "excludedFromEntities": true }, "783": { "excludedFromEntities": true } }, "specialFields": { "incomingProperties": { "1111": { "comment": "has appellation for language", "displayInBasicFields": { "position": 2 } } }, "outgoingProperties": { "4": { "comment": "has time-span (When)", "displayInBasicFields": { "position": 1000 } }, "1760": { "comment": "has web address (is web addess of) – P16", "displayInBasicFields": { "position": 5 } }, "1761": { "comment": "has short title", "displayInBasicFields": { "position": 1 } }, "1762": { "comment": "P18 has definition (is definition of)", "displayInBasicFields": { "position": 4 } }, "1763": { "comment": "P19 has comment (is comment about)", "displayInBasicFields": { "position": 6 } } }, "hasTypeSubproperties": { "comment": "all subproperties of has type (dfh.api_property.is_has_type_subproperty=true)", "displayInBasicFields": { "position": 3 } } }}'::json -FROM system.config t2 -WHERE t1.pk_entity = t2.pk_entity; diff --git a/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-down.sql b/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-up.sql b/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-up.sql deleted file mode 100644 index bf9fb4eab..000000000 --- a/server/db-migrate/migrations/sqls/20210416202742-change-sys-config-up.sql +++ /dev/null @@ -1,240 +0,0 @@ -UPDATE - system.config t1 -SET - config = '{ - "classes": { - "1": { - "excludedFromEntities": true - }, - "40": { - "valueObjectType": { - "appellation": "true" - }, - "excludedFromEntities": true - }, - "50": { - "excludedFromEntities": true - }, - "51": { - "valueObjectType": { - "place": "true" - }, - "excludedFromEntities": true - }, - "52": { - "valueObjectType": { - "dimension": { - "measurementUnitClass": 56 - } - }, - "excludedFromEntities": true - }, - "54": { - "valueObjectType": { - "language": "true" - }, - "excludedFromEntities": true - }, - "70": { - "excludedFromEntities": true - }, - "218": { - "excludedFromEntities": true - }, - "335": { - "valueObjectType": { - "timePrimitive": "true" - }, - "excludedFromEntities": true - }, - "445": { - "excludedFromEntities": true - }, - "454": { - "excludedFromEntities": true - }, - "455": { - "excludedFromEntities": true - }, - "456": { - "excludedFromEntities": true - }, - "457": { - "excludedFromEntities": true - }, - "518": { - "excludedFromEntities": true - }, - "521": { - "excludedFromEntities": true - }, - "657": { - "valueObjectType": { - "langString": "true" - }, - "excludedFromEntities": true - }, - "689": { - "valueObjectType": { - "dimension": { - "measurementUnitClass": 690 - } - }, - "excludedFromEntities": true - }, - "707": { - "excludedFromEntities": true - }, - "709": { - "excludedFromEntities": true - }, - "713": { - "excludedFromEntities": true - }, - "716": { - "excludedFromEntities": true - }, - "717": { - "excludedFromEntities": true - }, - "783": { - "excludedFromEntities": true - }, - "784": { - "valueObjectType": { - "langString": "true" - }, - "excludedFromEntities": true - }, - "785": { - "valueObjectType": { - "langString": "true" - }, - "excludedFromEntities": true - } - }, - "specialFields": { - "incomingProperties": { - "1111": { - "comment": "has appellation for language", - "displayInBasicFields": { - "position": 2 - } - }, - "1782": { - "comment": "has identification – P18", - "displayInBasicFields": { - "position": 9 - } - }, - "1499": { - "comment": "has to be preferred to", - "displayInBasicFields": { - "position": 11 - } - } - }, - "outgoingProperties": { - "4": { - "comment": "has time-span (When)", - "displayInBasicFields": { - "position": 7 - }, - "isHasTimeSpanShortCut": true - }, - "145": { - "comment": "during (When)", - "displayInBasicFields": { - "position": 8 - }, - "isHasTimeSpanShortCut": true - }, - "1760": { - "comment": "has web address (is web addess of) – P16", - "displayInBasicFields": { - "position": 5 - } - }, - "1761": { - "comment": "has short title", - "displayInBasicFields": { - "position": 1 - } - }, - "1762": { - "comment": "P18 has definition (is definition of)", - "displayInBasicFields": { - "position": 4 - } - }, - "1763": { - "comment": "P19 has comment (is comment about)", - "displayInBasicFields": { - "position": 6 - } - }, - "1499": { - "comment": "has to be merged with", - "displayInBasicFields": { - "position": 10 - } - } - }, - "hasTypeSubproperties": { - "comment": "all subproperties of has type (dfh.api_property.is_has_type_subproperty=true)", - "displayInBasicFields": { - "position": 3 - } - } - }, - "addProperty": [ - { - "comment": "add to all teEn, peIt and types except for appe for lang itself", - "wherePkProperty": 1111, - "whereFkDomain":365, - "isOutgoing": false, - "toSourceClass": { - "wherePkClassNotIn": [365], - "whereBasicTypeIn": [8,9,30] - } - }, - { - "comment": "add to all teEn, peIt and types", - "wherePkProperty": 1762, - "isOutgoing": true, - "toSourceClass": { - "whereBasicTypeIn": [8,9,30] - } - }, - { - "comment": "add to all teEn", - "wherePkProperty": 4, - "isOutgoing": true, - "toSourceClass": { - "whereBasicTypeIn": [9] - } - }, - { - "comment": "add to teEn, peIt and types", - "wherePkProperty": 1782, - "isOutgoing": false, - "toSourceClass": { - "whereBasicTypeIn": [8,9,30] - } - }, - { - "comment": "add to a lot of classes", - "wherePkProperty": 1499, - "isOutgoing": true, - "toSourceClass": { - "whereBasicTypeIn": [8, 9, 10, 30] - }, - "replaceTargetClassWithSourceClass": true - } - ] -}' -FROM - system.config t2 -WHERE - t1.pk_entity = t2.pk_entity; - diff --git a/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-down.sql b/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-down.sql deleted file mode 100644 index 9456fab2c..000000000 --- a/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-down.sql +++ /dev/null @@ -1,456 +0,0 @@ --- 4 - -CREATE OR REPLACE VIEW data_for_history.v_label - AS - SELECT DISTINCT ON (t1.dfh_profile_label, t1.dfh_profile_label_language) 'label'::text AS type, - t1.dfh_profile_label AS label, - t1.dfh_profile_label_language AS language, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_profile_definition, t1.dfh_profile_definition_language) 'definition'::text AS type, - t1.dfh_profile_definition AS label, - t1.dfh_profile_definition_language AS language, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_project_label, t1.dfh_project_label_language) 'label'::text AS type, - t1.dfh_project_label AS label, - t1.dfh_project_label_language AS language, - NULL::integer AS fk_profile, - t1.dfh_owned_by_project AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_property_label, t1.dfh_property_label_language) 'label'::text AS type, - t1.dfh_property_label AS label, - t1.dfh_property_label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_property t1 -UNION - SELECT DISTINCT ON (t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) 'scope_note'::text AS type, - t1.dfh_property_scope_note AS label, - t1.dfh_property_scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_property t1 -UNION - SELECT DISTINCT ON (t1.dfh_class_label, t1.dfh_class_label_language) 'label'::text AS type, - t1.dfh_class_label AS label, - t1.dfh_class_label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_class t1 -UNION - SELECT DISTINCT ON (t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) 'scope_note'::text AS type, - t1.dfh_class_scope_note AS label, - t1.dfh_class_scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_class t1 -UNION - SELECT DISTINCT ON (t1.label, t1.label_language) 'label'::text AS type, - t1.label, - t1.label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property - FROM data_for_history.property_of_property t1 -UNION - SELECT DISTINCT ON (t1.scope_note, t1.scope_note_language) 'scope_note'::text AS type, - t1.scope_note AS label, - t1.scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property - FROM data_for_history.property_of_property t1; - - --- 3 - -CREATE OR REPLACE FUNCTION data_for_history.update_api_properties_profile_table( - param_profile_id integer, - param_requested_language character varying, - param_tmsp_last_dfh_update timestamp with time zone, - param_properties_profile_data json DEFAULT '[]'::json) - RETURNS json - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -Declare - removed JSON; - updated JSON; - inserted JSON; -Begin - /* - * create a table with same type as from json - */ - Drop Table If Exists properties_profile_from_api; - Create Table properties_profile_from_api As - Select - param_requested_language As requested_language, - "propertyID" As dfh_pk_property, - "propertyLabelLanguage" As dfh_property_label_language, - "propertyLabel" As dfh_property_label, - "propertyScopeNoteLanguage" As dfh_property_scope_note_language, - "propertyScopeNote" As dfh_property_scope_note, - "isInherited" As dfh_is_inherited, - "propertyDomain" As dfh_property_domain, - "domainInstancesMinQuantifier" As dfh_domain_instances_min_quantifier, - "domainInstancesMaxQuantifier" As dfh_domain_instances_max_quantifier, - "propertyRange" As dfh_property_range, - "rangeInstancesMinQuantifier" As dfh_range_instances_min_quantifier, - "rangeInstancesMaxQuantifier" As dfh_range_instances_max_quantifier, - "identityDefining" As dfh_identity_defining, - "isHasTypeSubproperty" As dfh_is_has_type_subproperty, - "propertyIdentifierInNamespace" As dfh_property_identifier_in_namespace, - "namespaceURI" As dfh_namespace_uri, - "namespaceID" As dfh_fk_namespace, - "namespaceLabelLanguage" As dfh_namespace_label_language, - "namespaceLabel" As dfh_namespace_label, - "profileAssociationType" As dfh_profile_association_type, - "profileID" As dfh_fk_profile, - "profileLabelLanguage" As dfh_profile_label_language, - "profileLabel" As dfh_profile_label - From - json_to_recordset(param_properties_profile_data) As x ("propertyID" INT, - "propertyLabelLanguage" VARCHAR, - "propertyLabel" TEXT, - "propertyScopeNoteLanguage" VARCHAR, - "propertyScopeNote" TEXT, - "isInherited" BOOLEAN, - "propertyDomain" INTEGER, - "domainInstancesMinQuantifier" INTEGER, - "domainInstancesMaxQuantifier" INTEGER, - "propertyRange" INTEGER, - "rangeInstancesMinQuantifier" INTEGER, - "rangeInstancesMaxQuantifier" INTEGER, - "identityDefining" BOOLEAN, - "isHasTypeSubproperty" BOOLEAN, - "propertyIdentifierInNamespace" VARCHAR, - "namespaceURI" TEXT, - "namespaceID" INTEGER, - "namespaceLabelLanguage" VARCHAR, - "namespaceLabel" TEXT, - "profileAssociationType" TEXT, - "profileID" INTEGER, - "profileLabelLanguage" VARCHAR, - "profileLabel" TEXT); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - Update - data_for_history.api_property - Set - tmsp_last_dfh_update = param_tmsp_last_dfh_update - Where - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - With tw1 As ( - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - data_for_history.api_property - Where - dfh_fk_profile = param_profile_id - Except - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - properties_profile_from_api - Where - dfh_fk_profile = param_profile_id -), -tw2 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = True - From - tw1 t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) -Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into removed -From - tw2; - - /* - * Update language dependent fields of existing records - */ - /* - * Update property_labels - */ - Update - data_for_history.api_property t1 - Set - dfh_property_label = t2.dfh_property_label - From - properties_profile_from_api t2 - Where - t1.dfh_property_label_language = t2.dfh_property_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update scope_notes - */ - Update - data_for_history.api_property t1 - Set - dfh_property_scope_note = t2.dfh_property_scope_note - From - properties_profile_from_api t2 - Where - t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_namespace_label - */ - Update - data_for_history.api_property t1 - Set - dfh_namespace_label = t2.dfh_namespace_label - From - properties_profile_from_api t2 - Where - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_profile_label - */ - Update - data_for_history.api_property t1 - Set - dfh_profile_label = t2.dfh_profile_label - From - properties_profile_from_api t2 - Where - t1.dfh_profile_label_language = t2.dfh_profile_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - With tw1 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = False, - dfh_pk_property = t2.dfh_pk_property, - dfh_is_inherited = t2.dfh_is_inherited, - dfh_property_domain = t2.dfh_property_domain, - dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, - dfh_property_range = t2.dfh_property_range, - dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, - dfh_identity_defining = t2.dfh_identity_defining, - dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_fk_profile = t2.dfh_fk_profile - From - properties_profile_from_api t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into updated - From - tw1; - - /* - * Insert or update all new records - */ - With tw1 As ( -Insert Into data_for_history.api_property (tmsp_last_dfh_update, - removed_from_api, - requested_language, - dfh_pk_property, - dfh_property_label_language, - dfh_property_label, - dfh_property_scope_note_language, - dfh_property_scope_note, - dfh_is_inherited, - dfh_property_domain, - dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier, - dfh_property_range, - dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier, - dfh_identity_defining, - dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace, - dfh_namespace_uri, - dfh_fk_namespace, - dfh_namespace_label_language, - dfh_namespace_label, - dfh_profile_association_type, - dfh_fk_profile, - dfh_profile_label_language, - dfh_profile_label) - Select Distinct On (t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - False, - t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_label_language, - t1.dfh_property_label, - t1.dfh_property_scope_note_language, - t1.dfh_property_scope_note, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_namespace_uri, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - From - properties_profile_from_api t1 - Where - t1.requested_language = param_requested_language - And t1.dfh_fk_profile = param_profile_id On Conflict (requested_language, - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile) - Do - Update - Set - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - requested_language = EXCLUDED.requested_language, - dfh_pk_property = EXCLUDED.dfh_pk_property, - dfh_property_label_language = EXCLUDED.dfh_property_label_language, - dfh_property_label = EXCLUDED.dfh_property_label, - dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, - dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, - dfh_is_inherited = EXCLUDED.dfh_is_inherited, - dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, - dfh_identity_defining = EXCLUDED.dfh_identity_defining, - dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into inserted - From - tw1; - - /* - * Return kind of a protocol - */ - Return json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -End; -$BODY$; - --- 2 -ALTER TABLE data_for_history.api_property -DROP COLUMN dfh_property_inverse_label; - -ALTER TABLE data_for_history.api_property_vt -DROP COLUMN dfh_property_inverse_label; - --- 1 -ALTER TABLE data_for_history.class_profile_view_deprecated RENAME TO class_profile_view; -ALTER TABLE data_for_history.class_profile_view_vt_deprecated RENAME TO class_profile_view_vt; -ALTER TABLE data_for_history.associates_system_type_deprecated RENAME TO associates_system_type; -ALTER TABLE data_for_history.associates_system_type_vt_deprecated RENAME TO associates_system_type_vt; -ALTER TABLE data_for_history.label_deprecated RENAME TO label; -ALTER TABLE data_for_history.label_vt_deprecated RENAME TO label_vt; -ALTER TABLE data_for_history.property_profile_view_deprecated RENAME TO property_profile_view; -ALTER TABLE data_for_history.property_profile_view_vt_deprecated RENAME TO property_profile_view_vt; -ALTER TABLE data_for_history.system_type_deprecated RENAME TO system_type; -ALTER TABLE data_for_history.system_type_vt_deprecated RENAME TO system_type_vt; -ALTER TABLE data_for_history.text_property_deprecated RENAME TO text_property; -ALTER TABLE data_for_history.text_property_vt_deprecated RENAME TO text_property_vt; diff --git a/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-up.sql b/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-up.sql deleted file mode 100644 index 215f7e8c6..000000000 --- a/server/db-migrate/migrations/sqls/20210423083104-dfh-t-api-property-update-up.sql +++ /dev/null @@ -1,485 +0,0 @@ --- 1 -ALTER TABLE data_for_history.class_profile_view RENAME TO class_profile_view_deprecated; -ALTER TABLE data_for_history.class_profile_view_vt RENAME TO class_profile_view_vt_deprecated; -ALTER TABLE data_for_history.associates_system_type RENAME TO associates_system_type_deprecated; -ALTER TABLE data_for_history.associates_system_type_vt RENAME TO associates_system_type_vt_deprecated; -ALTER TABLE data_for_history.label RENAME TO label_deprecated; -ALTER TABLE data_for_history.label_vt RENAME TO label_vt_deprecated; -ALTER TABLE data_for_history.property_profile_view RENAME TO property_profile_view_deprecated; -ALTER TABLE data_for_history.property_profile_view_vt RENAME TO property_profile_view_vt_deprecated; -ALTER TABLE data_for_history.system_type RENAME TO system_type_deprecated; -ALTER TABLE data_for_history.system_type_vt RENAME TO system_type_vt_deprecated; -ALTER TABLE data_for_history.text_property RENAME TO text_property_deprecated; -ALTER TABLE data_for_history.text_property_vt RENAME TO text_property_vt_deprecated; - --- 2 -ALTER TABLE data_for_history.api_property -ADD COLUMN dfh_property_inverse_label text; - -ALTER TABLE data_for_history.api_property_vt -ADD COLUMN dfh_property_inverse_label text; - --- 3 - -CREATE OR REPLACE FUNCTION data_for_history.update_api_properties_profile_table( - param_profile_id integer, - param_requested_language character varying, - param_tmsp_last_dfh_update timestamp with time zone, - param_properties_profile_data json DEFAULT '[]'::json) - RETURNS json - LANGUAGE 'plpgsql' - - COST 100 - VOLATILE - -AS $BODY$ -Declare - removed JSON; - updated JSON; - inserted JSON; -Begin - /* - * create a table with same type as from json - */ - Drop Table If Exists properties_profile_from_api; - Create Table properties_profile_from_api As - Select - param_requested_language As requested_language, - "propertyID" As dfh_pk_property, - "propertyLabelLanguage" As dfh_property_label_language, - "propertyLabel" As dfh_property_label, - "propertyInverseLabel" As dfh_property_inverse_label, - "propertyScopeNoteLanguage" As dfh_property_scope_note_language, - "propertyScopeNote" As dfh_property_scope_note, - "isInherited" As dfh_is_inherited, - "propertyDomain" As dfh_property_domain, - "domainInstancesMinQuantifier" As dfh_domain_instances_min_quantifier, - "domainInstancesMaxQuantifier" As dfh_domain_instances_max_quantifier, - "propertyRange" As dfh_property_range, - "rangeInstancesMinQuantifier" As dfh_range_instances_min_quantifier, - "rangeInstancesMaxQuantifier" As dfh_range_instances_max_quantifier, - "identityDefining" As dfh_identity_defining, - "isHasTypeSubproperty" As dfh_is_has_type_subproperty, - "propertyIdentifierInNamespace" As dfh_property_identifier_in_namespace, - "namespaceURI" As dfh_namespace_uri, - "namespaceID" As dfh_fk_namespace, - "namespaceLabelLanguage" As dfh_namespace_label_language, - "namespaceLabel" As dfh_namespace_label, - "profileAssociationType" As dfh_profile_association_type, - "profileID" As dfh_fk_profile, - "profileLabelLanguage" As dfh_profile_label_language, - "profileLabel" As dfh_profile_label - From - json_to_recordset(param_properties_profile_data) As x ("propertyID" INT, - "propertyLabelLanguage" VARCHAR, - "propertyLabel" TEXT, - "propertyInverseLabel" TEXT, - "propertyScopeNoteLanguage" VARCHAR, - "propertyScopeNote" TEXT, - "isInherited" BOOLEAN, - "propertyDomain" INTEGER, - "domainInstancesMinQuantifier" INTEGER, - "domainInstancesMaxQuantifier" INTEGER, - "propertyRange" INTEGER, - "rangeInstancesMinQuantifier" INTEGER, - "rangeInstancesMaxQuantifier" INTEGER, - "identityDefining" BOOLEAN, - "isHasTypeSubproperty" BOOLEAN, - "propertyIdentifierInNamespace" VARCHAR, - "namespaceURI" TEXT, - "namespaceID" INTEGER, - "namespaceLabelLanguage" VARCHAR, - "namespaceLabel" TEXT, - "profileAssociationType" TEXT, - "profileID" INTEGER, - "profileLabelLanguage" VARCHAR, - "profileLabel" TEXT); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - Update - data_for_history.api_property - Set - tmsp_last_dfh_update = param_tmsp_last_dfh_update - Where - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - With tw1 As ( - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - data_for_history.api_property - Where - dfh_fk_profile = param_profile_id - Except - Select - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - From - properties_profile_from_api - Where - dfh_fk_profile = param_profile_id -), -tw2 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = True - From - tw1 t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) -Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into removed -From - tw2; - - /* - * Update language dependent fields of existing records - */ - /* - * Update property_labels - */ - Update - data_for_history.api_property t1 - Set - dfh_property_label = t2.dfh_property_label - From - properties_profile_from_api t2 - Where - t1.dfh_property_label_language = t2.dfh_property_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update property_inverse_labels - */ - Update - data_for_history.api_property t1 - Set - dfh_property_inverse_label = t2.dfh_property_inverse_label - From - properties_profile_from_api t2 - Where - t1.dfh_property_label_language = t2.dfh_property_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update scope_notes - */ - Update - data_for_history.api_property t1 - Set - dfh_property_scope_note = t2.dfh_property_scope_note - From - properties_profile_from_api t2 - Where - t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_namespace_label - */ - Update - data_for_history.api_property t1 - Set - dfh_namespace_label = t2.dfh_namespace_label - From - properties_profile_from_api t2 - Where - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_profile_label - */ - Update - data_for_history.api_property t1 - Set - dfh_profile_label = t2.dfh_profile_label - From - properties_profile_from_api t2 - Where - t1.dfh_profile_label_language = t2.dfh_profile_label_language - And t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - With tw1 As ( - Update - data_for_history.api_property t1 - Set - removed_from_api = False, - dfh_pk_property = t2.dfh_pk_property, - dfh_is_inherited = t2.dfh_is_inherited, - dfh_property_domain = t2.dfh_property_domain, - dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, - dfh_property_range = t2.dfh_property_range, - dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, - dfh_identity_defining = t2.dfh_identity_defining, - dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_fk_profile = t2.dfh_fk_profile - From - properties_profile_from_api t2 - Where - t1.dfh_fk_profile = t2.dfh_fk_profile - And t1.dfh_pk_property = t2.dfh_pk_property - And t1.dfh_property_domain = t2.dfh_property_domain - And t1.dfh_property_range = t2.dfh_property_range - Returning - t1.* -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into updated - From - tw1; - - /* - * Insert or update all new records - */ - With tw1 As ( -Insert Into data_for_history.api_property (tmsp_last_dfh_update, - removed_from_api, - requested_language, - dfh_pk_property, - dfh_property_label_language, - dfh_property_label, - dfh_property_inverse_label, - dfh_property_scope_note_language, - dfh_property_scope_note, - dfh_is_inherited, - dfh_property_domain, - dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier, - dfh_property_range, - dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier, - dfh_identity_defining, - dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace, - dfh_namespace_uri, - dfh_fk_namespace, - dfh_namespace_label_language, - dfh_namespace_label, - dfh_profile_association_type, - dfh_fk_profile, - dfh_profile_label_language, - dfh_profile_label) - Select Distinct On (t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - False, - t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_label_language, - t1.dfh_property_label, - t1.dfh_property_inverse_label, - t1.dfh_property_scope_note_language, - t1.dfh_property_scope_note, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_namespace_uri, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - From - properties_profile_from_api t1 - Where - t1.requested_language = param_requested_language - And t1.dfh_fk_profile = param_profile_id On Conflict (requested_language, - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile) - Do - Update - Set - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - requested_language = EXCLUDED.requested_language, - dfh_pk_property = EXCLUDED.dfh_pk_property, - dfh_property_label_language = EXCLUDED.dfh_property_label_language, - dfh_property_label = EXCLUDED.dfh_property_label, - dfh_property_inverse_label = EXCLUDED.dfh_property_inverse_label, - dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, - dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, - dfh_is_inherited = EXCLUDED.dfh_is_inherited, - dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, - dfh_identity_defining = EXCLUDED.dfh_identity_defining, - dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - Returning - * -) - Select - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) Into inserted - From - tw1; - - /* - * Return kind of a protocol - */ - Return json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -End; -$BODY$; - --- 4 - -CREATE OR REPLACE VIEW data_for_history.v_label - AS - SELECT DISTINCT ON (t1.dfh_profile_label, t1.dfh_profile_label_language) 'label'::text AS type, - t1.dfh_profile_label AS label, - t1.dfh_profile_label_language AS language, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_profile_definition, t1.dfh_profile_definition_language) 'definition'::text AS type, - t1.dfh_profile_definition AS label, - t1.dfh_profile_definition_language AS language, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_project_label, t1.dfh_project_label_language) 'label'::text AS type, - t1.dfh_project_label AS label, - t1.dfh_project_label_language AS language, - NULL::integer AS fk_profile, - t1.dfh_owned_by_project AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_profile t1 -UNION - SELECT DISTINCT ON (t1.dfh_property_label, t1.dfh_property_label_language) 'label'::text AS type, - t1.dfh_property_label AS label, - t1.dfh_property_label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_property t1 -UNION - SELECT DISTINCT ON (t1.dfh_property_inverse_label, t1.dfh_property_label_language) 'inverse_label'::text AS type, - t1.dfh_property_inverse_label AS label, - t1.dfh_property_label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_property t1 - WHERE t1.dfh_property_inverse_label IS NOT NULL -UNION - SELECT DISTINCT ON (t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) 'scope_note'::text AS type, - t1.dfh_property_scope_note AS label, - t1.dfh_property_scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_property t1 -UNION - SELECT DISTINCT ON (t1.dfh_class_label, t1.dfh_class_label_language) 'label'::text AS type, - t1.dfh_class_label AS label, - t1.dfh_class_label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_class t1 -UNION - SELECT DISTINCT ON (t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) 'scope_note'::text AS type, - t1.dfh_class_scope_note AS label, - t1.dfh_class_scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property - FROM data_for_history.api_class t1 -UNION - SELECT DISTINCT ON (t1.label, t1.label_language) 'label'::text AS type, - t1.label, - t1.label_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property - FROM data_for_history.property_of_property t1 -UNION - SELECT DISTINCT ON (t1.scope_note, t1.scope_note_language) 'scope_note'::text AS type, - t1.scope_note AS label, - t1.scope_note_language AS language, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property - FROM data_for_history.property_of_property t1; diff --git a/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-down.sql b/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-down.sql deleted file mode 100644 index 7d717f154..000000000 --- a/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-down.sql +++ /dev/null @@ -1,167 +0,0 @@ --- [1] remove create partition function -DROP FUNCTION tables.create_row_table_for_digital (integer); - --- [2] remove column position -ALTER TABLE tables.row - DROP COLUMN position; - --- [3] remove all the partitions -DO $$ -DECLARE - fkdigitals integer ARRAY; - fkdigital integer; -BEGIN - SELECT - array_agg(DISTINCT fk_digital) INTO fkdigitals - FROM - tables.row; - IF fkdigitals IS NOT NULL THEN - FOREACH fkdigital IN ARRAY ( - SELECT - array_agg(DISTINCT fk_digital) - FROM - tables.row) - LOOP - -- insert data into table - EXECUTE ' - INSERT INTO tables.row (pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt) - SELECT pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt - FROM tables.row_' || fkdigital::text || '; - '; - -- insert data into table _vt - EXECUTE ' - INSERT INTO tables.row_vt (pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt) - SELECT pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt - FROM tables.row_' || fkdigital::text || '_vt; - '; - -- change the constraint on the tables.cell_xxx - EXECUTE 'ALTER TABLE tables.cell_' || fkdigital::text || ' DROP CONSTRAINT cell_' || fkdigital::text || '_fk_row_fkey;'; - EXECUTE ' - ALTER TABLE tables.cell_' || fkdigital::text || ' - ADD CONSTRAINT cell_' || fkdigital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables.row (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - '; - -- remove the _vt table - EXECUTE 'DROP TABLE tables.row_' || fkdigital::text || '_vt;'; - -- remove the table - EXECUTE 'DROP TABLE tables.row_' || fkdigital::text || ';'; - END LOOP; - END IF; -END -$$; - --- [4] create the triggers for tables.row -CREATE TRIGGER create_entity_version_key - BEFORE INSERT ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.create_entity_version_key (); - -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - -CREATE TRIGGER update_entity_version_key - BEFORE UPDATE ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE commons.update_entity_version_key (); - -CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE ON tables."row" - FOR EACH ROW - EXECUTE PROCEDURE public.versioning ('sys_period', 'tables.row_vt', 'true'); - --- [5] change the cell table creation function -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital (pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; -BEGIN - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result; - IF test_query_result THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists'; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING hash(id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING hash(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); '; - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - END IF; - RETURN result_text; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-up.sql b/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-up.sql deleted file mode 100644 index 321a5a8d0..000000000 --- a/server/db-migrate/migrations/sqls/20210429100404-partition-tables-row-up.sql +++ /dev/null @@ -1,271 +0,0 @@ --- [1] Rename tables.row > tables.row_old -ALTER TABLE tables.row RENAME TO row_old; - -ALTER TABLE tables.row_vt RENAME TO row_old_vt; - -ALTER TABLE tables.row_old RENAME CONSTRAINT row_pkey TO row_pkey_old; - -ALTER TABLE tables.row_old RENAME CONSTRAINT row_fk_digital_fkey TO row_fk_digital_fkey_old; - --- [2] Create parent table -CREATE TABLE tables."row" ( - pk_row bigint NOT NULL DEFAULT nextval('tables.row_pk_row_seq'::regclass), - fk_digital integer NOT NULL, - position decimal NOT NULL, - entity_version integer NOT NULL, - fk_publication_status integer, - fk_license integer, - fk_namespace integer, - notes text COLLATE pg_catalog."default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone DEFAULT now(), - tmsp_last_modification timestamp with time zone, - sys_period tstzrange DEFAULT tstzrange(now(), NULL::timestamp with time zone), - metadata jsonb, - id_for_import integer, - id_for_import_txt text COLLATE pg_catalog."default", - CONSTRAINT row_pkey PRIMARY KEY (pk_row), - CONSTRAINT row_fk_digital_fkey FOREIGN KEY (fk_digital) REFERENCES data.digital (pk_entity) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION) -TABLESPACE pg_default; - --- [3] Create parent vt table -CREATE TABLE tables.row_vt ( - pk_row bigint NOT NULL, - fk_digital integer NOT NULL, - position decimal NOT NULL, - entity_version integer NOT NULL, - fk_publication_status integer, - fk_license integer, - fk_namespace integer, - notes text COLLATE pg_catalog."default", - fk_creator integer, - fk_last_modifier integer, - tmsp_creation timestamp with time zone, - tmsp_last_modification timestamp with time zone, - sys_period tstzrange, - metadata jsonb, - id_for_import integer, - id_for_import_txt text COLLATE pg_catalog."default") -TABLESPACE pg_default; - --- [4] Create the function to create partition -CREATE OR REPLACE FUNCTION tables.create_row_table_for_digital (pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; -BEGIN - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''row_' || pk_digital::text || ''';' INTO test_query_result; - IF test_query_result THEN - result_text := 'tables.row_' || pk_digital::text || ' already exists'; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.row_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_row_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_row), - CONSTRAINT row_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.row); - - CREATE INDEX row_' || pk_digital::text || '_fk_digital_idx - ON tables.row_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.row_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.row_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX row_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.row_' || pk_digital::text || ' USING hash(id_for_import_txt); - - CREATE INDEX row_' || pk_digital::text || '_pk_row_idx - ON tables.row_' || pk_digital::text || ' USING btree(pk_row); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.row_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.row_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.row_' || pk_digital::text || '_vt ( ) INHERITS (tables.row_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.row_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.row_' || pk_digital::text || '_vt'', ''true''); '; - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.row_' || pk_digital::text; - END IF; - RETURN result_text; -END; -$BODY$; - --- [5] Create all the partitions -DO $$ -DECLARE - fkdigitals integer ARRAY; - fkdigital integer; -BEGIN - SELECT - array_agg(DISTINCT fk_digital) INTO fkdigitals - FROM - tables.row_old; - IF fkdigitals IS NOT NULL THEN - FOREACH fkdigital IN ARRAY ( - SELECT - array_agg(DISTINCT fk_digital) - FROM - tables.row_old) - LOOP - -- create table and vt table - EXECUTE 'SELECT tables.create_row_table_for_digital(' || fkdigital || ');'; - -- disable trigger - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER create_entity_version_key;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER creation_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER last_modification_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER update_entity_version_key;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER versioning_trigger;'; - -- insert data into table - EXECUTE ' - INSERT INTO tables.row_' || fkdigital::text || ' (pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt, position) - SELECT pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt, pk_row as position - FROM tables.row_old - WHERE fk_digital=' || fkdigital ||'; - '; - -- insert data into vt table - EXECUTE ' - INSERT INTO tables.row_' || fkdigital::text || '_vt (pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt, position) - SELECT pk_row, fk_digital, entity_version, fk_publication_status, fk_license, fk_namespace, notes, fk_creator, fk_last_modifier, tmsp_creation, tmsp_last_modification, sys_period, metadata, id_for_import, id_for_import_txt, pk_row as position - FROM tables.row_old_vt - WHERE fk_digital=' || fkdigital ||'; - '; - -- enable trigger - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' ENABLE TRIGGER versioning_trigger;'; - -- change the constraint on the tables.cell_xxx - EXECUTE 'ALTER TABLE tables.cell_' || fkdigital::text || ' DROP CONSTRAINT cell_' || fkdigital::text || '_fk_row_fkey;'; - EXECUTE ' - ALTER TABLE tables.cell_' || fkdigital::text || ' - ADD CONSTRAINT cell_' || fkdigital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables.row_' || fkdigital::text || ' (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - '; - END LOOP; - END IF; -END -$$; - --- [6] Change all tables.quill_doc_cell constraint -ALTER TABLE tables.quill_doc_cell - DROP CONSTRAINT quill_doc_cell_fk_row_fkey; - -ALTER TABLE tables.quill_doc_cell - ADD CONSTRAINT quill_doc_cell_fk_row_fkey FOREIGN KEY (fk_row) REFERENCES tables.row (pk_row) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION; - --- [7] delete old tables -DROP TABLE tables.row_old, tables.row_old_vt; - --- [8] change the cell table creation function -CREATE OR REPLACE FUNCTION tables.create_cell_table_for_digital (pk_digital integer) - RETURNS text - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - test_query_result boolean; - create_query text; - result_text text; -BEGIN - EXECUTE 'SELECT COUNT(*) > 0 FROM information_schema.tables WHERE table_schema = ''tables'' - AND table_name = ''cell_' || pk_digital::text || ''';' INTO test_query_result; - IF test_query_result THEN - result_text := 'tables.cell_' || pk_digital::text || ' already exists'; - ELSE - create_query := 'CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || ' - ( - CHECK (fk_digital = ' || pk_digital::text || '), - CONSTRAINT data_cell_' || pk_digital::text || '_pk_entity_primary_key PRIMARY KEY (pk_cell), - CONSTRAINT cell_' || pk_digital::text || '_fk_column_fkey FOREIGN KEY (fk_column) - REFERENCES data."column" (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_digital_fkey FOREIGN KEY (fk_digital) - REFERENCES data.digital (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION, - CONSTRAINT cell_' || pk_digital::text || '_fk_row_fkey FOREIGN KEY (fk_row) - REFERENCES tables."row_' || pk_digital::text || '" (pk_row) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION - ) - INHERITS (tables.cell); - - CREATE INDEX cell_' || pk_digital::text || '_fk_digital_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_digital); - - CREATE TRIGGER creation_tmsp BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_creation (); - - CREATE TRIGGER last_modification_tmsp BEFORE INSERT OR UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.tmsp_last_modification (); - - CREATE INDEX cell_' || pk_digital::text || '_fk_column_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_column); - - CREATE INDEX cell_' || pk_digital::text || '_fk_row_idx - ON tables.cell_' || pk_digital::text || ' USING btree - (fk_row); - - CREATE INDEX cell_' || pk_digital::text || '_id_for_import_txt_idx - ON tables.cell_' || pk_digital::text || ' USING hash(id_for_import_txt); - - CREATE INDEX cell_' || pk_digital::text || '_pk_cell_idx - ON tables.cell_' || pk_digital::text || ' USING btree(pk_cell); - - CREATE INDEX cell_' || pk_digital::text || '_string_value_idx - ON tables.cell_' || pk_digital::text || ' USING hash(string_value); - - CREATE TRIGGER create_entity_version_key BEFORE INSERT ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.create_entity_version_key (); - - CREATE TRIGGER update_entity_version_key BEFORE UPDATE ON tables.cell_' || pk_digital::text || ' - FOR - EACH ROW EXECUTE PROCEDURE commons.update_entity_version_key (); - - CREATE TABLE IF NOT EXISTS tables.cell_' || pk_digital::text || '_vt ( ) INHERITS (tables.cell_vt); - - CREATE TRIGGER versioning_trigger - BEFORE INSERT OR DELETE OR UPDATE - ON tables.cell_' || pk_digital::text || ' - FOR EACH ROW - EXECUTE PROCEDURE public.versioning(''sys_period'', ''tables.cell_' || pk_digital::text || '_vt'', ''true''); '; - RAISE NOTICE '%', create_query; - EXECUTE create_query; - result_text := 'tables.cell_' || pk_digital::text; - END IF; - RETURN result_text; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-down.sql b/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-down.sql deleted file mode 100644 index 67e1fd8d1..000000000 --- a/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-down.sql +++ /dev/null @@ -1,173 +0,0 @@ -/* Replace with your SQL commands */ --- 9 - -ALTER TABLE information.dimension DROP CONSTRAINT dimension_fk_measurement_unit_fkey; - -ALTER TABLE information.dimension - ADD CONSTRAINT dimension_fk_measurement_unit_fkey FOREIGN KEY (fk_measurement_unit) - REFERENCES information.persistent_item_backup (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - -ALTER TABLE projects.argument DROP CONSTRAINT assertion_fk_assertion_method_type_fkey; - -ALTER TABLE projects.argument - ADD CONSTRAINT assertion_fk_assertion_method_type_fkey FOREIGN KEY (fk_argument_method_type) - REFERENCES information.persistent_item_backup (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - -ALTER TABLE system.system_relevant_type DROP CONSTRAINT system_relevant_type_fk_type_fkey; - -ALTER TABLE system.system_relevant_type - ADD CONSTRAINT system_relevant_type_fk_type_fkey FOREIGN KEY (fk_type) - REFERENCES information.persistent_item_backup (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - --- 8 -DROP TABLE information.resource_vt; --- 7 - -ALTER TABLE information.resource NO INHERIT information.entity; - --- 6 -ALTER TABLE information.persistent_item_backup RENAME TO persistent_item; - -ALTER TABLE information.temporal_entity_backup RENAME TO temporal_entity; - -ALTER TABLE information.persistent_item_vt_backup RENAME TO persistent_item_vt; - -ALTER TABLE information.temporal_entity_vt_backup RENAME TO temporal_entity_vt; - --- 5 -ALTER TABLE information.persistent_item INHERIT information.entity; - -ALTER TABLE information.temporal_entity INHERIT information.entity; - --- 4 -CREATE OR REPLACE FUNCTION information.is_persistent_item_or_temporal_entity (integer) - RETURNS boolean - LANGUAGE 'sql' - COST 100 VOLATILE - AS $BODY$ - SELECT - EXISTS ( - SELECT - pk_entity - FROM - information.persistent_item - WHERE - pk_entity = $1 - UNION - SELECT - pk_entity - FROM - information.temporal_entity - WHERE - pk_entity = $1) -$BODY$; - -CREATE FUNCTION information.v_persistent_item_find_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_row information.persistent_item; -BEGIN - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - SELECT - * - FROM - INTO resulting_row information.persistent_item - WHERE - pk_entity = NEW.pk_entity; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO information.persistent_item (fk_class) - VALUES (NEW.fk_class) - -- return all fields of the new row - RETURNING - *) - SELECT - * - FROM - INTO resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - RETURN resulting_row; -END; -$BODY$; - -CREATE FUNCTION information.v_temporal_entity_find_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_row information.temporal_entity; -BEGIN - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - SELECT - * - FROM - INTO resulting_row information.temporal_entity - WHERE - pk_entity = NEW.pk_entity; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO information.temporal_entity (fk_class) - VALUES (NEW.fk_class) - -- return all fields of the new row - RETURNING - *) - SELECT - * - FROM - INTO resulting_row _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - RETURN resulting_row; -END; -$BODY$; - - --- 3 -CREATE OR REPLACE VIEW information.v_temporal_entity - AS - SELECT temporal_entity.pk_entity, - temporal_entity.schema_name, - temporal_entity.table_name, - temporal_entity.notes, - temporal_entity.fk_creator, - temporal_entity.fk_last_modifier, - temporal_entity.tmsp_creation, - temporal_entity.tmsp_last_modification, - temporal_entity.sys_period, - temporal_entity.fk_class - FROM information.temporal_entity; -CREATE OR REPLACE VIEW information.v_persistent_item - AS - SELECT persistent_item.pk_entity, - persistent_item.schema_name, - persistent_item.table_name, - persistent_item.notes, - persistent_item.fk_creator, - persistent_item.fk_last_modifier, - persistent_item.tmsp_creation, - persistent_item.tmsp_last_modification, - persistent_item.sys_period, - persistent_item.metadata, - persistent_item.fk_class - FROM information.persistent_item; --- 2 + 1 -DROP table information.resource; diff --git a/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-up.sql b/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-up.sql deleted file mode 100644 index 18eb7a8b1..000000000 --- a/server/db-migrate/migrations/sqls/20210505080407-inf-t-resource-up.sql +++ /dev/null @@ -1,75 +0,0 @@ --- 1 create merged table having all data from persistent_item and temporal_entity -CREATE TABLE information.resource as - SELECT * FROM information.temporal_entity - UNION - SELECT * FROM information.persistent_item -; -UPDATE information.resource -SET table_name = 'resource'; - --- 2 attach pk_entity to sequence - -ALTER TABLE information.resource ALTER COLUMN pk_entity SET DEFAULT nextval('information.entity_pk_entity_seq'::regclass); - --- 3 remove views -DROP VIEW information.v_persistent_item; -DROP VIEW information.v_temporal_entity; - --- 4 drop functions -drop function information.is_persistent_item_or_temporal_entity; -drop function information.v_persistent_item_find_or_create; -drop function information.v_temporal_entity_find_or_create; - --- 5 un-inherit persistent_item and temporal_entity tables -ALTER TABLE information.persistent_item NO INHERIT information.entity; -ALTER TABLE information.temporal_entity NO INHERIT information.entity; - --- 6 rename tables -ALTER TABLE information.persistent_item RENAME TO persistent_item_backup; -ALTER TABLE information.temporal_entity RENAME TO temporal_entity_backup; -ALTER TABLE information.persistent_item_vt RENAME TO persistent_item_vt_backup; -ALTER TABLE information.temporal_entity_vt RENAME TO temporal_entity_vt_backup; - --- 7 make resource child of entity -ALTER TABLE information.resource ALTER COLUMN pk_entity SET NOT NULL; -ALTER TABLE information.resource ALTER COLUMN schema_name SET NOT NULL; -ALTER TABLE information.resource ALTER COLUMN table_name SET NOT NULL; - -ALTER TABLE information.resource INHERIT information.entity; - --- 8 add triggers and _vt table -SELECT - commons.init_entity_child_table ('information.resource'); - -CREATE TRIGGER notify_modification - AFTER INSERT OR DELETE OR UPDATE - ON information.resource - FOR EACH STATEMENT - EXECUTE PROCEDURE commons.notify_modification_trigger(); - --- 9 redirect foreign keys to new table -ALTER TABLE information.dimension DROP CONSTRAINT dimension_fk_measurement_unit_fkey; - -ALTER TABLE information.dimension - ADD CONSTRAINT dimension_fk_measurement_unit_fkey FOREIGN KEY (fk_measurement_unit) - REFERENCES information.resource (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - - -ALTER TABLE projects.argument DROP CONSTRAINT assertion_fk_assertion_method_type_fkey; - -ALTER TABLE projects.argument - ADD CONSTRAINT assertion_fk_assertion_method_type_fkey FOREIGN KEY (fk_argument_method_type) - REFERENCES information.resource (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; - - -ALTER TABLE system.system_relevant_type DROP CONSTRAINT system_relevant_type_fk_type_fkey; - -ALTER TABLE system.system_relevant_type - ADD CONSTRAINT system_relevant_type_fk_type_fkey FOREIGN KEY (fk_type) - REFERENCES information.resource (pk_entity) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE NO ACTION; diff --git a/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-down.sql b/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-down.sql deleted file mode 100644 index aa23bcc20..000000000 --- a/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-down.sql +++ /dev/null @@ -1,4 +0,0 @@ - -Drop TABLE war.field_change; - -DROP FUNCTION war.field_change__notify_upsert(); diff --git a/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-up.sql b/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-up.sql deleted file mode 100644 index 2ab376864..000000000 --- a/server/db-migrate/migrations/sqls/20210516190526-war-t-field-change-up.sql +++ /dev/null @@ -1,54 +0,0 @@ - -CREATE TABLE war.field_change -( - fk_project integer NOT NULL, - fk_source_info integer NOT NULL, - fk_property integer NOT NULL, - fk_property_of_property integer NOT NULL, - is_outgoing boolean NOT NULL, - tmsp_last_modification timestamp with time zone NOT NULL -); - -ALTER TABLE war.field_change - ADD CONSTRAINT field_change_uniq UNIQUE (fk_project, fk_source_info,fk_property,fk_property_of_property,is_outgoing); - -CREATE UNIQUE INDEX field_change_uniq_idx - ON war.field_change USING btree - (fk_project, fk_source_info,fk_property,fk_property_of_property,is_outgoing); - -CREATE OR replace FUNCTION war.field_change__notify_upsert() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ -DECLARE - item json; -BEGIN - - FOR item in SELECT row_to_json(new_table) FROM new_table - LOOP - PERFORM pg_notify('field_change'::text, item::text); - end LOOP; - -RETURN NEW; -END; -$BODY$; - - - -CREATE TRIGGER after_update_field_change - AFTER UPDATE - ON war.field_change - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert(); - - -CREATE TRIGGER after_insert_field_change - AFTER inseRT - ON war.field_change - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert(); - diff --git a/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-down.sql b/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-down.sql deleted file mode 100644 index 102e0fbda..000000000 --- a/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-down.sql +++ /dev/null @@ -1,26 +0,0 @@ -DO $$ -DECLARE - fkdigitals integer ARRAY; - fkdigital integer; -BEGIN - SELECT - array_agg(DISTINCT fk_digital) INTO fkdigitals - FROM - tables.row; - IF fkdigitals IS NOT NULL THEN - FOREACH fkdigital IN ARRAY ( - SELECT - array_agg(DISTINCT fk_digital) - FROM - tables.row) - LOOP - - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER create_entity_version_key;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER creation_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER last_modification_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' DISABLE TRIGGER update_entity_version_key;'; - - END LOOP; - END IF; -END -$$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-up.sql b/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-up.sql deleted file mode 100644 index d29de4a0a..000000000 --- a/server/db-migrate/migrations/sqls/20210602123515-table-editing-correction-up.sql +++ /dev/null @@ -1,26 +0,0 @@ -DO $$ -DECLARE - fkdigitals integer ARRAY; - fkdigital integer; -BEGIN - SELECT - array_agg(DISTINCT fk_digital) INTO fkdigitals - FROM - tables.row; - IF fkdigitals IS NOT NULL THEN - FOREACH fkdigital IN ARRAY ( - SELECT - array_agg(DISTINCT fk_digital) - FROM - tables.row) - LOOP - - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' ENABLE TRIGGER create_entity_version_key;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' ENABLE TRIGGER creation_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' ENABLE TRIGGER last_modification_tmsp;'; - EXECUTE 'ALTER TABLE tables.row_' || fkdigital::text || ' ENABLE TRIGGER update_entity_version_key;'; - - END LOOP; - END IF; -END -$$; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-down.sql b/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-down.sql deleted file mode 100644 index b4966caf0..000000000 --- a/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-down.sql +++ /dev/null @@ -1,42 +0,0 @@ - -CREATE OR REPLACE VIEW information.v_entity_class_map - AS - SELECT appellation.pk_entity, - appellation.fk_class, - 'appellation'::text AS table_name - FROM information.appellation -UNION ALL - SELECT language.pk_entity, - language.fk_class, - 'language'::text AS table_name - FROM information.language -UNION ALL - SELECT persistent_item_backup.pk_entity, - persistent_item_backup.fk_class, - 'persistent_item'::text AS table_name - FROM information.persistent_item_backup -UNION ALL - SELECT place.pk_entity, - place.fk_class, - 'place'::text AS table_name - FROM information.place -UNION ALL - SELECT dimension.pk_entity, - dimension.fk_class, - 'dimension'::text AS table_name - FROM information.dimension -UNION ALL - SELECT lang_string.pk_entity, - lang_string.fk_class, - 'lang_string'::text AS table_name - FROM information.lang_string -UNION ALL - SELECT temporal_entity_backup.pk_entity, - temporal_entity_backup.fk_class, - 'temporal_entity'::text AS table_name - FROM information.temporal_entity_backup -UNION ALL - SELECT time_primitive.pk_entity, - time_primitive.fk_class, - 'time_primitive'::text AS table_name - FROM information.time_primitive; diff --git a/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-up.sql b/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-up.sql deleted file mode 100644 index 6db3c4138..000000000 --- a/server/db-migrate/migrations/sqls/20210708095207-inf-v-entity-class-map-up.sql +++ /dev/null @@ -1,37 +0,0 @@ - -CREATE OR REPLACE VIEW information.v_entity_class_map - AS - SELECT appellation.pk_entity, - appellation.fk_class, - 'appellation'::text AS table_name - FROM information.appellation -UNION ALL - SELECT language.pk_entity, - language.fk_class, - 'language'::text AS table_name - FROM information.language -UNION ALL - SELECT resource.pk_entity, - resource.fk_class, - 'resource'::text AS table_name - FROM information.resource -UNION ALL - SELECT place.pk_entity, - place.fk_class, - 'place'::text AS table_name - FROM information.place -UNION ALL - SELECT dimension.pk_entity, - dimension.fk_class, - 'dimension'::text AS table_name - FROM information.dimension -UNION ALL - SELECT lang_string.pk_entity, - lang_string.fk_class, - 'lang_string'::text AS table_name - FROM information.lang_string -UNION ALL - SELECT time_primitive.pk_entity, - time_primitive.fk_class, - 'time_primitive'::text AS table_name - FROM information.time_primitive; diff --git a/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-down.sql b/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-down.sql deleted file mode 100644 index 8b54cd706..000000000 --- a/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE information.resource DROP COLUMN community_visibility; -ALTER TABLE information.resource_vt DROP COLUMN community_visibility; diff --git a/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-up.sql b/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-up.sql deleted file mode 100644 index f078e0cfa..000000000 --- a/server/db-migrate/migrations/sqls/20210708183326-inf-t-resource-add-visibility-field-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* Replace with your SQL commands */ -ALTER TABLE information.resource - ADD COLUMN community_visibility JSONB; - -ALTER TABLE information.resource_vt - ADD COLUMN community_visibility JSONB; - -UPDATE - information.resource -SET - community_visibility = '{"toolbox":true,"website":false,"dataApi":false}'; - diff --git a/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-down.sql b/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-down.sql deleted file mode 100644 index f620c9590..000000000 --- a/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-down.sql +++ /dev/null @@ -1,121 +0,0 @@ - - -- 3 - CREATE OR REPLACE FUNCTION projects.v_info_proj_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), - ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), - ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num_of_domain, - ord_num_of_range, - ord_num_of_text_property, - entity_version, - fk_creator, - fk_last_modifier - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num_of_domain, - NEW.ord_num_of_range, - NEW.ord_num_of_text_property, - 1, - NEW.fk_creator, - NEW.fk_last_modifier - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; --- 2 -DROP VIEW projects.v_info_proj_rel; -CREATE OR REPLACE VIEW projects.v_info_proj_rel - AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.entity_version, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num_of_domain, - info_proj_rel.fk_project, - info_proj_rel.ord_num_of_range, - info_proj_rel.ord_num_of_text_property - FROM projects.info_proj_rel; - --- 1 -ALTER TABLE projects.info_proj_rel DROP COLUMN project_visibility; -ALTER TABLE projects.info_proj_rel_vt DROP COLUMN project_visibility; diff --git a/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-up.sql b/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-up.sql deleted file mode 100644 index 36acf3e3f..000000000 --- a/server/db-migrate/migrations/sqls/20210708183712-pro-t-info-proj-rel-up.sql +++ /dev/null @@ -1,150 +0,0 @@ --- 1 -ALTER TABLE projects.info_proj_rel ADD COLUMN project_visibility JSONB; -ALTER TABLE projects.info_proj_rel_vt ADD COLUMN project_visibility JSONB; - --- 2 -CREATE OR REPLACE VIEW projects.v_info_proj_rel - AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.entity_version, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num_of_domain, - info_proj_rel.fk_project, - info_proj_rel.ord_num_of_range, - info_proj_rel.ord_num_of_text_property, - info_proj_rel.project_visibility - FROM projects.info_proj_rel; - --- 2 -CREATE OR REPLACE VIEW projects.v_info_proj_rel - AS - SELECT info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.entity_version, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num_of_domain, - info_proj_rel.fk_project, - info_proj_rel.ord_num_of_range, - info_proj_rel.ord_num_of_text_property, - info_proj_rel.project_visibility - FROM projects.info_proj_rel; - - -- 3 - CREATE OR REPLACE FUNCTION projects.v_info_proj_rel_update_or_create() - RETURNS trigger - LANGUAGE 'plpgsql' - COST 100 - VOLATILE NOT LEAKPROOF -AS $BODY$ - DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; - BEGIN - - RAISE INFO 'input values: %', NEW; - - ------ if existing, store in resulting_pk ... ----- - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - - ------ ... and update the found row ----- - - IF FOUND THEN - - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - - UPDATE projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), - ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), - ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier), - project_visibility = COALESCE(NEW.project_visibility, resulting_row.project_visibility) - WHERE pk_entity = resulting_row.pk_entity; - - ------- if not existing, insert and store in result ----- - ELSE - - -- RAISE INFO 'Not found, creating new...'; - - WITH _insert AS ( - INSERT INTO projects.info_proj_rel ( - fk_project, - fk_entity, - fk_entity_version, - fk_entity_version_concat, - is_in_project, - is_standard_in_project, - calendar, - ord_num_of_domain, - ord_num_of_range, - ord_num_of_text_property, - entity_version, - fk_creator, - fk_last_modifier, - project_visibility - ) - VALUES ( - NEW.fk_project, - NEW.fk_entity, - NEW.fk_entity_version, - NEW.fk_entity_version_concat, - NEW.is_in_project, - NEW.is_standard_in_project, - NEW.calendar, - NEW.ord_num_of_domain, - NEW.ord_num_of_range, - NEW.ord_num_of_text_property, - 1, - NEW.fk_creator, - NEW.fk_last_modifier, - NEW.project_visibility - ) - -- return all fields of the new row - RETURNING * - ) - SELECT pk_entity FROM INTO resulting_pk _insert; - - -- RAISE INFO 'result of insert: %', resulting_row; - - END IF; - - SELECT * FROM INTO resulting_row projects.v_info_proj_rel - WHERE pk_entity = resulting_pk OR pk_entity = resulting_row.pk_entity; - - RETURN resulting_row; - END; - $BODY$; diff --git a/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-down.sql b/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-down.sql deleted file mode 100644 index a30f880f0..000000000 --- a/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-down.sql +++ /dev/null @@ -1,15 +0,0 @@ --- 5 -DROP INDEX war.entity_preview_key_idx; - --- 4 -DROP TRIGGER generate_key ON war.entity_preview; - --- 3 -DROP FUNCTION war.entity_preview_generate_key (); - --- 2 --- no need --- 1 -ALTER TABLE war.entity_preview - DROP COLUMN key; - diff --git a/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-up.sql b/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-up.sql deleted file mode 100644 index 919f09ff9..000000000 --- a/server/db-migrate/migrations/sqls/20210819120553-war-t-entity-preview-key-column-up.sql +++ /dev/null @@ -1,35 +0,0 @@ --- 1 -ALTER TABLE war.entity_preview - ADD COLUMN key VARCHAR; - --- 2 -UPDATE - war.entity_preview t0 -SET - key = concat(t1.project, '_', t1.pk_entity) -FROM - war.entity_preview t1 -WHERE - t0.project = t1.project - AND t0.pk_entity = t1.pk_entity; - --- 3 -CREATE FUNCTION war.entity_preview_generate_key () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - AS $BODY$ -BEGIN - NEW.key = concat(NEW.project, '_', NEW.pk_entity); - RETURN NEW; -END; -$BODY$; - --- 4 -CREATE TRIGGER generate_key - BEFORE INSERT OR UPDATE ON war.entity_preview - FOR EACH ROW - EXECUTE PROCEDURE war.entity_preview_generate_key (); - --- 5 -CREATE INDEX entity_preview_key_idx ON war.entity_preview USING btree (key); - diff --git a/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-down.sql b/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-down.sql deleted file mode 100644 index 2419235eb..000000000 --- a/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-down.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE data.factoid_mapping -DROP COLUMN title; - -ALTER TABLE data.factoid_mapping -DROP COLUMN comment; - -ALTER TABLE data.factoid_property_mapping -DROP COLUMN comment; - -ALTER TABLE data.factoid_property_mapping -DROP COLUMN fk_default_entity; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-up.sql b/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-up.sql deleted file mode 100644 index 17841e767..000000000 --- a/server/db-migrate/migrations/sqls/20211007090627-add-title-comment-to-factoids-up.sql +++ /dev/null @@ -1,11 +0,0 @@ -ALTER TABLE data.factoid_mapping -ADD COLUMN title text; - -ALTER TABLE data.factoid_mapping -ADD COLUMN comment text; - -ALTER TABLE data.factoid_property_mapping -ADD COLUMN comment text; - -ALTER TABLE data.factoid_property_mapping -ADD COLUMN fk_default int; \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-down.sql b/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-down.sql deleted file mode 100644 index 1c5cc4949..000000000 --- a/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-down.sql +++ /dev/null @@ -1,66 +0,0 @@ -CREATE OR REPLACE VIEW information.v_appellation AS -SELECT - appellation.pk_entity, - appellation.schema_name, - appellation.table_name, - appellation.notes, - appellation.fk_creator, - appellation.fk_last_modifier, - appellation.tmsp_creation, - appellation.tmsp_last_modification, - appellation.sys_period, - appellation.fk_class, - appellation.quill_doc, - appellation.string -FROM - information.appellation; - -CREATE FUNCTION information.v_appellation_find_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_pk integer; - resulting_row information.v_appellation; -BEGIN - RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - SELECT - * - FROM - INTO resulting_row information.v_appellation - WHERE - string = COALESCE(NEW.string, commons.quill_doc_to_string (NEW.quill_doc)) - AND fk_class = NEW.fk_class; - RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO information.appellation (string, quill_doc, fk_class) - VALUES (NEW.string, NEW.quill_doc, NEW.fk_class) - -- return all fields of the new row - RETURNING - *) - SELECT - pk_entity - FROM - INTO resulting_pk _insert; - SELECT - * - FROM - INTO resulting_row information.v_appellation - WHERE - pk_entity = resulting_pk; - RAISE INFO 'result of insert: %', resulting_row; - END IF; - RETURN resulting_row; -END; -$BODY$; - -CREATE TRIGGER _02_find_or_create - INSTEAD OF INSERT ON information.v_appellation - FOR EACH ROW - EXECUTE PROCEDURE information.v_appellation_find_or_create (); - diff --git a/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-up.sql b/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-up.sql deleted file mode 100644 index 775d98bb4..000000000 --- a/server/db-migrate/migrations/sqls/20211202153801-inf-v-appellation-remove-view-up.sql +++ /dev/null @@ -1,5 +0,0 @@ -/* Replace with your SQL commands */ -DROP VIEW information.v_appellation; - -DROP FUNCTION information.v_appellation_find_or_create (); - diff --git a/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-down.sql b/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-down.sql deleted file mode 100644 index d9db57a05..000000000 --- a/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-down.sql +++ /dev/null @@ -1,14 +0,0 @@ --- 4 -ALTER TABLE information.time_primitive - DROP CONSTRAINT time_primitive_unique_constraint; - -ALTER TABLE information.time_primitive - ADD CONSTRAINT time_primitive_unique_constraint UNIQUE (julian_day, duration, fk_class); - --- 1 -ALTER TABLE information.time_primitive - DROP COLUMN calendar; - -ALTER TABLE information.time_primitive_vt - DROP COLUMN calendar; - diff --git a/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-up.sql b/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-up.sql deleted file mode 100644 index c1a58482c..000000000 --- a/server/db-migrate/migrations/sqls/20211209093129-inf-t-time-primitive-add-cal-up.sql +++ /dev/null @@ -1,97 +0,0 @@ -/* Replace with your SQL commands */ --- 1 add column -ALTER TABLE information.time_primitive - ADD COLUMN calendar calendar_type; - -ALTER TABLE information.time_primitive_vt - ADD COLUMN calendar calendar_type; - --- 2 fill calendar data --- messy first: at time of writing 4 out of 15k have mixed calendars --- resetting them according to threshold julian_day -WITH tw1 AS ( - SELECT - t1.pk_entity AS pk_tp, - t1.julian_day, - count(t3.calendar) FILTER (WHERE t3.calendar = 'gregorian') gregorian_count, - count(t3.calendar) FILTER (WHERE t3.calendar = 'julian') julian_count - FROM - information.time_primitive t1, - information.statement t2, - projects.info_proj_rel t3 - WHERE - t1.pk_entity = t2.fk_object_info - AND t2.pk_entity = t3.fk_entity - AND t3.calendar IS NOT NULL - GROUP BY - t1.pk_entity, -- tp - t1.julian_day -), -tw2 AS ( - SELECT - t1.pk_tp, - CASE WHEN t1.julian_day < 2299161 THEN - 'julian'::calendar_type - ELSE - 'gregorian'::calendar_type - END calendar - FROM - tw1 t1 - WHERE - gregorian_count > 0 - AND julian_count > 0) -UPDATE - information.time_primitive t1 -SET - calendar = t2.calendar -FROM - tw2 t2 -WHERE - t1.pk_entity = t2.pk_tp; - --- clean second -WITH tw1 AS ( - SELECT DISTINCT ON (t1.pk_entity) - t1.pk_entity AS pk_tp, - t3.calendar - FROM - information.time_primitive t1, - information.statement t2, - projects.info_proj_rel t3 - WHERE - t1.pk_entity = t2.fk_object_info - AND t2.pk_entity = t3.fk_entity - AND t3.calendar IS NOT NULL) -UPDATE - information.time_primitive t1 -SET - calendar = t2.calendar -FROM - tw1 t2 -WHERE - t1.pk_entity = t2.pk_tp; - --- cleanup the ones that have no relation to a stmt with a info_proj_rel -UPDATE - information.time_primitive t1 -SET - calendar = ( - CASE WHEN t1.julian_day < 2299161 THEN - 'julian'::calendar_type - ELSE - 'gregorian'::calendar_type - END) -WHERE - calendar IS NULL; - --- 3 set calendar column to not null -ALTER TABLE information.time_primitive - ALTER COLUMN calendar SET NOT NULL; - --- 4 update uniq contraint -ALTER TABLE information.time_primitive - DROP CONSTRAINT time_primitive_unique_constraint; - -ALTER TABLE information.time_primitive - ADD CONSTRAINT time_primitive_unique_constraint UNIQUE (julian_day, duration, calendar, fk_class); - diff --git a/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-down.sql b/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-down.sql deleted file mode 100644 index 3fdbed524..000000000 --- a/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-down.sql +++ /dev/null @@ -1,72 +0,0 @@ --- 1 -DROP VIEW information.v_time_primitive; - -CREATE OR REPLACE VIEW information.v_time_primitive AS -SELECT - time_primitive.pk_entity, - time_primitive.schema_name, - time_primitive.table_name, - time_primitive.notes, - time_primitive.fk_creator, - time_primitive.fk_last_modifier, - time_primitive.tmsp_creation, - time_primitive.tmsp_last_modification, - time_primitive.sys_period, - time_primitive.metadata, - time_primitive.duration, - time_primitive.fk_class, - time_primitive.julian_day -FROM - information.time_primitive; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT ON information.v_time_primitive - FOR EACH ROW - EXECUTE PROCEDURE information.v_time_primitive_find_or_create (); - --- 2 -CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_pk integer; - resulting_row information.v_time_primitive; -BEGIN - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - SELECT - pk_entity - FROM - INTO resulting_pk information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND fk_class = NEW.fk_class; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO information.time_primitive (julian_day, duration, fk_class) - VALUES (NEW.julian_day, NEW.duration, NEW.fk_class) - -- return all fields of the new row - RETURNING - *) - SELECT - pk_entity - FROM - INTO resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - SELECT - * - FROM - INTO resulting_row information.v_time_primitive - WHERE - pk_entity = resulting_pk; - RETURN resulting_row; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-up.sql b/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-up.sql deleted file mode 100644 index 8123f6f87..000000000 --- a/server/db-migrate/migrations/sqls/20211209103755-inf-v-time-primitive-add-cal-up.sql +++ /dev/null @@ -1,54 +0,0 @@ --- 1 -CREATE OR REPLACE VIEW information.v_time_primitive AS -SELECT - * -FROM - information.time_primitive; - --- 2 -CREATE OR REPLACE FUNCTION information.v_time_primitive_find_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_pk integer; - resulting_row information.v_time_primitive; -BEGIN - -- RAISE INFO 'input values: %', NEW; - ------ if existing, store in result ----- - SELECT - pk_entity - FROM - INTO resulting_pk information.time_primitive - WHERE - julian_day = NEW.julian_day - AND duration = NEW.duration - AND calendar = NEW.calendar - AND fk_class = NEW.fk_class; - -- RAISE INFO 'result of select: %', resulting_row; - ------- if not existing, insert and store in result ----- - IF NOT FOUND THEN - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO information.time_primitive (julian_day, duration, calendar, fk_class) - VALUES (NEW.julian_day, NEW.duration, NEW.calendar, NEW.fk_class) - -- return all fields of the new row - RETURNING - *) - SELECT - pk_entity - FROM - INTO resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - SELECT - * - FROM - INTO resulting_row information.v_time_primitive - WHERE - pk_entity = resulting_pk; - RETURN resulting_row; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-down.sql b/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-down.sql deleted file mode 100644 index a05522029..000000000 --- a/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-down.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.time_primitive__pretty_json (time_primitive information.time_primitive, calendar calendar_type) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - from_day int; - from_second bigint; - from_julian_cal varchar; - from_gregorian_cal varchar; - from_gregorian_cal_iso8601 varchar; - to_day int; - to_second bigint; - to_julian_cal varchar; - to_gregorian_cal varchar; - to_gregorian_cal_iso8601 varchar; - label varchar; -BEGIN - from_day = time_primitive.julian_day; - SELECT - commons.time_primitive__get_first_second (from_day) INTO from_second; - SELECT - concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO from_julian_cal - FROM - commons.julian_cal__year_month_day (from_day) t; - SELECT - to_char((('J' || from_day)::timestamp), 'YYYY-MM-DD') INTO from_gregorian_cal; - SELECT - commons.julian_second__to_iso_8601 (from_second) INTO from_gregorian_cal_iso8601; - SELECT - commons.time_primitive__get_to_day (from_day, time_primitive.duration, calendar) INTO to_day; - SELECT - commons.time_primitive__get_first_second (to_day) INTO to_second; - SELECT - concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO to_julian_cal - FROM - commons.julian_cal__year_month_day (to_day) t; - SELECT - to_char((('J' || to_day)::timestamp), 'YYYY-MM-DD') INTO to_gregorian_cal; - SELECT - commons.julian_second__to_iso_8601 (to_second) INTO to_gregorian_cal_iso8601; - SELECT - CASE WHEN calendar = 'gregorian' THEN - concat(from_gregorian_cal, ' (', time_primitive.duration, ')') - ELSE - concat(from_julian_cal, ' (', time_primitive.duration, ')') - END INTO label; - RETURN jsonb_build_object('pkEntity', time_primitive.pk_entity, 'fkClass', time_primitive.fk_class, 'julianDay', time_primitive.julian_day, 'duration', time_primitive.duration, 'calendar', calendar::text, 'label', label, 'from', jsonb_build_object('julianDay', from_day, 'julianSecond', from_second, 'calGregorian', from_gregorian_cal, 'calGregorianIso8601', from_gregorian_cal_iso8601, 'calJulian', from_julian_cal), 'to', jsonb_build_object('julianDay', to_day, 'julianSecond', to_second, 'calGregorian', to_gregorian_cal, 'calGregorianIso8601', to_gregorian_cal_iso8601, 'calJulian', to_julian_cal)); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-up.sql b/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-up.sql deleted file mode 100644 index cb167f9e4..000000000 --- a/server/db-migrate/migrations/sqls/20211209105150-com-f-time-primitive-pretty-json-up.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.time_primitive__pretty_json (time_primitive information.time_primitive) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - from_day int; - from_second bigint; - from_julian_cal varchar; - from_gregorian_cal varchar; - from_gregorian_cal_iso8601 varchar; - to_day int; - to_second bigint; - to_julian_cal varchar; - to_gregorian_cal varchar; - to_gregorian_cal_iso8601 varchar; - label varchar; -BEGIN - from_day = time_primitive.julian_day; - SELECT - commons.time_primitive__get_first_second (from_day) INTO from_second; - SELECT - concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO from_julian_cal - FROM - commons.julian_cal__year_month_day (from_day) t; - SELECT - to_char((('J' || from_day)::timestamp), 'YYYY-MM-DD') INTO from_gregorian_cal; - SELECT - commons.julian_second__to_iso_8601 (from_second) INTO from_gregorian_cal_iso8601; - SELECT - commons.time_primitive__get_to_day (from_day, time_primitive.duration, time_primitive.calendar) INTO to_day; - SELECT - commons.time_primitive__get_first_second (to_day) INTO to_second; - SELECT - concat(to_char(t.year, 'fm0000'), '-', to_char(t.month, 'fm00'), '-', to_char(t.day, 'fm00')) INTO to_julian_cal - FROM - commons.julian_cal__year_month_day (to_day) t; - SELECT - to_char((('J' || to_day)::timestamp), 'YYYY-MM-DD') INTO to_gregorian_cal; - SELECT - commons.julian_second__to_iso_8601 (to_second) INTO to_gregorian_cal_iso8601; - SELECT - CASE WHEN time_primitive.calendar = 'gregorian' THEN - concat(from_gregorian_cal, ' (', time_primitive.duration, ')') - ELSE - concat(from_julian_cal, ' (', time_primitive.duration, ')') - END INTO label; - RETURN jsonb_build_object('pkEntity', time_primitive.pk_entity, 'fkClass', time_primitive.fk_class, 'julianDay', time_primitive.julian_day, 'duration', time_primitive.duration, 'calendar', time_primitive.calendar::text, 'label', label, 'from', jsonb_build_object('julianDay', from_day, 'julianSecond', from_second, 'calGregorian', from_gregorian_cal, 'calGregorianIso8601', from_gregorian_cal_iso8601, 'calJulian', from_julian_cal), 'to', jsonb_build_object('julianDay', to_day, 'julianSecond', to_second, 'calGregorian', to_gregorian_cal, 'calGregorianIso8601', to_gregorian_cal_iso8601, 'calJulian', to_julian_cal)); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-down.sql b/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-down.sql deleted file mode 100644 index b46b18006..000000000 --- a/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-down.sql +++ /dev/null @@ -1,230 +0,0 @@ --- 3 -ALTER TABLE projects.info_proj_rel RENAME COLUMN calendar_backup TO calendar; - -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN calendar_backup TO calendar; - --- 1 --- View: information.v_statement -DROP VIEW information.v_statement; - -CREATE OR REPLACE VIEW information.v_statement AS -SELECT - t1.pk_entity, - t1.fk_property, - t1.fk_property_of_property, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_subject_data, - t1.fk_subject_tables_row, - t1.fk_subject_tables_cell, - t1.fk_object_data, - t1.fk_object_tables_row, - t1.fk_object_tables_cell, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t2.community_favorite_calendar, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -FROM - information.statement t1 - LEFT JOIN LATERAL ( - SELECT - count(info_proj_rel.pk_entity)::integer AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer AS is_standard_in_project_count, - mode() WITHIN GROUP (ORDER BY info_proj_rel.calendar) AS community_favorite_calendar - FROM - projects.info_proj_rel - WHERE - info_proj_rel.fk_entity = t1.pk_entity - AND info_proj_rel.is_in_project = TRUE GROUP BY - info_proj_rel.fk_entity) t2 ON TRUE; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT ON information.v_statement - FOR EACH ROW - EXECUTE PROCEDURE information.v_statement_find_or_create (); - --- 2 -DROP FUNCTION information.get_outgoing_statements_to_add (integer, integer); - -CREATE OR REPLACE FUNCTION information.get_outgoing_statements_to_add (entity_id integer, project_id integer) - RETURNS TABLE ( - pk_entity integer, - fk_object_info integer, - fk_subject_info integer, - calendar calendar_type) - LANGUAGE 'sql' - COST 100 VOLATILE ROWS 1000 - AS $BODY$ - WITH tw1 AS ( - -- select profiles the project - SELECT - fk_profile - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = project_id - UNION - SELECT - 5 AS fk_profile -- GEOVISTORY BASICS -), -tw2 AS ( - -- select properties of the project - SELECT DISTINCT ON (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - FROM - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - WHERE - t1.fk_profile = t2.dfh_fk_profile - AND t3.pk_property = t2.dfh_pk_property -), -tw3 AS ( - -- select all outgoing statements, joined with range and domain class - SELECT - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t3.fk_class range_class, - t1.fk_property, - CASE WHEN t4.range_instances_max_quantifier = - 1 THEN - FLOAT8 '+infinity' - WHEN t4.range_instances_max_quantifier IS NULL THEN - FLOAT8 '+infinity' - ELSE - t4.range_instances_max_quantifier - END target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() OVER (PARTITION BY t3.fk_class, - t1.fk_property ORDER BY is_in_project_count DESC) AS rank, - t1.community_favorite_calendar calendar - FROM - information.v_statement t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - WHERE - fk_subject_info = entity_id - AND t1.fk_subject_info = t2.pk_entity - AND t1.fk_object_info = t3.pk_entity - AND t1.fk_property = t4.pk_property - AND t1.is_in_project_count > 0 - AND t4.has_domain IN (t2.fk_class, 50 -- make every class to a timespan class -) - AND t3.fk_class = t4.has_range -) -SELECT - pk_entity, - fk_object_info, - fk_subject_info, - calendar -FROM - tw3 -WHERE - target_max_quantifier >= rank; - -$BODY$; - --- 4 -DROP VIEW projects.v_info_proj_rel; - -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS -SELECT - info_proj_rel.pk_entity, - info_proj_rel.schema_name, - info_proj_rel.table_name, - info_proj_rel.entity_version, - info_proj_rel.notes, - info_proj_rel.fk_creator, - info_proj_rel.fk_last_modifier, - info_proj_rel.tmsp_creation, - info_proj_rel.tmsp_last_modification, - info_proj_rel.sys_period, - info_proj_rel.fk_entity, - info_proj_rel.fk_entity_version, - info_proj_rel.fk_entity_version_concat, - info_proj_rel.is_in_project, - info_proj_rel.is_standard_in_project, - info_proj_rel.calendar, - info_proj_rel.ord_num_of_domain, - info_proj_rel.fk_project, - info_proj_rel.ord_num_of_range, - info_proj_rel.ord_num_of_text_property, - info_proj_rel.project_visibility -FROM - projects.info_proj_rel; - --- 5 -CREATE OR REPLACE FUNCTION projects.v_info_proj_rel_update_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; -BEGIN - RAISE INFO 'input values: %', NEW; - ------ if existing, store in resulting_pk ... ----- - SELECT - * - FROM - INTO resulting_row projects.v_info_proj_rel - WHERE - fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - ------ ... and update the found row ----- - IF FOUND THEN - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - UPDATE - projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - calendar = COALESCE(NEW.calendar, resulting_row.calendar), - ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), - ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), - ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier), - project_visibility = COALESCE(NEW.project_visibility, resulting_row.project_visibility) - WHERE - pk_entity = resulting_row.pk_entity; - ------- if not existing, insert and store in result ----- - ELSE - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version, fk_creator, fk_last_modifier, project_visibility) - VALUES (NEW.fk_project, NEW.fk_entity, NEW.fk_entity_version, NEW.fk_entity_version_concat, NEW.is_in_project, NEW.is_standard_in_project, NEW.calendar, NEW.ord_num_of_domain, NEW.ord_num_of_range, NEW.ord_num_of_text_property, 1, NEW.fk_creator, NEW.fk_last_modifier, NEW.project_visibility) - -- return all fields of the new row - RETURNING - *) - SELECT - pk_entity - FROM - INTO resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - SELECT - * - FROM - INTO resulting_row projects.v_info_proj_rel - WHERE - pk_entity = resulting_pk - OR pk_entity = resulting_row.pk_entity; - RETURN resulting_row; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-up.sql b/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-up.sql deleted file mode 100644 index e502e4d55..000000000 --- a/server/db-migrate/migrations/sqls/20211209105458-pro-t-info-proj-rel-drop-calendar-up.sql +++ /dev/null @@ -1,204 +0,0 @@ --- 1 -DROP VIEW information.v_statement; - -CREATE OR REPLACE VIEW information.v_statement AS -SELECT - t1.pk_entity, - t1.fk_property, - t1.fk_property_of_property, - t1.fk_object_info, - t1.fk_subject_info, - t1.fk_subject_data, - t1.fk_subject_tables_row, - t1.fk_subject_tables_cell, - t1.fk_object_data, - t1.fk_object_tables_row, - t1.fk_object_tables_cell, - t2.is_in_project_count, - t2.is_standard_in_project_count, - t1.notes, - t1.tmsp_creation, - t1.tmsp_last_modification, - t1.sys_period -FROM - information.statement t1 - LEFT JOIN LATERAL ( - SELECT - count(info_proj_rel.pk_entity)::integer AS is_in_project_count, - COALESCE(count(*) FILTER (WHERE info_proj_rel.ord_num_of_domain = 0), 0::bigint)::integer AS is_standard_in_project_count - FROM - projects.info_proj_rel - WHERE - info_proj_rel.fk_entity = t1.pk_entity - AND info_proj_rel.is_in_project = TRUE - GROUP BY - info_proj_rel.fk_entity) t2 ON TRUE; - -CREATE TRIGGER on_insert - INSTEAD OF INSERT ON information.v_statement - FOR EACH ROW - EXECUTE PROCEDURE information.v_statement_find_or_create (); - --- 2 -DROP FUNCTION information.get_outgoing_statements_to_add (integer, integer); - -CREATE OR REPLACE FUNCTION information.get_outgoing_statements_to_add (entity_id integer, project_id integer) - RETURNS TABLE ( - pk_entity integer, - fk_object_info integer, - fk_subject_info integer) - LANGUAGE 'sql' - COST 100 VOLATILE ROWS 1000 - AS $BODY$ - WITH tw1 AS ( - -- select profiles the project - SELECT - fk_profile - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = project_id - UNION - SELECT - 5 AS fk_profile -- GEOVISTORY BASICS -), -tw2 AS ( - -- select properties of the project - SELECT DISTINCT ON (pk_property, - has_domain, - has_range) - pk_property, - has_domain, - has_range, - range_instances_max_quantifier - FROM - tw1 t1, - data_for_history.api_property t2, - data_for_history.v_property t3 - WHERE - t1.fk_profile = t2.dfh_fk_profile - AND t3.pk_property = t2.dfh_pk_property -), -tw3 AS ( - -- select all outgoing statements, joined with range and domain class - SELECT - t1.pk_entity, - t1.fk_object_info, - t1.fk_subject_info, - t3.fk_class range_class, - t1.fk_property, - CASE WHEN t4.range_instances_max_quantifier = - 1 THEN - FLOAT8 '+infinity' - WHEN t4.range_instances_max_quantifier IS NULL THEN - FLOAT8 '+infinity' - ELSE - t4.range_instances_max_quantifier - END target_max_quantifier, - t1.is_in_project_count, - -- counts the items of same domain and property - row_number() OVER (PARTITION BY t3.fk_class, - t1.fk_property ORDER BY is_in_project_count DESC) AS rank - FROM - information.v_statement t1, - information.v_entity_class_map t2, - information.v_entity_class_map t3, - tw2 t4 - WHERE - fk_subject_info = entity_id - AND t1.fk_subject_info = t2.pk_entity - AND t1.fk_object_info = t3.pk_entity - AND t1.fk_property = t4.pk_property - AND t1.is_in_project_count > 0 - AND t4.has_domain IN (t2.fk_class, 50 -- make every class to a timespan class -) - AND t3.fk_class = t4.has_range -) -SELECT - pk_entity, - fk_object_info, - fk_subject_info -FROM - tw3 -WHERE - target_max_quantifier >= rank; - -$BODY$; - --- 3 -ALTER TABLE projects.info_proj_rel RENAME COLUMN calendar TO calendar_backup; - -ALTER TABLE projects.info_proj_rel_vt RENAME COLUMN calendar TO calendar_backup; - --- 4 -DROP VIEW projects.v_info_proj_rel; - -CREATE OR REPLACE VIEW projects.v_info_proj_rel AS -SELECT - * -FROM - projects.info_proj_rel; - --- 5 -CREATE OR REPLACE FUNCTION projects.v_info_proj_rel_update_or_create () - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - resulting_pk integer; - resulting_row projects.v_info_proj_rel; -BEGIN - RAISE INFO 'input values: %', NEW; - ------ if existing, store in resulting_pk ... ----- - SELECT - * - FROM - INTO resulting_row projects.v_info_proj_rel - WHERE - fk_entity = NEW.fk_entity - AND fk_project = NEW.fk_project; - ------ ... and update the found row ----- - IF FOUND THEN - -- RAISE INFO 'result of select: %', resulting_row; - -- RAISE INFO 'v %', COALESCE(NEW.entity_version, resulting_row.entity_version); - UPDATE - projects.info_proj_rel - SET - fk_entity_version = COALESCE(NEW.fk_entity_version, resulting_row.fk_entity_version), - fk_entity_version_concat = COALESCE(NEW.fk_entity_version_concat, resulting_row.fk_entity_version_concat), - is_in_project = COALESCE(NEW.is_in_project, resulting_row.is_in_project), - is_standard_in_project = COALESCE(NEW.is_standard_in_project, resulting_row.is_standard_in_project), - ord_num_of_domain = COALESCE(NEW.ord_num_of_domain, resulting_row.ord_num_of_domain), - ord_num_of_range = COALESCE(NEW.ord_num_of_range, resulting_row.ord_num_of_range), - ord_num_of_text_property = COALESCE(NEW.ord_num_of_text_property, resulting_row.ord_num_of_text_property), - fk_creator = COALESCE(NEW.fk_creator, resulting_row.fk_creator), - fk_last_modifier = COALESCE(NEW.fk_last_modifier, resulting_row.fk_last_modifier), - project_visibility = COALESCE(NEW.project_visibility, resulting_row.project_visibility) - WHERE - pk_entity = resulting_row.pk_entity; - ------- if not existing, insert and store in result ----- - ELSE - -- RAISE INFO 'Not found, creating new...'; - WITH _insert AS ( -INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version, fk_creator, fk_last_modifier, project_visibility) - VALUES (NEW.fk_project, NEW.fk_entity, NEW.fk_entity_version, NEW.fk_entity_version_concat, NEW.is_in_project, NEW.is_standard_in_project, NEW.ord_num_of_domain, NEW.ord_num_of_range, NEW.ord_num_of_text_property, 1, NEW.fk_creator, NEW.fk_last_modifier, NEW.project_visibility) - -- return all fields of the new row - RETURNING - *) - SELECT - pk_entity - FROM - INTO resulting_pk _insert; - -- RAISE INFO 'result of insert: %', resulting_row; - END IF; - SELECT - * - FROM - INTO resulting_row projects.v_info_proj_rel - WHERE - pk_entity = resulting_pk - OR pk_entity = resulting_row.pk_entity; - RETURN resulting_row; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-down.sql b/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-down.sql deleted file mode 100644 index a8f217829..000000000 --- a/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-down.sql +++ /dev/null @@ -1,132 +0,0 @@ -CREATE OR REPLACE VIEW data_for_history.v_label AS SELECT DISTINCT ON (t1.dfh_profile_label, t1.dfh_profile_label_language) - 'label'::text AS type, - t1.dfh_profile_label AS label, - t1.dfh_profile_label_language AS - LANGUAGE, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_profile_definition, t1.dfh_profile_definition_language) - 'definition'::text AS type, - t1.dfh_profile_definition AS label, - t1.dfh_profile_definition_language AS - LANGUAGE, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_project_label, t1.dfh_project_label_language) - 'label'::text AS type, - t1.dfh_project_label AS label, - t1.dfh_project_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - t1.dfh_owned_by_project AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_property_label, t1.dfh_property_label_language) - 'label'::text AS type, - t1.dfh_property_label AS label, - t1.dfh_property_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -UNION -SELECT DISTINCT ON (t1.dfh_property_inverse_label, t1.dfh_property_label_language) - 'inverse_label'::text AS type, - t1.dfh_property_inverse_label AS label, - t1.dfh_property_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -WHERE - t1.dfh_property_inverse_label IS NOT NULL -UNION -SELECT DISTINCT ON (t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) - 'scope_note'::text AS type, - t1.dfh_property_scope_note AS label, - t1.dfh_property_scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -UNION -SELECT DISTINCT ON (t1.dfh_class_label, t1.dfh_class_label_language) - 'label'::text AS type, - t1.dfh_class_label AS label, - t1.dfh_class_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_class t1 -UNION -SELECT DISTINCT ON (t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) - 'scope_note'::text AS type, - t1.dfh_class_scope_note AS label, - t1.dfh_class_scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_class t1 -UNION -SELECT DISTINCT ON (t1.label, t1.label_language) - 'label'::text AS type, - t1.label, - t1.label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property -FROM - data_for_history.property_of_property t1 -UNION -SELECT DISTINCT ON (t1.scope_note, t1.scope_note_language) - 'scope_note'::text AS type, - t1.scope_note AS label, - t1.scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property -FROM - data_for_history.property_of_property t1; - diff --git a/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-up.sql b/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-up.sql deleted file mode 100644 index bcaa6f4a2..000000000 --- a/server/db-migrate/migrations/sqls/20211220193215-dfh-v-labels-fix-up.sql +++ /dev/null @@ -1,132 +0,0 @@ -CREATE OR REPLACE VIEW data_for_history.v_label AS SELECT DISTINCT ON (t1.dfh_pk_profile, t1.dfh_profile_label, t1.dfh_profile_label_language) - 'label'::text AS type, - t1.dfh_profile_label AS label, - t1.dfh_profile_label_language AS - LANGUAGE, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_pk_profile, t1.dfh_profile_definition, t1.dfh_profile_definition_language) - 'definition'::text AS type, - t1.dfh_profile_definition AS label, - t1.dfh_profile_definition_language AS - LANGUAGE, - t1.dfh_pk_profile AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_owned_by_project, t1.dfh_project_label, t1.dfh_project_label_language) - 'label'::text AS type, - t1.dfh_project_label AS label, - t1.dfh_project_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - t1.dfh_owned_by_project AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_profile t1 -UNION -SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_label, t1.dfh_property_label_language) - 'label'::text AS type, - t1.dfh_property_label AS label, - t1.dfh_property_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -UNION -SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_inverse_label, t1.dfh_property_label_language) - 'inverse_label'::text AS type, - t1.dfh_property_inverse_label AS label, - t1.dfh_property_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -WHERE - t1.dfh_property_inverse_label IS NOT NULL -UNION -SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_scope_note, t1.dfh_property_scope_note_language) - 'scope_note'::text AS type, - t1.dfh_property_scope_note AS label, - t1.dfh_property_scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - t1.dfh_pk_property AS fk_property, - NULL::integer AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_property t1 -UNION -SELECT DISTINCT ON (t1.dfh_pk_class, t1.dfh_class_label, t1.dfh_class_label_language) - 'label'::text AS type, - t1.dfh_class_label AS label, - t1.dfh_class_label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_class t1 -UNION -SELECT DISTINCT ON (t1.dfh_pk_class, t1.dfh_class_scope_note, t1.dfh_class_scope_note_language) - 'scope_note'::text AS type, - t1.dfh_class_scope_note AS label, - t1.dfh_class_scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - t1.dfh_pk_class AS fk_class, - NULL::integer AS fk_property_of_property -FROM - data_for_history.api_class t1 -UNION -SELECT DISTINCT ON (t1.pk_property_of_property, t1.label, t1.label_language) - 'label'::text AS type, - t1.label, - t1.label_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property -FROM - data_for_history.property_of_property t1 -UNION -SELECT DISTINCT ON (t1.pk_property_of_property, t1.scope_note, t1.scope_note_language) - 'scope_note'::text AS type, - t1.scope_note AS label, - t1.scope_note_language AS - LANGUAGE, - NULL::integer AS fk_profile, - NULL::integer AS fk_project, - NULL::integer AS fk_property, - NULL::integer AS fk_class, - t1.pk_property_of_property AS fk_property_of_property -FROM - data_for_history.property_of_property t1; - diff --git a/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-down.sql b/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-down.sql deleted file mode 100644 index 0eaeaf5ab..000000000 --- a/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-down.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE tables.cell - DROP COLUMN fk_class; - -ALTER TABLE tables.cell_vt - DROP COLUMN fk_class; - diff --git a/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-up.sql b/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-up.sql deleted file mode 100644 index 22d8c9e87..000000000 --- a/server/db-migrate/migrations/sqls/20211223151845-tab-t-cell-add-fk-class-up.sql +++ /dev/null @@ -1,7 +0,0 @@ -/* Replace with your SQL commands */ -ALTER TABLE tables.cell - ADD COLUMN fk_class INT NOT NULL DEFAULT 521; - -ALTER TABLE tables.cell_vt - ADD COLUMN fk_class INT; - diff --git a/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-down.sql b/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-down.sql deleted file mode 100644 index 5f9ab1d5e..000000000 --- a/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-down.sql +++ /dev/null @@ -1,31 +0,0 @@ --- Table: war.field_change -DROP TABLE war.field_change; - -CREATE TABLE war.field_change ( - fk_project integer NOT NULL, - fk_source_info integer NOT NULL, - fk_property integer NOT NULL, - fk_property_of_property integer NOT NULL, - is_outgoing boolean NOT NULL, - tmsp_last_modification timestamp with time zone NOT NULL, - CONSTRAINT field_change_uniq UNIQUE (fk_project, fk_source_info, fk_property, fk_property_of_property, is_outgoing) -); - --- Index: field_change_uniq_idx --- DROP INDEX war.field_change_uniq_idx; -CREATE UNIQUE INDEX field_change_uniq_idx ON war.field_change USING btree (fk_project ASC NULLS LAST, fk_source_info ASC NULLS LAST, fk_property ASC NULLS LAST, fk_property_of_property ASC NULLS LAST, is_outgoing ASC NULLS LAST) TABLESPACE pg_default; - --- Trigger: after_insert_field_change --- DROP TRIGGER after_insert_field_change ON war.field_change; -CREATE TRIGGER after_insert_field_change - AFTER INSERT ON war.field_change REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert (); - --- Trigger: after_update_field_change --- DROP TRIGGER after_update_field_change ON war.field_change; -CREATE TRIGGER after_update_field_change - AFTER UPDATE ON war.field_change REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert (); - diff --git a/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-up.sql b/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-up.sql deleted file mode 100644 index 25f768bb1..000000000 --- a/server/db-migrate/migrations/sqls/20211228155902-war-t-field-change-add-col-up.sql +++ /dev/null @@ -1,32 +0,0 @@ --- Table: war.field_change -DROP TABLE war.field_change; - -CREATE TABLE war.field_change ( - fk_project integer NOT NULL, - fk_source_info integer NOT NULL, - fk_source_tables_cell integer NOT NULL, - fk_property integer NOT NULL, - fk_property_of_property integer NOT NULL, - is_outgoing boolean NOT NULL, - tmsp_last_modification timestamp with time zone NOT NULL, - CONSTRAINT field_change_uniq UNIQUE (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing) -); - --- Index: field_change_uniq_idx --- DROP INDEX war.field_change_uniq_idx; -CREATE UNIQUE INDEX field_change_uniq_idx ON war.field_change USING btree (fk_project ASC NULLS LAST, fk_source_info ASC NULLS LAST, fk_source_tables_cell ASC NULLS LAST, fk_property ASC NULLS LAST, fk_property_of_property ASC NULLS LAST, is_outgoing ASC NULLS LAST) TABLESPACE pg_default; - --- Trigger: after_insert_field_change --- DROP TRIGGER after_insert_field_change ON war.field_change; -CREATE TRIGGER after_insert_field_change - AFTER INSERT ON war.field_change REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert (); - --- Trigger: after_update_field_change --- DROP TRIGGER after_update_field_change ON war.field_change; -CREATE TRIGGER after_update_field_change - AFTER UPDATE ON war.field_change REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE PROCEDURE war.field_change__notify_upsert (); - diff --git a/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-down.sql b/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-down.sql deleted file mode 100644 index 2f8f83247..000000000 --- a/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-down.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_property - DROP COLUMN dfh_parent_properties; - -ALTER TABLE data_for_history.api_property_vt - DROP COLUMN dfh_parent_properties; - -ALTER TABLE data_for_history.api_property - DROP COLUMN dfh_ancestor_properties; - -ALTER TABLE data_for_history.api_property_vt - DROP COLUMN dfh_ancestor_properties; - diff --git a/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-up.sql b/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-up.sql deleted file mode 100644 index 4a10cb9f7..000000000 --- a/server/db-migrate/migrations/sqls/20220114093806-dfh-t-api-property-add-hierarchy-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_property - ADD COLUMN dfh_parent_properties INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_property_vt - ADD COLUMN dfh_parent_properties INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_property - ADD COLUMN dfh_ancestor_properties INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_property_vt - ADD COLUMN dfh_ancestor_properties INT[] DEFAULT '{}' NOT NULL; - diff --git a/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-down.sql b/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-down.sql deleted file mode 100644 index de382b0d8..000000000 --- a/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-down.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_class - DROP COLUMN dfh_parent_classes; - -ALTER TABLE data_for_history.api_class_vt - DROP COLUMN dfh_parent_classes; - -ALTER TABLE data_for_history.api_class - DROP COLUMN dfh_ancestor_classes; - -ALTER TABLE data_for_history.api_class_vt - DROP COLUMN dfh_ancestor_classes; - diff --git a/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-up.sql b/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-up.sql deleted file mode 100644 index c4077bf3d..000000000 --- a/server/db-migrate/migrations/sqls/20220114094250-dfh-t-api-class-add-hierarchy-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_class - ADD COLUMN dfh_parent_classes INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_class_vt - ADD COLUMN dfh_parent_classes INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_class - ADD COLUMN dfh_ancestor_classes INT[] DEFAULT '{}' NOT NULL; - -ALTER TABLE data_for_history.api_class_vt - ADD COLUMN dfh_ancestor_classes INT[] DEFAULT '{}' NOT NULL; - diff --git a/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-down.sql b/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-down.sql deleted file mode 100644 index c5f278e27..000000000 --- a/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-down.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_profile - DROP COLUMN dfh_is_root_profile; - -ALTER TABLE data_for_history.api_profile_vt - DROP COLUMN dfh_is_root_profile; - -ALTER TABLE data_for_history.api_profile - DROP COLUMN dfh_fk_root_profile; - -ALTER TABLE data_for_history.api_profile_vt - DROP COLUMN dfh_fk_root_profile; - diff --git a/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-up.sql b/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-up.sql deleted file mode 100644 index 0da1c8fe7..000000000 --- a/server/db-migrate/migrations/sqls/20220114100023-dfh-t-api-profiles-add-hierarchy-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -ALTER TABLE data_for_history.api_profile - ADD COLUMN dfh_is_root_profile BOOLEAN DEFAULT FALSE; - -ALTER TABLE data_for_history.api_profile_vt - ADD COLUMN dfh_is_root_profile BOOLEAN DEFAULT FALSE; - -ALTER TABLE data_for_history.api_profile - ADD COLUMN dfh_fk_root_profile INT; - -ALTER TABLE data_for_history.api_profile_vt - ADD COLUMN dfh_fk_root_profile INT; - diff --git a/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-down.sql b/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-down.sql deleted file mode 100644 index 039a0d035..000000000 --- a/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-down.sql +++ /dev/null @@ -1,124 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_profiles_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_profile_data json DEFAULT NULL::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_profile - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_pk_profile = param_profile_id; - - /* - * Q: Is profile still present in API ? - */ - IF (param_profile_data IS NULL) THEN - /* - * A: No. Profile is removed from API - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_profile - SET - removed_from_api = TRUE - WHERE - dfh_pk_profile = param_profile_id - AND removed_from_api = FALSE - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_profile_label', dfh_profile_label)) INTO removed - FROM - tw1; - ELSE - /* - * A: Yes. Profile is still present in API - */ - /* - * Update profile_label - */ - UPDATE - data_for_history.api_profile - SET - dfh_profile_label = param_profile_data ->> 'profileLabel' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_profile_label_language = param_profile_data ->> 'profileLabelLanguage'; - - /* - * Update profile_definition - */ - UPDATE - data_for_history.api_profile - SET - dfh_profile_definition = param_profile_data ->> 'profileDefinition' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_profile_definition_language = param_profile_data ->> 'profileDefinitionLanguage'; - - /* - * Update project_label - */ - UPDATE - data_for_history.api_profile - SET - dfh_project_label = param_profile_data ->> 'ownedByProjectLabel' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_project_label_language = param_profile_data ->> 'ownedByProjectLabelLanguage'; - - /* - * Update language independent fields of existing records - * of the queried profile - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_profile - SET - removed_from_api = FALSE, - dfh_owned_by_project = (param_profile_data ->> 'ownedByProjectID')::int, - dfh_is_ongoing_forced_publication = (param_profile_data ->> 'isOngoingForcedPublication')::bool, - dfh_date_profile_published = (param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE, - dfh_date_profile_deprecated = (param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE - WHERE - dfh_pk_profile = param_profile_id - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO updated - FROM - tw1; - - /* - * Insert or update all fields - * of the queried profile and the requested language - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_profile (tmsp_last_dfh_update, requested_language, dfh_pk_profile, dfh_profile_label_language, dfh_profile_label, dfh_profile_definition_language, dfh_profile_definition, dfh_owned_by_project, dfh_project_label_language, dfh_project_label, dfh_is_ongoing_forced_publication, dfh_date_profile_published, dfh_date_profile_deprecated) - VALUES (param_tmsp_last_dfh_update, param_requested_language, (param_profile_data ->> 'profileID')::int, param_profile_data ->> 'profileLabelLanguage', param_profile_data ->> 'profileLabel', param_profile_data ->> 'profileDefinitionLanguage', param_profile_data ->> 'profileDefinition', (param_profile_data ->> 'ownedByProjectID')::int, param_profile_data ->> 'ownedByProjectLabelLanguage', param_profile_data ->> 'ownedByProjectLabel', (param_profile_data ->> 'isOngoingForcedPublication')::bool, (param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE, (param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE) - ON CONFLICT (dfh_pk_profile, requested_language) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, requested_language = EXCLUDED.requested_language, dfh_pk_profile = EXCLUDED.dfh_pk_profile, dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, dfh_profile_label = EXCLUDED.dfh_profile_label, dfh_profile_definition_language = EXCLUDED.dfh_profile_definition_language, dfh_profile_definition = EXCLUDED.dfh_profile_definition, dfh_owned_by_project = EXCLUDED.dfh_owned_by_project, dfh_project_label_language = EXCLUDED.dfh_project_label_language, dfh_project_label = EXCLUDED.dfh_project_label, dfh_is_ongoing_forced_publication = EXCLUDED.dfh_is_ongoing_forced_publication, dfh_date_profile_published = EXCLUDED.dfh_date_profile_published, dfh_date_profile_deprecated = EXCLUDED.dfh_date_profile_deprecated - RETURNING - *) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO inserted - FROM - tw1; - END IF; - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-up.sql b/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-up.sql deleted file mode 100644 index ce9ddebfb..000000000 --- a/server/db-migrate/migrations/sqls/20220114125221-dfh-f-update-profiles-up.sql +++ /dev/null @@ -1,124 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_profiles_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_profile_data json DEFAULT NULL::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_profile - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_pk_profile = param_profile_id; - - /* - * Q: Is profile still present in API ? - */ - IF (param_profile_data IS NULL) THEN - /* - * A: No. Profile is removed from API - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_profile - SET - removed_from_api = TRUE - WHERE - dfh_pk_profile = param_profile_id - AND removed_from_api = FALSE - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_profile_label', dfh_profile_label)) INTO removed - FROM - tw1; - ELSE - /* - * A: Yes. Profile is still present in API - */ - /* - * Update profile_label - */ - UPDATE - data_for_history.api_profile - SET - dfh_profile_label = param_profile_data ->> 'profileLabel' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_profile_label_language = param_profile_data ->> 'profileLabelLanguage'; - - /* - * Update profile_definition - */ - UPDATE - data_for_history.api_profile - SET - dfh_profile_definition = param_profile_data ->> 'profileDefinition' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_profile_definition_language = param_profile_data ->> 'profileDefinitionLanguage'; - - /* - * Update project_label - */ - UPDATE - data_for_history.api_profile - SET - dfh_project_label = param_profile_data ->> 'ownedByProjectLabel' - WHERE - dfh_pk_profile = param_profile_id - AND dfh_project_label_language = param_profile_data ->> 'ownedByProjectLabelLanguage'; - - /* - * Update language independent fields of existing records - * of the queried profile - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_profile - SET - removed_from_api = FALSE, - dfh_owned_by_project = (param_profile_data ->> 'ownedByProjectID')::int, - dfh_is_ongoing_forced_publication = (param_profile_data ->> 'isOngoingForcedPublication')::bool, - dfh_date_profile_published = (param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE, - dfh_date_profile_deprecated = (param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE - WHERE - dfh_pk_profile = param_profile_id - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO updated - FROM - tw1; - - /* - * Insert or update all fields - * of the queried profile and the requested language - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_profile (tmsp_last_dfh_update, requested_language, dfh_pk_profile, dfh_profile_label_language, dfh_profile_label, dfh_profile_definition_language, dfh_profile_definition, dfh_owned_by_project, dfh_project_label_language, dfh_project_label, dfh_is_ongoing_forced_publication, dfh_date_profile_published, dfh_date_profile_deprecated, dfh_is_root_profile, dfh_fk_root_profile) - VALUES (param_tmsp_last_dfh_update, param_requested_language, (param_profile_data ->> 'profileID')::int, param_profile_data ->> 'profileLabelLanguage', param_profile_data ->> 'profileLabel', param_profile_data ->> 'profileDefinitionLanguage', param_profile_data ->> 'profileDefinition', (param_profile_data ->> 'ownedByProjectID')::int, param_profile_data ->> 'ownedByProjectLabelLanguage', param_profile_data ->> 'ownedByProjectLabel', (param_profile_data ->> 'isOngoingForcedPublication')::bool, (param_profile_data ->> 'dateProfilePublished')::timestamp With TIME ZONE, (param_profile_data ->> 'dateProfileDeprecated')::timestamp With TIME ZONE, (param_profile_data ->> 'isRootProfile')::bool, (param_profile_data ->> 'fkRootProfile')::int) - ON CONFLICT (dfh_pk_profile, requested_language) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, requested_language = EXCLUDED.requested_language, dfh_pk_profile = EXCLUDED.dfh_pk_profile, dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, dfh_profile_label = EXCLUDED.dfh_profile_label, dfh_profile_definition_language = EXCLUDED.dfh_profile_definition_language, dfh_profile_definition = EXCLUDED.dfh_profile_definition, dfh_owned_by_project = EXCLUDED.dfh_owned_by_project, dfh_project_label_language = EXCLUDED.dfh_project_label_language, dfh_project_label = EXCLUDED.dfh_project_label, dfh_is_ongoing_forced_publication = EXCLUDED.dfh_is_ongoing_forced_publication, dfh_date_profile_published = EXCLUDED.dfh_date_profile_published, dfh_date_profile_deprecated = EXCLUDED.dfh_date_profile_deprecated, dfh_is_root_profile = EXCLUDED.dfh_is_root_profile, dfh_fk_root_profile = EXCLUDED.dfh_fk_root_profile - RETURNING - *) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_profile', dfh_pk_profile, 'requested_language', requested_language, 'dfh_profile_label', dfh_profile_label)) INTO inserted - FROM - tw1; - END IF; - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-down.sql b/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-down.sql deleted file mode 100644 index f7b8bf8bd..000000000 --- a/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-down.sql +++ /dev/null @@ -1,256 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_classes_profile_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_classes_profile_data json DEFAULT '[]' ::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * create a table with same type as from json - */ - DROP TABLE IF EXISTS classes_profile_from_api; - CREATE TEMP TABLE classes_profile_from_api AS - SELECT - param_requested_language AS requested_language, - "classID" AS dfh_pk_class, - "classIdentifierInNamespace" AS dfh_class_identifier_in_namespace, - "classLabelLanguage" AS dfh_class_label_language, - "classLabel" AS dfh_class_label, - "classScopeNoteLanguage" AS dfh_class_scope_note_language, - "classScopeNote" AS dfh_class_scope_note, - "entityBasicType" AS dfh_basic_type, - "entityBasicTypeLabel" AS dfh_basic_type_label, - "namespaceID" AS dfh_fk_namespace, - "namespaceLabelLanguage" AS dfh_namespace_label_language, - "namespaceLabel" AS dfh_namespace_label, - "namespaceURI" AS dfh_namespace_uri, - "profileAssociationType" AS dfh_profile_association_type, - "profileID" AS dfh_fk_profile, - "profileLabelLanguage" AS dfh_profile_label_language, - "profileLabel" AS dfh_profile_label - FROM - json_to_recordset(param_classes_profile_data) AS x ("classID" int, - "classIdentifierInNamespace" varchar, - "classLabel" text, - "classLabelLanguage" varchar, - "classScopeNote" text, - "classScopeNoteLanguage" varchar, - "entityBasicType" int, - "entityBasicTypeLabel" text, - "namespaceID" int, - "namespaceLabel" text, - "namespaceLabelLanguage" varchar, - "namespaceURI" text, - "profileAssociationType" text, - "profileID" int, - "profileLabel" text, - "profileLabelLanguage" varchar); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_class - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - WITH tw1 AS ( - SELECT - dfh_pk_class, - dfh_fk_profile - FROM - data_for_history.api_class - WHERE - dfh_fk_profile = param_profile_id - EXCEPT - SELECT - dfh_pk_class, - dfh_fk_profile - FROM - classes_profile_from_api - WHERE - dfh_fk_profile = param_profile_id -), -tw2 AS ( - UPDATE - data_for_history.api_class t1 - SET - removed_from_api = TRUE - FROM - tw1 t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class - RETURNING - t1.* -) -SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) INTO removed -FROM - tw2; - - /* - * Update class_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_class_label = t2.dfh_class_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_class_label_language = t2.dfh_class_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update class_scope_note - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_class_scope_note = t2.dfh_class_scope_note - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_class_scope_note_language = t2.dfh_class_scope_note_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update namespace_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_namespace_label = t2.dfh_namespace_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update profile_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_profile_label = t2.dfh_profile_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_profile_label_language = t2.dfh_profile_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_class t1 - SET - removed_from_api = FALSE, - dfh_class_identifier_in_namespace = t2.dfh_class_identifier_in_namespace, - dfh_basic_type = t2.dfh_basic_type, - dfh_basic_type_label = t2.dfh_basic_type_label, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_profile_association_type = t2.dfh_profile_association_type - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class - RETURNING - t1.* -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) INTO updated - FROM - tw1; - - /* - * Insert all new records - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_class (tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_class, dfh_class_identifier_in_namespace, dfh_class_label_language, dfh_class_label, dfh_class_scope_note_language, dfh_class_scope_note, dfh_basic_type, dfh_basic_type_label, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_namespace_uri, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label) - SELECT DISTINCT ON (t1.requested_language, - t1.dfh_pk_class, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - FALSE, - t1.requested_language, - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_class_label_language, - t1.dfh_class_label, - t1.dfh_class_scope_note_language, - t1.dfh_class_scope_note, - t1.dfh_basic_type, - t1.dfh_basic_type_label, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_namespace_uri, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - FROM - classes_profile_from_api t1 - WHERE - t1.requested_language = param_requested_language - AND t1.dfh_fk_profile = param_profile_id - ON CONFLICT (requested_language, - dfh_pk_class, - dfh_fk_profile) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - --requested_language = EXCLUDED.requested_language, - --dfh_pk_class = EXCLUDED.dfh_pk_class, - dfh_class_identifier_in_namespace = EXCLUDED.dfh_class_identifier_in_namespace, - dfh_class_label_language = EXCLUDED.dfh_class_label_language, - dfh_class_label = EXCLUDED.dfh_class_label, - dfh_class_scope_note_language = EXCLUDED.dfh_class_scope_note_language, - dfh_class_scope_note = EXCLUDED.dfh_class_scope_note, - dfh_basic_type = EXCLUDED.dfh_basic_type, - dfh_basic_type_label = EXCLUDED.dfh_basic_type_label, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - -- dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) INTO inserted - FROM - tw1; - - /* - * Return kind of a protocol - */ - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-up.sql b/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-up.sql deleted file mode 100644 index 0a97162ac..000000000 --- a/server/db-migrate/migrations/sqls/20220114130505-dfh-f-update-classes-up.sql +++ /dev/null @@ -1,266 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_classes_profile_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_classes_profile_data json DEFAULT '[]' ::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * create a table with same type as from json - */ - DROP TABLE IF EXISTS classes_profile_from_api; - CREATE TEMP TABLE classes_profile_from_api AS - SELECT - param_requested_language AS requested_language, - "classID" AS dfh_pk_class, - "classIdentifierInNamespace" AS dfh_class_identifier_in_namespace, - "classLabelLanguage" AS dfh_class_label_language, - "classLabel" AS dfh_class_label, - "classScopeNoteLanguage" AS dfh_class_scope_note_language, - "classScopeNote" AS dfh_class_scope_note, - "entityBasicType" AS dfh_basic_type, - "entityBasicTypeLabel" AS dfh_basic_type_label, - "namespaceID" AS dfh_fk_namespace, - "namespaceLabelLanguage" AS dfh_namespace_label_language, - "namespaceLabel" AS dfh_namespace_label, - "namespaceURI" AS dfh_namespace_uri, - "profileAssociationType" AS dfh_profile_association_type, - "profileID" AS dfh_fk_profile, - "profileLabelLanguage" AS dfh_profile_label_language, - "profileLabel" AS dfh_profile_label, - "parentClasses" AS dfh_parent_classes, - "ancestorClasses" AS dfh_ancestor_classes - FROM - json_to_recordset(param_classes_profile_data) AS x ("classID" int, - "classIdentifierInNamespace" varchar, - "classLabel" text, - "classLabelLanguage" varchar, - "classScopeNote" text, - "classScopeNoteLanguage" varchar, - "entityBasicType" int, - "entityBasicTypeLabel" text, - "namespaceID" int, - "namespaceLabel" text, - "namespaceLabelLanguage" varchar, - "namespaceURI" text, - "profileAssociationType" text, - "profileID" int, - "profileLabel" text, - "profileLabelLanguage" varchar, - "parentClasses" int[], - "ancestorClasses" int[]); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_class - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - WITH tw1 AS ( - SELECT - dfh_pk_class, - dfh_fk_profile - FROM - data_for_history.api_class - WHERE - dfh_fk_profile = param_profile_id - EXCEPT - SELECT - dfh_pk_class, - dfh_fk_profile - FROM - classes_profile_from_api - WHERE - dfh_fk_profile = param_profile_id -), -tw2 AS ( - UPDATE - data_for_history.api_class t1 - SET - removed_from_api = TRUE - FROM - tw1 t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class - RETURNING - t1.* -) -SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label)) INTO removed -FROM - tw2; - - /* - * Update class_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_class_label = t2.dfh_class_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_class_label_language = t2.dfh_class_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update class_scope_note - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_class_scope_note = t2.dfh_class_scope_note - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_class_scope_note_language = t2.dfh_class_scope_note_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update namespace_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_namespace_label = t2.dfh_namespace_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update profile_label - */ - UPDATE - data_for_history.api_class t1 - SET - dfh_profile_label = t2.dfh_profile_label - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_profile_label_language = t2.dfh_profile_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_class t1 - SET - removed_from_api = FALSE, - dfh_class_identifier_in_namespace = t2.dfh_class_identifier_in_namespace, - dfh_basic_type = t2.dfh_basic_type, - dfh_basic_type_label = t2.dfh_basic_type_label, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_parent_classes = t2.dfh_parent_classes, - dfh_ancestor_classes = t2.dfh_ancestor_classes - FROM - classes_profile_from_api t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_class = t2.dfh_pk_class - RETURNING - t1.* -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label, 'dfh_parent_classes', dfh_parent_classes, 'dfh_ancestor_classes', dfh_ancestor_classes)) INTO updated - FROM - tw1; - - /* - * Insert all new records - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_class (tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_class, dfh_class_identifier_in_namespace, dfh_class_label_language, dfh_class_label, dfh_class_scope_note_language, dfh_class_scope_note, dfh_basic_type, dfh_basic_type_label, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_namespace_uri, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label, dfh_parent_classes, dfh_ancestor_classes) - SELECT DISTINCT ON (t1.requested_language, - t1.dfh_pk_class, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - FALSE, - t1.requested_language, - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_class_label_language, - t1.dfh_class_label, - t1.dfh_class_scope_note_language, - t1.dfh_class_scope_note, - t1.dfh_basic_type, - t1.dfh_basic_type_label, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_namespace_uri, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label, - t1.dfh_parent_classes, - t1.dfh_ancestor_classes - FROM - classes_profile_from_api t1 - WHERE - t1.requested_language = param_requested_language - AND t1.dfh_fk_profile = param_profile_id - ON CONFLICT (requested_language, - dfh_pk_class, - dfh_fk_profile) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - --requested_language = EXCLUDED.requested_language, - --dfh_pk_class = EXCLUDED.dfh_pk_class, - dfh_class_identifier_in_namespace = EXCLUDED.dfh_class_identifier_in_namespace, - dfh_class_label_language = EXCLUDED.dfh_class_label_language, - dfh_class_label = EXCLUDED.dfh_class_label, - dfh_class_scope_note_language = EXCLUDED.dfh_class_scope_note_language, - dfh_class_scope_note = EXCLUDED.dfh_class_scope_note, - dfh_basic_type = EXCLUDED.dfh_basic_type, - dfh_basic_type_label = EXCLUDED.dfh_basic_type_label, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - -- dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label, - dfh_parent_classes = EXCLUDED.dfh_parent_classes, - dfh_ancestor_classes = EXCLUDED.dfh_ancestor_classes - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_class', dfh_pk_class, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_class_label', dfh_class_label, 'dfh_parent_classes', dfh_parent_classes, 'dfh_ancestor_classes', dfh_ancestor_classes)) INTO inserted - FROM - tw1; - - /* - * Return kind of a protocol - */ - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-down.sql b/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-down.sql deleted file mode 100644 index 27e1206e3..000000000 --- a/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-down.sql +++ /dev/null @@ -1,324 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_properties_profile_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_properties_profile_data json DEFAULT '[]' ::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * create a table with same type as from json - */ - DROP TABLE IF EXISTS properties_profile_from_api; - CREATE TABLE properties_profile_from_api AS - SELECT - param_requested_language AS requested_language, - "propertyID" AS dfh_pk_property, - "propertyLabelLanguage" AS dfh_property_label_language, - "propertyLabel" AS dfh_property_label, - "propertyInverseLabel" AS dfh_property_inverse_label, - "propertyScopeNoteLanguage" AS dfh_property_scope_note_language, - "propertyScopeNote" AS dfh_property_scope_note, - "isInherited" AS dfh_is_inherited, - "propertyDomain" AS dfh_property_domain, - "domainInstancesMinQuantifier" AS dfh_domain_instances_min_quantifier, - "domainInstancesMaxQuantifier" AS dfh_domain_instances_max_quantifier, - "propertyRange" AS dfh_property_range, - "rangeInstancesMinQuantifier" AS dfh_range_instances_min_quantifier, - "rangeInstancesMaxQuantifier" AS dfh_range_instances_max_quantifier, - "identityDefining" AS dfh_identity_defining, - "isHasTypeSubproperty" AS dfh_is_has_type_subproperty, - "propertyIdentifierInNamespace" AS dfh_property_identifier_in_namespace, - "namespaceURI" AS dfh_namespace_uri, - "namespaceID" AS dfh_fk_namespace, - "namespaceLabelLanguage" AS dfh_namespace_label_language, - "namespaceLabel" AS dfh_namespace_label, - "profileAssociationType" AS dfh_profile_association_type, - "profileID" AS dfh_fk_profile, - "profileLabelLanguage" AS dfh_profile_label_language, - "profileLabel" AS dfh_profile_label - FROM - json_to_recordset(param_properties_profile_data) AS x ("propertyID" INT, - "propertyLabelLanguage" VARCHAR, - "propertyLabel" TEXT, - "propertyInverseLabel" TEXT, - "propertyScopeNoteLanguage" VARCHAR, - "propertyScopeNote" TEXT, - "isInherited" BOOLEAN, - "propertyDomain" INTEGER, - "domainInstancesMinQuantifier" INTEGER, - "domainInstancesMaxQuantifier" INTEGER, - "propertyRange" INTEGER, - "rangeInstancesMinQuantifier" INTEGER, - "rangeInstancesMaxQuantifier" INTEGER, - "identityDefining" BOOLEAN, - "isHasTypeSubproperty" BOOLEAN, - "propertyIdentifierInNamespace" VARCHAR, - "namespaceURI" TEXT, - "namespaceID" INTEGER, - "namespaceLabelLanguage" VARCHAR, - "namespaceLabel" TEXT, - "profileAssociationType" TEXT, - "profileID" INTEGER, - "profileLabelLanguage" VARCHAR, - "profileLabel" TEXT); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_property - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - WITH tw1 AS ( - SELECT - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - FROM - data_for_history.api_property - WHERE - dfh_fk_profile = param_profile_id - EXCEPT - SELECT - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - FROM - properties_profile_from_api - WHERE - dfh_fk_profile = param_profile_id -), -tw2 AS ( - UPDATE - data_for_history.api_property t1 - SET - removed_from_api = TRUE - FROM - tw1 t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range - RETURNING - t1.* -) -SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO removed -FROM - tw2; - - /* - * Update language dependent fields of existing records - */ - /* - * Update property_labels - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_label = t2.dfh_property_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_label_language = t2.dfh_property_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update property_inverse_labels - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_inverse_label = t2.dfh_property_inverse_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_label_language = t2.dfh_property_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update scope_notes - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_scope_note = t2.dfh_property_scope_note - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_namespace_label - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_namespace_label = t2.dfh_namespace_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_profile_label - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_profile_label = t2.dfh_profile_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_profile_label_language = t2.dfh_profile_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_property t1 - SET - removed_from_api = FALSE, - dfh_pk_property = t2.dfh_pk_property, - dfh_is_inherited = t2.dfh_is_inherited, - dfh_property_domain = t2.dfh_property_domain, - dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, - dfh_property_range = t2.dfh_property_range, - dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, - dfh_identity_defining = t2.dfh_identity_defining, - dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_fk_profile = t2.dfh_fk_profile - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range - RETURNING - t1.* -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO updated - FROM - tw1; - - /* - * Insert or update all new records - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_property (tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_property, dfh_property_label_language, dfh_property_label, dfh_property_inverse_label, dfh_property_scope_note_language, dfh_property_scope_note, dfh_is_inherited, dfh_property_domain, dfh_domain_instances_min_quantifier, dfh_domain_instances_max_quantifier, dfh_property_range, dfh_range_instances_min_quantifier, dfh_range_instances_max_quantifier, dfh_identity_defining, dfh_is_has_type_subproperty, dfh_property_identifier_in_namespace, dfh_namespace_uri, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label) - SELECT DISTINCT ON (t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - FALSE, - t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_label_language, - t1.dfh_property_label, - t1.dfh_property_inverse_label, - t1.dfh_property_scope_note_language, - t1.dfh_property_scope_note, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_namespace_uri, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label - FROM - properties_profile_from_api t1 - WHERE - t1.requested_language = param_requested_language - AND t1.dfh_fk_profile = param_profile_id - ON CONFLICT (requested_language, - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - requested_language = EXCLUDED.requested_language, - dfh_pk_property = EXCLUDED.dfh_pk_property, - dfh_property_label_language = EXCLUDED.dfh_property_label_language, - dfh_property_label = EXCLUDED.dfh_property_label, - dfh_property_inverse_label = EXCLUDED.dfh_property_inverse_label, - dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, - dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, - dfh_is_inherited = EXCLUDED.dfh_is_inherited, - dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, - dfh_identity_defining = EXCLUDED.dfh_identity_defining, - dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO inserted - FROM - tw1; - - /* - * Return kind of a protocol - */ - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-up.sql b/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-up.sql deleted file mode 100644 index 68e75afad..000000000 --- a/server/db-migrate/migrations/sqls/20220114131303-dfh-f-update-properties-up.sql +++ /dev/null @@ -1,334 +0,0 @@ -CREATE OR REPLACE FUNCTION data_for_history.update_api_properties_profile_table (param_profile_id integer, param_requested_language character varying, param_tmsp_last_dfh_update timestamp with time zone, param_properties_profile_data json DEFAULT '[]' ::json) - RETURNS json - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - removed json; - updated json; - inserted json; -BEGIN - /* - * create a table with same type as from json - */ - DROP TABLE IF EXISTS properties_profile_from_api; - CREATE TABLE properties_profile_from_api AS - SELECT - param_requested_language AS requested_language, - "propertyID" AS dfh_pk_property, - "propertyLabelLanguage" AS dfh_property_label_language, - "propertyLabel" AS dfh_property_label, - "propertyInverseLabel" AS dfh_property_inverse_label, - "propertyScopeNoteLanguage" AS dfh_property_scope_note_language, - "propertyScopeNote" AS dfh_property_scope_note, - "isInherited" AS dfh_is_inherited, - "propertyDomain" AS dfh_property_domain, - "domainInstancesMinQuantifier" AS dfh_domain_instances_min_quantifier, - "domainInstancesMaxQuantifier" AS dfh_domain_instances_max_quantifier, - "propertyRange" AS dfh_property_range, - "rangeInstancesMinQuantifier" AS dfh_range_instances_min_quantifier, - "rangeInstancesMaxQuantifier" AS dfh_range_instances_max_quantifier, - "identityDefining" AS dfh_identity_defining, - "isHasTypeSubproperty" AS dfh_is_has_type_subproperty, - "propertyIdentifierInNamespace" AS dfh_property_identifier_in_namespace, - "namespaceURI" AS dfh_namespace_uri, - "namespaceID" AS dfh_fk_namespace, - "namespaceLabelLanguage" AS dfh_namespace_label_language, - "namespaceLabel" AS dfh_namespace_label, - "profileAssociationType" AS dfh_profile_association_type, - "profileID" AS dfh_fk_profile, - "profileLabelLanguage" AS dfh_profile_label_language, - "profileLabel" AS dfh_profile_label, - "parentProperties" AS dfh_parent_properties, - coalesce("ancestorProperties", '{}'::int[]) AS dfh_ancestor_properties - FROM - json_to_recordset(param_properties_profile_data) AS x ("propertyID" INT, - "propertyLabelLanguage" VARCHAR, - "propertyLabel" TEXT, - "propertyInverseLabel" TEXT, - "propertyScopeNoteLanguage" VARCHAR, - "propertyScopeNote" TEXT, - "isInherited" BOOLEAN, - "propertyDomain" INTEGER, - "domainInstancesMinQuantifier" INTEGER, - "domainInstancesMaxQuantifier" INTEGER, - "propertyRange" INTEGER, - "rangeInstancesMinQuantifier" INTEGER, - "rangeInstancesMaxQuantifier" INTEGER, - "identityDefining" BOOLEAN, - "isHasTypeSubproperty" BOOLEAN, - "propertyIdentifierInNamespace" VARCHAR, - "namespaceURI" TEXT, - "namespaceID" INTEGER, - "namespaceLabelLanguage" VARCHAR, - "namespaceLabel" TEXT, - "profileAssociationType" TEXT, - "profileID" INTEGER, - "profileLabelLanguage" VARCHAR, - "profileLabel" TEXT, - "parentProperties" int[], - "ancestorProperties" int[]); - - /* - * Update tmsp_last_dfh_update for all records of given - * profile_id - */ - UPDATE - data_for_history.api_property - SET - tmsp_last_dfh_update = param_tmsp_last_dfh_update - WHERE - dfh_fk_profile = param_profile_id; - - /* - * Mark all records missing in the json data - * as removed from api. - * (this is independent from the requested language) - */ - WITH tw1 AS ( - SELECT - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - FROM - data_for_history.api_property - WHERE - dfh_fk_profile = param_profile_id - EXCEPT - SELECT - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile - FROM - properties_profile_from_api - WHERE - dfh_fk_profile = param_profile_id -), -tw2 AS ( - UPDATE - data_for_history.api_property t1 - SET - removed_from_api = TRUE - FROM - tw1 t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range - RETURNING - t1.* -) -SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_domain, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO removed -FROM - tw2; - - /* - * Update language dependent fields of existing records - */ - /* - * Update property_labels - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_label = t2.dfh_property_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_label_language = t2.dfh_property_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update property_inverse_labels - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_inverse_label = t2.dfh_property_inverse_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_label_language = t2.dfh_property_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update scope_notes - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_property_scope_note = t2.dfh_property_scope_note - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_property_scope_note_language = t2.dfh_property_scope_note_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_namespace_label - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_namespace_label = t2.dfh_namespace_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_namespace_label_language = t2.dfh_namespace_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update dfh_profile_label - */ - UPDATE - data_for_history.api_property t1 - SET - dfh_profile_label = t2.dfh_profile_label - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_profile_label_language = t2.dfh_profile_label_language - AND t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property; - - /* - * Update language independent fields of existing records - * This affects also records of other languages than the requested - */ - WITH tw1 AS ( - UPDATE - data_for_history.api_property t1 - SET - removed_from_api = FALSE, - dfh_pk_property = t2.dfh_pk_property, - dfh_is_inherited = t2.dfh_is_inherited, - dfh_property_domain = t2.dfh_property_domain, - dfh_domain_instances_min_quantifier = t2.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = t2.dfh_domain_instances_max_quantifier, - dfh_property_range = t2.dfh_property_range, - dfh_range_instances_min_quantifier = t2.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = t2.dfh_range_instances_max_quantifier, - dfh_identity_defining = t2.dfh_identity_defining, - dfh_is_has_type_subproperty = t2.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = t2.dfh_property_identifier_in_namespace, - dfh_namespace_uri = t2.dfh_namespace_uri, - dfh_fk_namespace = t2.dfh_fk_namespace, - dfh_profile_association_type = t2.dfh_profile_association_type, - dfh_fk_profile = t2.dfh_fk_profile, - dfh_parent_properties = t2.dfh_parent_properties, - dfh_ancestor_properties = t2.dfh_ancestor_properties - FROM - properties_profile_from_api t2 - WHERE - t1.dfh_fk_profile = t2.dfh_fk_profile - AND t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range - RETURNING - t1.* -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO updated - FROM - tw1; - - /* - * Insert or update all new records - */ - WITH tw1 AS ( -INSERT INTO data_for_history.api_property (tmsp_last_dfh_update, removed_from_api, requested_language, dfh_pk_property, dfh_property_label_language, dfh_property_label, dfh_property_inverse_label, dfh_property_scope_note_language, dfh_property_scope_note, dfh_is_inherited, dfh_property_domain, dfh_domain_instances_min_quantifier, dfh_domain_instances_max_quantifier, dfh_property_range, dfh_range_instances_min_quantifier, dfh_range_instances_max_quantifier, dfh_identity_defining, dfh_is_has_type_subproperty, dfh_property_identifier_in_namespace, dfh_namespace_uri, dfh_fk_namespace, dfh_namespace_label_language, dfh_namespace_label, dfh_profile_association_type, dfh_fk_profile, dfh_profile_label_language, dfh_profile_label, dfh_parent_properties, dfh_ancestor_properties) - SELECT DISTINCT ON (t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.dfh_fk_profile) - param_tmsp_last_dfh_update, - FALSE, - t1.requested_language, - t1.dfh_pk_property, - t1.dfh_property_label_language, - t1.dfh_property_label, - t1.dfh_property_inverse_label, - t1.dfh_property_scope_note_language, - t1.dfh_property_scope_note, - t1.dfh_is_inherited, - t1.dfh_property_domain, - t1.dfh_domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier, - t1.dfh_property_range, - t1.dfh_range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier, - t1.dfh_identity_defining, - t1.dfh_is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace, - t1.dfh_namespace_uri, - t1.dfh_fk_namespace, - t1.dfh_namespace_label_language, - t1.dfh_namespace_label, - t1.dfh_profile_association_type, - t1.dfh_fk_profile, - t1.dfh_profile_label_language, - t1.dfh_profile_label, - t1.dfh_parent_properties, - t1.dfh_ancestor_properties - FROM - properties_profile_from_api t1 - WHERE - t1.requested_language = param_requested_language - AND t1.dfh_fk_profile = param_profile_id - ON CONFLICT (requested_language, - dfh_pk_property, - dfh_property_domain, - dfh_property_range, - dfh_fk_profile) - DO UPDATE SET - tmsp_last_dfh_update = EXCLUDED.tmsp_last_dfh_update, - removed_from_api = EXCLUDED.removed_from_api, - requested_language = EXCLUDED.requested_language, - dfh_pk_property = EXCLUDED.dfh_pk_property, - dfh_property_label_language = EXCLUDED.dfh_property_label_language, - dfh_property_label = EXCLUDED.dfh_property_label, - dfh_property_inverse_label = EXCLUDED.dfh_property_inverse_label, - dfh_property_scope_note_language = EXCLUDED.dfh_property_scope_note_language, - dfh_property_scope_note = EXCLUDED.dfh_property_scope_note, - dfh_is_inherited = EXCLUDED.dfh_is_inherited, - dfh_domain_instances_min_quantifier = EXCLUDED.dfh_domain_instances_min_quantifier, - dfh_domain_instances_max_quantifier = EXCLUDED.dfh_domain_instances_max_quantifier, - dfh_range_instances_min_quantifier = EXCLUDED.dfh_range_instances_min_quantifier, - dfh_range_instances_max_quantifier = EXCLUDED.dfh_range_instances_max_quantifier, - dfh_identity_defining = EXCLUDED.dfh_identity_defining, - dfh_is_has_type_subproperty = EXCLUDED.dfh_is_has_type_subproperty, - dfh_property_identifier_in_namespace = EXCLUDED.dfh_property_identifier_in_namespace, - dfh_namespace_uri = EXCLUDED.dfh_namespace_uri, - dfh_fk_namespace = EXCLUDED.dfh_fk_namespace, - dfh_namespace_label_language = EXCLUDED.dfh_namespace_label_language, - dfh_namespace_label = EXCLUDED.dfh_namespace_label, - dfh_profile_association_type = EXCLUDED.dfh_profile_association_type, - dfh_fk_profile = EXCLUDED.dfh_fk_profile, - dfh_profile_label_language = EXCLUDED.dfh_profile_label_language, - dfh_profile_label = EXCLUDED.dfh_profile_label, - dfh_parent_properties = EXCLUDED.dfh_parent_properties, - dfh_ancestor_properties = EXCLUDED.dfh_ancestor_properties - RETURNING - * -) - SELECT - jsonb_agg(jsonb_build_object('dfh_pk_property', dfh_pk_property, 'dfh_property_domain', dfh_property_range, 'dfh_property_range', dfh_property_range, 'dfh_fk_profile', dfh_fk_profile, 'requested_language', requested_language, 'removed_from_api', removed_from_api, 'dfh_property_label', dfh_property_label)) INTO inserted - FROM - tw1; - - /* - * Return kind of a protocol - */ - RETURN json_build_object('removed', removed, 'updated', updated, 'inserted', inserted); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-down.sql b/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-down.sql deleted file mode 100644 index 9f8d62511..000000000 --- a/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-down.sql +++ /dev/null @@ -1,17 +0,0 @@ -DROP VIEW data_for_history.v_class; - -CREATE VIEW data_for_history.v_class AS -SELECT - t1.dfh_pk_class AS pk_class, - t1.dfh_class_identifier_in_namespace AS identifier_in_namespace, - t1.dfh_basic_type AS basic_type, - t1.dfh_basic_type_label AS basic_type_label, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) AS profiles -FROM - data_for_history.api_class t1 -GROUP BY - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_basic_type, - t1.dfh_basic_type_label; - diff --git a/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-up.sql b/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-up.sql deleted file mode 100644 index 5f4ecaf2d..000000000 --- a/server/db-migrate/migrations/sqls/20220114161239-dfh-v-class-up.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE OR REPLACE VIEW data_for_history.v_class AS -SELECT - t1.dfh_pk_class AS pk_class, - t1.dfh_class_identifier_in_namespace AS identifier_in_namespace, - t1.dfh_basic_type AS basic_type, - t1.dfh_basic_type_label AS basic_type_label, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) AS profiles, - t1.dfh_parent_classes AS parent_classes, - t1.dfh_ancestor_classes AS ancestor_classes -FROM - data_for_history.api_class t1 -GROUP BY - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_basic_type, - t1.dfh_basic_type_label, - t1.dfh_ancestor_classes, - t1.dfh_parent_classes; - diff --git a/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-down.sql b/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-down.sql deleted file mode 100644 index 398bdd1b0..000000000 --- a/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-down.sql +++ /dev/null @@ -1,89 +0,0 @@ -DROP VIEW data_for_history.v_property; - -CREATE VIEW data_for_history.v_property AS -WITH tw0 AS ( - SELECT - t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_identity_defining, - t1_1.dfh_is_has_type_subproperty, - t1_1.dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM - data_for_history.api_property t1_1 - UNION - SELECT - 1111 AS dfh_pk_property, - TRUE AS dfh_is_inherited, - 365 AS dfh_property_domain, - 0 AS dfh_domain_instances_min_quantifier, - '-1'::integer AS dfh_domain_instances_max_quantifier, - t1_1.dfh_pk_class AS dfh_property_range, - 1 AS dfh_range_instances_min_quantifier, - 1 AS dfh_range_instances_max_quantifier, - TRUE AS dfh_identity_defining, - FALSE AS dfh_is_has_type_subproperty, - 'histP9'::character varying AS dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api - FROM - data_for_history.api_class t1_1 - WHERE - t1_1.dfh_pk_class <> 365 - AND (t1_1.dfh_basic_type = ANY (ARRAY[8, - 9, - 30])) - GROUP BY - t1_1.dfh_fk_profile, - t1_1.removed_from_api, - t1_1.dfh_pk_class, - t1_1.dfh_class_identifier_in_namespace, - t1_1.dfh_basic_type, - t1_1.dfh_basic_type_label -), -tw1 AS ( - SELECT - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles -FROM - tw0 t1_1 -GROUP BY - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range -) -SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range) - t1.dfh_pk_property AS pk_property, - t1.dfh_is_inherited AS is_inherited, - t1.dfh_property_domain AS has_domain, - t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1.dfh_property_range AS has_range, - t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1.dfh_identity_defining AS identity_defining, - t1.dfh_is_has_type_subproperty AS is_has_type_subproperty, - t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - t2.profiles -FROM - tw0 t1, - tw1 t2 -WHERE - t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range -ORDER BY - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.removed_from_api; - diff --git a/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-up.sql b/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-up.sql deleted file mode 100644 index 46c0dd32d..000000000 --- a/server/db-migrate/migrations/sqls/20220114161348-dfh-v-property-up.sql +++ /dev/null @@ -1,59 +0,0 @@ -DROP VIEW data_for_history.v_property; - -CREATE VIEW data_for_history.v_property AS -WITH tw0 AS ( - SELECT - t1_1.dfh_pk_property, - t1_1.dfh_is_inherited, - t1_1.dfh_property_domain, - t1_1.dfh_domain_instances_min_quantifier, - t1_1.dfh_domain_instances_max_quantifier, - t1_1.dfh_property_range, - t1_1.dfh_range_instances_min_quantifier, - t1_1.dfh_range_instances_max_quantifier, - t1_1.dfh_property_identifier_in_namespace, - t1_1.dfh_fk_profile, - t1_1.removed_from_api, - t1_1.dfh_parent_properties, - t1_1.dfh_ancestor_properties - FROM - data_for_history.api_property t1_1 -), -tw1 AS ( - SELECT - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1_1.dfh_fk_profile, 'removed_from_api', t1_1.removed_from_api)) AS profiles -FROM - tw0 t1_1 -GROUP BY - t1_1.dfh_pk_property, - t1_1.dfh_property_domain, - t1_1.dfh_property_range -) -SELECT DISTINCT ON (t1.dfh_pk_property, t1.dfh_property_domain, t1.dfh_property_range) - t1.dfh_pk_property AS pk_property, - t1.dfh_property_domain AS has_domain, - t1.dfh_domain_instances_min_quantifier AS domain_instances_min_quantifier, - t1.dfh_domain_instances_max_quantifier AS domain_instances_max_quantifier, - t1.dfh_property_range AS has_range, - t1.dfh_range_instances_min_quantifier AS range_instances_min_quantifier, - t1.dfh_range_instances_max_quantifier AS range_instances_max_quantifier, - t1.dfh_property_identifier_in_namespace AS identifier_in_namespace, - t1.dfh_parent_properties AS parent_properties, - t1.dfh_ancestor_properties AS ancestor_properties, - t2.profiles -FROM - tw0 t1, - tw1 t2 -WHERE - t1.dfh_pk_property = t2.dfh_pk_property - AND t1.dfh_property_domain = t2.dfh_property_domain - AND t1.dfh_property_range = t2.dfh_property_range -ORDER BY - t1.dfh_pk_property, - t1.dfh_property_domain, - t1.dfh_property_range, - t1.removed_from_api; - diff --git a/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-down.sql b/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-down.sql deleted file mode 100644 index 5f4ecaf2d..000000000 --- a/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-down.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE OR REPLACE VIEW data_for_history.v_class AS -SELECT - t1.dfh_pk_class AS pk_class, - t1.dfh_class_identifier_in_namespace AS identifier_in_namespace, - t1.dfh_basic_type AS basic_type, - t1.dfh_basic_type_label AS basic_type_label, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) AS profiles, - t1.dfh_parent_classes AS parent_classes, - t1.dfh_ancestor_classes AS ancestor_classes -FROM - data_for_history.api_class t1 -GROUP BY - t1.dfh_pk_class, - t1.dfh_class_identifier_in_namespace, - t1.dfh_basic_type, - t1.dfh_basic_type_label, - t1.dfh_ancestor_classes, - t1.dfh_parent_classes; - diff --git a/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-up.sql b/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-up.sql deleted file mode 100644 index 4b9472ea6..000000000 --- a/server/db-migrate/migrations/sqls/20220117204624-dfh-v-class-up-fix-up.sql +++ /dev/null @@ -1,23 +0,0 @@ -CREATE OR REPLACE VIEW data_for_history.v_class AS -WITH tw1 AS ( - SELECT - t1.dfh_pk_class, - jsonb_agg(DISTINCT jsonb_build_object('fk_profile', t1.dfh_fk_profile, 'removed_from_api', t1.removed_from_api)) AS profiles - FROM - data_for_history.api_class t1 - GROUP BY - t1.dfh_pk_class -) -SELECT DISTINCT ON (t1.dfh_pk_class) - t1.dfh_pk_class AS pk_class, - t1.dfh_class_identifier_in_namespace AS identifier_in_namespace, - t1.dfh_basic_type AS basic_type, - t1.dfh_basic_type_label AS basic_type_label, - tw1.profiles, - t1.dfh_parent_classes AS parent_classes, - t1.dfh_ancestor_classes AS ancestor_classes -FROM - tw1, - data_for_history.api_class t1 -WHERE - tw1.dfh_pk_class = t1.dfh_pk_class diff --git a/server/db-migrate/migrations/sqls/20220126133300-add-indexes-down.sql b/server/db-migrate/migrations/sqls/20220126133300-add-indexes-down.sql deleted file mode 100644 index fc3d3ed19..000000000 --- a/server/db-migrate/migrations/sqls/20220126133300-add-indexes-down.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* ADD INDEXES TO STATEMENT TABLE*/ - -DROP INDEX information.statement_fk_subject_tables_cell_idx; - -DROP INDEX information.statement_fk_property_idx; - - -/* ADD INDEXES TO PARENT CELL TABLE*/ - -DROP INDEX tables.cell_pk_cell_idx; - -DROP INDEX tables.cell_fk_row_idx; - -DROP INDEX tables.cell_fk_column_idx; diff --git a/server/db-migrate/migrations/sqls/20220126133300-add-indexes-up.sql b/server/db-migrate/migrations/sqls/20220126133300-add-indexes-up.sql deleted file mode 100644 index 68189c333..000000000 --- a/server/db-migrate/migrations/sqls/20220126133300-add-indexes-up.sql +++ /dev/null @@ -1,25 +0,0 @@ -/* ADD INDEXES TO PARENT CELL TABLE*/ - -CREATE INDEX cell_fk_column_idx - ON tables.cell USING btree - (fk_column ASC NULLS LAST) - TABLESPACE pg_default; - -CREATE INDEX cell_fk_row_idx - ON tables.cell USING btree - (fk_row ASC NULLS LAST) - TABLESPACE pg_default; - -CREATE INDEX cell_pk_cell_idx - ON tables.cell USING btree - (pk_cell ASC NULLS LAST); - -/* ADD INDEXES TO STATEMENT TABLE*/ - -CREATE INDEX statement_fk_property_idx - ON information.statement USING btree - (fk_property ASC NULLS LAST); - -CREATE INDEX statement_fk_subject_tables_cell_idx - ON information.statement USING btree - (fk_subject_tables_cell ASC NULLS LAST); diff --git a/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-down.sql b/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-down.sql deleted file mode 100644 index 125d04863..000000000 --- a/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TRIGGER on_insert ON projects.v_info_proj_rel; diff --git a/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-up.sql b/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-up.sql deleted file mode 100644 index 83f67942d..000000000 --- a/server/db-migrate/migrations/sqls/20220203135515-pro-v-info-pro-rel-trigger-up.sql +++ /dev/null @@ -1,4 +0,0 @@ -create trigger on_insert instead of -insert - on - projects.v_info_proj_rel for each row execute procedure projects.v_info_proj_rel_update_or_create() diff --git a/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-down.sql b/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-down.sql deleted file mode 100644 index 54802e261..000000000 --- a/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-down.sql +++ /dev/null @@ -1,297 +0,0 @@ --- DROP FUNCTION commons.clone_sandbox_project(integer); -CREATE OR REPLACE FUNCTION commons.clone_sandbox_project (account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_sandbox_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add account to project - */ - INSERT INTO public.account_project_rel (fk_project, account_id, ROLE) - VALUES (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_sandbox_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_sandbox_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.digital t2 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace; - - /* - * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new digital's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.digital t3 - WHERE - fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 AS fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace - AND t3.pk_text = t2.fk_text - AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new chunk's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.chunk t3 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the statements pointing to data to the new project - */ - INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) - SELECT - t1.pk_entity AS fk_entity, - pk_new_project AS fk_project, - TRUE AS is_in_project - FROM - information.statement t1, - data.entity t2 - WHERE - t1.fk_subject_data = t2.pk_entity - AND t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - FROM - war.entity_preview - WHERE - fk_project = pk_sandbox_project - ON CONFLICT ON CONSTRAINT war_entity_preview_unique - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - account_id AS fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_sandbox_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-up.sql b/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-up.sql deleted file mode 100644 index 6d3a4f24e..000000000 --- a/server/db-migrate/migrations/sqls/20220305141243-com-f-clone-project-fix-up.sql +++ /dev/null @@ -1,296 +0,0 @@ --- DROP FUNCTION commons.clone_sandbox_project(integer); -CREATE OR REPLACE FUNCTION commons.clone_sandbox_project (account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_sandbox_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add account to project - */ - INSERT INTO public.account_project_rel (fk_project, account_id, ROLE) - VALUES (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_sandbox_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_sandbox_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.digital t2 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace; - - /* - * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new digital's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.digital t3 - WHERE - fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 AS fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.pk_entity = t2.fk_namespace - AND t3.pk_text = t2.fk_text - AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new chunk's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.chunk t3 - WHERE - t1.fk_project = pk_sandbox_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the statements pointing to data to the new project - */ - INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) - SELECT - t1.pk_entity AS fk_entity, - pk_new_project AS fk_project, - TRUE AS is_in_project - FROM - information.statement t1, - data.entity t2 - WHERE - t1.fk_subject_data = t2.pk_entity - AND t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - FROM - war.entity_preview - WHERE - fk_project = pk_sandbox_project - ON CONFLICT ON CONSTRAINT war_entity_preview_unique - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - account_id AS fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_sandbox_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-down.sql b/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-up.sql b/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-up.sql deleted file mode 100644 index eba22c6fe..000000000 --- a/server/db-migrate/migrations/sqls/20220305141244-data-cleanup-chunks-up.sql +++ /dev/null @@ -1,89 +0,0 @@ -CREATE TEMP TABLE to_delete ON COMMIT DROP AS -SELECT - t1.fk_object_info, t1.pk_entity statement_id, t2.pk_entity chunk_id, t4.pk_entity info_project_rel_id, t2.string chunk_string, t2.fk_text, t2.fk_namespace chunk_namespace, t3.fk_project chunk_namespace_project, t4.fk_project statement_project, t4.is_in_project, t5.pk_entity digital_id, t5.fk_namespace digital_namespace, t1.metadata -FROM - information.statement t1, data.chunk t2, data.namespace t3, projects.info_proj_rel t4, data.digital t5 -WHERE - t1.fk_subject_data = t2.pk_entity - AND t2.fk_namespace = t3.pk_entity - AND t1.pk_entity = t4.fk_entity - AND t5.pk_text = t2.fk_text - AND t2.fk_namespace != t5.fk_namespace; - -DELETE FROM projects.info_proj_rel t1 USING to_delete -WHERE to_delete.info_project_rel_id = t1.pk_entity; - -DELETE FROM information.statement t1 USING to_delete -WHERE to_delete.statement_id = t1.pk_entity; - -DELETE FROM projects.info_proj_rel t1 USING to_delete -WHERE to_delete.info_project_rel_id = t1.pk_entity; - -DELETE FROM data.chunk t1 USING to_delete -WHERE to_delete.chunk_id = t1.pk_entity; - - -/* these can be used to test the result of the migration - --- should be zero -SELECT count(*) -FROM information.statement t1, - data.chunk t2, - data.namespace t3, - projects.info_proj_rel t4, - data.digital t5 -WHERE t1.fk_subject_data = t2.pk_entity -AND t2.fk_namespace = t3.pk_entity -AND t1.pk_entity = t4.fk_entity -AND t5.pk_text = t2.fk_text -AND t2.fk_namespace != t5.fk_namespace; - --- number of chunks, statements and info_project_rels per project wrongly linked to a digital of another namespace --- should be zero -SELECT count(*), t4.fk_project, t1.fk_object_info -FROM information.statement t1, - data.chunk t2, - data.namespace t3, - projects.info_proj_rel t4, - data.digital t5 -WHERE t1.fk_subject_data = t2.pk_entity -AND t2.fk_namespace = t3.pk_entity -AND t1.pk_entity = t4.fk_entity -AND t5.pk_text = t2.fk_text -AND t2.fk_namespace != t5.fk_namespace -GROUP BY (t1.fk_object_info, t4.fk_project) -ORDER BY count(t2.pk_entity) desc; - --- count should be 3 in each project -SELECT count(*), t4.fk_project, t1.fk_object_info -FROM information.statement t1, - data.chunk t2, - data.namespace t3, - projects.info_proj_rel t4, - data.digital t5 -WHERE t1.fk_subject_data = t2.pk_entity -AND t2.fk_namespace = t3.pk_entity -AND t1.pk_entity = t4.fk_entity -AND t5.pk_text = t2.fk_text ---AND t1.fk_object_info = 25442 -AND t2.fk_namespace = t5.fk_namespace -GROUP BY (t1.fk_object_info, t4.fk_project) -ORDER BY count(t2.pk_entity) desc; - - --- Should be 1416 for project 591 -SELECT count(*), t4.fk_project, t1.fk_object_info -FROM information.statement t1, - data.chunk t2, - data.namespace t3, - projects.info_proj_rel t4, - data.digital t5 -WHERE t1.fk_subject_data = t2.pk_entity -AND t2.fk_namespace = t3.pk_entity -AND t1.pk_entity = t4.fk_entity -AND t5.pk_text = t2.fk_text -AND t1.fk_object_info = 774022 -AND t2.fk_namespace = t5.fk_namespace -GROUP BY (t1.fk_object_info, t4.fk_project) -ORDER BY count(t2.pk_entity) desc; - */ diff --git a/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-down.sql b/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-down.sql deleted file mode 100644 index fb3259345..000000000 --- a/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-down.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE commons.text - ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc (quill_doc)); - -ALTER TABLE information.appellation - ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc (quill_doc)); - -ALTER TABLE information.lang_string - ADD CONSTRAINT text_quill_doc_check CHECK (quill_doc IS NULL OR commons.validate_quill_doc (quill_doc)); - diff --git a/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-up.sql b/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-up.sql deleted file mode 100644 index f9457a453..000000000 --- a/server/db-migrate/migrations/sqls/20220312142049-digitals-migrate-definitions-up.sql +++ /dev/null @@ -1,142 +0,0 @@ --- drop quill doc checks, for performance reasons -ALTER TABLE commons.text - DROP CONSTRAINT IF EXISTS text_quill_doc_check; - -ALTER TABLE information.appellation - DROP CONSTRAINT IF EXISTS text_quill_doc_check; - -ALTER TABLE information.lang_string - DROP CONSTRAINT IF EXISTS text_quill_doc_check; - --- select 'has-definition' statements and its language strings -CREATE TEMP TABLE stmt_has_def ON COMMIT DROP AS -SELECT - t1.pk_entity AS pk_statement, t2.pk_entity AS pk_lang_string, t2.quill_doc, t2.fk_language -FROM - information.statement t1, information.lang_string t2 -WHERE - fk_property = 1762 - AND t1.fk_object_info = t2.pk_entity - AND t2.quill_doc IS NOT NULL; - --- for each, create an information.resource of class (Definition) --- and store the pk_entity of the 'has-definition' statement in the metadata -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 899, - '{ "dataApi": true, "toolbox": true, "website": true}', - json_build_object('id', 'digitals', 'created', 'By Jonas Schneider for Digitals', 'hasDefinitionStatement', pk_statement) -FROM - stmt_has_def; - ---SELECT * FROM information.resource ---WHERE metadata->>'id'= 'digitals'; --- create an information.appellation (String) --- and store the pk_entity of the 'has-definition' statement in the metadata -INSERT INTO information.appellation (fk_class, quill_doc, metadata) -SELECT - 339, - quill_doc, - json_build_object('id', 'digitals', 'created', 'By Jonas Schneider for Digitals', 'hasDefinitionStatement', pk_statement) -FROM - stmt_has_def; - -SELECT - * -FROM - information.appellation -WHERE - metadata ->> 'id' = 'digitals'; - -CREATE TEMP TABLE stmt_as_def_and_new_resource ON COMMIT DROP AS -SELECT - t1.*, t2.pk_entity AS pk_definition -FROM - stmt_has_def t1, information.resource t2 -WHERE - t1.pk_statement = (t2.metadata ->> 'hasDefinitionStatement')::int - AND t2.metadata ->> 'id' = 'digitals'; - --- update the statement to the definition -UPDATE - information.statement t1 -SET - fk_object_info = t0.pk_definition, - metadata = json_build_object('id', 'digitals', 'updated', 'By Jonas Schneider for Digitals', 'hasDefinitionStatement', pk_statement) -FROM - stmt_as_def_and_new_resource t0 -WHERE - t0.pk_statement = t1.pk_entity; - --- and the statement to the language -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_definition, - 63, - t1.fk_language, - json_build_object('id', 'digitals', 'created', 'By Jonas Schneider for Digitals', 'hasDefinitionStatement', pk_statement) -FROM - stmt_as_def_and_new_resource t1 -RETURNING - pk_entity; - --- and the statement to the app -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_definition, - 1864, - t2.pk_entity, - json_build_object('id', 'digitals', 'created', 'By Jonas Schneider for Digitals', 'hasDefinitionStatement', pk_statement) -FROM - stmt_as_def_and_new_resource t1, - information.appellation t2 -WHERE - t1.pk_statement = (t2.metadata ->> 'hasDefinitionStatement')::int - AND t2.metadata ->> 'id' = 'digitals'; - -CREATE TEMP TABLE stmt_project_rels ON COMMIT DROP AS -SELECT - t3.pk_entity, fk_project, t1.fk_last_modifier, t1.fk_creator -FROM - projects.info_proj_rel t1, stmt_has_def t2, information.statement t3 -WHERE - t1.fk_entity = t2.pk_statement - AND t1.is_in_project = TRUE - AND t2.pk_statement = (t3.metadata ->> 'hasDefinitionStatement')::int - AND t3.metadata ->> 'id' = 'digitals' - AND t3.metadata ->> 'created' IS NOT NULL; - --- add the statements and the definition to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, is_in_project) -SELECT - pk_entity, - fk_project, - fk_last_modifier, - fk_creator, - TRUE -FROM - stmt_project_rels; - --- add the definitions to the project -CREATE TEMP TABLE resource_project_rels ON COMMIT DROP AS -SELECT - t3.pk_entity, fk_project, t1.fk_last_modifier, t1.fk_creator -FROM - projects.info_proj_rel t1, stmt_has_def t2, information.resource t3 -WHERE - t1.fk_entity = t2.pk_statement - AND t1.is_in_project = TRUE - AND t2.pk_statement = (t3.metadata ->> 'hasDefinitionStatement')::int - AND t3.metadata ->> 'id' = 'digitals' - AND t3.metadata ->> 'created' IS NOT NULL; - -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, is_in_project) -SELECT - pk_entity, - fk_project, - fk_last_modifier, - fk_creator, - TRUE -FROM - resource_project_rels; - diff --git a/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-down.sql b/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-up.sql b/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-up.sql deleted file mode 100644 index 01f3e2b70..000000000 --- a/server/db-migrate/migrations/sqls/20220314141559-digitals-migrate-mentionings-up.sql +++ /dev/null @@ -1,203 +0,0 @@ --- select 'mentions' statements -CREATE TEMP TABLE stmt_mentions ON COMMIT DROP AS -SELECT - t1.pk_entity AS pk_statement, t1.fk_subject_info AS pk_source, t1.fk_object_info AS pk_mentioned_entity -FROM - information.statement t1 -WHERE - t1.fk_property = 1218; - --- create the new resource of class 935, C28 Mentioning --- and store the pk_entity of the 'mentions' statement in the metadata -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 935, - '{ "dataApi": true, "toolbox": true, "website": true}', - json_build_object('id', 'digitals_2', 'created', 'By Jonas Schneider for Digitals', 'mentionsStatement', pk_statement) -FROM - stmt_mentions; - -CREATE TEMP TABLE new_resources ON COMMIT DROP AS -SELECT - *, (metadata ->> 'mentionsStatement')::int AS pk_orig_statement -FROM - information.resource -WHERE - metadata ->> 'id' = 'digitals_2'; - -CREATE TEMP TABLE stmt_mentions_and_new_resource ON COMMIT DROP AS -SELECT - t1.*, t2.pk_entity AS pk_mentioning, t2.pk_orig_statement -FROM - stmt_mentions t1 - INNER JOIN new_resources t2 ON t1.pk_statement = t2.pk_orig_statement; - -SELECT - * -FROM - stmt_mentions_and_new_resource; - --- create C28 Mentioning → geov:P26 mentions (is mentioned in) 1876 → E1 CRM Entity -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_mentioning, - 1876, - t1.pk_mentioned_entity, - json_build_object('id', 'digitals_2', 'created', 'By Jonas Schneider for Digitals', 'mentionsStatement', t1.pk_statement) -FROM - stmt_mentions_and_new_resource t1 -RETURNING - pk_entity; - --- create C28 Mentioning → geov:P27 is mentioned in (mentions) 1877 → E77 Persistent Item -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_mentioning, - 1877, - t1.pk_source, - json_build_object('id', 'digitals_2', 'created', 'By Jonas Schneider for Digitals', 'mentionsStatement', t1.pk_statement) -FROM - stmt_mentions_and_new_resource t1 -RETURNING - pk_entity; - -CREATE TEMP TABLE has_reference_statement ON COMMIT DROP AS -SELECT - t1.pk_entity AS pk_has_reference, t1.fk_object_info AS pk_reference, t2.pk_statement AS pk_mentions_statement, t2.pk_mentioning -FROM - information.statement t1, stmt_mentions_and_new_resource t2 -WHERE - t2.pk_statement = t1.fk_subject_info - AND t1.fk_property_of_property = 1; - --- create C28 Mentioning → geov:P28 at position 1878 → C11 Reference -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_mentioning, - 1878, - t1.pk_reference, - json_build_object('id', 'digitals_2', 'created', 'By Jonas Schneider for Digitals', 'hasReferenceStatement', t1.pk_has_reference) -FROM - has_reference_statement t1 -RETURNING - *; - --- select project relations of mentions statements -CREATE TEMP TABLE mentions_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.pk_statement, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, stmt_mentions t2 -WHERE - t1.fk_entity = t2.pk_statement - AND t1.is_in_project = TRUE; - --- select project relations of reference statements -CREATE TEMP TABLE has_reference_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.pk_has_reference, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, has_reference_statement t2 -WHERE - t1.fk_entity = t2.pk_has_reference - AND t1.is_in_project = TRUE; - -SELECT - * -FROM - has_reference_stmt_project_rels; - --- disable triggers to keep original timestamps -DROP TRIGGER creation_tmsp ON projects.info_proj_rel; - -DROP TRIGGER last_modification_tmsp ON projects.info_proj_rel; - --- create project relations of mentions statements -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - mentions_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'mentionsStatement')::int - AND t1.metadata ->> 'id' = 'digitals_2' - AND t1.metadata ->> 'created' IS NOT NULL -RETURNING - *; - --- create project relations of resources statements -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.resource t1, - mentions_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'mentionsStatement')::int - AND t1.metadata ->> 'id' = 'digitals_2' - AND t1.metadata ->> 'created' IS NOT NULL -RETURNING - *; - --- create project relations of reference statements -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - has_reference_stmt_project_rels t2 -WHERE - t2.pk_has_reference = (t1.metadata ->> 'hasReferenceStatement')::int - AND t1.metadata ->> 'id' = 'digitals_2' - AND t1.metadata ->> 'created' IS NOT NULL -RETURNING - *; - -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - --- REMOVE old statements from all projects -UPDATE - projects.info_proj_rel t1 -SET - is_in_project = FALSE -FROM - mentions_stmt_project_rels t2 -WHERE - t1.pk_entity = t2.pk_proj_rel; - -UPDATE - projects.info_proj_rel t1 -SET - is_in_project = FALSE -FROM - has_reference_stmt_project_rels t2 -WHERE - t1.pk_entity = t2.pk_proj_rel; - diff --git a/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-down.sql b/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-up.sql b/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-up.sql deleted file mode 100644 index 0ff2cf7db..000000000 --- a/server/db-migrate/migrations/sqls/20220315115101-digitals-migrate-texts-up.sql +++ /dev/null @@ -1,194 +0,0 @@ --- drop the index on appellation.string -DROP INDEX information.appellation_string_idx; - --- select the digitals with system type text -CREATE TEMP TABLE texts ON COMMIT DROP AS -SELECT - t1.pk_entity, t1.quill_doc, t1.tmsp_creation, t1.tmsp_last_modification, t1.fk_namespace -FROM - data.digital t1 -WHERE - t1.fk_system_type = 3286; - --- create the resources -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 785, - '{ "dataApi": false, "toolbox": false, "website": false}', - json_build_object('id', 'digitals_3', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', pk_entity) -FROM - texts; - --- create the appellations -INSERT INTO information.appellation (fk_class, quill_doc, metadata) -SELECT - 339, - quill_doc, - json_build_object('id', 'digitals_3', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', pk_entity) -FROM - texts; - --- update the is reproduction of statements -UPDATE - information.statement t1 -SET - metadata = json_build_object('id', 'digitals_3', 'updated', 'By Jonas Schneider for Digitals', 'pkDigital', t1.fk_subject_data), - fk_subject_data = 0, - fk_subject_info = t2.pk_entity -FROM - information.resource t2 -WHERE - t1.fk_subject_data = (t2.metadata ->> 'pkDigital')::int - AND (t2.metadata ->> 'id') = 'digitals_3' - AND t1.fk_property = 1216; - --- select the digital_vt with system type text -CREATE TEMP TABLE old_texts ON COMMIT DROP AS -SELECT - t1.pk_entity, t1.quill_doc, t1.tmsp_creation, t1.tmsp_last_modification -FROM - data.digital_vt t1 -WHERE - t1.fk_system_type = 3286 -ORDER BY - pk_entity, entity_version ASC; - --- disable triggers to keep original timestamps -DROP TRIGGER creation_tmsp ON information.statement; - -DROP TRIGGER last_modification_tmsp ON information.statement; - --- create the has value version statements for digital_vt (no adding to project) in chronological order -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, tmsp_creation, tmsp_last_modification, metadata) -SELECT - t2.pk_entity, - 1864, - t3.pk_entity, - t1.tmsp_creation, - t1.tmsp_last_modification, - json_build_object('id', 'digitals_3', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', t1.pk_entity, 'fromVersionTable', TRUE) -FROM - old_texts t1, - information.resource t2, - information.appellation t3 -WHERE - t1.pk_entity = (t2.metadata ->> 'pkDigital')::int - AND t2.metadata ->> 'id' = 'digitals_3' - AND t1.pk_entity = (t3.metadata ->> 'pkDigital')::int - AND t3.metadata ->> 'id' = 'digitals_3' -RETURNING - *; - --- create the has value version statements for digitals -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, tmsp_creation, tmsp_last_modification, metadata) -SELECT - t2.pk_entity, - 1864, - t3.pk_entity, - t1.tmsp_creation, - t1.tmsp_last_modification, - json_build_object('id', 'digitals_3', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', t1.pk_entity, 'fromVersionTable', FALSE) -FROM - texts t1, - information.resource t2, - information.appellation t3 -WHERE - t1.pk_entity = (t2.metadata ->> 'pkDigital')::int - AND t2.metadata ->> 'id' = 'digitals_3' - AND t1.pk_entity = (t3.metadata ->> 'pkDigital')::int - AND t3.metadata ->> 'id' = 'digitals_3' -RETURNING - *; - --- select the project relations of the has reproduction statements -CREATE TEMP TABLE has_repro_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.metadata ->> 'pkDigital' pk_digital, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, information.statement t2 -WHERE - t1.fk_entity = t2.pk_entity - AND t1.is_in_project = TRUE - AND t2.metadata ->> 'id' = 'digitals_3' - AND t2.metadata ->> 'updated' IS NOT NULL - AND t2.fk_property = 1216; - -DROP TRIGGER creation_tmsp ON projects.info_proj_rel; - -DROP TRIGGER last_modification_tmsp ON projects.info_proj_rel; - --- add the has value version statements, not coming from version table, to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - has_repro_stmt_project_rels t2 -WHERE (t1.metadata ->> 'fromVersionTable')::boolean = FALSE - AND t1.metadata ->> 'id' = 'digitals_3' - AND t1.metadata ->> 'pkDigital' = t2.pk_digital -RETURNING - *; - --- add the resources to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.resource t1, - has_repro_stmt_project_rels t2 -WHERE - t1.metadata ->> 'id' = 'digitals_3' - AND t1.metadata ->> 'pkDigital' = t2.pk_digital; - --- add entity label config for texts -DELETE FROM projects.entity_label_config -WHERE fk_project = 375669 - AND fk_class = 785; - -INSERT INTO projects.entity_label_config (fk_project, fk_class, config) - VALUES (375669, 785, '{ - "labelParts": [ - { - "field": { - "fkProperty": 1761, - "isOutgoing": true, - "nrOfStatementsInLabel": 1 - }, - "ordNum": 0 - } - ] -}'); - -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON information.statement - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON information.statement - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - diff --git a/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-down.sql b/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-up.sql b/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-up.sql deleted file mode 100644 index ecf417f6a..000000000 --- a/server/db-migrate/migrations/sqls/20220315131122-digitals-text-add-short-title-up.sql +++ /dev/null @@ -1,59 +0,0 @@ --- select texts and entity labels and default language of project -CREATE TEMP TABLE text_labels ON COMMIT DROP AS -SELECT - t1.pk_entity, t3.entity_label, t5.fk_language, (t1.metadata ->> 'pkDigital')::int pk_digital, t4.fk_project -FROM - information.resource t1, information.statement t2, war.entity_preview t3, projects.info_proj_rel t4, projects.project t5 -WHERE - t1.metadata ->> 'id' = 'digitals_3' - AND t2.fk_subject_info = t1.pk_entity - AND t2.fk_property = 1216 - AND t3.pk_entity = t2.fk_object_info - AND t1.pk_entity = t4.fk_entity - AND t4.is_in_project = TRUE - AND t5.pk_entity = t4.fk_project - AND t3.fk_project = t4.fk_project; - --- create lang strings -INSERT INTO information.lang_string (fk_class, string, fk_language) -SELECT DISTINCT - 784, - entity_label, - fk_language -FROM - text_labels -ON CONFLICT - DO NOTHING; - --- create statements -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_entity, - 1761, - t2.pk_entity, - json_build_object('id', 'digitals_4', 'created', 'By Jonas Schneider for Digitals', 'fkProject', t1.fk_project) -FROM - text_labels t1, - information.lang_string t2 -WHERE - t1.entity_label = t2.string - AND t1.fk_language = t2.fk_language - AND t2.fk_class = 784 -RETURNING - *; - --- add to projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, is_in_project) -SELECT - t1.pk_entity, - (t1.metadata ->> 'fkProject')::int, - 7, - 7, - TRUE -FROM - information.statement t1 -WHERE - t1.metadata ->> 'id' = 'digitals_4' -RETURNING - *; - diff --git a/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-down.sql b/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-up.sql b/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-up.sql deleted file mode 100644 index 2f8e5a0db..000000000 --- a/server/db-migrate/migrations/sqls/20220316083216-digitals-text-cleanup-up.sql +++ /dev/null @@ -1,3 +0,0 @@ -DELETE FROM data.digital t1 -WHERE t1.fk_system_type = 3286; - diff --git a/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-down.sql b/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-up.sql b/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-up.sql deleted file mode 100644 index aabde2cfe..000000000 --- a/server/db-migrate/migrations/sqls/20220316091135-digitals-migrate-annotations-in-text-up.sql +++ /dev/null @@ -1,160 +0,0 @@ --- select 'refersto' statements (v2) -CREATE TEMP TABLE stmt_refersto ON COMMIT DROP AS -SELECT - t1.pk_entity AS pk_statement, t1.fk_subject_data AS pk_spot, -- chunk - t2.quill_doc, -- chunk - t1.fk_object_info AS pk_referred_entity, -- entity, the stmt refers to - t4.pk_entity AS pk_text -- entity (Text), of which the spot is part of -FROM - information.statement t1, data.chunk t2, ( SELECT DISTINCT - pk_text, pk_entity - FROM - data.digital_vt) AS t3, information.resource t4 -WHERE - t1.fk_property = 1334 - AND t1.fk_subject_data = t2.pk_entity - AND t2.fk_text = t3.pk_text - AND t3.pk_entity = (t4.metadata ->> 'pkDigital')::int; - --- For each stmt_refersto we create a new information.appellation of class Chunk 456 -INSERT INTO information.appellation (fk_class, quill_doc, metadata) -SELECT - 456, - quill_doc, - json_build_object('id', 'digitals_5', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', pk_statement, 'pkChunk', pk_spot) -FROM - stmt_refersto; - --- For each stmt_refersto, we create a new information.resource of class Annotation in Text 933 -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 933, - '{ "dataApi": false, "toolbox": false, "website": false}', - json_build_object('id', 'digitals_5', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', pk_statement) -FROM - stmt_refersto; - -CREATE TEMP TABLE stmt_refersto_and_new_resource ON COMMIT DROP AS -SELECT - t1.*, t2.pk_entity AS pk_annotation_in_text -FROM - stmt_refersto t1, information.resource t2 -WHERE - t1.pk_statement = (t2.metadata ->> 'refersToStmt')::int - AND t2.metadata ->> 'id' = 'digitals_5'; - -CREATE TEMP TABLE stmt_refersto_and_new_chunk ON COMMIT DROP AS -SELECT - t1.*, t2.pk_entity AS pk_appellation_chunk -FROM - stmt_refersto_and_new_resource t1, information.appellation t2 -WHERE - t1.pk_statement = (t2.metadata ->> 'refersToStmt')::int - AND t2.metadata ->> 'id' = 'digitals_5'; - --- For each stmt_refersto, we create a new information.statement --- C26 Annotation in Text > P23 is annotated in (has annotation) 1872 > geov:C16 Text -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_annotation_in_text, - 1872, - t1.pk_text, - json_build_object('id', 'digitals_5', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_resource t1; - --- For each stmt_refersto, we create a new information.statement --- C26 Annotation in Text P24 at position (is spot of) 1874 geov:C2 Chunk -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_annotation_in_text, - 1874, - t1.pk_appellation_chunk, - json_build_object('id', 'digitals_5', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_chunk t1; - --- For each stmt_refersto, we create a new information.statement --- C26 Annotation in Text P25 annotated entity (is annotated by) 1875 crm:E1 CRM Entity -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_annotation_in_text, - 1875, - t1.pk_referred_entity, - json_build_object('id', 'digitals_5', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_resource t1; - -------- project relations -------- --- disable triggers to keep original timestamps -DROP TRIGGER creation_tmsp ON projects.info_proj_rel; - -DROP TRIGGER last_modification_tmsp ON projects.info_proj_rel; - --- select project relations of original statements -CREATE TEMP TABLE refersto_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.pk_statement, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, stmt_refersto t2 -WHERE - t1.fk_entity = t2.pk_statement - AND t1.is_in_project = TRUE; - --- add the new statements to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - refersto_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'refersToStmt')::int - AND t1.metadata ->> 'id' = 'digitals_5' - AND t1.metadata ->> 'created' IS NOT NULL; - --- add the new entity to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.resource t1, - refersto_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'refersToStmt')::int - AND t1.metadata ->> 'id' = 'digitals_5' - AND t1.metadata ->> 'created' IS NOT NULL; - --- enable the triggers again -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - --- remove the original statement from all projects -UPDATE - projects.info_proj_rel t1 -SET - is_in_project = FALSE -FROM - refersto_stmt_project_rels t2 -WHERE - t1.pk_entity = t2.pk_proj_rel; - diff --git a/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-down.sql b/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-up.sql b/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-up.sql deleted file mode 100644 index a85df7c6a..000000000 --- a/server/db-migrate/migrations/sqls/20220316102431-digitals-migrate-tables-up.sql +++ /dev/null @@ -1,133 +0,0 @@ --- select the digitals with system type table -CREATE TEMP TABLE tables ON COMMIT DROP AS -SELECT - t1.pk_entity, t1.tmsp_creation, t1.tmsp_last_modification, t1.fk_namespace -FROM - data.digital t1 -WHERE - t1.fk_system_type = 3287; - --- create the resources of class C18 Table 898 -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 898, - '{ "dataApi": false, "toolbox": false, "website": false}', - json_build_object('id', 'digitals_6', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', pk_entity) -FROM - tables; - --- update the is reproduction of statements --- C18 Table → P1 is reproduction of (has reproduction) 1216 → expression/portion --- To obtain this, the existing statement is updated: --- the subject from the data.digital (fk_subject_data) now points to the new Text entity (fk_subject_info). -UPDATE - information.statement t1 -SET - metadata = json_build_object('id', 'digitals_6', 'updated', 'By Jonas Schneider for Digitals', 'pkDigital', t1.fk_subject_data), - fk_subject_data = 0, - fk_subject_info = t2.pk_entity -FROM - information.resource t2 -WHERE - t1.fk_subject_data = (t2.metadata ->> 'pkDigital')::int - AND (t2.metadata ->> 'id') = 'digitals_6' - AND t1.fk_property = 1216; - --- create the has value statements for digitals ---C18 Table → P29 has value (is value of) 1879 -> geov:C29 Table Value --- The fk_object_data points to the data.digital (pk_entity) -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_data, metadata) -SELECT - t2.pk_entity, -- the new entity C28 Table - 1879, - t1.pk_entity, -- the digital (now acting as geov:C29 Table Value) - json_build_object('id', 'digitals_6', 'created', 'By Jonas Schneider for Digitals', 'pkDigital', t1.pk_entity) -FROM - tables t1, - information.resource t2 -WHERE - t1.pk_entity = (t2.metadata ->> 'pkDigital')::int - AND t2.metadata ->> 'id' = 'digitals_6'; - --- select the project relations of the has reproduction statements -CREATE TEMP TABLE has_repro_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.metadata ->> 'pkDigital' pk_digital, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, information.statement t2 -WHERE - t1.fk_entity = t2.pk_entity - AND t1.is_in_project = TRUE - AND t2.metadata ->> 'id' = 'digitals_6' - AND t2.metadata ->> 'updated' IS NOT NULL - AND t2.fk_property = 1216; - -DROP TRIGGER creation_tmsp ON projects.info_proj_rel; - -DROP TRIGGER last_modification_tmsp ON projects.info_proj_rel; - --- add the has value statements to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - has_repro_stmt_project_rels t2 -WHERE - t1.metadata ->> 'id' = 'digitals_6' - AND t1.metadata ->> 'pkDigital' = t2.pk_digital - AND t1.fk_property = 1879; - --- add the resources to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.resource t1, - has_repro_stmt_project_rels t2 -WHERE - t1.metadata ->> 'id' = 'digitals_6' - AND t1.metadata ->> 'pkDigital' = t2.pk_digital; - --- add entity label config for tables -DELETE FROM projects.entity_label_config -WHERE fk_project = 375669 - AND fk_class = 898; - -INSERT INTO projects.entity_label_config (fk_project, fk_class, config) - VALUES (375669, 898, '{ - "labelParts": [ - { - "field": { - "fkProperty": 1761, - "isOutgoing": true, - "nrOfStatementsInLabel": 1 - }, - "ordNum": 0 - } - ] -}'); - --- add the triggers again -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - diff --git a/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-down.sql b/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-up.sql b/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-up.sql deleted file mode 100644 index a0ae881bc..000000000 --- a/server/db-migrate/migrations/sqls/20220316105300-digitas-table-add-short-title-up.sql +++ /dev/null @@ -1,55 +0,0 @@ --- select tables and entity labels and default language of project -CREATE TEMP TABLE table_labels ON COMMIT DROP AS -SELECT - t1.pk_entity, t3.entity_label, t5.fk_language, (t1.metadata ->> 'pkDigital')::int pk_digital, t4.fk_project -FROM - information.resource t1, information.statement t2, war.entity_preview t3, projects.info_proj_rel t4, projects.project t5 -WHERE - t1.metadata ->> 'id' = 'digitals_6' - AND t2.fk_subject_info = t1.pk_entity - AND t2.fk_property = 1216 - AND t3.pk_entity = t2.fk_object_info - AND t1.pk_entity = t4.fk_entity - AND t4.is_in_project = TRUE - AND t5.pk_entity = t4.fk_project - AND t3.fk_project = t4.fk_project; - --- create lang strings -INSERT INTO information.lang_string (fk_class, string, fk_language) -SELECT DISTINCT - 784, - entity_label, - fk_language -FROM - table_labels -ON CONFLICT - DO NOTHING; - --- create statements -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_entity, - 1761, - t2.pk_entity, - json_build_object('id', 'digitals_7', 'created', 'By Jonas Schneider for Digitals', 'fkProject', t1.fk_project) -FROM - table_labels t1, - information.lang_string t2 -WHERE - t1.entity_label = t2.string - AND t1.fk_language = t2.fk_language - AND t2.fk_class = 784; - --- add to projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, is_in_project) -SELECT - t1.pk_entity, - (t1.metadata ->> 'fkProject')::int, - 7, - 7, - TRUE -FROM - information.statement t1 -WHERE - t1.metadata ->> 'id' = 'digitals_7'; - diff --git a/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-down.sql b/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-up.sql b/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-up.sql deleted file mode 100644 index 87428870e..000000000 --- a/server/db-migrate/migrations/sqls/20220316105615-digitals-migrate-annotations-in-table-up.sql +++ /dev/null @@ -1,137 +0,0 @@ --- select 'refersto' statements -CREATE TEMP TABLE stmt_refersto ON COMMIT DROP AS -SELECT - t1.pk_entity AS pk_statement, t1.fk_subject_tables_cell AS pk_spot, -- cell - t1.fk_object_info AS pk_referred_entity, -- entity, the stmt refers to - t3.pk_entity AS pk_table -- entity (Table), of which the spot is part of -FROM - information.statement t1, tables.cell t2, information.resource t3 -WHERE - t1.fk_property = 1334 - AND t1.fk_subject_tables_cell = t2.pk_cell - AND t2.fk_digital = (t3.metadata ->> 'pkDigital')::int; - --- For each cell -> refers to statement, we create a new information.resource of class Annotation in Table 934 -INSERT INTO information.resource (fk_class, community_visibility, metadata) -SELECT - 934, - '{ "dataApi": false, "toolbox": false, "website": false}', - json_build_object('id', 'digitals_8', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', pk_statement) -FROM - stmt_refersto; - -CREATE TEMP TABLE stmt_refersto_and_new_resource ON COMMIT DROP AS -SELECT - t1.*, t2.pk_entity AS pk_annotation_in_table -FROM - stmt_refersto t1, information.resource t2 -WHERE - t1.pk_statement = (t2.metadata ->> 'refersToStmt')::int - AND t2.metadata ->> 'id' = 'digitals_8'; - --- For each stmt_refersto, we create a new information.statement --- C27 Annotation in Table > P23 is annotated in (has annotation) 1872 > geov:C18 Table -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_annotation_in_table, - 1872, - t1.pk_table, - json_build_object('id', 'digitals_8', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_resource t1; - --- For each stmt_refersto, we create a new information.statement --- C27 Annotation in Table > P24 at position (is spot of) 1874 > geov:C7 Cell -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_tables_cell, metadata) -SELECT - t1.pk_annotation_in_table, - 1874, - t1.pk_spot, - json_build_object('id', 'digitals_8', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_resource t1; - --- For each stmt_refersto, we create a new information.statement --- C27 Annotation in Table > P25 annotated entity (is annotated by) 1875 > crm:E1 CRM Entity -INSERT INTO information.statement (fk_subject_info, fk_property, fk_object_info, metadata) -SELECT - t1.pk_annotation_in_table, - 1875, - t1.pk_referred_entity, - json_build_object('id', 'digitals_8', 'created', 'By Jonas Schneider for Digitals', 'refersToStmt', t1.pk_statement) -FROM - stmt_refersto_and_new_resource t1; - -------- project relations -------- --- disable triggers to keep original timestamps -DROP TRIGGER creation_tmsp ON projects.info_proj_rel; - -DROP TRIGGER last_modification_tmsp ON projects.info_proj_rel; - --- select project relations of original statements -CREATE TEMP TABLE refersto_stmt_project_rels ON COMMIT DROP AS -SELECT - t2.pk_statement, t1.fk_project, t1.fk_last_modifier, t1.fk_creator, t1.tmsp_last_modification, t1.tmsp_creation, t1.pk_entity AS pk_proj_rel -FROM - projects.info_proj_rel t1, stmt_refersto t2 -WHERE - t1.fk_entity = t2.pk_statement - AND t1.is_in_project = TRUE; - --- add the new statements to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.statement t1, - refersto_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'refersToStmt')::int - AND t1.metadata ->> 'id' = 'digitals_8' - AND t1.metadata ->> 'created' IS NOT NULL; - --- add the new entity to the projects -INSERT INTO projects.info_proj_rel (fk_entity, fk_project, fk_last_modifier, fk_creator, tmsp_last_modification, tmsp_creation, is_in_project) -SELECT - t1.pk_entity, - t2.fk_project, - t2.fk_last_modifier, - t2.fk_creator, - t2.tmsp_last_modification, - t2.tmsp_creation, - TRUE -FROM - information.resource t1, - refersto_stmt_project_rels t2 -WHERE - t2.pk_statement = (t1.metadata ->> 'refersToStmt')::int - AND t1.metadata ->> 'id' = 'digitals_8' - AND t1.metadata ->> 'created' IS NOT NULL; - --- enable the triggers again -CREATE TRIGGER creation_tmsp - BEFORE INSERT ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_creation (); - -CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE ON projects.info_proj_rel - FOR EACH ROW - EXECUTE PROCEDURE commons.tmsp_last_modification (); - --- remove the original statement from all projects -UPDATE - projects.info_proj_rel t1 -SET - is_in_project = FALSE -FROM - refersto_stmt_project_rels t2 -WHERE - t1.pk_entity = t2.pk_proj_rel; - diff --git a/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-down.sql b/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-up.sql b/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-up.sql deleted file mode 100644 index 963f651f7..000000000 --- a/server/db-migrate/migrations/sqls/20220316112234-digitals-update-ord-num-up.sql +++ /dev/null @@ -1,15 +0,0 @@ -/* Replace with your SQL commands */ -UPDATE - projects.info_proj_rel -SET - ord_num_of_range = ord_num_of_range + 1 -WHERE - ord_num_of_range IS NOT NULL; - -UPDATE - projects.info_proj_rel -SET - ord_num_of_domain = ord_num_of_domain + 1 -WHERE - ord_num_of_domain IS NOT NULL; - diff --git a/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-down.sql b/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-down.sql deleted file mode 100644 index ddb9c9d85..000000000 --- a/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TRIGGER notify_modification ON system.config; - diff --git a/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-up.sql b/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-up.sql deleted file mode 100644 index bd8e93e08..000000000 --- a/server/db-migrate/migrations/sqls/20220323190916-sys-t-config-add-notify-trigger-up.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TRIGGER notify_modification - AFTER INSERT OR DELETE OR UPDATE ON system.config - FOR EACH STATEMENT - EXECUTE PROCEDURE commons.notify_modification_trigger (); - diff --git a/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-down.sql b/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-up.sql b/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-up.sql deleted file mode 100644 index 72e006adf..000000000 --- a/server/db-migrate/migrations/sqls/20220408133506-inf-migrate-property-is-about-up.sql +++ /dev/null @@ -1,7 +0,0 @@ -UPDATE - information.statement -SET - fk_property = 1889 -WHERE - fk_property = 117; - diff --git a/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-down.sql b/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-down.sql deleted file mode 100644 index 844e0105d..000000000 --- a/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX war.entity_preview_full_text; - diff --git a/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-up.sql b/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-up.sql deleted file mode 100644 index 21c9ffccd..000000000 --- a/server/db-migrate/migrations/sqls/20220420113713-war-t-entity-preview-add-gin-index-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE INDEX entity_preview_full_text ON war.entity_preview USING GIN (ts_vector); - diff --git a/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-down.sql b/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-down.sql deleted file mode 100644 index 266f06b73..000000000 --- a/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX information.statement_fk_object_tables_cell_idx; - diff --git a/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-up.sql b/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-up.sql deleted file mode 100644 index 30a00ba3d..000000000 --- a/server/db-migrate/migrations/sqls/20220427111358-inf-t-statement-add-idx-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE INDEX statement_fk_object_tables_cell_idx ON information.statement USING btree (fk_object_tables_cell ASC NULLS LAST); - diff --git a/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-down.sql b/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-up.sql b/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-up.sql deleted file mode 100644 index 298c21608..000000000 --- a/server/db-migrate/migrations/sqls/20220427114007-pro-inf-proj-rel-add-ordnum-for-content-tree-up.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* Replace with your SQL commands */ -WITH tw0 AS ( - SELECT - t2.pk_entity pk_info_proj_rel, - ROW_NUMBER() OVER (PARTITION BY t1.fk_object_info, - t2.fk_project ORDER BY t2.ord_num_of_domain ASC, - t1.pk_entity ASC) - FROM information.statement t1, - projects.info_proj_rel t2 - WHERE t2.fk_entity = t1.pk_entity - AND t1.fk_property = 1317) -UPDATE - projects.info_proj_rel t1 -SET - ord_num_of_domain = tw0.ROW_NUMBER -FROM - tw0 -WHERE - tw0.pk_info_proj_rel = pk_entity; - diff --git a/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-down.sql b/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-down.sql deleted file mode 100644 index 9cee213a3..000000000 --- a/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-down.sql +++ /dev/null @@ -1,285 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.clone_project (pk_project integer, project_label text, project_description text) - RETURNS integer - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - SELECT - fk_language INTO fk_project_default_language - FROM - projects.project - WHERE - pk_entity = pk_project; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, calendar, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.calendar, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.digital t2 - WHERE - t1.fk_project = pk_project - AND t1.pk_entity = t2.fk_namespace; - - /* - * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new digital's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.digital t3 - WHERE - fk_project = pk_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 AS fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - WHERE - t1.fk_project = pk_project - AND t1.pk_entity = t2.fk_namespace - AND t3.pk_text = t2.fk_text - AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new chunk's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.chunk t3 - WHERE - t1.fk_project = pk_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the statements pointing to data to the new project - */ - INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) - SELECT - t1.pk_entity AS fk_entity, - pk_new_project AS fk_project, - TRUE AS is_in_project - FROM - information.statement t1, - data.entity t2 - WHERE - t1.fk_subject_data = t2.pk_entity - AND t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, first_second, last_second, tmsp_last_modification) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - first_second, - last_second, - tmsp_last_modification - FROM - war.entity_preview - WHERE - fk_project = pk_project - ON CONFLICT ON CONSTRAINT war_entity_preview_unique - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_project; - RETURN pk_new_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-up.sql b/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-up.sql deleted file mode 100644 index 04619af8d..000000000 --- a/server/db-migrate/migrations/sqls/20220824080013-com-f-clone-project-fix-up.sql +++ /dev/null @@ -1,284 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.clone_project (pk_project integer, project_label text, project_description text) - RETURNS integer - LANGUAGE 'plpgsql' - COST 100 VOLATILE - AS $BODY$ -DECLARE - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - SELECT - fk_language INTO fk_project_default_language - FROM - projects.project - WHERE - pk_entity = pk_project; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * copy digitals from sandbox namespace to project's namespace, keeping track of the original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.digital (fk_namespace, fk_system_type, quill_doc, metadata) - -- Select all digitals of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.fk_system_type, - t2.quill_doc, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.digital t2 - WHERE - t1.fk_project = pk_project - AND t1.pk_entity = t2.fk_namespace; - - /* - * copy statements pointing to digitals, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new digital's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new digital - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.digital t3 - WHERE - fk_project = pk_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - - /* - * copy chunks from sandbox namespace to project's namespace, keeping track of original pk_entity (in metadata, fk_cloned_from) - */ - INSERT INTO data.chunk (fk_namespace, quill_doc, fk_text, fk_entity_version, metadata) - -- Select all chunks of sandbox project - SELECT - pk_new_default_namespace AS fk_namespace, - t2.quill_doc, - t4.pk_text, - 1 AS fk_entity_version, - jsonb_build_object('fk_cloned_from', t2.pk_entity) - FROM - data.namespace t1, - data.chunk t2, - data.digital t3, - data.digital t4 - WHERE - t1.fk_project = pk_project - AND t1.pk_entity = t2.fk_namespace - AND t3.pk_text = t2.fk_text - AND (t4.metadata ->> 'fk_cloned_from')::int = t3.pk_entity; - - /* - * copy statements pointing to chunks, using the pk_entity of the above created, where fk_cloned_from - * and add them to the project - */ - INSERT INTO information.statement (fk_subject_info, fk_subject_data, fk_subject_tables_cell, fk_subject_tables_row, fk_property, fk_property_of_property, fk_object_info, fk_object_data, fk_object_tables_cell, fk_object_tables_row, metadata) - -- select statements pointing to the new chunk's fk_cloned_from - SELECT - coalesce(t2.fk_subject_info, 0), - t3.pk_entity AS fk_subject_data, -- pk of new chunk - coalesce(t2.fk_subject_tables_cell, 0), - coalesce(t2.fk_subject_tables_row, 0), - coalesce(t2.fk_property, 0), - coalesce(t2.fk_property_of_property, 0), - coalesce(t2.fk_object_info, 0), - coalesce(t2.fk_object_data, 0), - coalesce(t2.fk_object_tables_cell, 0), - coalesce(t2.fk_object_tables_row, 0), - jsonb_build_object('fk_cloned_from', t2.pk_entity) -- keep track of original entity_asssociacion - FROM - projects.info_proj_rel t1, - information.statement t2, - data.chunk t3 - WHERE - t1.fk_project = pk_project - AND t1.is_in_project = TRUE - AND t1.fk_entity = t2.pk_entity - AND t2.fk_subject_data = (t3.metadata ->> 'fk_cloned_from')::int - AND t3.fk_namespace = pk_new_default_namespace; - -- make sure this is a chunk of this new project's namespace - /* - * Add the statements pointing to data to the new project - */ - INSERT INTO projects.info_proj_rel (fk_entity, fk_project, is_in_project) - SELECT - t1.pk_entity AS fk_entity, - pk_new_project AS fk_project, - TRUE AS is_in_project - FROM - information.statement t1, - data.entity t2 - WHERE - t1.fk_subject_data = t2.pk_entity - AND t2.fk_namespace = pk_new_default_namespace; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, first_second, last_second, tmsp_last_modification) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - first_second, - last_second, - tmsp_last_modification - FROM - war.entity_preview - WHERE - fk_project = pk_project - ON CONFLICT ON CONSTRAINT war_entity_preview_unique - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_project; - RETURN pk_new_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-down.sql b/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-down.sql deleted file mode 100644 index 51706b9be..000000000 --- a/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-down.sql +++ /dev/null @@ -1,186 +0,0 @@ -ALTER TABLE IF EXISTS "data"."avatar" - DROP CONSTRAINT IF EXISTS avatar_pkey; - -ALTER TABLE IF EXISTS "data"."chunk" - DROP CONSTRAINT IF EXISTS chunk_pkey; - -ALTER TABLE IF EXISTS "data"."class_column_mapping" - DROP CONSTRAINT IF EXISTS class_column_mapping_pkey; - -ALTER TABLE IF EXISTS "data"."column" - DROP CONSTRAINT IF EXISTS column_pkey; - -ALTER TABLE IF EXISTS "data"."data_association" - DROP CONSTRAINT IF EXISTS data_association_pkey; - -ALTER TABLE IF EXISTS "data"."data_association_mapping" - DROP CONSTRAINT IF EXISTS data_association_mapping_pkey; - -ALTER TABLE IF EXISTS "data"."digital" - DROP CONSTRAINT IF EXISTS digital_pkey; - -ALTER TABLE IF EXISTS "data"."factoid" - DROP CONSTRAINT IF EXISTS factoid_pkey; - -ALTER TABLE IF EXISTS "data"."factoid_mapping" - DROP CONSTRAINT IF EXISTS factoid_mapping_pkey; - -ALTER TABLE IF EXISTS "data"."factoid_property_mapping" - DROP CONSTRAINT IF EXISTS factoid_property_mapping_pkey; - -ALTER TABLE IF EXISTS "data"."factoid_role" - DROP CONSTRAINT IF EXISTS factoid_role_pkey; - -ALTER TABLE IF EXISTS "data"."namespace" - DROP CONSTRAINT IF EXISTS namespace_pkey; - -ALTER TABLE IF EXISTS "data"."property_of_property" - DROP CONSTRAINT IF EXISTS property_of_property_pkey; - -ALTER TABLE IF EXISTS "data"."property_of_property_mapping" - DROP CONSTRAINT IF EXISTS property_of_property_mapping_pkey; - -ALTER TABLE IF EXISTS "data"."text_property" - DROP CONSTRAINT IF EXISTS text_property_pkey; - -ALTER TABLE IF EXISTS "data"."values_association" - DROP CONSTRAINT IF EXISTS values_association_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."api_class" - DROP CONSTRAINT IF EXISTS api_class_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."api_profile" - DROP CONSTRAINT IF EXISTS api_profile_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."api_property" - DROP CONSTRAINT IF EXISTS api_property_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."associates_system_type_deprecated" - DROP CONSTRAINT IF EXISTS associates_system_type_deprecated_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."class_profile_view_deprecated" - DROP CONSTRAINT IF EXISTS class_profile_view_deprecated_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."label_deprecated" - DROP CONSTRAINT IF EXISTS label_deprecated_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."property_of_property" - DROP CONSTRAINT IF EXISTS property_of_property_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."property_profile_view_deprecated" - DROP CONSTRAINT IF EXISTS property_profile_view_deprecated_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."system_type_deprecated" - DROP CONSTRAINT IF EXISTS system_type_deprecated_pkey; - -ALTER TABLE IF EXISTS "data_for_history"."text_property_deprecated" - DROP CONSTRAINT IF EXISTS text_property_deprecated_pkey; - -ALTER TABLE IF EXISTS "information"."_backup_entity_association" - DROP CONSTRAINT IF EXISTS _backup_entity_association_pkey; - -ALTER TABLE IF EXISTS "information"."appellation" - DROP CONSTRAINT IF EXISTS appellation_pkey; - -ALTER TABLE IF EXISTS "information"."dimension" - DROP CONSTRAINT IF EXISTS dimension_pkey; - -ALTER TABLE IF EXISTS "information"."lang_string" - DROP CONSTRAINT IF EXISTS lang_string_pkey; - -ALTER TABLE IF EXISTS "information"."persistent_item_backup" - DROP CONSTRAINT IF EXISTS persistent_item_backup_pkey; - -ALTER TABLE IF EXISTS "information"."place" - DROP CONSTRAINT IF EXISTS place_pkey; - -ALTER TABLE IF EXISTS "information"."resource" - DROP CONSTRAINT IF EXISTS resource_pkey; - -ALTER TABLE IF EXISTS "information"."statement" - DROP CONSTRAINT IF EXISTS statement_pkey; - -ALTER TABLE IF EXISTS "information"."temporal_entity_backup" - DROP CONSTRAINT IF EXISTS temporal_entity_backup_pkey; - -ALTER TABLE IF EXISTS "information"."text_property" - DROP CONSTRAINT IF EXISTS text_property_pkey; - -ALTER TABLE IF EXISTS "information"."time_primitive" - DROP CONSTRAINT IF EXISTS time_primitive_pkey; - -ALTER TABLE IF EXISTS "projects"."_backup_class_field_config" - DROP CONSTRAINT IF EXISTS _backup_class_field_config_pkey; - -ALTER TABLE IF EXISTS "projects"."analysis" - DROP CONSTRAINT IF EXISTS analysis_pkey; - -ALTER TABLE IF EXISTS "projects"."argument" - DROP CONSTRAINT IF EXISTS argument_pkey; - -ALTER TABLE IF EXISTS "projects"."class_field_config" - DROP CONSTRAINT IF EXISTS class_field_config_pkey; - -ALTER TABLE IF EXISTS "projects"."dfh_profile_proj_rel" - DROP CONSTRAINT IF EXISTS dfh_profile_proj_rel_pkey; - -ALTER TABLE IF EXISTS "projects"."entity_label_config" - DROP CONSTRAINT IF EXISTS entity_label_config_pkey; - -ALTER TABLE IF EXISTS "projects"."info_proj_rel" - DROP CONSTRAINT IF EXISTS info_proj_rel_pkey; - -ALTER TABLE IF EXISTS "projects"."project" - DROP CONSTRAINT IF EXISTS project_pkey; - -ALTER TABLE IF EXISTS "projects"."property_label_deprecated" - DROP CONSTRAINT IF EXISTS property_label_deprecated_pkey; - -ALTER TABLE IF EXISTS "projects"."query" - DROP CONSTRAINT IF EXISTS query_pkey; - -ALTER TABLE IF EXISTS "projects"."table_config" - DROP CONSTRAINT IF EXISTS table_config_pkey; - -ALTER TABLE IF EXISTS "projects"."text_property" - DROP CONSTRAINT IF EXISTS text_property_pkey; - -ALTER TABLE IF EXISTS "projects"."visual" - DROP CONSTRAINT IF EXISTS visual_pkey; - -ALTER TABLE IF EXISTS "system"."analysis_type_deprecated" - DROP CONSTRAINT IF EXISTS analysis_type_deprecated_pkey; - -ALTER TABLE IF EXISTS "system"."app_context" - DROP CONSTRAINT IF EXISTS app_context_pkey; - -ALTER TABLE IF EXISTS "system"."class_field" - DROP CONSTRAINT IF EXISTS class_field_pkey; - -ALTER TABLE IF EXISTS "system"."class_field_property_rel" - DROP CONSTRAINT IF EXISTS class_field_property_rel_pkey; - -ALTER TABLE IF EXISTS "system"."class_has_type_property" - DROP CONSTRAINT IF EXISTS class_has_type_property_pkey; - -ALTER TABLE IF EXISTS "system"."config" - DROP CONSTRAINT IF EXISTS config_pkey; - -ALTER TABLE IF EXISTS "system"."system_relevant_class" - DROP CONSTRAINT IF EXISTS system_relevant_class_pkey; - -ALTER TABLE IF EXISTS "system"."system_relevant_type" - DROP CONSTRAINT IF EXISTS system_relevant_type_pkey; - -ALTER TABLE IF EXISTS "system"."system_type" - DROP CONSTRAINT IF EXISTS system_type_pkey; - -ALTER TABLE IF EXISTS "war"."class_preview" - DROP CONSTRAINT IF EXISTS class_preview_pkey; - -ALTER TABLE IF EXISTS "war"."field_change" - DROP CONSTRAINT IF EXISTS field_change_pkey; - -ALTER TABLE IF EXISTS "war"."statement" - DROP CONSTRAINT IF EXISTS statement_pkey; - diff --git a/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-up.sql b/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-up.sql deleted file mode 100644 index d441b5904..000000000 --- a/server/db-migrate/migrations/sqls/20230202080447-add-primary-keys-for-replica-identity-up.sql +++ /dev/null @@ -1,202 +0,0 @@ -/* - -- select all tables that have no PRIMARY KEY - -- and show if they have a pk_entity column - select tab.table_schema, - tab.table_name, - c.column_name - from information_schema.tables tab - left join information_schema.table_constraints tco - on tab.table_schema = tco.table_schema - and tab.table_name = tco.table_name - and tco.constraint_type = 'PRIMARY KEY' - left join information_schema.columns c - on c.table_name = tab.table_name - and c.table_schema = tab.table_schema - and c.column_name = 'pk_entity' - where tab.table_type = 'BASE TABLE' - and tab.table_schema not in ('pg_catalog', 'information_schema', 'public') - and tab.table_name NOT ILIKE '%_vt' - and tco.constraint_name is null - order by table_schema, - table_name - */ -ALTER TABLE IF EXISTS "data"."avatar" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."chunk" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."class_column_mapping" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."column" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."data_association" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."data_association_mapping" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."digital" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."factoid" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."factoid_mapping" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."factoid_property_mapping" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."factoid_role" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."namespace" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."property_of_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."property_of_property_mapping" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."text_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data"."values_association" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."api_class" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."api_profile" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."api_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."associates_system_type_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."class_profile_view_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."label_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."property_of_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."property_profile_view_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."system_type_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "data_for_history"."text_property_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."_backup_entity_association" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."appellation" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."dimension" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."lang_string" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."place" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."resource" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."statement" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."text_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "information"."time_primitive" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."_backup_class_field_config" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."analysis" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."argument" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."class_field_config" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."dfh_profile_proj_rel" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."entity_label_config" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."info_proj_rel" - ADD PRIMARY KEY (fk_entity, fk_project); - -ALTER TABLE IF EXISTS "projects"."project" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."property_label_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."query" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."table_config" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."text_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "projects"."visual" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."analysis_type_deprecated" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."app_context" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."class_field" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."class_field_property_rel" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."class_has_type_property" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."config" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."system_relevant_class" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."system_relevant_type" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "system"."system_type" - ADD PRIMARY KEY (pk_entity); - -ALTER TABLE IF EXISTS "war"."class_preview" - ADD PRIMARY KEY (fk_class, fk_project); - -ALTER TABLE IF EXISTS "war"."field_change" - ADD PRIMARY KEY (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing); - -ALTER TABLE IF EXISTS "war"."statement" - ADD PRIMARY KEY (pk_entity, project); - diff --git a/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-down.sql b/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-down.sql deleted file mode 100644 index 1fba1bef1..000000000 --- a/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE IF EXISTS war.entity_preview_template; - diff --git a/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-up.sql b/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-up.sql deleted file mode 100644 index 02b3113a9..000000000 --- a/server/db-migrate/migrations/sqls/20230202150611-add-entity-preview-template-table-up.sql +++ /dev/null @@ -1,41 +0,0 @@ -CREATE TABLE IF NOT EXISTS war.entity_preview_template ( - pk_entity integer NOT NULL, - fk_project integer, - project integer NOT NULL DEFAULT 0, - entity_type text COLLATE pg_catalog."default", - fk_class integer, - class_label character varying COLLATE pg_catalog."default", - entity_label text COLLATE pg_catalog."default", - full_text text COLLATE pg_catalog."default", - ts_vector tsvector, - type_label text COLLATE pg_catalog."default", - fk_type integer, - time_span jsonb, - first_second bigint, - last_second bigint, - tmsp_last_modification timestamp with time zone, - key character varying COLLATE pg_catalog."default" NOT NULL, - entity_id character varying COLLATE pg_catalog."default" NOT NULL, - parent_classes jsonb NOT NULL, - ancestor_classes jsonb NOT NULL, - project_id integer NOT NULL, - type_id character varying COLLATE pg_catalog."default", - CONSTRAINT entity_preview_template_pkey PRIMARY KEY (entity_id, project_id)) -TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_entity_label_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_entity_label_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_entity_label_idx ON war.entity_preview_template USING btree (entity_label COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_key_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_key_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_key_idx ON war.entity_preview_template USING btree (key COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx ON war.entity_preview_template USING btree (pk_entity ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx ON war.entity_preview_template USING gin (ts_vector) TABLESPACE pg_default; - diff --git a/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-down.sql b/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-down.sql deleted file mode 100644 index 780f57ce5..000000000 --- a/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP FUNCTION war.create_sink_table_entity_preview (character varying); - diff --git a/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-up.sql b/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-up.sql deleted file mode 100644 index 9d9dd48d8..000000000 --- a/server/db-migrate/migrations/sqls/20230202150806-war-f-create-sink-table-entity-preview-up.sql +++ /dev/null @@ -1,29 +0,0 @@ -CREATE OR REPLACE FUNCTION war.create_sink_table_entity_preview (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE TABLE %1$s (LIKE war.entity_preview_template INCLUDING ALL); - - CREATE TRIGGER generate_key - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_generate_key(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION commons.tmsp_last_modification(); - - CREATE TRIGGER ts_vector - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_ts_vector(); - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-down.sql b/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-down.sql deleted file mode 100644 index 4b5b06c3d..000000000 --- a/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-down.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP FUNCTION war.switch_entity_preview_table (character varying); - diff --git a/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-up.sql b/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-up.sql deleted file mode 100644 index 0b55c54a8..000000000 --- a/server/db-migrate/migrations/sqls/20230202151106-war-f-switch-entity-preview-table-up.sql +++ /dev/null @@ -1,31 +0,0 @@ -CREATE OR REPLACE FUNCTION war.switch_entity_preview_table (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE OR REPLACE VIEW war.entity_preview AS - SELECT * FROM %1$s; - - DROP TRIGGER IF EXISTS after_insert_on_entity_preview ON %1$s; - - CREATE TRIGGER after_insert_on_entity_preview - AFTER INSERT - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - DROP TRIGGER IF EXISTS after_update_on_entity_preview ON %1$s; - - CREATE TRIGGER after_update_on_entity_preview - AFTER UPDATE - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-down.sql b/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-down.sql deleted file mode 100644 index 9e8456799..000000000 --- a/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back diff --git a/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-up.sql b/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-up.sql deleted file mode 100644 index 70490ee85..000000000 --- a/server/db-migrate/migrations/sqls/20230202151301-war-t-entity-preview-rename-up.sql +++ /dev/null @@ -1 +0,0 @@ ---ALTER TABLE IF EXISTS war.entity_preview RENAME TO backup_entity_preview; diff --git a/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-down.sql b/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-down.sql deleted file mode 100644 index 7a17e9542..000000000 --- a/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-down.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 4 -DROP FUNCTION war.switch_field_change_table; - --- 3 -DROP FUNCTION war.create_sink_table_field_change; - --- 2 -DROP TABLE war.field_change_template; - --- 1 -CREATE TABLE IF NOT EXISTS war.field_change ( - fk_project integer NOT NULL, - fk_source_info integer NOT NULL, - fk_source_tables_cell integer NOT NULL, - fk_property integer NOT NULL, - fk_property_of_property integer NOT NULL, - is_outgoing boolean NOT NULL, - tmsp_last_modification timestamp with time zone NOT NULL, - CONSTRAINT field_change_pkey PRIMARY KEY (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing), - CONSTRAINT field_change_uniq UNIQUE (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing)) diff --git a/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-up.sql b/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-up.sql deleted file mode 100644 index 169f564cc..000000000 --- a/server/db-migrate/migrations/sqls/20230209103227-war-adapt-field-change-to-ts-up.sql +++ /dev/null @@ -1,58 +0,0 @@ --- 1 -DROP TABLE war.field_change; - --- 2 -CREATE TABLE IF NOT EXISTS war.field_change_template ( - fk_project integer NOT NULL, - fk_source_info integer NOT NULL, - fk_source_tables_cell bigint NOT NULL, - fk_property integer NOT NULL, - fk_property_of_property integer NOT NULL, - is_outgoing boolean NOT NULL, - tmsp_last_modification timestamp with time zone NOT NULL, - CONSTRAINT field_change_pkey PRIMARY KEY (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing), - CONSTRAINT field_change_uniq UNIQUE (fk_project, fk_source_info, fk_source_tables_cell, fk_property, fk_property_of_property, is_outgoing) -); - --- 3 -CREATE OR REPLACE FUNCTION war.create_sink_table_field_change (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format('CREATE TABLE %1$s (LIKE war.field_change_template INCLUDING ALL);', schema_and_table_name); -END -$BODY$; - --- 4 -CREATE OR REPLACE FUNCTION war.switch_field_change_table (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE OR REPLACE VIEW war.field_change AS - SELECT * FROM %1$s; - - DROP TRIGGER IF EXISTS after_insert_field_change ON %1$s; - - CREATE TRIGGER after_insert_field_change - AFTER INSERT - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.field_change__notify_upsert(); - - DROP TRIGGER IF EXISTS after_update_field_change ON %1$s; - - CREATE TRIGGER after_update_field_change - AFTER UPDATE - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.field_change__notify_upsert();', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-down.sql b/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-down.sql deleted file mode 100644 index 070b3a68e..000000000 --- a/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-down.sql +++ /dev/null @@ -1,183 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.clone_sandbox_project (account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_sandbox_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add account to project - */ - INSERT INTO public.account_project_rel (fk_project, account_id, ROLE) - VALUES (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_sandbox_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_sandbox_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification - FROM - war.entity_preview - WHERE - fk_project = pk_sandbox_project - ON CONFLICT ON CONSTRAINT war_entity_preview_unique - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - account_id AS fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_sandbox_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-up.sql b/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-up.sql deleted file mode 100644 index 5f012d9d4..000000000 --- a/server/db-migrate/migrations/sqls/20230308121239-com-f-clone-sandbox-up.sql +++ /dev/null @@ -1,189 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.clone_sandbox_project (account_id integer) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - pk_sandbox_project int; - fk_project_default_language int; - fk_system_type__project_label int; - fk_system_type__project_description int; - project_label varchar; - project_description varchar; - pk_new_project int; - pk_new_default_namespace int; -BEGIN - -- pk_entity of the sandbox project - pk_sandbox_project = 375232; - -- default language = english - fk_project_default_language = 18889; - -- system type for project label - fk_system_type__project_label = 639; - -- system type for project description - fk_system_type__project_description = 638; - -- the label of the new project - project_label = 'Sandbox Project'; - -- the description of the new project - project_description = 'This is a sandbox project. You can use it to explore the functionalities of Geovistory BETA and experiment with them. Enjoy!'; - - /* - * create the project - */ - INSERT INTO projects.project (fk_language, fk_cloned_from_project) - VALUES (fk_project_default_language, pk_sandbox_project) - ON CONFLICT - DO NOTHING - RETURNING - pk_entity INTO pk_new_project; - - /* - * add label of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_label, fk_system_type__project_label, fk_project_default_language); - - /* - * add description of project - */ - INSERT INTO projects.text_property (fk_project, fk_pro_project, string, fk_system_type, fk_language) - VALUES (pk_new_project, pk_new_project, project_description, fk_system_type__project_description, fk_project_default_language); - - /* - * add dfh profiles to project - */ - INSERT INTO projects.dfh_profile_proj_rel (fk_project, fk_profile, enabled) - SELECT - pk_new_project AS fk_project, - fk_profile, - enabled - FROM - projects.dfh_profile_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add dfh classes to project - */ - INSERT INTO projects.dfh_class_proj_rel (fk_project, fk_class, enabled_in_entities) - SELECT - pk_new_project AS fk_project, - fk_class, - enabled_in_entities - FROM - projects.dfh_class_proj_rel - WHERE - fk_project = pk_sandbox_project; - - /* - * add default namespace to project - */ - INSERT INTO data.namespace (fk_project, standard_label) - VALUES (pk_new_project, 'Default Namespace') - RETURNING - pk_entity INTO pk_new_default_namespace; - - /* - * add account to project - */ - INSERT INTO public.account_project_rel (fk_project, account_id, ROLE) - VALUES (pk_new_project, account_id, 'owner'); - - /* - * add all information to project except for statements referencing to data - */ - WITH tw1 AS ( - /* - * select all info_proj_rel of sandbox except those that are - * referencing an statement associating entities in data schema - */ - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1 - WHERE - fk_project = pk_sandbox_project - EXCEPT - SELECT - t1.pk_entity - FROM - projects.info_proj_rel t1, - information.statement t2 - WHERE - fk_project = pk_sandbox_project - AND t1.fk_entity = t2.pk_entity - AND (t2.fk_subject_tables_cell != 0 - OR t2.fk_object_tables_cell != 0 - OR t2.fk_subject_tables_row != 0 - OR t2.fk_object_tables_row != 0 - OR t2.fk_subject_data != 0 - OR t2.fk_object_data != 0)) - INSERT INTO projects.info_proj_rel (fk_project, fk_entity, fk_entity_version, fk_entity_version_concat, is_in_project, is_standard_in_project, ord_num_of_domain, ord_num_of_range, ord_num_of_text_property, entity_version) - SELECT - pk_new_project AS fk_project, - t1.fk_entity, - t1.fk_entity_version, - t1.fk_entity_version_concat, - t1.is_in_project, - t1.is_standard_in_project, - t1.ord_num_of_domain, - t1.ord_num_of_range, - t1.ord_num_of_text_property, - t1.entity_version - FROM - projects.info_proj_rel t1, - tw1 t2 - WHERE - t1.pk_entity = t2.pk_entity; - - /* - * Clone all entity_previews from sandbox project - * so that warehouse for this project is ready instantly - */ - INSERT INTO war.entity_preview (pk_entity, fk_project, project, fk_class, entity_type, class_label, entity_label, time_span, fk_type, type_label, full_text, ts_vector, first_second, last_second, tmsp_last_modification, entity_id, parent_classes, ancestor_classes, project_id, type_id) - SELECT - pk_entity, - pk_new_project AS fk_project, - pk_new_project AS project, - fk_class, - entity_type, - class_label, - entity_label, - time_span, - fk_type, - type_label, - full_text, - ts_vector, - first_second, - last_second, - tmsp_last_modification, - entity_id, - parent_classes, - ancestor_classes, - project_id, - type_id - FROM - war.entity_preview - WHERE - fk_project = pk_sandbox_project - ON CONFLICT (entity_id, - project_id) - DO NOTHING; - - /* - * Clone analysis - */ - INSERT INTO projects.analysis (fk_last_modifier, fk_project, fk_analysis_type, name, description, analysis_definition) - SELECT - account_id AS fk_last_modifier, - pk_new_project AS fk_project, - fk_analysis_type, - name, - description, - analysis_definition - FROM - projects.analysis - WHERE - fk_project = pk_sandbox_project; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-down.sql b/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-down.sql deleted file mode 100644 index dfaed8a52..000000000 --- a/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-down.sql +++ /dev/null @@ -1,12 +0,0 @@ --- 4 -DROP FUNCTION war.switch_statement_table; - --- 3 -DROP FUNCTION war.create_sink_table_statement; - --- 2 -DROP TABLE war.statement_template; - --- 1 -ALTER TABLE IF EXISTS war.statement_backup RENAME TO statement; - diff --git a/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-up.sql b/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-up.sql deleted file mode 100644 index db969dde1..000000000 --- a/server/db-migrate/migrations/sqls/20230311122107-war-v-statements-up.sql +++ /dev/null @@ -1,66 +0,0 @@ --- 1 -ALTER TABLE IF EXISTS war.statement RENAME TO statement_backup; - --- 2 -CREATE TABLE IF NOT EXISTS war.statement_template ( - pk_entity integer NOT NULL, - project integer NOT NULL DEFAULT 0, - fk_project integer, - fk_property integer, - fk_object_info integer, - fk_subject_info integer, - ord_num_of_domain integer, - ord_num_of_range integer, - is_in_project_count integer, - object_info_value jsonb, - CONSTRAINT statement_template_pkey PRIMARY KEY (pk_entity, project), - CONSTRAINT statement_template_pk_entity_project_key UNIQUE (pk_entity, project) -); - -CREATE INDEX IF NOT EXISTS statement_template_fk_object_info_idx ON war.statement_template USING btree (fk_object_info ASC NULLS LAST) TABLESPACE pg_default; - --- Index: statement_template_fk_project_idx --- DROP INDEX IF EXISTS war.statement_template_fk_project_idx; -CREATE INDEX IF NOT EXISTS statement_template_fk_project_idx ON war.statement_template USING btree (fk_project ASC NULLS LAST) TABLESPACE pg_default; - --- Index: statement_template_fk_property_idx --- DROP INDEX IF EXISTS war.statement_template_fk_property_idx; -CREATE INDEX IF NOT EXISTS statement_template_fk_property_idx ON war.statement_template USING btree (fk_property ASC NULLS LAST) TABLESPACE pg_default; - --- Index: statement_template_fk_subject_info_idx --- DROP INDEX IF EXISTS war.statement_template_fk_subject_info_idx; -CREATE INDEX IF NOT EXISTS statement_template_fk_subject_info_idx ON war.statement_template USING btree (fk_subject_info ASC NULLS LAST) TABLESPACE pg_default; - --- Index: statement_template_pk_entity_idx --- DROP INDEX IF EXISTS war.statement_template_pk_entity_idx; -CREATE INDEX IF NOT EXISTS statement_template_pk_entity_idx ON war.statement_template USING btree (pk_entity ASC NULLS LAST) TABLESPACE pg_default; - --- Index: statement_template_pk_entity_project_idx --- DROP INDEX IF EXISTS war.statement_template_pk_entity_project_idx; -CREATE UNIQUE INDEX IF NOT EXISTS statement_template_pk_entity_project_idx ON war.statement_template USING btree (pk_entity ASC NULLS LAST, project ASC NULLS LAST) TABLESPACE pg_default; - --- 3 -CREATE OR REPLACE FUNCTION war.create_sink_table_statement (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format('CREATE TABLE %1$s (LIKE war.statement_template INCLUDING ALL);', schema_and_table_name); -END -$BODY$; - --- 4 -CREATE OR REPLACE FUNCTION war.switch_statement_table (schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE OR REPLACE VIEW war.statement AS - SELECT * FROM %1$s; - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-down.sql b/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-down.sql deleted file mode 100644 index 6afdd7dba..000000000 --- a/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-down.sql +++ /dev/null @@ -1,8 +0,0 @@ -DROP INDEX IF EXISTS war.entity_preview_template_project_idx; - -DROP INDEX IF EXISTS war.entity_preview_template_fk_project_idx; - -DROP INDEX IF EXISTS war.entity_preview_template_fk_class_idx; - -DROP INDEX IF EXISTS war.entity_preview_template_entity_type_idx; - diff --git a/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-up.sql b/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-up.sql deleted file mode 100644 index bc83d199d..000000000 --- a/server/db-migrate/migrations/sqls/20230615145144-war-t-entity-preview-template-indexes-up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE INDEX IF NOT EXISTS entity_preview_template_project_idx ON war.entity_preview_template(project); - -CREATE INDEX IF NOT EXISTS entity_preview_template_fk_project_idx ON war.entity_preview_template(fk_project); - -CREATE INDEX IF NOT EXISTS entity_preview_template_fk_class_idx ON war.entity_preview_template(fk_class); - -CREATE INDEX IF NOT EXISTS entity_preview_template_entity_type_idx ON war.entity_preview_template(entity_type); - diff --git a/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-down.sql b/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-down.sql deleted file mode 100644 index 9e8456799..000000000 --- a/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-down.sql +++ /dev/null @@ -1 +0,0 @@ --- no way back diff --git a/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-up.sql b/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-up.sql deleted file mode 100644 index 8de330e7d..000000000 --- a/server/db-migrate/migrations/sqls/20230615145659-inf-t-appellation-vt-remove-index-up.sql +++ /dev/null @@ -1,2 +0,0 @@ -DROP INDEX IF EXISTS information.appellation_vt_string_idx; - diff --git a/server/db-migrate/migrations/sqls/20230627104438-add-indexes-down.sql b/server/db-migrate/migrations/sqls/20230627104438-add-indexes-down.sql deleted file mode 100644 index f86ab9b16..000000000 --- a/server/db-migrate/migrations/sqls/20230627104438-add-indexes-down.sql +++ /dev/null @@ -1,8 +0,0 @@ -DROP INDEX IF EXISTS information.resource_pk_entity_idx; - -DROP INDEX IF EXISTS information.resource_fk_class_idx; - -DROP INDEX IF EXISTS war.ancestor_classes_idx; - -DROP INDEX IF EXISTS war.parent_classes_idx; - diff --git a/server/db-migrate/migrations/sqls/20230627104438-add-indexes-up.sql b/server/db-migrate/migrations/sqls/20230627104438-add-indexes-up.sql deleted file mode 100644 index 4da51e2ad..000000000 --- a/server/db-migrate/migrations/sqls/20230627104438-add-indexes-up.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE INDEX IF NOT EXISTS resource_pk_entity_idx ON information.resource USING btree(pk_entity ASC NULLS LAST) TABLESPACE pg_default; - -CREATE INDEX IF NOT EXISTS resource_fk_class_idx ON information.resource USING btree(fk_class ASC NULLS LAST) TABLESPACE pg_default; - -CREATE INDEX IF NOT EXISTS ancestor_classes_idx ON war.entity_preview_template USING GIN(ancestor_classes); - -CREATE INDEX IF NOT EXISTS parent_classes_idx ON war.entity_preview_template USING GIN(parent_classes); - diff --git a/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-down.sql b/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-down.sql deleted file mode 100644 index 99914e6fc..000000000 --- a/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-down.sql +++ /dev/null @@ -1,64 +0,0 @@ --- 1 --- Remove partitioning of the table war.entity_preview_template -DROP TABLE IF EXISTS war.entity_preview_template; - -CREATE TABLE IF NOT EXISTS war.entity_preview_template( - pk_entity integer NOT NULL, - fk_project integer, - project integer NOT NULL DEFAULT 0, - entity_type text COLLATE pg_catalog."default", - fk_class integer, - class_label character varying COLLATE pg_catalog."default", - entity_label text COLLATE pg_catalog."default", - full_text text COLLATE pg_catalog."default", - ts_vector tsvector, - type_label text COLLATE pg_catalog."default", - fk_type integer, - time_span jsonb, - first_second bigint, - last_second bigint, - tmsp_last_modification timestamp with time zone, - key character varying COLLATE pg_catalog."default" NOT NULL, - entity_id character varying COLLATE pg_catalog."default" NOT NULL, - parent_classes jsonb NOT NULL, - ancestor_classes jsonb NOT NULL, - project_id integer NOT NULL, - type_id character varying COLLATE pg_catalog."default", - CONSTRAINT entity_preview_template_pkey PRIMARY KEY (entity_id, project_id) -) -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS war.entity_preview_template OWNER TO postgres; - --- Index: entity_preview_template_entity_type_idx --- DROP INDEX IF EXISTS war.entity_preview_template_entity_type_idx; -CREATE INDEX IF NOT EXISTS entity_preview_template_entity_type_idx ON war.entity_preview_template USING btree(entity_type COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - --- Index: entity_preview_template_fk_class_idx --- DROP INDEX IF EXISTS war.entity_preview_template_fk_class_idx; -CREATE INDEX IF NOT EXISTS entity_preview_template_fk_class_idx ON war.entity_preview_template USING btree(fk_class ASC NULLS LAST) TABLESPACE pg_default; - --- Index: entity_preview_template_fk_project_idx --- DROP INDEX IF EXISTS war.entity_preview_template_fk_project_idx; -CREATE INDEX IF NOT EXISTS entity_preview_template_fk_project_idx ON war.entity_preview_template USING btree(fk_project ASC NULLS LAST) TABLESPACE pg_default; - --- Index: entity_preview_template_project_idx --- DROP INDEX IF EXISTS war.entity_preview_template_project_idx; -CREATE INDEX IF NOT EXISTS entity_preview_template_project_idx ON war.entity_preview_template USING btree(project ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_entity_label_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_entity_label_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_entity_label_idx ON war.entity_preview_template USING btree(entity_label COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_key_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_key_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_key_idx ON war.entity_preview_template USING btree(key COLLATE pg_catalog."default" ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_pk_entity_idx ON war.entity_preview_template USING btree(pk_entity ASC NULLS LAST) TABLESPACE pg_default; - --- Index: ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx --- DROP INDEX IF EXISTS war.ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx; -CREATE INDEX IF NOT EXISTS ts_v1_dev_0_1_0_pr_46_3_ts_vector_idx ON war.entity_preview_template USING gin(ts_vector) TABLESPACE pg_default; - diff --git a/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-up.sql b/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-up.sql deleted file mode 100644 index 852ab676e..000000000 --- a/server/db-migrate/migrations/sqls/20230727091628-war-t-entity-preview-partitioning-up.sql +++ /dev/null @@ -1,46 +0,0 @@ --- 1 --- Add partitioning to the table war.entity_preview_template -DROP TABLE IF EXISTS war.entity_preview_template CASCADE; - -CREATE TABLE IF NOT EXISTS war.entity_preview_template( - pk_entity integer NOT NULL, - fk_project integer, - project integer NOT NULL DEFAULT 0, - entity_type text COLLATE pg_catalog."default", - fk_class integer, - class_label character varying COLLATE pg_catalog."default", - entity_label text COLLATE pg_catalog."default", - full_text text COLLATE pg_catalog."default", - ts_vector tsvector, - type_label text COLLATE pg_catalog."default", - fk_type integer, - time_span jsonb, - first_second bigint, - last_second bigint, - tmsp_last_modification timestamp with time zone, - key character varying COLLATE pg_catalog."default" NOT NULL, - entity_id character varying COLLATE pg_catalog."default" NOT NULL, - parent_classes jsonb NOT NULL, - ancestor_classes jsonb NOT NULL, - project_id integer NOT NULL, - type_id character varying COLLATE pg_catalog."default", - CONSTRAINT entity_preview_template_pkey PRIMARY KEY (entity_id, project_id) -) -PARTITION BY LIST (project_id); - -CREATE INDEX IF NOT EXISTS ep__entity_type_idx ON war.entity_preview_template USING btree(entity_type COLLATE pg_catalog."default" ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__fk_class_idx ON war.entity_preview_template USING btree(fk_class ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__fk_project_idx ON war.entity_preview_template USING btree(fk_project ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__project_idx ON war.entity_preview_template USING btree(project ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__entity_label_idx ON war.entity_preview_template USING btree(entity_label COLLATE pg_catalog."default" ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__key_idx ON war.entity_preview_template USING btree(key COLLATE pg_catalog."default" ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__pk_entity_idx ON war.entity_preview_template USING btree(pk_entity ASC NULLS LAST); - -CREATE INDEX IF NOT EXISTS ep__ts_vector_idx ON war.entity_preview_template USING gin(ts_vector); - diff --git a/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-down.sql b/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-down.sql deleted file mode 100644 index 675b6878b..000000000 --- a/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-down.sql +++ /dev/null @@ -1,30 +0,0 @@ -CREATE OR REPLACE FUNCTION war.create_sink_table_entity_preview(schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE TABLE %1$s (LIKE war.entity_preview_template INCLUDING ALL); - - CREATE TRIGGER generate_key - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_generate_key(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION commons.tmsp_last_modification(); - - CREATE TRIGGER ts_vector - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_ts_vector(); - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-up.sql b/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-up.sql deleted file mode 100644 index e81cc612e..000000000 --- a/server/db-migrate/migrations/sqls/20230727092320-war-f-create-sink-table-entity-preview-up.sql +++ /dev/null @@ -1,46 +0,0 @@ -CREATE OR REPLACE FUNCTION war.create_sink_table_entity_preview(schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - project_id int; -BEGIN - -- Create table and triggers - EXECUTE format(' - CREATE TABLE %1$s (LIKE war.entity_preview_template INCLUDING ALL) - PARTITION BY LIST (project_id); - - CREATE TRIGGER generate_key - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_generate_key(); - - CREATE TRIGGER last_modification_tmsp - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION commons.tmsp_last_modification(); - - CREATE TRIGGER ts_vector - BEFORE INSERT OR UPDATE - ON %1$s - FOR EACH ROW - EXECUTE FUNCTION war.entity_preview_ts_vector(); - ', schema_and_table_name); - -- Create partitions for each project - FOR project_id IN - SELECT - pk_entity - FROM - projects.project LOOP - -- Construct and execute the dynamic SQL statement - -- e.g CREATE TABLE war.entity_preview_xyz_33 PARTITION OF war.entity_preview_xyz FOR VALUES IN (33); - EXECUTE format('CREATE TABLE %1$s_%2$s PARTITION OF %1$s FOR VALUES IN (%2$s);', schema_and_table_name, project_id); - END LOOP; - -- Create partition for community data - EXECUTE format('CREATE TABLE %1$s_0 PARTITION OF %1$s FOR VALUES IN (0);', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-down.sql b/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-down.sql deleted file mode 100644 index 44f074ea8..000000000 --- a/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-down.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace with your SQL commands */ \ No newline at end of file diff --git a/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-up.sql b/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-up.sql deleted file mode 100644 index ab128e72e..000000000 --- a/server/db-migrate/migrations/sqls/20230727102618-pro-t-projects-add-entity-preview-partition-trigger-up.sql +++ /dev/null @@ -1,48 +0,0 @@ --- 1 --- create function to extract the schema.table name --- currently used by the view war.entity_previw -CREATE OR REPLACE FUNCTION commons.get_entity_preview_table_name() - RETURNS text - AS $$ -DECLARE - table_name text; -BEGIN - SELECT - substring(view_definition FROM 'FROM[[:space:]]+([[:alnum:]_\.]+)') - FROM - information_schema.views - WHERE - table_schema = 'war' - AND table_name = 'entity_preview' INTO table_name; - RETURN table_name; -END; -$$ -LANGUAGE plpgsql; - --- 2 --- Create trigger function that adds a partition for the project --- to the current entity_preview table -CREATE OR REPLACE FUNCTION projects.add_entity_preview_partition() - RETURNS TRIGGER - LANGUAGE 'plpgsql' - COST 100 VOLATILE NOT LEAKPROOF - AS $BODY$ -DECLARE - entity_preview_table text; -BEGIN - -- get the table name of the current - SELECT - commons.get_entity_preview_table_name() INTO entity_preview_table; - -- create the partition - EXECUTE format('CREATE TABLE %1$s_%2$s PARTITION OF %1$s FOR VALUES IN (%2$s);', entity_preview_table, NEW.pk_entity); - RETURN NEW; -END; -$BODY$; - --- 3 --- add trigger -CREATE TRIGGER add_entity_preview_partition - BEFORE INSERT ON projects.project - FOR EACH ROW - EXECUTE FUNCTION projects.add_entity_preview_partition(); - diff --git a/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-down.sql b/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-down.sql deleted file mode 100644 index ce1edbfc0..000000000 --- a/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-down.sql +++ /dev/null @@ -1,34 +0,0 @@ -DROP FUNCTION IF EXISTS war.switch_entity_preview_table(character varying); - -CREATE OR REPLACE FUNCTION war.switch_entity_preview_table(schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE OR REPLACE VIEW war.entity_preview AS - SELECT * FROM %1$s; - - DROP TRIGGER IF EXISTS after_insert_on_entity_preview ON %1$s; - - CREATE TRIGGER after_insert_on_entity_preview - AFTER INSERT - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - DROP TRIGGER IF EXISTS after_update_on_entity_preview ON %1$s; - - CREATE TRIGGER after_update_on_entity_preview - AFTER UPDATE - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-up.sql b/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-up.sql deleted file mode 100644 index a0eb3901f..000000000 --- a/server/db-migrate/migrations/sqls/20230727152222-war-f-switch-entity-preview-table-up.sql +++ /dev/null @@ -1,54 +0,0 @@ -DROP FUNCTION IF EXISTS war.switch_entity_preview_table(character varying); - -CREATE OR REPLACE FUNCTION war.switch_entity_preview_table(schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - CREATE OR REPLACE VIEW war.entity_preview AS - SELECT - pk_entity, - entity_type, - fk_class, - class_label, - entity_label, - full_text, - ts_vector, - type_label, - fk_type, - time_span, - first_second, - last_second, - tmsp_last_modification, - key, - entity_id, - parent_classes, - ancestor_classes, - project_id, - type_id - FROM %1$s; - - DROP TRIGGER IF EXISTS after_insert_on_entity_preview ON %1$s; - - CREATE TRIGGER after_insert_on_entity_preview - AFTER INSERT - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - DROP TRIGGER IF EXISTS after_update_on_entity_preview ON %1$s; - - CREATE TRIGGER after_update_on_entity_preview - AFTER UPDATE - ON %1$s - REFERENCING NEW TABLE AS new_table - FOR EACH STATEMENT - EXECUTE FUNCTION war.entity_previews__notify_upsert(); - - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-down.sql b/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-down.sql deleted file mode 100644 index 4ce1ca69e..000000000 --- a/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-down.sql +++ /dev/null @@ -1,159 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.analysis__create_temporal_distribution(param_pk_entities integer[], param_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - res jsonb; -BEGIN - WITH tw0 AS ( - SELECT - first_second, - last_second, - pk_entity - FROM - war.entity_preview - WHERE - pk_entity = ANY (param_pk_entities) - AND project = param_project - AND first_second IS NOT NULL - AND last_second IS NOT NULL -), -tw1 AS ( - SELECT - first_second julian_second, - pk_entity - FROM - tw0 - UNION - SELECT - last_second julian_second, - pk_entity - FROM - tw0 - ORDER BY - 1 -), -tw2 AS ( - SELECT DISTINCT ON (julian_second) - julian_second - FROM - tw1 -), -tw3 AS ( - SELECT - julian_second, - row_number() OVER () pk, -(row_number() OVER () + 1) fk_next -FROM tw2 -), -tw4 AS ( - SELECT - t1.julian_second x1, - t2.julian_second x2 - FROM - tw3 t1, - tw3 t2 - WHERE - t1.fk_next = t2.pk -), -tw5 AS ( - SELECT - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - json_strip_nulls(json_agg(t2.pk_entity)) AS data, - count(t2.pk_entity) - FROM - tw4 t1 - LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 - AND t2.last_second > t1.x1 - GROUP BY - t1.x1, - t1.x2 - ORDER BY - t1.x1 -), -tw6 AS ( - -- select the very first point - SELECT - x1 x, - 0 y, - '[]'::json AS data, - x1, - x2 - FROM - tw5 - ORDER BY - x1 - LIMIT 1 -), -tw7 AS ( - -- select the very last point - SELECT - x2 x, - 0 y, - '[]'::json AS data, - x1, - x2 - FROM - tw5 - ORDER BY - x1 DESC - LIMIT 1 -), -tw8 AS ( - -- first point - SELECT - 0, - x, - y, - data, - x1, - x2 - FROM - tw6 - UNION ALL - -- all other points - SELECT - 2, - x1 x, - count y, - data, - x1, - x2 - FROM - tw5 - UNION ALL - SELECT - 1, - x2 x, - count y, - data, - x1, - x2 - FROM - tw5 - UNION ALL - -- last point - SELECT - 3, - x, - y, - data, - x1, - x2 - FROM - tw7 - ORDER BY - x, - 1 -) -SELECT - jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) INTO res -FROM - tw8; - RETURN coalesce(res, '[]'::jsonb); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-up.sql b/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-up.sql deleted file mode 100644 index dde5bda3a..000000000 --- a/server/db-migrate/migrations/sqls/20230815102214-com-f-analysis-temporal-distribution-up.sql +++ /dev/null @@ -1,159 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.analysis__create_temporal_distribution(param_pk_entities integer[], param_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - res jsonb; -BEGIN - WITH tw0 AS ( - SELECT - first_second, - last_second, - pk_entity - FROM - war.entity_preview - WHERE - pk_entity = ANY (param_pk_entities) - AND project_id = param_project - AND first_second IS NOT NULL - AND last_second IS NOT NULL -), -tw1 AS ( - SELECT - first_second julian_second, - pk_entity - FROM - tw0 - UNION - SELECT - last_second julian_second, - pk_entity - FROM - tw0 - ORDER BY - 1 -), -tw2 AS ( - SELECT DISTINCT ON (julian_second) - julian_second - FROM - tw1 -), -tw3 AS ( - SELECT - julian_second, - row_number() OVER () pk, -(row_number() OVER () + 1) fk_next -FROM tw2 -), -tw4 AS ( - SELECT - t1.julian_second x1, - t2.julian_second x2 - FROM - tw3 t1, - tw3 t2 - WHERE - t1.fk_next = t2.pk -), -tw5 AS ( - SELECT - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - json_strip_nulls(json_agg(t2.pk_entity)) AS data, - count(t2.pk_entity) - FROM - tw4 t1 - LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 - AND t2.last_second > t1.x1 - GROUP BY - t1.x1, - t1.x2 - ORDER BY - t1.x1 -), -tw6 AS ( - -- select the very first point - SELECT - x1 x, - 0 y, - '[]'::json AS data, - x1, - x2 - FROM - tw5 - ORDER BY - x1 - LIMIT 1 -), -tw7 AS ( - -- select the very last point - SELECT - x2 x, - 0 y, - '[]'::json AS data, - x1, - x2 - FROM - tw5 - ORDER BY - x1 DESC - LIMIT 1 -), -tw8 AS ( - -- first point - SELECT - 0, - x, - y, - data, - x1, - x2 - FROM - tw6 - UNION ALL - -- all other points - SELECT - 2, - x1 x, - count y, - data, - x1, - x2 - FROM - tw5 - UNION ALL - SELECT - 1, - x2 x, - count y, - data, - x1, - x2 - FROM - tw5 - UNION ALL - -- last point - SELECT - 3, - x, - y, - data, - x1, - x2 - FROM - tw7 - ORDER BY - x, - 1 -) -SELECT - jsonb_agg(json_build_object('x', x, 'y', y, 'data', data)) INTO res -FROM - tw8; - RETURN coalesce(res, '[]'::jsonb); -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-down.sql b/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-down.sql deleted file mode 100644 index 02f6400c9..000000000 --- a/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-down.sql +++ /dev/null @@ -1,193 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.analysis__time_chart_cont__czml_time_values(param_pk_entities integer[], param_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - res jsonb; -BEGIN - WITH tw0 AS ( - -- temporal entities - SELECT - first_second, - last_second, - pk_entity - FROM - war.entity_preview - WHERE - pk_entity = ANY (param_pk_entities) - AND project = param_project - AND first_second IS NOT NULL - AND last_second IS NOT NULL -), -tw1 AS ( - SELECT - first_second julian_second, - pk_entity - FROM - tw0 - UNION - SELECT - last_second julian_second, - pk_entity - FROM - tw0 - ORDER BY - 1 -), -tw2 AS ( - SELECT DISTINCT ON (julian_second) - julian_second - FROM - tw1 -), -tw3 AS ( - SELECT - julian_second, - row_number() OVER () pk, -(row_number() OVER () + 1) fk_next -FROM tw2 -), -tw4 AS ( - SELECT - t1.julian_second x1, - t2.julian_second x2 - FROM - tw3 t1, - tw3 t2 - WHERE - t1.fk_next = t2.pk -), -tw5 AS ( - SELECT - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601(t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601(t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) FILTER (WHERE t2.pk_entity IS NOT NULL), '[]') AS data, -count(t2.pk_entity) -FROM - tw4 t1 - LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 - AND t2.last_second > t1.x1 -GROUP BY - t1.x1, - t1.x2 -ORDER BY - t1.x1 -), -tw6 AS ( - -- select the very first point - SELECT - x1 x, - commons.julian_second__to_iso_8601(x1 - 1) iso_x, - 0 y, - '[]'::json AS data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - ORDER BY - x1 - LIMIT 1 -), -tw7 AS ( - -- select the very last point - SELECT - x2 x, - commons.julian_second__to_iso_8601(x2 + 1) iso_x, - 0 y, - '[]'::json AS data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - ORDER BY - x1 DESC - LIMIT 1 -), -tw8 AS ( - -- first point - SELECT - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw6 - UNION ALL - -- all other points - SELECT - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - UNION ALL - SELECT - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - UNION ALL - -- last point - SELECT - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw7 - ORDER BY - x, - 1 -), -tw9 AS ( - SELECT - row_number() OVER () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM tw8 -) -SELECT - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) INTO res -FROM - tw9; - RETURN res; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-up.sql b/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-up.sql deleted file mode 100644 index 3b23b9b8c..000000000 --- a/server/db-migrate/migrations/sqls/20230815102806-com-f-analysis-time-chart-cont--czml-time-values-up.sql +++ /dev/null @@ -1,193 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.analysis__time_chart_cont__czml_time_values(param_pk_entities integer[], param_project integer) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -DECLARE - res jsonb; -BEGIN - WITH tw0 AS ( - -- temporal entities - SELECT - first_second, - last_second, - pk_entity - FROM - war.entity_preview - WHERE - pk_entity = ANY (param_pk_entities) - AND project_id = param_project - AND first_second IS NOT NULL - AND last_second IS NOT NULL -), -tw1 AS ( - SELECT - first_second julian_second, - pk_entity - FROM - tw0 - UNION - SELECT - last_second julian_second, - pk_entity - FROM - tw0 - ORDER BY - 1 -), -tw2 AS ( - SELECT DISTINCT ON (julian_second) - julian_second - FROM - tw1 -), -tw3 AS ( - SELECT - julian_second, - row_number() OVER () pk, -(row_number() OVER () + 1) fk_next -FROM tw2 -), -tw4 AS ( - SELECT - t1.julian_second x1, - t2.julian_second x2 - FROM - tw3 t1, - tw3 t2 - WHERE - t1.fk_next = t2.pk -), -tw5 AS ( - SELECT - t1.x1, - t1.x2, - -- for czml we need to remove a very little ms here to that the x vals stay unique - commons.julian_second__to_iso_8601(t1.x1 + 1) iso_x1, - commons.julian_second__to_iso_8601(t1.x2) iso_x2, - coalesce(json_agg(t2.pk_entity) FILTER (WHERE t2.pk_entity IS NOT NULL), '[]') AS data, -count(t2.pk_entity) -FROM - tw4 t1 - LEFT JOIN tw0 t2 ON t2.first_second < t1.x2 - AND t2.last_second > t1.x1 -GROUP BY - t1.x1, - t1.x2 -ORDER BY - t1.x1 -), -tw6 AS ( - -- select the very first point - SELECT - x1 x, - commons.julian_second__to_iso_8601(x1 - 1) iso_x, - 0 y, - '[]'::json AS data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - ORDER BY - x1 - LIMIT 1 -), -tw7 AS ( - -- select the very last point - SELECT - x2 x, - commons.julian_second__to_iso_8601(x2 + 1) iso_x, - 0 y, - '[]'::json AS data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - ORDER BY - x1 DESC - LIMIT 1 -), -tw8 AS ( - -- first point - SELECT - 0, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw6 - UNION ALL - -- all other points - SELECT - 2, - x1 x, - iso_x1 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - UNION ALL - SELECT - 1, - x2 x, - iso_x2 iso_x, - count y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw5 - UNION ALL - -- last point - SELECT - 3, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM - tw7 - ORDER BY - x, - 1 -), -tw9 AS ( - SELECT - row_number() OVER () data_id, - x, - iso_x, - y, - data, - x1, - x2, - iso_x1, - iso_x2 - FROM tw8 -) -SELECT - json_build_object('data_lookup', coalesce(jsonb_object_agg(tw9.data_id, tw9.data), '{}'::jsonb), 'timeCzmlValues', coalesce(jsonb_agg(json_build_object('iso_x', tw9.iso_x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb), 'timeLinePoints', coalesce(jsonb_agg(json_build_object('x', tw9.x, 'y', tw9.y, 'data_ref', tw9.data_id::text)), '[]'::jsonb)) INTO res -FROM - tw9; - RETURN res; -END; -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-down.sql b/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-down.sql deleted file mode 100644 index a8c7f02e0..000000000 --- a/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-down.sql +++ /dev/null @@ -1,639 +0,0 @@ -DO $$ -BEGIN - IF NOT EXISTS( - SELECT - 1 - FROM - pg_type - WHERE - typname = 'war_gv_statement_target') THEN - CREATE TYPE public.war_gv_statement_target AS( - target_obj jsonb, - target_class integer, - target_label text -); -END IF; -END -$$; - -CREATE OR REPLACE FUNCTION war.gv_field_page_incoming_in_project(_project_id integer, _fk_property integer, _source_info_id integer, _source_data_id integer, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit integer, _offset integer, _req json) - RETURNS TABLE( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count integer, - req json) - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE ROWS 1 - AS $BODY$ -BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit = 0 THEN - '[]'::json - ELSE - COALESCE(json_agg(stmt.obj ORDER BY ord_num_of_domain ASC NULLS LAST, pk_entity DESC), '[]'::json) - END AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls(json_build_object('projRel', war.gv_to_jsonb(t2), 'isOutgoing', FALSE, 'ordNum', t2.ord_num_of_domain, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', war.gv_to_jsonb(t1))) obj, - count(*) OVER() AS full_count, - t2.ord_num_of_domain, - t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2, - war.gv_get_statement_target(_project_id, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - -------------------------------------------------------------------------- - -- order the statements according to order number of target - -------------------------------------------------------------------------- - ORDER BY - t2.ord_num_of_domain ASC NULLS LAST, - t1.pk_entity DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit = 0 THEN - 1 - ELSE - _limit - END OFFSET _offset) AS stmt; -END -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_field_page_incoming_in_repo(_fk_property integer, _source_info_id integer, _source_data_id integer, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit integer, _offset integer, _req json) - RETURNS TABLE( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count integer, - req json) - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE ROWS 1 - AS $BODY$ -BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit = 0 THEN - '[]'::json - ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls(json_build_object('isOutgoing', FALSE, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', war.gv_to_jsonb(t1))) obj, - count(*) OVER() AS full_count - FROM - information.v_statement t1, - war.gv_get_statement_target(0, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - -------------------------------------------------------------------------- - -- ORDER STATEMENTS USED BY MORE PROJECTS FIRST - -------------------------------------------------------------------------- - ORDER BY - t1.is_in_project_count DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit = 0 THEN - 1 - ELSE - _limit - END OFFSET _offset) AS stmt; -END -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_field_page_outgoing_in_project(_project_id integer, _fk_property integer, _fk_subject_info integer, _fk_subject_data integer, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit integer, _offset integer, _req json) - RETURNS TABLE( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count integer, - req json) - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE ROWS 1 - AS $BODY$ -BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit = 0 THEN - '[]'::json - ELSE - COALESCE(json_agg(stmt.obj ORDER BY ord_num_of_range ASC NULLS LAST, pk_entity DESC), '[]'::json) - END AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls(json_build_object('projRel', war.gv_to_jsonb(t2), 'isOutgoing', TRUE, 'ordNum', t2.ord_num_of_range, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', war.gv_to_jsonb(t1))) obj, - count(*) OVER() AS full_count, - t2.ord_num_of_range, - t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2, - war.gv_get_statement_target(_project_id, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - -------------------------------------------------------------------------- - -- order the statements according to order number of target - -------------------------------------------------------------------------- - ORDER BY - t2.ord_num_of_range ASC NULLS LAST, - t1.pk_entity DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit = 0 THEN - 1 - ELSE - _limit - END OFFSET _offset) AS stmt; -END -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_field_page_outgoing_in_repo(_fk_property integer, _fk_subject_info integer, _fk_subject_data integer, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit integer, _offset integer, _req json) - RETURNS TABLE( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count integer, - req json) - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE ROWS 1 - AS $BODY$ -BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit = 0 THEN - '[]'::json - ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls(json_build_object('isOutgoing', TRUE, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', war.gv_to_jsonb(t1))) obj, - count(*) OVER() AS full_count - FROM - information.v_statement t1, - war.gv_get_statement_target(0, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - -------------------------------------------------------------------------- - -- ORDER STATEMENTS USED BY MORE PROJECTS FIRST - -------------------------------------------------------------------------- - ORDER BY - t1.is_in_project_count DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit = 0 THEN - 1 - ELSE - _limit - END OFFSET _offset) AS stmt; -END -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_get_statement_target(_project_id integer, _info_id integer, _data_id integer, _tables_cell_id bigint, _tables_row_id bigint) - RETURNS SETOF war_gv_statement_target - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE ROWS 1000 - AS $BODY$ -BEGIN - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET LANGUAGE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('language', war.gv_to_jsonb(t3)) target_obj, - fk_class target_class, - notes target_label - FROM - information.language t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET APPPELLATION - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('appellation', war.gv_to_jsonb(t3)) target_obj, - fk_class target_class, - string target_label - FROM - information.appellation t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET LANG_STRING - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('langString', jsonb_build_object('langString', war.gv_to_jsonb(t3), 'language', language.obj)) target_obj, - fk_class target_class, - --concat(t3.string, ' (', language.iso6391, ')' ) target_label - t3.string target_label - FROM - information.v_lang_string t3 - LEFT JOIN LATERAL( - -- LANGUAGE OF LANG_STRING - SELECT - war.gv_to_jsonb(t4) obj, - iso6391 - FROM - information.language t4 - WHERE - t4.pk_entity = t3.fk_language) - LANGUAGE ON - TRUE - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET PLACE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('place', war.gv_to_jsonb(t3)) target_obj, - fk_class target_class, - concat('WGS84: ', lat, '°, ', long, '°') target_label - FROM - information.v_place t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET TIME PRIMITIVE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('timePrimitive', jsonb_build_object('infTimePrimitive', war.gv_to_jsonb(t3), 'timePrimitive', json_build_object('duration', t3.duration, 'julianDay', t3.julian_day, 'calendar', t3.calendar, 'firstSecond', commons.time_primitive__get_first_second(t3.julian_day), 'lastSecond', commons.time_primitive__get_last_second(t3.julian_day, t3.duration, t3.calendar)))) target_obj, - fk_class target_class, - 'todo' target_label - FROM - information.v_time_primitive t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET DIMENSION - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('dimension', jsonb_build_object('dimension', war.gv_to_jsonb(t3), 'unitPreview', entity_preview.obj)) target_obj, - fk_class target_class, - concat_ws(' ', t3.numeric_value, entity_preview.entity_label) target_label - FROM - information.v_dimension t3 - LEFT JOIN LATERAL( SELECT DISTINCT ON(pk_entity) - war.gv_to_jsonb(e.t4) obj, - e.entity_label - FROM( - --repo version - SELECT - t4, - entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = t3.fk_measurement_unit - AND t4.project = 0 - UNION - --project version - SELECT - t4, - entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = t3.fk_measurement_unit - AND t4.project = _project_id) e) entity_preview ON TRUE -WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET ENTITY - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('entity', jsonb_build_object('resource', war.gv_to_jsonb(t3), 'entityPreview', entity_preview.obj)) target_obj, - fk_class target_class, - entity_preview.entity_label target_label - FROM - information.resource t3 - LEFT JOIN LATERAL( SELECT DISTINCT ON(pk_entity) - war.gv_to_jsonb(e.t4) obj, - e.entity_label - FROM( - --repo version - SELECT - t4, - entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = _info_id - AND t4.project = 0 - UNION - --project version - SELECT - t4, - entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = _info_id - AND t4.project = _project_id) e) entity_preview ON TRUE -WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET DIGITAL - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('digital', war.gv_to_jsonb(t3)) target_obj, - 0 target_class, - '' target_label - FROM - data.digital t3 - WHERE - t3.pk_entity = _data_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET CELL - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('cell', war.gv_to_jsonb(t3)) target_obj, - fk_class target_class, - coalesce(string_value, numeric_value::text) target_label - FROM - tables.cell t3 - WHERE - t3.pk_cell = _tables_cell_id; - IF FOUND THEN - RETURN; - END IF; - -- Uncomment this block for joining rows and create column row (fk_class) - -- ---------------------------------------------------------------------- - -- --JOIN STATEMENT'S TARGET ROW - -- ---------------------------------------------------------------------- - -- RETURN QUERY - -- SELECT - -- jsonb_build_object('row', war.gv_to_jsonb (t3)) target_obj, - -- fk_class target_class, - -- 'todo' target_label - -- FROM - -- tables.row t3 - -- WHERE - -- t3.pk_row = _tables_row_id; - -- IF FOUND THEN - -- RETURN; - -- END IF; - ---------------------------------------------------------------------- - --ELSE RETURN 0 ROWS - ---------------------------------------------------------------------- - RETURN; -END -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row data.digital) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'entity_version', _row.entity_version, 'pk_text', _row.pk_text, 'quill_doc', _row.quill_doc, 'string', _row.string, 'fk_system_type', _row.fk_system_type, 'fk_namespace', _row.fk_namespace); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.appellation) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'quill_doc', _row.quill_doc, 'fk_class', _row.fk_class, 'string', _row.string); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.language) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'pk_language', _row.pk_language, 'lang_type', _row.lang_type, 'scope', _row.scope, 'iso6392b', _row.iso6392b, 'iso6392t', _row.iso6392t, 'iso6391', _row.iso6391, 'notes', _row.notes); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.resource) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'community_visibility', _row.community_visibility); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.v_dimension) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'fk_measurement_unit', _row.fk_measurement_unit, 'numeric_value', _row.numeric_value); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.v_lang_string) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'quill_doc', _row.quill_doc, 'string', _row.string, 'fk_language', _row.fk_language); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.v_place) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'long', _row.long, 'lat', _row.lat, 'fk_class', _row.fk_class); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.v_statement) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_subject_info', _row.fk_subject_info, 'fk_subject_data', _row.fk_subject_data, 'fk_subject_tables_cell', _row.fk_subject_tables_cell, 'fk_subject_tables_row', _row.fk_subject_tables_row, 'fk_property', _row.fk_property, 'fk_property_of_property', _row.fk_property_of_property, 'fk_object_info', _row.fk_object_info, 'fk_object_data', _row.fk_object_data, 'fk_object_tables_cell', _row.fk_object_tables_cell, 'fk_object_tables_row', _row.fk_object_tables_row, 'is_in_project_count', _row.is_in_project_count, 'is_standard_in_project_count', _row.is_standard_in_project_count); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row information.v_time_primitive) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_class', _row.fk_class, 'julian_day', _row.julian_day, 'duration', _row.duration, 'calendar', _row.calendar); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row projects.v_info_proj_rel) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_entity', _row.pk_entity, 'fk_project', _row.fk_project, 'fk_entity', _row.fk_entity, 'fk_entity_version', _row.fk_entity_version, 'fk_entity_version_concat', _row.fk_entity_version_concat, 'is_in_project', _row.is_in_project, 'is_standard_in_project', _row.is_standard_in_project, 'ord_num_of_domain', _row.ord_num_of_domain, 'ord_num_of_range', _row.ord_num_of_range, 'fk_creator', _row.fk_creator, 'fk_last_modifier', _row.fk_last_modifier, 'project_visibility', _row.project_visibility); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row tables."row") - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_row', _row.pk_row, 'fk_digital', _row.fk_digital, 'position', _row.position); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row tables.cell) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('pk_cell', _row.pk_cell, 'fk_class', _row.fk_class, 'fk_column', _row.fk_column, 'fk_row', _row.fk_row, 'fk_digital', _row.fk_digital, 'string_value', _row.string_value, 'numeric_value', _row.numeric_value); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.gv_to_jsonb(_row war.entity_preview) - RETURNS jsonb - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - RETURN jsonb_build_object('key', _row.key, 'pk_entity', _row.pk_entity, 'fk_project', _row.fk_project, 'project', _row.project, 'fk_class', _row.fk_class, 'class_label', _row.class_label, 'entity_label', _row.entity_label, 'entity_type', _row.entity_type, 'type_label', _row.type_label, 'fk_type', _row.fk_type, 'time_span', _row.time_span, 'first_second', _row.first_second, 'last_second', _row.last_second, 'tmsp_last_modification', _row.tmsp_last_modification); -END; -$BODY$; - -CREATE OR REPLACE FUNCTION war.update_view_entity_preview(schema_and_table_name character varying) - RETURNS void - LANGUAGE 'plpgsql' - COST 100 VOLATILE PARALLEL UNSAFE - AS $BODY$ -BEGIN - EXECUTE format(' - DROP VIEW IF EXISTS war.entity_preview; - - CREATE VIEW war.entity_preview AS - SELECT * FROM %1$s; - ', schema_and_table_name); -END -$BODY$; - diff --git a/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-up.sql b/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-up.sql deleted file mode 100644 index 04d0a02d7..000000000 --- a/server/db-migrate/migrations/sqls/20230823080214-war-f-remove-unused-functions-up.sql +++ /dev/null @@ -1,38 +0,0 @@ -DROP FUNCTION IF EXISTS war.gv_field_page_incoming_in_project(integer, integer, integer, integer, bigint, bigint, integer, integer, json); - -DROP FUNCTION IF EXISTS war.gv_field_page_incoming_in_repo(integer, integer, integer, bigint, bigint, integer, integer, json); - -DROP FUNCTION IF EXISTS war.gv_field_page_outgoing_in_project(integer, integer, integer, integer, bigint, bigint, integer, integer, json); - -DROP FUNCTION IF EXISTS war.gv_field_page_outgoing_in_repo(integer, integer, integer, bigint, bigint, integer, integer, json); - -DROP FUNCTION IF EXISTS war.gv_get_statement_target(integer, integer, integer, bigint, bigint); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(data.digital); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.appellation); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.language); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.resource); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.v_dimension); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.v_lang_string); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.v_place); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.v_statement); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(information.v_time_primitive); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(projects.v_info_proj_rel); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(tables."row"); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(tables.cell); - -DROP FUNCTION IF EXISTS war.gv_to_jsonb(war.entity_preview_backup); - -DROP FUNCTION IF EXISTS war.update_view_entity_preview(character varying); - diff --git a/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-down.sql b/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-down.sql deleted file mode 100644 index ab7073ccd..000000000 --- a/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-down.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.get_entity_preview_table_name() - RETURNS text - AS $$ -DECLARE - table_name text; -BEGIN - SELECT - substring(view_definition FROM 'FROM[[:space:]]+([[:alnum:]_\.]+)') - FROM - information_schema.views - WHERE - table_schema = 'war' - AND table_name = 'entity_preview' INTO table_name; - RETURN table_name; -END; -$$ -LANGUAGE plpgsql; - diff --git a/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-up.sql b/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-up.sql deleted file mode 100644 index 1b56e7b6a..000000000 --- a/server/db-migrate/migrations/sqls/20230907152905-com-f-hotfix-up.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE FUNCTION commons.get_entity_preview_table_name() - RETURNS text - AS $$ -DECLARE - table_name text; -BEGIN - SELECT - substring(view_definition FROM 'FROM[[:space:]]+([[:alnum:]_\.]+)') - FROM - information_schema.views t1 - WHERE - t1.table_schema = 'war' - AND t1.table_name = 'entity_preview' INTO table_name; - RETURN table_name; -END; -$$ -LANGUAGE plpgsql; - diff --git a/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-down.sql b/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-down.sql deleted file mode 100644 index 6f9be4676..000000000 --- a/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-down.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP TABLE projects.visibility_settings; - -DROP TABLE projects.visibility_settings_vt; - diff --git a/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql b/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql deleted file mode 100644 index fb3bcc545..000000000 --- a/server/db-migrate/migrations/sqls/20240109102503-pro-t-visibility-settings-up.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* Replace with your SQL commands */ -CREATE TABLE projects.visibility_settings( - fk_project integer NOT NULL REFERENCES projects.project(pk_entity) UNIQUE, - settings jsonb NOT NULL -) -INHERITS ( - projects.entity -); - -SELECT - commons.init_entity_child_table('projects.visibility_settings'); - diff --git a/server/db-migrate/up.sh b/server/db-migrate/up.sh index cb92cb6d3..825a2a83e 100644 --- a/server/db-migrate/up.sh +++ b/server/db-migrate/up.sh @@ -17,5 +17,5 @@ export DB_MIGRATE_URL=$DB_MIGRATE_URL $DIR/../node_modules/.bin/db-migrate \ --config $DIR/config.json \ - --migrations-dir $DIR/migrations \ + --migrations-dir $DIR/../../database/migrations \ up "$@" diff --git a/server/package-lock.json b/server/package-lock.json index 2baf718eb..47a5e38fa 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -605,6 +605,11 @@ "to-fast-properties": "^2.0.0" } }, + "@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==" + }, "@cspotcode/source-map-consumer": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", @@ -4368,9 +4373,9 @@ "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==" }, "db-migrate": { - "version": "0.11.12", - "resolved": "https://registry.npmjs.org/db-migrate/-/db-migrate-0.11.12.tgz", - "integrity": "sha512-HUS8T5A3sKGCi+hz9XMKMwAKfU9sqhpDufW9nbVSRc5wxDO695uxA5lDe+If0OdvwwQOVxOnEZqkzAAxgyeFWg==", + "version": "0.11.14", + "resolved": "https://registry.npmjs.org/db-migrate/-/db-migrate-0.11.14.tgz", + "integrity": "sha512-8e+/YsIlM3d69hj+cb6qG6WyubR8nwXfDf9gGLWl4AxHpI6mTomcqhRLNfPrs7Le7AZv2eEsgK8hkXDSQqfIvg==", "requires": { "balanced-match": "^1.0.0", "bluebird": "^3.1.1", @@ -4425,12 +4430,17 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-5.0.1.tgz", "integrity": "sha512-4As8uPrjfwb7VXC+WnLCbXK7y+Ueb2B3zgNCePYfhxS1PYeaO1YTeplffTEcbfLhvFNGLAz90VvJs9yomG7bow==" }, + "minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" + }, "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", "requires": { - "minimist": "^1.2.5" + "minimist": "^1.2.6" } }, "wrap-ansi": { @@ -5948,7 +5958,7 @@ "final-fs": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/final-fs/-/final-fs-1.6.1.tgz", - "integrity": "sha1-1tzZLvb+T+jAer1WjHE1YQ7eMjY=", + "integrity": "sha512-r5dgz23H8qh1LxKVJK84zet2PhWSWkIOgbLVUd5PlNFAULD/kCDBH9JEMwJt9dpdTnLsSD4rEqS56p2MH7Wbvw==", "requires": { "node-fs": "~0.1.5", "when": "~2.0.1" @@ -10159,7 +10169,7 @@ "mongodb-uri": { "version": "0.9.7", "resolved": "https://registry.npmjs.org/mongodb-uri/-/mongodb-uri-0.9.7.tgz", - "integrity": "sha1-D3ca0W9IOuZfQoeWlCjp+8SqYYE=" + "integrity": "sha512-s6BdnqNoEYfViPJgkH85X5Nw5NpzxN8hoflKLweNa7vBxt2V7kaS06d74pAtqDxde8fn4r9h4dNdLiFGoNV0KA==" }, "ms": { "version": "2.1.3", @@ -10383,7 +10393,7 @@ "node-fs": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz", - "integrity": "sha1-MjI8zLRsn78PwRgS1FAhzDHTJbs=" + "integrity": "sha512-XqDBlmUKgDGe76+lZ/0sRBF3XW2vVcK07+ZPvdpUTK8jrvtPahUd0aBqJ9+ZjB01ANjZLuvK3O/eoMVmz62rpA==" }, "node-gyp": { "version": "7.1.2", @@ -11431,7 +11441,7 @@ "parse-database-url": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/parse-database-url/-/parse-database-url-0.3.0.tgz", - "integrity": "sha1-NpZmMh6SfJreY838Gqr2+zdFPQ0=", + "integrity": "sha512-YRxDoVBAUk3ksGF9pud+aqWwXmThZzhX9Z1PPxKU03BB3/gu2RcgyMA4rktMYhkIJ9KxwW7lIj00U+TSNz80wg==", "requires": { "mongodb-uri": ">= 0.9.7" } @@ -11786,28 +11796,33 @@ } }, "prompt": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.2.0.tgz", - "integrity": "sha512-iGerYRpRUg5ZyC+FJ/25G5PUKuWAGRjW1uOlhX7Pi3O5YygdK6R+KEaBjRbHSkU5vfS5PZCltSPZdDtUYwRCZA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.3.0.tgz", + "integrity": "sha512-ZkaRWtaLBZl7KKAKndKYUL8WqNT+cQHKRZnT4RYYms48jQkFw3rrBL+/N5K/KtdEveHkxs982MX2BkDKub2ZMg==", "requires": { - "async": "~0.9.0", - "colors": "^1.1.2", + "@colors/colors": "1.5.0", + "async": "3.2.3", "read": "1.0.x", "revalidator": "0.1.x", "winston": "2.x" }, "dependencies": { "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, + "colors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "integrity": "sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw==" }, "winston": { - "version": "2.4.5", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz", - "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==", + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.7.tgz", + "integrity": "sha512-vLB4BqzCKDnnZH9PHGoS2ycawueX4HLqENXQitvFHczhgW2vFpSOn31LZtVr1KU8YTw7DS4tM+cqyovxo8taVg==", "requires": { - "async": "~1.0.0", + "async": "^2.6.4", "colors": "1.0.x", "cycle": "1.0.x", "eyes": "0.1.x", @@ -11816,14 +11831,12 @@ }, "dependencies": { "async": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", - "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=" - }, - "colors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", - "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=" + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", + "requires": { + "lodash": "^4.17.14" + } } } } @@ -13517,6 +13530,17 @@ "lodash": "^4.17.20" } }, + "ssh2": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.4.0.tgz", + "integrity": "sha512-XvXwcXKvS452DyQvCa6Ct+chpucwc/UyxgliYz+rWXJ3jDHdtBb9xgmxJdMmnIn5bpgGAEV3KaEsH98ZGPHqwg==", + "requires": { + "asn1": "^0.2.4", + "bcrypt-pbkdf": "^1.0.2", + "cpu-features": "0.0.2", + "nan": "^2.15.0" + } + }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", @@ -14580,18 +14604,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - }, - "ssh2": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.4.0.tgz", - "integrity": "sha512-XvXwcXKvS452DyQvCa6Ct+chpucwc/UyxgliYz+rWXJ3jDHdtBb9xgmxJdMmnIn5bpgGAEV3KaEsH98ZGPHqwg==", - "requires": { - "asn1": "^0.2.4", - "bcrypt-pbkdf": "^1.0.2", - "cpu-features": "0.0.2", - "nan": "^2.15.0" - } + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" } } }, @@ -15224,7 +15237,7 @@ "when": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/when/-/when-2.0.1.tgz", - "integrity": "sha1-jYcv4V5oQkyRtLck6EjggH2rZkI=" + "integrity": "sha512-h0l57vFJ4YQe1/U+C+oqBfAoopxXABUm6VqWM0x2gg4pARru4IUWo/PAxyawWgbGtndXrZbA41EzsfxacZVEXQ==" }, "which": { "version": "2.0.2", diff --git a/server/package.json b/server/package.json index 9e278a18c..b145c7a23 100644 --- a/server/package.json +++ b/server/package.json @@ -34,7 +34,6 @@ "build:mock": "node ./scripts/build-mock.js", "build:sdk-windows": "build-ngx-sdk.sh", "build:lb3-sdk": "./node_modules/.bin/lb-sdk lb3app/server/server ../client/projects/lib-sdk-lb3/src/lib/sdk -d ng2web -l angular2", - "start:warehouse": "node ./scripts/start-warehouse.js", "prestart:webserver": "node ./scripts/check-version.js", "start:webserver": "node ./scripts/start-webserver.js", "test:all": "node ./scripts/test.js", @@ -81,7 +80,7 @@ "aws-sdk": "^2.747.0", "bcryptjs": "^2.4.3", "cli-color": "^1.2.0", - "db-migrate": "^0.11.5", + "db-migrate": "^0.11.14", "db-migrate-pg": "^0.4.0", "express-sslify": "^1.2.0", "forever": "^0.15.3", diff --git a/server/scripts/__chooseGvAndWhDb.js b/server/scripts/__chooseGvAndWhDb.js deleted file mode 100644 index 7f84b4d1c..000000000 --- a/server/scripts/__chooseGvAndWhDb.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * This script loads the env vars from .env file - * - * Environment variables declared on the host machine - * override the variables in the .env file! - */ -require('./__dotenv'); -const prompts = require('prompts'); - -async function chooseDb() { - const response = await prompts([ - { - type: 'select', - name: 'gvDbUrl', - message: 'What database should be used as DATABASE_URL?', - choices: [ - {title: 'GV_DB_REVIEW_COPY', value: process.env.GV_DB_REVIEW_COPY}, - {title: 'GV_DB_PROD_COPY', value: process.env.GV_DB_PROD_COPY}, - {title: 'GV_DB_FOR_SEEDING', value: process.env.GV_DB_FOR_SEEDING}, - { - title: 'GV_DB_SCHEMA_TEMPLATE', - value: process.env.GV_DB_SCHEMA_TEMPLATE, - }, - ], - }, - ]); - - if (!response.gvDbUrl) process.exit(); - process.env.DATABASE_URL = response.gvDbUrl; -} -module.exports = chooseDb; diff --git a/server/scripts/__chooseGvDb.js b/server/scripts/__chooseGvDb.js index c50bc9c8d..48ed8d307 100644 --- a/server/scripts/__chooseGvDb.js +++ b/server/scripts/__chooseGvDb.js @@ -14,13 +14,9 @@ async function chooseDb() { name: 'gvDbUrl', message: 'What database should be used as DATABASE_URL?', choices: [ - {title: 'GV_DB_REVIEW_COPY', value: process.env.GV_DB_REVIEW_COPY}, - {title: 'GV_DB_PROD_COPY', value: process.env.GV_DB_PROD_COPY}, - {title: 'GV_DB_FOR_SEEDING', value: process.env.GV_DB_FOR_SEEDING}, - { - title: 'GV_DB_SCHEMA_TEMPLATE', - value: process.env.GV_DB_SCHEMA_TEMPLATE, - }, + {title: 'GV_DB_DEV', value: process.env.GV_DB_DEV}, + {title: 'GV_DB_TEST', value: process.env.GV_DB_TEST}, + {title: 'GV_DB_REMOTE', value: process.env.GV_DB_REMOTE} ], } ]); diff --git a/server/scripts/__execShell.js b/server/scripts/__execShell.js index e32bbc288..4901d6fd2 100644 --- a/server/scripts/__execShell.js +++ b/server/scripts/__execShell.js @@ -9,7 +9,7 @@ module.exports = { const path = require('path'); const script = path.join(__dirname, scriptPath); const myShellScript = exec( - `sh ${script} ${process.argv.slice(2).join(' ')}`, + `bash ${script} ${process.argv.slice(2).join(' ')}`, ); myShellScript.stdout.on('data', data => console.log(data)); myShellScript.stderr.on('data', data => console.error(data)); diff --git a/server/scripts/start-warehouse.js b/server/scripts/start-warehouse.js deleted file mode 100644 index ca2b037f1..000000000 --- a/server/scripts/start-warehouse.js +++ /dev/null @@ -1,45 +0,0 @@ -require('./__dotenv'); -const chooseGvAndWhDB = require('./__chooseGvAndWhDb'); -const prompts = require('prompts'); - -async function chooseStartMode() { - const warehouse = require('../dist/warehouse/startScripts'); - const response = await prompts({ - type: 'select', - name: 'selectedStartFn', - message: 'How should the warehouse be started?', - choices: [ - { - title: 'Start', - description: `Starts the warehouse. If warehouse data is found, - it will only index the changes that happened since last update. - Else will (re-)create the full index.`, - value: warehouse.startDev, - }, - { - title: 'Clean-and-start', - description: - 'Cleans the warehouse data first, then starts the warehouse. This will (re-)create the full index.', - value: warehouse.cleanAndStartDev, - }, - ], - }); - if (!response.selectedStartFn) process.exit(); - - return response.selectedStartFn; -} - -async function start() { - await chooseGvAndWhDB(); - const startFn = await chooseStartMode(); - - await startFn(); -} - -start().catch(err => { - console.log(`***************************************`); - console.error('Warehouse was up and running, when this error occured:'); - console.error(err); - console.log(`***************************************`); - process.exit(1); -}); diff --git a/server/scripts/test.js b/server/scripts/test.js index 303b3d087..bb7be8739 100644 --- a/server/scripts/test.js +++ b/server/scripts/test.js @@ -3,7 +3,7 @@ const prompts = require('prompts'); const path = require('path'); const fs = require('fs'); const helpers = require('./__helpers'); -const chooseGvAndWhDB = require('./__chooseGvAndWhDb'); +const chooseGvAndWhDB = require('./__chooseGvDb'); process.env.LOGS = 'OFF'; process.env.NO_LOGS = 'true'; diff --git a/server/src/__tests__/acceptance/controllers/project-data/subfield-page.controller.acceptance.ts b/server/src/__tests__/acceptance/controllers/project-data/subfield-page.controller.acceptance.ts index 8e09bfdb0..72c521619 100644 --- a/server/src/__tests__/acceptance/controllers/project-data/subfield-page.controller.acceptance.ts +++ b/server/src/__tests__/acceptance/controllers/project-data/subfield-page.controller.acceptance.ts @@ -1,7 +1,10 @@ import {Client, expect} from '@loopback/testlab'; import {GeovistoryApplication} from '../../../../application'; import {GvPaginationObject} from '../../../../models'; -import {GvFieldPageReqMock, modifiedScope} from '../../../helpers/data/api-requests/GvFieldPageReq'; +import { + GvFieldPageReqMock, + modifiedScope, +} from '../../../helpers/data/api-requests/GvFieldPageReq'; import {GvPaginationObjectMock} from '../../../helpers/data/api-responses/GvPaginationObjectMock'; import {InfResourceMock} from '../../../helpers/data/gvDB/InfResourceMock'; import {ProProjectMock} from '../../../helpers/data/gvDB/ProProjectMock'; @@ -9,7 +12,6 @@ import {SubfieldHelper} from '../../../helpers/graphs/subfield-page.helper'; import {setupApplication} from '../../../helpers/gv-server-helpers'; import {cleanDb} from '../../../helpers/meta/clean-db.helper'; - describe('SubfieldPageController', () => { let server: GeovistoryApplication; let client: Client; @@ -18,15 +20,16 @@ describe('SubfieldPageController', () => { before(async () => { ({server, client} = await setupApplication()); - }) + }); beforeEach(async () => { await cleanDb(); - const d = await SubfieldHelper.makeProject1() + const d = await SubfieldHelper.makeProject1(); // eslint-disable-next-line @typescript-eslint/no-unused-vars pkProject = d.pk_entity; - const res = await client.post('/login') - .send({email: "gaetan.muck@kleiolab.ch", password: "testtest1"}); - lb4Token = res.body.lb4Token + const res = await client + .post('/login') + .send({email: 'gaetan.muck@kleiolab.ch', password: 'testtest1'}); + lb4Token = res.body.lb4Token; }); after(async () => { try { @@ -38,115 +41,156 @@ describe('SubfieldPageController', () => { describe('POST /subfield-page/load-subfield-page', () => { it('should reject unauthorized', async () => { - await client.post('/subfield-page/load-subfield-page') + await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) - .send([{ - ...GvFieldPageReqMock.appeTeEnRefersToName, - pkProject: -99 - }]) + .send([ + { + ...GvFieldPageReqMock.appeTeEnRefersToName, + pkProject: -99, + }, + ]) .expect(403); }); it('should return field page for appeTeEnRefersToName (targetType: appellation)', async () => { - await SubfieldHelper.appeTeEnRefersToName() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.appeTeEnRefersToName(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.appeTeEnRefersToName]) .expect(200); checkPaginationObject(res.body, GvPaginationObjectMock.appeTeEnHasAppeVt); }); it('should return count 1 even when limit 0', async () => { - await SubfieldHelper.appeTeEnRefersToName() - const tmpl = GvFieldPageReqMock.appeTeEnRefersToName - const req = {...tmpl, page: {...tmpl.page, limit: 0}} - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.appeTeEnRefersToName(); + const tmpl = GvFieldPageReqMock.appeTeEnRefersToName; + const req = {...tmpl, page: {...tmpl.page, limit: 0}}; + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([req]) .expect(200); - expect((res.body as GvPaginationObject).subfieldPages[0].count).to.equal(1) + expect((res.body as GvPaginationObject).subfieldPages[0].count).to.equal( + 1, + ); }); it('should return empty page', async () => { // await SubfieldHelper.appeTeEnRefersToName() We don't seed data! - const res = await client.post('/subfield-page/load-subfield-page') + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.appeTeEnRefersToName]) .expect(200); - expect(res.body).to.containDeep(GvPaginationObjectMock.appeTeEnHasAppeVtEmpty); + expect(res.body).to.containDeep( + GvPaginationObjectMock.appeTeEnHasAppeVtEmpty, + ); }); it('should return field page for appeTeEnUsedInLanguage (targetType: language)', async () => { - await SubfieldHelper.appeTeEnUsedInLanguage() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.appeTeEnUsedInLanguage(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.appeTeEnUsedInLanguage]) .expect(200); - checkPaginationObject(res.body, GvPaginationObjectMock.appeTeEnUsedInLanguage); + checkPaginationObject( + res.body, + GvPaginationObjectMock.appeTeEnUsedInLanguage, + ); }); it('should return 4 field pages for 4 requests', async () => { - await SubfieldHelper.definitionHasValueVersions() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.definitionHasValueVersions(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([ GvFieldPageReqMock.definitionHasValueVersion, - modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, {notInProject: ProProjectMock.PROJECT_1.pk_entity}), - modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, {inRepo: true}), - modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, {noContraint: true}), + modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, { + notInProject: ProProjectMock.PROJECT_1.pk_entity, + }), + modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, { + inRepo: true, + }), + modifiedScope(GvFieldPageReqMock.definitionHasValueVersion, { + noContraint: true, + }), ]) .expect(200); const pages: GvPaginationObject = res.body; - expect(pages.subfieldPages.length).equal(4) - const inRepo = pages.subfieldPages.find(p => p.req.page.scope.inRepo) - expect(inRepo?.count).equal(1) - const noContraint = pages.subfieldPages.find(p => p.req.page.scope.noContraint) - expect(noContraint?.count).equal(2) - + expect(pages.subfieldPages.length).equal(4); + const inRepo = pages.subfieldPages.find(p => p.page.scope.inRepo); + expect(inRepo?.count).equal(1); + const noContraint = pages.subfieldPages.find( + p => p.page.scope.noContraint, + ); + expect(noContraint?.count).equal(2); }); it('should return field page for appeTeEnIsAppeOfPerson (targetType: entityPreview)', async () => { - await SubfieldHelper.appeTeEnIsAppeOfPerson() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.appeTeEnIsAppeOfPerson(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.appeTeEnIsAppeOfPerson]) .expect(200); - checkPaginationObject(res.body, GvPaginationObjectMock.appeTeEnIsAppeOfPerson); + checkPaginationObject( + res.body, + GvPaginationObjectMock.appeTeEnIsAppeOfPerson, + ); }); it('should return field page for madridsPresenceWasAtPlace (targetType: place)', async () => { - await SubfieldHelper.madridsPresenceWasAtPlace() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.madridsPresenceWasAtPlace(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.madridsPresenceWasAtPlace]) .expect(200); - checkPaginationObject(res.body, GvPaginationObjectMock.madridsPresenceWasAtPlace); - + checkPaginationObject( + res.body, + GvPaginationObjectMock.madridsPresenceWasAtPlace, + ); }); it('should return field page for journeyHasDuration (targetType: dimension)', async () => { - await SubfieldHelper.journeyHasDuration() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.journeyHasDuration(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.journyeHasDuration]) .expect(200); - checkPaginationObject(res.body, GvPaginationObjectMock.journeyHasDuration); + checkPaginationObject( + res.body, + GvPaginationObjectMock.journeyHasDuration, + ); }); it('should return field page for manifSingletonHasShortTitleMurderer', async () => { - await SubfieldHelper.manifSingletonHasShortTitleMurderer() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.manifSingletonHasShortTitleMurderer(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.manifSingletonHasShortTitleMurderer]) .expect(200); - checkPaginationObject(res.body, GvPaginationObjectMock.manifSingletonHasShortTitleMurderer); + checkPaginationObject( + res.body, + GvPaginationObjectMock.manifSingletonHasShortTitleMurderer, + ); }); it('should return field page for shipVoyageAtSomeTimeWithin (targetType: timePrimirive)', async () => { - await SubfieldHelper.shipVoyageAtSomeTimeWithin() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.shipVoyageAtSomeTimeWithin(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.shipVoyageAtSomeTimeWithin]) .expect(200); - expect(res.body).to.containDeep(GvPaginationObjectMock.shipVoyageAtSomeTimeWithin); + expect(res.body).to.containDeep( + GvPaginationObjectMock.shipVoyageAtSomeTimeWithin, + ); }); it('should return field page for personHasAppeTeEn (targetType: nestedResource)', async () => { - await SubfieldHelper.personHasAppeTeEn() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.personHasAppeTeEn(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.person1HasAppeTeEn]) .expect(200); @@ -154,58 +198,64 @@ describe('SubfieldPageController', () => { }); it('should return field pages for personHasTwoAppeTeEn (targetType: nestedResource)', async () => { - await SubfieldHelper.personHasTwoAppeTeEn() - const res = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.personHasTwoAppeTeEn(); + const res = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.person1HasAppeTeEn]) .expect(200); - expect((res.body as GvPaginationObject).subfieldPages.length).to.equal(3) + expect((res.body as GvPaginationObject).subfieldPages.length).to.equal(3); - expect((res.body as GvPaginationObject).subfieldPages[0].count) - .to.equal(GvPaginationObjectMock.personHasTwoAppeTeEn.subfieldPages[0].count) + expect((res.body as GvPaginationObject).subfieldPages[0].count).to.equal( + GvPaginationObjectMock.personHasTwoAppeTeEn.subfieldPages[0].count, + ); for (const fkSource of [ InfResourceMock.PERSON_1.pk_entity, InfResourceMock.NAMING_1.pk_entity, - InfResourceMock.NAMING_2.pk_entity + InfResourceMock.NAMING_2.pk_entity, ]) { - const result = (res.body as GvPaginationObject).subfieldPages - .find(s => s.req.page.source.fkInfo === fkSource) - const expected = GvPaginationObjectMock.personHasTwoAppeTeEn.subfieldPages - .find(s => s.req.page.source.fkInfo === fkSource) - expect(result?.count).to.deepEqual(expected?.count) - expect(result?.req).to.containDeep(expected?.req) - expect(result?.paginatedStatements).to.containDeep(expected?.paginatedStatements) - expect(result).to.containDeep(expected) + const result = (res.body as GvPaginationObject).subfieldPages.find( + s => s.page.source.fkInfo === fkSource, + ); + const expected = + GvPaginationObjectMock.personHasTwoAppeTeEn.subfieldPages.find( + s => s.page.source.fkInfo === fkSource, + ); + expect(result?.count).to.deepEqual(expected?.count); + expect(result?.page).to.containDeep(expected?.page); + expect(result?.paginatedStatements).to.containDeep( + expected?.paginatedStatements, + ); + expect(result).to.containDeep(expected); } }); it('should return field page with a timestamp', async () => { - await SubfieldHelper.personHasAppeTeEn() - const res: {body: GvPaginationObject} = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.personHasAppeTeEn(); + const res: {body: GvPaginationObject} = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.person1HasAppeTeEn]) .expect(200); - const d = res.body.subfieldPages[0].validFor?.toString() as string + const d = res.body.subfieldPages[0].validFor?.toString() as string; expect(new Date(d) > new Date('1999-01-01')).to.be.true(); }); - it('should not return statement pointing to entity with disabled toolbox-commnity-visibility', async () => { - await SubfieldHelper.hasReproduction() - const res: {body: GvPaginationObject} = await client.post('/subfield-page/load-subfield-page') + await SubfieldHelper.hasReproduction(); + const res: {body: GvPaginationObject} = await client + .post('/subfield-page/load-subfield-page') .set('Authorization', lb4Token) .send([GvFieldPageReqMock.hasReproductionNotInProject]) .expect(200); - expect((res.body as GvPaginationObject).subfieldPages[0].count).to.equal(1) + expect((res.body as GvPaginationObject).subfieldPages[0].count).to.equal( + 1, + ); expect( - (res.body as GvPaginationObject) - .subfieldPages[0] - .paginatedStatements[0] - .target.entity?.resource.community_visibility.toolbox - ).to.equal(true) - - + (res.body as GvPaginationObject).subfieldPages[0].paginatedStatements[0] + .target.entity?.resource.community_visibility.toolbox, + ).to.equal(true); }); // it('should return field page for propertyOfProperty (targetType: languageString)', async () => { @@ -218,63 +268,48 @@ describe('SubfieldPageController', () => { // // expect(res.body).to.containDeep(GvPaginationObjectMock.statementOfStatementHasExactReference); // }); - }); - }); -function checkPaginationObject(result: GvPaginationObject, expected: GvPaginationObject) { - - expect( - result.subfieldPages[0].count - ).to.containDeep( - expected.subfieldPages[0].count +function checkPaginationObject( + result: GvPaginationObject, + expected: GvPaginationObject, +) { + expect(result.subfieldPages[0].count).to.containDeep( + expected.subfieldPages[0].count, ); - expect( - result.subfieldPages[0].req - ).to.containDeep( - expected.subfieldPages[0].req + expect(result.subfieldPages[0].page).to.containDeep( + expected.subfieldPages[0].page, ); expect( - result.subfieldPages[0].paginatedStatements[0].statement - ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].statement - ); - expect( - result.subfieldPages[0].paginatedStatements[0].projRel - ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].projRel + result.subfieldPages[0].paginatedStatements[0].statement, + ).to.containDeep(expected.subfieldPages[0].paginatedStatements[0].statement); + expect(result.subfieldPages[0].paginatedStatements[0].projRel).to.containDeep( + expected.subfieldPages[0].paginatedStatements[0].projRel, ); - expect( - result.subfieldPages[0].paginatedStatements[0].ordNum - ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].ordNum + expect(result.subfieldPages[0].paginatedStatements[0].ordNum).to.containDeep( + expected.subfieldPages[0].paginatedStatements[0].ordNum, ); expect( - result.subfieldPages[0].paginatedStatements[0].isOutgoing - ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].isOutgoing - ); + result.subfieldPages[0].paginatedStatements[0].isOutgoing, + ).to.containDeep(expected.subfieldPages[0].paginatedStatements[0].isOutgoing); - expect( - result.subfieldPages[0].paginatedStatements[0].target - ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].target + expect(result.subfieldPages[0].paginatedStatements[0].target).to.containDeep( + expected.subfieldPages[0].paginatedStatements[0].target, ); expect( - result.subfieldPages[0].paginatedStatements[0].targetClass + result.subfieldPages[0].paginatedStatements[0].targetClass, ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].targetClass + expected.subfieldPages[0].paginatedStatements[0].targetClass, ); expect( - result.subfieldPages[0].paginatedStatements[0].targetLabel + result.subfieldPages[0].paginatedStatements[0].targetLabel, ).to.containDeep( - expected.subfieldPages[0].paginatedStatements[0].targetLabel + expected.subfieldPages[0].paginatedStatements[0].targetLabel, ); } - diff --git a/server/src/__tests__/acceptance/controllers/war-entity-preview.controller.acceptance.ts b/server/src/__tests__/acceptance/controllers/war-entity-preview.controller.acceptance.ts index f1f2b7980..1a1df8174 100644 --- a/server/src/__tests__/acceptance/controllers/war-entity-preview.controller.acceptance.ts +++ b/server/src/__tests__/acceptance/controllers/war-entity-preview.controller.acceptance.ts @@ -30,7 +30,7 @@ describe('WarEntityPreviewController', () => { await cleanDb(); entityPreview = await createWarEntityPreview(new WarEntityPreviewWithFulltext({ pk_entity: 4, - project_id: 8, + fk_project: 8, fk_class: 21, entity_label: 'foo', })); @@ -41,8 +41,8 @@ describe('WarEntityPreviewController', () => { const url = server.url; const socketClient = io(`${url}/WarEntityPreview`); // add to stream - const key = entityPreview.project_id + '_' + entityPreview.pk_entity; - socketClient.emit('addToStream', {pkProject: entityPreview.project_id, pks: [key]}); + const key = entityPreview.fk_project + '_' + entityPreview.pk_entity; + socketClient.emit('addToStream', {pkProject: entityPreview.fk_project, pks: [key]}); // wait for response of server being received by client const reply = await pEvent(socketClient, 'entityPreview'); @@ -58,8 +58,8 @@ describe('WarEntityPreviewController', () => { const url = server.url; const socketClient = io(`${url}/WarEntityPreview`); // add to stream - const key = entityPreview.project_id + '_' + entityPreview.pk_entity; - socketClient.emit('addToStream', {pkProject: entityPreview.project_id, pks: [key]}); + const key = entityPreview.fk_project + '_' + entityPreview.pk_entity; + socketClient.emit('addToStream', {pkProject: entityPreview.fk_project, pks: [key]}); // wait for response of server being received by client const reply = await pEvent(socketClient, 'entityPreview'); @@ -112,14 +112,14 @@ describe('WarEntityPreviewController', () => { // add repo variant createWarEntityPreview(new WarEntityPreviewWithFulltext({ pk_entity: pkEntity1, - project_id: 0, + fk_project: 0, entity_label: 'foo repo', fk_class: 21, })) // add project variant createWarEntityPreview(new WarEntityPreviewWithFulltext({ pk_entity: pkEntity1, - project_id: pkProject, + fk_project: pkProject, entity_label: 'foo', fk_class: 21, })) @@ -133,12 +133,12 @@ describe('WarEntityPreviewController', () => { let reply; // update repo variant - updateWarEntityPreview({pk_entity: pkEntity1, project_id: 0}, + updateWarEntityPreview({pk_entity: pkEntity1, fk_project: 0}, {entity_label: 'foo repo 2'} ).then(_ => { setTimeout(() => { // update prioject variant - updateWarEntityPreview({pk_entity: pkEntity1, project_id: pkProject}, + updateWarEntityPreview({pk_entity: pkEntity1, fk_project: pkProject}, {entity_label: 'foo project 2'} ) }, 10) diff --git a/server/src/__tests__/helpers/atomic/war-entity-preview.helper.ts b/server/src/__tests__/helpers/atomic/war-entity-preview.helper.ts index d0cc74214..a4f25e7c6 100644 --- a/server/src/__tests__/helpers/atomic/war-entity-preview.helper.ts +++ b/server/src/__tests__/helpers/atomic/war-entity-preview.helper.ts @@ -17,7 +17,7 @@ export async function getWarEntityPreview(pkEntity: number, fkProject = 0) { return createWarEntityPreviewRepo().find({ where: { and: [ - {project_id: {eq: fkProject}}, + {fk_project: {eq: fkProject}}, {pk_entity: {eq: pkEntity}}, ] } diff --git a/server/src/__tests__/helpers/data/api-responses/GvPaginationObjectMock.ts b/server/src/__tests__/helpers/data/api-responses/GvPaginationObjectMock.ts index eb7f7ee4c..ed00f27a7 100644 --- a/server/src/__tests__/helpers/data/api-responses/GvPaginationObjectMock.ts +++ b/server/src/__tests__/helpers/data/api-responses/GvPaginationObjectMock.ts @@ -1,55 +1,68 @@ -import {GvFieldPageReq, GvPaginationObject, InfAppellation, InfDimension, InfLangString, InfLanguage, InfPlace, InfResource, InfStatement, InfTimePrimitive, ProInfoProjRel, WarEntityPreview} from '../../../../models' -import {TrueEnum} from '../../../../models/enums/TrueEnum' -import {StatementWithTarget} from '../../../../models/field-response/gv-statement-with-target' -import {SatementTarget} from '../../../../models/field-response/SatementTarget' -import {GvFieldPageReqMock} from '../api-requests/GvFieldPageReq' -import {DfhApiClassMock} from '../gvDB/DfhApiClassMock' -import {DfhApiPropertyMock} from '../gvDB/DfhApiPropertyMock' -import {InfAppellationMock} from '../gvDB/InfAppellationMock' -import {InfDimensionMock} from '../gvDB/InfDimensionMock' -import {InfLangStringMock} from '../gvDB/InfLangStringMock' -import {InfLanguageMock} from '../gvDB/InfLanguageMock' -import {InfPlaceMock} from '../gvDB/InfPlaceMock' -import {InfResourceMock} from '../gvDB/InfResourceMock' -import {InfStatementMock} from '../gvDB/InfStatementMock' -import {DEFAULT_DURATION, InfTimePrimitiveMock} from '../gvDB/InfTimePrimitiveMock' -import {NewDfhApiProperty, OmitEntity} from '../gvDB/local-model.helpers' -import {ProInfoProjRelMock} from '../gvDB/ProInfoProjRelMock' -import {ProProjectMock} from '../gvDB/ProProjectMock' -import {PubAccountMock} from '../gvDB/PubAccountMock' -import {WarEntityPreviewMock} from '../gvDB/WarEntityPreviewMock' +import { + GvFieldPage, + GvPaginationObject, + InfAppellation, + InfDimension, + InfLangString, + InfLanguage, + InfPlace, + InfResource, + InfStatement, + InfTimePrimitive, + ProInfoProjRel, + WarEntityPreview, +} from '../../../../models'; +import {StatementWithTarget} from '../../../../models/field-response/gv-statement-with-target'; +import {SatementTarget} from '../../../../models/field-response/SatementTarget'; +import {GvFieldPageReqMock} from '../api-requests/GvFieldPageReq'; +import {DfhApiPropertyMock} from '../gvDB/DfhApiPropertyMock'; +import {InfAppellationMock} from '../gvDB/InfAppellationMock'; +import {InfDimensionMock} from '../gvDB/InfDimensionMock'; +import {InfLangStringMock} from '../gvDB/InfLangStringMock'; +import {InfLanguageMock} from '../gvDB/InfLanguageMock'; +import {InfPlaceMock} from '../gvDB/InfPlaceMock'; +import {InfResourceMock} from '../gvDB/InfResourceMock'; +import {InfStatementMock} from '../gvDB/InfStatementMock'; +import { + DEFAULT_DURATION, + InfTimePrimitiveMock, +} from '../gvDB/InfTimePrimitiveMock'; +import {NewDfhApiProperty, OmitEntity} from '../gvDB/local-model.helpers'; +import {ProInfoProjRelMock} from '../gvDB/ProInfoProjRelMock'; +import {ProProjectMock} from '../gvDB/ProProjectMock'; +import {PubAccountMock} from '../gvDB/PubAccountMock'; +import {WarEntityPreviewMock} from '../gvDB/WarEntityPreviewMock'; - -export function createStatementWithTarget(statement: OmitEntity, accountId = 1001, target: SatementTarget, isOutgoing: boolean, projRel?: OmitEntity): StatementWithTarget { - - let targetLabel = '' +export function createStatementWithTarget( + statement: OmitEntity, + accountId = 1001, + target: SatementTarget, + isOutgoing: boolean, + projRel?: OmitEntity, +): StatementWithTarget { + let targetLabel = ''; if (target.appellation) { - targetLabel = target.appellation?.string ?? '' - } - else if (target.dimension) { - targetLabel = `${target.dimension.dimension.numeric_value} ${target.dimension?.unitPreview?.entity_label}` // todo add ${unitPreview.entity_label} - } - else if (target.langString) { - targetLabel = `${target.langString.langString.string} (${target.langString.language.iso6391})` // todo add - } - else if (target.language) { - targetLabel = `${target.language.notes ?? target.language.iso6391}` // todo add (${language.iso6391}) - } - else if (target.entity) { - targetLabel = `${target.entity.entityPreview?.entity_label}` - } - else if (target.timePrimitive) { - targetLabel = `todo` // todo - } - else if (target.place) { - targetLabel = `WGS84: ${target.place.lat}°, ${target.place.long}°` // todo + targetLabel = target.appellation?.string ?? ''; + } else if (target.dimension) { + targetLabel = `${target.dimension.dimension.numeric_value} ${target.dimension?.unitPreview?.entity_label}`; // todo add ${unitPreview.entity_label} + } else if (target.langString) { + targetLabel = `${target.langString.langString.string} (${target.langString.language.iso6391})`; // todo add + } else if (target.language) { + targetLabel = `${target.language.notes ?? target.language.iso6391}`; // todo add (${language.iso6391}) + } else if (target.entity) { + targetLabel = `${target.entity.entityPreview?.entity_label}`; + } else if (target.timePrimitive) { + targetLabel = `todo`; // todo + } else if (target.place) { + targetLabel = `WGS84: ${target.place.lat}°, ${target.place.long}°`; // todo } return { isOutgoing, ordNum: isOutgoing ? projRel?.ord_num_of_range : projRel?.ord_num_of_domain, statement, target, - targetClass: target.appellation?.fk_class ?? + targetClass: + target.appellation?.fk_class ?? target.dimension?.dimension.fk_class ?? target.entity?.resource.fk_class ?? target.langString?.langString?.fk_class ?? @@ -58,63 +71,62 @@ export function createStatementWithTarget(statement: OmitEntity, a target.timePrimitive?.infTimePrimitive.fk_class ?? -1, targetLabel, - projRel - } + projRel, + }; } const appeTeEnHasAppeVt: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnRefersToName, + page: GvFieldPageReqMock.appeTeEnRefersToName.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ), ], - } - ] -} + }, + ], +}; const appeTeEnHasAppeVtEmpty: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnRefersToName, + page: GvFieldPageReqMock.appeTeEnRefersToName.page, count: 0, paginatedStatements: [], - } - ] -} + }, + ], +}; const appeTeEnUsedInLanguage: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnUsedInLanguage, + page: GvFieldPageReqMock.appeTeEnUsedInLanguage.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_LANG, PubAccountMock.GAETAN_VERIFIED.id, { - language: InfLanguageMock.ENGLISH as InfLanguage + language: InfLanguageMock.ENGLISH as InfLanguage, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_LANG, - ) + ), ], - } + }, ], - -} +}; const appeTeEnIsAppeOfPerson: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.appeTeEnIsAppeOfPerson, + page: GvFieldPageReqMock.appeTeEnIsAppeOfPerson.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -123,20 +135,20 @@ const appeTeEnIsAppeOfPerson: GvPaginationObject = { { entity: { resource: InfResourceMock.PERSON_1 as InfResource, - entityPreview: WarEntityPreviewMock.PERSON_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.PERSON_1 as WarEntityPreview, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, - ) + ), ], - } + }, ], -} +}; const madridsPresenceWasAtPlace: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.madridsPresenceWasAtPlace, + page: GvFieldPageReqMock.madridsPresenceWasAtPlace.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -147,15 +159,15 @@ const madridsPresenceWasAtPlace: GvPaginationObject = { }, true, ProInfoProjRelMock.PROJ_1_STMT_MADRIDS_PRESENCE_WAS_AT_PLACE_123, - ) + ), ], - } + }, ], -} +}; const journeyHasDuration: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.journyeHasDuration, + page: GvFieldPageReqMock.journyeHasDuration.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -164,20 +176,22 @@ const journeyHasDuration: GvPaginationObject = { { dimension: { dimension: InfDimensionMock.ONE_MONTH as InfDimension, - unitPreview: WarEntityPreviewMock.TIME_UNIT_ONE_MONTH as WarEntityPreview - } + unitPreview: + WarEntityPreviewMock.TIME_UNIT_ONE_MONTH as WarEntityPreview, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_ACCOUNT_OF_JOURNEY_HAS_DURATION, - )], - } + ), + ], + }, ], -} +}; const manifSingletonHasShortTitleMurderer: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.manifSingletonHasShortTitleMurderer, + page: GvFieldPageReqMock.manifSingletonHasShortTitleMurderer.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -185,21 +199,23 @@ const manifSingletonHasShortTitleMurderer: GvPaginationObject = { PubAccountMock.GAETAN_VERIFIED.id, { langString: { - langString: InfLangStringMock.EN_SHORT_TITLE_THE_MURDERER as InfLangString, - language: InfLanguageMock.ENGLISH as InfLanguage - } + langString: + InfLangStringMock.EN_SHORT_TITLE_THE_MURDERER as InfLangString, + language: InfLanguageMock.ENGLISH as InfLanguage, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_MANIF_SINGLETON_HAS_SHORT_TITLE_MURDERER, - )], - } - ] -} + ), + ], + }, + ], +}; const shipVoyageAtSomeTimeWithin: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.shipVoyageAtSomeTimeWithin, + page: GvFieldPageReqMock.shipVoyageAtSomeTimeWithin.page, count: 1, paginatedStatements: [ createStatementWithTarget( @@ -209,41 +225,42 @@ const shipVoyageAtSomeTimeWithin: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_2 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_2.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_2.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_2.julian_day, calendar: InfTimePrimitiveMock.TP_2.calendar, - } - } + }, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_AT_SOME_TIME_WITHIN_TP_2, - ) + ), ], - } + }, ], -} +}; const shipVoyageHasTimeSpan: GvPaginationObject = { subfieldPages: [ { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_71_ONGOING_THROUGHOUT + DfhApiPropertyMock.EN_71_ONGOING_THROUGHOUT, ), count: 0, paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_72_AT_SOME_TIME_WITHIN + DfhApiPropertyMock.EN_72_AT_SOME_TIME_WITHIN, ), count: 0, paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_152_BEGIN_OF_THE_BEGIN + DfhApiPropertyMock.EN_152_BEGIN_OF_THE_BEGIN, ), count: 1, paginatedStatements: [ @@ -255,29 +272,30 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_5 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_5.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_5.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_5.julian_day, - calendar: InfTimePrimitiveMock.TP_5.calendar - } - } + calendar: InfTimePrimitiveMock.TP_5.calendar, + }, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_BEGIN_TP_5, - ) + ), ], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_150_END_OF_THE_BEGIN + DfhApiPropertyMock.EN_150_END_OF_THE_BEGIN, ), count: 0, paginatedStatements: [], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_151_BEGIN_OF_THE_END + DfhApiPropertyMock.EN_151_BEGIN_OF_THE_END, ), count: 1, paginatedStatements: [ @@ -288,35 +306,35 @@ const shipVoyageHasTimeSpan: GvPaginationObject = { timePrimitive: { infTimePrimitive: InfTimePrimitiveMock.TP_4 as InfTimePrimitive, timePrimitive: { - duration: InfTimePrimitiveMock.TP_4.duration ?? DEFAULT_DURATION, + duration: + InfTimePrimitiveMock.TP_4.duration ?? DEFAULT_DURATION, julianDay: InfTimePrimitiveMock.TP_4.julian_day, - calendar: InfTimePrimitiveMock.TP_4.calendar - } - } + calendar: InfTimePrimitiveMock.TP_4.calendar, + }, + }, }, true, ProInfoProjRelMock.PROJ_1_STMT_SHIP_VOYAGE_BEGIN_OF_THE_END_TP_4, - ) + ), ], }, { - req: createTimeSpanSubPage( + page: createTimeSpanSubPage( InfResourceMock.SHIP_VOYAGE.pk_entity as number, - DfhApiPropertyMock.EN_153_END_OF_THE_END + DfhApiPropertyMock.EN_153_END_OF_THE_END, ), count: 0, paginatedStatements: [], }, ], - -} +}; const personHasAppeTeEn: GvPaginationObject = { subfieldPages: [ { - req: { - ...GvFieldPageReqMock.person1HasAppeTeEn, - page: {...GvFieldPageReqMock.person1HasAppeTeEn.page, isOutgoing: false}, + page: { + ...GvFieldPageReqMock.person1HasAppeTeEn.page, + isOutgoing: false, }, count: 1, paginatedStatements: [ @@ -326,18 +344,18 @@ const personHasAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_1 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview, + }, }, false, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, - ) + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEnRefersToName, - page: {...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1}, + page: { + ...GvFieldPageReqMock.appeTeEnRefersToName.page, + limit: 1, }, count: 1, paginatedStatements: [ @@ -345,21 +363,21 @@ const personHasAppeTeEn: GvPaginationObject = { InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ), ], }, ], -} +}; const personHasTwoAppeTeEn: GvPaginationObject = { subfieldPages: [ { - req: { - ...GvFieldPageReqMock.person1HasAppeTeEn, - page: {...GvFieldPageReqMock.person1HasAppeTeEn.page, isOutgoing: false}, + page: { + ...GvFieldPageReqMock.person1HasAppeTeEn.page, + isOutgoing: false, }, count: 2, paginatedStatements: [ @@ -369,8 +387,8 @@ const personHasTwoAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_1 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_1 as WarEntityPreview, + }, }, false, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_PERSON, @@ -381,56 +399,50 @@ const personHasTwoAppeTeEn: GvPaginationObject = { { entity: { resource: InfResourceMock.NAMING_2 as InfResource, - entityPreview: WarEntityPreviewMock.NAMING_2 as WarEntityPreview - } + entityPreview: WarEntityPreviewMock.NAMING_2 as WarEntityPreview, + }, }, false, ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_PERSON, - ) + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEnRefersToName, - page: {...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1}, - }, + page: {...GvFieldPageReqMock.appeTeEnRefersToName.page, limit: 1}, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_1_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation + appellation: InfAppellationMock.JACK_THE_FOO as InfAppellation, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_1_TO_APPE, - ) + ), ], }, { - req: { - ...GvFieldPageReqMock.appeTeEn2RefersToName, - page: {...GvFieldPageReqMock.appeTeEn2RefersToName.page, limit: 1}, - }, + page: {...GvFieldPageReqMock.appeTeEn2RefersToName.page, limit: 1}, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.NAME_2_TO_APPE, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.JACK as InfAppellation + appellation: InfAppellationMock.JACK as InfAppellation, }, true, ProInfoProjRelMock.PROJ_1_STMT_NAME_2_TO_APPE, - ) + ), ], }, ], -} +}; // const statementOfStatementHasExactReference: GvPaginationObject = { // subfieldPages: [ // { -// req: GvFieldPageReqMock.statementOfStatementHasExactReference, +// page: GvFieldPageReqMock.statementOfStatementHasExactReference.page, // count: 1, // paginatedStatements: [ // createStatementWithTarget( @@ -449,26 +461,25 @@ const personHasTwoAppeTeEn: GvPaginationObject = { // ] // } - const definitionHasValueVersion: GvPaginationObject = { subfieldPages: [ { - req: GvFieldPageReqMock.definitionHasValueVersion, + page: GvFieldPageReqMock.definitionHasValueVersion.page, count: 1, paginatedStatements: [ createStatementWithTarget( InfStatementMock.DEFINITION_1_HAS_VALUE_VERSION_2, PubAccountMock.GAETAN_VERIFIED.id, { - appellation: InfAppellationMock.VALUE_VERSION_2 as InfAppellation + appellation: InfAppellationMock.VALUE_VERSION_2 as InfAppellation, }, true, ProInfoProjRelMock.PROJ_1_STMT_DEFINITION_1_HAS_VALUE_VERSION_2, - )], - } + ), + ], + }, ], -} - +}; export const GvPaginationObjectMock = { appeTeEnHasAppeVt, @@ -483,25 +494,19 @@ export const GvPaginationObjectMock = { personHasAppeTeEn, personHasTwoAppeTeEn, definitionHasValueVersion, -} +}; - -export function createTimeSpanSubPage(sourceEntity: number, property: NewDfhApiProperty): GvFieldPageReq { +export function createTimeSpanSubPage( + sourceEntity: number, + property: NewDfhApiProperty, +): GvFieldPage { return { - pkProject: ProProjectMock.PROJECT_1.pk_entity, - targets: { - [DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class]: { - timePrimitive: TrueEnum.true - } - }, - page: { - source: {fkInfo: sourceEntity}, - property: {fkProperty: property.dfh_pk_property}, - isOutgoing: true, - // targetClass: DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class, - scope: {inProject: ProProjectMock.PROJECT_1.pk_entity as number}, - limit: 1, - offset: 0 - } - } + source: {fkInfo: sourceEntity}, + property: {fkProperty: property.dfh_pk_property}, + isOutgoing: true, + // targetClass: DfhApiClassMock.EN_335_TIME_PRIMITIVE.dfh_pk_class, + scope: {inProject: ProProjectMock.PROJECT_1.pk_entity as number}, + limit: 1, + offset: 0, + }; } diff --git a/server/src/__tests__/helpers/data/gvDB/WarEntityPreviewMock.ts b/server/src/__tests__/helpers/data/gvDB/WarEntityPreviewMock.ts index acbe9f7ae..f8f56906f 100644 --- a/server/src/__tests__/helpers/data/gvDB/WarEntityPreviewMock.ts +++ b/server/src/__tests__/helpers/data/gvDB/WarEntityPreviewMock.ts @@ -14,7 +14,7 @@ import {ProProjectMock} from './ProProjectMock' export namespace WarEntityPreviewMock { export const GEO_PLACE_BASEL: OmitEntity = ({ pk_entity: 1000, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_363_GEO_PLACE.dfh_pk_class, class_label: 'Geographical Place', entity_label: 'Basel', @@ -25,7 +25,7 @@ export namespace WarEntityPreviewMock { export const BIRTH_OEKOLOMBAD: OmitEntity = ({ pk_entity: 1002, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_61_BIRTH.dfh_pk_class, class_label: 'Birth', entity_label: 'Johannes Oekolampad', @@ -41,7 +41,7 @@ export namespace WarEntityPreviewMock { export const BIRTH_ZWINGLI: OmitEntity = ({ pk_entity: 1003, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_61_BIRTH.dfh_pk_class, class_label: 'Birth', entity_label: 'Ulrich Zwingli', @@ -58,7 +58,7 @@ export namespace WarEntityPreviewMock { export const TIME_UNIT_ONE_MONTH: OmitEntity = ({ pk_entity: 2017, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_690_TIME_UNIT.dfh_pk_class, class_label: DfhApiClassMock.EN_690_TIME_UNIT.dfh_class_label, entity_label: InfLangStringMock.EN_SHORT_TITLE_MONTH.string, @@ -67,7 +67,7 @@ export namespace WarEntityPreviewMock { export const PERSON_1: OmitEntity = ({ pk_entity: 2001, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_21_PERSON.dfh_pk_class, class_label: DfhApiClassMock.EN_21_PERSON.dfh_class_label, entity_label: InfAppellationMock.JACK_THE_FOO.string, @@ -77,7 +77,7 @@ export namespace WarEntityPreviewMock { export const EXPRESSION_PORTION_HABS_EMP_CHAPTER_1: OmitEntity = ({ pk_entity: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_1.pk_entity, fk_class: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_503_EXPRESSION_PORTION.dfh_class_label, entity_label: 'Chapter 1', entity_type: 'peIt', @@ -85,7 +85,7 @@ export namespace WarEntityPreviewMock { export const EXPRESSION_PORTION_HABS_EMP_CHAPTER_2: OmitEntity = ({ pk_entity: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_2.pk_entity, fk_class: InfResourceMock.EXPRESSION_PORTION_HABS_EMP_CHAPTER_2.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_503_EXPRESSION_PORTION.dfh_class_label, entity_label: 'Chapter 2', entity_type: 'peIt', @@ -94,7 +94,7 @@ export namespace WarEntityPreviewMock { export const APPE_IN_LANG_TYPE_FIRST_NAME: OmitEntity = ({ pk_entity: InfResourceMock.APPE_IN_LANG_TYPE_FIRST_NAME.pk_entity, fk_class: InfResourceMock.APPE_IN_LANG_TYPE_FIRST_NAME.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_630_APPELLATION_IN_A_LANGUAGE_TYPE.dfh_class_label, entity_label: 'First Name', entity_type: 'peIt', @@ -103,7 +103,7 @@ export namespace WarEntityPreviewMock { export const APPE_IN_LANG_TYPE_LAST_NAME: OmitEntity = ({ pk_entity: InfResourceMock.APPE_IN_LANG_TYPE_LAST_NAME.pk_entity, fk_class: InfResourceMock.APPE_IN_LANG_TYPE_LAST_NAME.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_630_APPELLATION_IN_A_LANGUAGE_TYPE.dfh_class_label, entity_label: 'Last Name', entity_type: 'peIt', @@ -112,7 +112,7 @@ export namespace WarEntityPreviewMock { export const VOLUME_UNIT_CUBIC_METER: OmitEntity = ({ pk_entity: InfResourceMock.VOLUME_UNIT_CUBIC_METER.pk_entity, fk_class: InfResourceMock.VOLUME_UNIT_CUBIC_METER.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_715_VOLUME_MEASUREMENT_UNIT.dfh_class_label, entity_label: 'Cubic Meter', entity_type: 'peIt', @@ -121,7 +121,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_TYPE_CITY: OmitEntity = ({ pk_entity: InfResourceMock.GEO_PLACE_TYPE_CITY.pk_entity, fk_class: InfResourceMock.GEO_PLACE_TYPE_CITY.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_364_GEO_PLACE_TYPE.dfh_class_label, entity_label: 'City', entity_type: 'peIt', @@ -130,7 +130,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_TYPE_VILLAGE: OmitEntity = ({ pk_entity: InfResourceMock.GEO_PLACE_TYPE_VILLAGE.pk_entity, fk_class: InfResourceMock.GEO_PLACE_TYPE_VILLAGE.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_364_GEO_PLACE_TYPE.dfh_class_label, entity_label: 'Village', entity_type: 'peIt', @@ -139,7 +139,7 @@ export namespace WarEntityPreviewMock { export const NAMING_1: OmitEntity = ({ pk_entity: InfResourceMock.NAMING_1.pk_entity, fk_class: InfResourceMock.NAMING_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_365_NAMING.dfh_class_label, entity_label: 'Jack the foo', entity_type: 'teEn', @@ -148,7 +148,7 @@ export namespace WarEntityPreviewMock { export const NAMING_2: OmitEntity = ({ pk_entity: InfResourceMock.NAMING_2.pk_entity, fk_class: InfResourceMock.NAMING_2.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_365_NAMING.dfh_class_label, entity_label: 'Jack', entity_type: 'teEn', @@ -157,7 +157,7 @@ export namespace WarEntityPreviewMock { export const HABS_EMP_EXPR: OmitEntity = ({ pk_entity: InfResourceMock.HABS_EMP_EXPR.pk_entity, fk_class: InfResourceMock.HABS_EMP_EXPR.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_218_EXPRESSION.dfh_class_label, entity_label: 'Expression of Habs-Empire', entity_type: 'peIt', @@ -165,7 +165,7 @@ export namespace WarEntityPreviewMock { export const DEFINITION_1: OmitEntity = ({ pk_entity: InfResourceMock.DEFINITION_1.pk_entity, fk_class: InfResourceMock.DEFINITION_1.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: 'Definition', // todo: use DfhApiClassMock when available entity_label: 'This person is the famous jack the foo, invented by KleioLab and used in Geovistory mock data.', entity_type: 'peIt', @@ -174,7 +174,7 @@ export namespace WarEntityPreviewMock { export const TYPE_OF_MANIF_PROD_TYPE_BOOK: OmitEntity = ({ pk_entity: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_BOOK.pk_entity, fk_class: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_BOOK.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_452_TYPE_OF_MANIFESTATION_PRODUCT_TYPE.dfh_class_label, entity_label: 'Book', entity_type: 'peIt', @@ -182,7 +182,7 @@ export namespace WarEntityPreviewMock { export const TYPE_OF_MANIF_PROD_TYPE_JOURNAL: OmitEntity = ({ pk_entity: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_JOURNAL.pk_entity, fk_class: InfResourceMock.TYPE_OF_MANIF_PROD_TYPE_JOURNAL.fk_class, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, class_label: DfhApiClassMock.EN_452_TYPE_OF_MANIFESTATION_PRODUCT_TYPE.dfh_class_label, entity_label: 'Journal', entity_type: 'peIt', @@ -190,7 +190,7 @@ export namespace WarEntityPreviewMock { export const GEO_PLACE_ZURICH: OmitEntity = ({ pk_entity: 1001, - project_id: ProProjectMock.PROJECT_1.pk_entity, + fk_project: ProProjectMock.PROJECT_1.pk_entity, fk_class: DfhApiClassMock.EN_363_GEO_PLACE.dfh_pk_class, class_label: 'Geographical Place', entity_label: 'Zürich', diff --git a/server/src/__tests__/helpers/data/gvDB/WarFieldChangeMock.ts b/server/src/__tests__/helpers/data/gvDB/WarFieldChangeMock.ts index e55bc106c..f3b080547 100644 --- a/server/src/__tests__/helpers/data/gvDB/WarFieldChangeMock.ts +++ b/server/src/__tests__/helpers/data/gvDB/WarFieldChangeMock.ts @@ -10,7 +10,6 @@ export namespace WarFieldChangeMock { export const FIELD_1: OmitEntity = { fk_project: 1, fk_property: 2, - fk_property_of_property: 0, fk_source_info: 3, fk_source_tables_cell: 0, is_outgoing: true, @@ -18,8 +17,8 @@ export namespace WarFieldChangeMock { } export function toFieldId(f: OmitEntity): WarFieldChangeId { - const {fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing} = f; - return {fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing} + const {fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing} = f; + return {fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing} } } diff --git a/server/src/components/query/analysis/q-analysis-base.ts b/server/src/components/query/analysis/q-analysis-base.ts index 77e4a39ff..8f24619a8 100644 --- a/server/src/components/query/analysis/q-analysis-base.ts +++ b/server/src/components/query/analysis/q-analysis-base.ts @@ -80,7 +80,7 @@ export abstract class QAnalysisBase extends SqlBuilderLb4Models { limit = ''; offset = ''; - readonly STATAMENT_TABLE = 'war.statement' // 'war.vm_statement' + readonly STATAMENT_TABLE = 'pgwar.project_statements' constructor( dataSource: Postgres1DataSource, @@ -259,7 +259,7 @@ export abstract class QAnalysisBase extends SqlBuilderLb4Models { const joinOn = 'pk_entity' const selects = leftTables.map(leftTable => ` SELECT * - FROM war.entity_preview t + FROM pgwar.entity_preview t WHERE ${leftTable.table}.${leftTable.fk} = t.${joinOn} AND @@ -313,7 +313,7 @@ export abstract class QAnalysisBase extends SqlBuilderLb4Models { createEntityWhere(filter: QueryNode, tableAlias: string, fkProject: number) { - const whereProject = `${tableAlias}.project_id = ${this.addParam( + const whereProject = `${tableAlias}.fk_project = ${this.addParam( fkProject )}`; diff --git a/server/src/components/query/analysis/q-analysis-count.ts b/server/src/components/query/analysis/q-analysis-count.ts index ddcb56cd1..beda8f38e 100644 --- a/server/src/components/query/analysis/q-analysis-count.ts +++ b/server/src/components/query/analysis/q-analysis-count.ts @@ -34,7 +34,7 @@ export class QAnalysisCount extends QAnalysisBase { ); // root table from - this.filterFroms.push(`war.entity_preview ${rootTableAlias}`); + this.filterFroms.push(`pgwar.entity_preview ${rootTableAlias}`); this.froms.push(`tw1 ${rootTableAlias}`); // create froms and wheres according to filter definition diff --git a/server/src/components/query/analysis/q-analysis-map.ts b/server/src/components/query/analysis/q-analysis-map.ts index 12f725c45..a2189b6e1 100644 --- a/server/src/components/query/analysis/q-analysis-map.ts +++ b/server/src/components/query/analysis/q-analysis-map.ts @@ -24,7 +24,7 @@ export class QAnalysisMap extends QAnalysisBase { ); // root table from - this.filterFroms.push(`war.entity_preview ${rootTableAlias}`); + this.filterFroms.push(`pgwar.entity_preview ${rootTableAlias}`); this.froms.push(`tw1 ${rootTableAlias}`); // create froms and wheres according to filter definition @@ -73,14 +73,14 @@ export class QAnalysisMap extends QAnalysisBase { FROM tw2 t0, ${this.STATAMENT_TABLE} t1, - war.entity_preview t2, + pgwar.entity_preview t2, ${this.STATAMENT_TABLE} t3, information.v_place t4 WHERE t1.fk_object_info = t0.geo_entity_pk AND t1.fk_project = ${fkProject} AND - t2.pk_entity = t1.fk_subject_info AND t2.project_id = ${fkProject} + t2.pk_entity = t1.fk_subject_info AND t2.fk_project = ${fkProject} AND t2.fk_class = 84 --Presence AND t3.fk_subject_info = t2.pk_entity AND t3.fk_project = ${fkProject} diff --git a/server/src/components/query/analysis/q-analysis-table.ts b/server/src/components/query/analysis/q-analysis-table.ts index 6af29a6d3..47fc064ad 100644 --- a/server/src/components/query/analysis/q-analysis-table.ts +++ b/server/src/components/query/analysis/q-analysis-table.ts @@ -29,7 +29,7 @@ export class QAnalysisTable extends QAnalysisBase { ); // root table from - this.filterFroms.push(`war.entity_preview ${rootTableAlias}`); + this.filterFroms.push(`pgwar.entity_preview ${rootTableAlias}`); this.froms.push(`tw1 ${rootTableAlias}`); // create froms and wheres according to filter definition diff --git a/server/src/components/query/analysis/q-analysis-time.ts b/server/src/components/query/analysis/q-analysis-time.ts index 9cdc322aa..07926268b 100644 --- a/server/src/components/query/analysis/q-analysis-time.ts +++ b/server/src/components/query/analysis/q-analysis-time.ts @@ -26,7 +26,7 @@ export class QAnalysisTime extends QAnalysisBase { ); // root table from - this.filterFroms.push(`war.entity_preview ${rootTableAlias}`); + this.filterFroms.push(`pgwar.entity_preview ${rootTableAlias}`); this.froms.push(`tw1 ${rootTableAlias}`); // create froms and wheres according to filter definition diff --git a/server/src/components/query/pg-functions/gv-field-page-incoming-in-project-fn.ts b/server/src/components/query/pg-functions/gv-field-page-incoming-in-project-fn.ts deleted file mode 100644 index 2723f9040..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-incoming-in-project-fn.ts +++ /dev/null @@ -1,81 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=false and scope = {inProject:} - */ -export class SqlGvFieldPageIncomingInProject extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_incoming_in_project (_project_id int, _fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj ORDER BY ord_num_of_domain ASC NULLS LAST, pk_entity DESC), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('projRel', gv_to_jsonb (t2), 'isOutgoing', false, 'ordNum', t2.ord_num_of_domain, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count, - t2.ord_num_of_domain, - t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2, - gv_get_statement_target (_project_id, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - -------------------------------------------------------------------------- - -- order the statements according to order number of target - -------------------------------------------------------------------------- - ORDER BY - t2.ord_num_of_domain ASC NULLS LAST, t1.pk_entity DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-incoming-in-repo-fn.ts b/server/src/components/query/pg-functions/gv-field-page-incoming-in-repo-fn.ts deleted file mode 100644 index 76d8a7cf2..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-incoming-in-repo-fn.ts +++ /dev/null @@ -1,74 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=false and scope = {inRepo:true} - */ -export class SqlGvFieldPageIncomingInRepo extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_incoming_in_repo (_fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (0, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-incoming-no-constaint-fn.ts b/server/src/components/query/pg-functions/gv-field-page-incoming-no-constaint-fn.ts deleted file mode 100644 index 298c96109..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-incoming-no-constaint-fn.ts +++ /dev/null @@ -1,73 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=false and scope = {noConstraint:true} - */ -export class SqlGvFieldPageIncomingNoConstraint extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_incoming_no_constraint (_fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (0, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-incoming-not-in-project-fn.ts b/server/src/components/query/pg-functions/gv-field-page-incoming-not-in-project-fn.ts deleted file mode 100644 index c0a426341..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-incoming-not-in-project-fn.ts +++ /dev/null @@ -1,104 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=false and scope = {notInProject:} - */ -export class SqlGvFieldPageIncomingNotInProject extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_incoming_not_in_project (_project_id int, _fk_property int, _source_info_id int, _source_data_id int, _source_tables_cell_id bigint, _source_tables_row_id bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', false, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (_project_id, t1.fk_subject_info, t1.fk_subject_data, t1.fk_subject_tables_cell, t1.fk_subject_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - - -------------------------------------------------------------------------- - -- EXCLUDE STATEMENTS REFERENCING HIDDEN ENTITY - -------------------------------------------------------------------------- - AND (t3.target_obj->'entity'->'resource'->'community_visibility'->>'toolbox')::boolean IS DISTINCT FROM false - - AND t1.pk_entity NOT IN ( - -------------------------------------------------------------------------- - -- EXCLUDE STATEMENTS OF PROJECT - -------------------------------------------------------------------------- - SELECT t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_object_info = _source_info_id - AND t1.fk_object_data = _source_data_id - AND t1.fk_object_tables_cell = _source_tables_cell_id - AND t1.fk_object_tables_row = _source_tables_row_id - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - ) - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-outgoing-in-project-fn.ts b/server/src/components/query/pg-functions/gv-field-page-outgoing-in-project-fn.ts deleted file mode 100644 index 096f00aa4..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-outgoing-in-project-fn.ts +++ /dev/null @@ -1,80 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=true and scope = {inProject:} - */ -export class SqlGvFieldPageOutgoingInProject extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_outgoing_in_project (_project_id int, _fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj ORDER BY ord_num_of_range ASC NULLS LAST, pk_entity DESC), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('projRel', gv_to_jsonb (t2), 'isOutgoing', true, 'ordNum', t2.ord_num_of_range, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count, - t2.ord_num_of_range, - t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2, - gv_get_statement_target (_project_id, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - -------------------------------------------------------------------------- - -- order the statements according to order number of target - -------------------------------------------------------------------------- - ORDER BY - t2.ord_num_of_range ASC NULLS LAST, t1.pk_entity DESC - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-outgoing-in-repo.ts b/server/src/components/query/pg-functions/gv-field-page-outgoing-in-repo.ts deleted file mode 100644 index a64fa08aa..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-outgoing-in-repo.ts +++ /dev/null @@ -1,74 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=true and scope = {inRepo:true} - */ -export class SqlGvFieldPageOutgoingInRepo extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_outgoing_in_repo (_fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (0, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-outgoing-no-constraint-fn.ts b/server/src/components/query/pg-functions/gv-field-page-outgoing-no-constraint-fn.ts deleted file mode 100644 index 3dbab3530..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-outgoing-no-constraint-fn.ts +++ /dev/null @@ -1,73 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=true and scope = {noConstraint:true} - */ -export class SqlGvFieldPageOutgoingNoConstraint extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_outgoing_no_constraint (_fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (0, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-field-page-outgoing-not-in-project-fn.ts b/server/src/components/query/pg-functions/gv-field-page-outgoing-not-in-project-fn.ts deleted file mode 100644 index fd6b9daeb..000000000 --- a/server/src/components/query/pg-functions/gv-field-page-outgoing-not-in-project-fn.ts +++ /dev/null @@ -1,104 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that can be used in SQL Query to query a GvFieldPage - * with isOutgoing=true and scope = {notInProject:} - */ -export class SqlGvFieldPageOutgoingNotInProject extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - CREATE OR REPLACE FUNCTION gv_field_page_outgoing_not_in_project (_project_id int, _fk_property int, _fk_subject_info int, _fk_subject_data int, _fk_subject_tables_cell bigint, _fk_subject_tables_row bigint, _limit int, _offset int, _req json) - RETURNS TABLE ( - "validFor" timestamp with time zone, - "paginatedStatements" json, - count int, - req json) - LANGUAGE plpgsql - COST 100 VOLATILE ROWS 1 - AS $func$ - BEGIN - RETURN QUERY - -------------------------------------------------------------------------- - -- FINAL SELECT - -------------------------------------------------------------------------- - SELECT - now() "validFor", - CASE WHEN _limit=0 THEN - '[]'::json ELSE - COALESCE(json_agg(stmt.obj), '[]'::json) - END - AS "paginatedStatements", - COALESCE(max(full_count), 0)::int "count", - _req req - FROM ( - -------------------------------------------------------------------------- - -- PAGINATED SELECT - -------------------------------------------------------------------------- - SELECT - json_strip_nulls (json_build_object('isOutgoing', true, 'target', t3.target_obj, 'targetClass', t3.target_class, 'targetLabel', t3.target_label, 'statement', gv_to_jsonb (t1))) obj, - count(*) OVER () AS full_count - FROM - information.v_statement t1, - gv_get_statement_target (_project_id, t1.fk_object_info, t1.fk_object_data, t1.fk_object_tables_cell, t1.fk_object_tables_row) t3 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - AND t1.is_in_project_count > 0 - - -------------------------------------------------------------------------- - -- EXCLUDE STATEMENTS REFERENCING HIDDEN ENTITY - -------------------------------------------------------------------------- - AND (t3.target_obj->'entity'->'resource'->'community_visibility'->>'toolbox')::boolean IS DISTINCT FROM false - - AND t1.pk_entity NOT IN ( - -------------------------------------------------------------------------- - -- EXCLUDE STATEMENTS OF PROJECT - -------------------------------------------------------------------------- - SELECT t1.pk_entity - FROM - information.v_statement t1, - projects.v_info_proj_rel t2 - WHERE - -------------------------------------------------------------------------- - -- JOIN SOURCE ENTITY WITH STATEMENTS - -------------------------------------------------------------------------- - t1.fk_subject_info = _fk_subject_info - AND t1.fk_subject_data = _fk_subject_data - AND t1.fk_subject_tables_cell = _fk_subject_tables_cell - AND t1.fk_subject_tables_row = _fk_subject_tables_row - AND t1.fk_property = _fk_property - -------------------------------------------------------------------------- - -- JOIN STATEMENTS WITH PROJECT RELS - -------------------------------------------------------------------------- - AND t1.pk_entity = t2.fk_entity - AND t2.is_in_project = TRUE - AND t2.fk_project = _project_id - ) - - -------------------------------------------------------------------------- - -- THE FOLLOWING ORDER BY CLAUSE IS DISABLED FOR PERFORMANCE REASONS - -- ORDER BY - -- t1.pk_entity DESC - - -------------------------------------------------------------------------- - -- paginate according to the requested limit / offset - -------------------------------------------------------------------------- - LIMIT CASE WHEN _limit=0 THEN 1 ELSE _limit END - OFFSET _offset) AS stmt; - END - $func$; - - - ` - return this; - - } -} - diff --git a/server/src/components/query/pg-functions/gv-get-statement-target-fn.ts b/server/src/components/query/pg-functions/gv-get-statement-target-fn.ts deleted file mode 100644 index 3139df692..000000000 --- a/server/src/components/query/pg-functions/gv-get-statement-target-fn.ts +++ /dev/null @@ -1,245 +0,0 @@ -import {SqlBuilderLb4Models} from '../../../utils/sql-builders/sql-builder-lb4-models'; - - -/** - * Make SQL function that returns the target of a statement - */ -export class SqlGvGetStatementTarget extends SqlBuilderLb4Models { - generateFunctionSql() { - this.sql = ` - - DO $$ BEGIN - CREATE TYPE gv_statement_target AS ( - target_obj jsonb, - target_class int, - target_label text - ); - EXCEPTION - WHEN duplicate_object THEN null; - END $$; - - - CREATE OR REPLACE FUNCTION gv_get_statement_target (_project_id int, _info_id int, _data_id int, _tables_cell_id bigint, _tables_row_id bigint) - RETURNS SETOF gv_statement_target - LANGUAGE plpgsql - AS $func$ - BEGIN - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET LANGUAGE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('language', gv_to_jsonb (t3)) target_obj, - fk_class target_class, - notes target_label - FROM - information.language t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET APPPELLATION - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('appellation', gv_to_jsonb (t3)) target_obj, - fk_class target_class, - string target_label - FROM - information.appellation t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET LANG_STRING - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('langString', jsonb_build_object('langString', gv_to_jsonb (t3), 'language', language.obj)) target_obj, - fk_class target_class, - concat(t3.string, ' (', language.iso6391, ')' ) target_label - FROM - information.v_lang_string t3 - LEFT JOIN LATERAL ( - -- LANGUAGE OF LANG_STRING - SELECT - gv_to_jsonb (t4) obj, - iso6391 - FROM - information.language t4 - WHERE - t4.pk_entity = t3.fk_language) - LANGUAGE ON - TRUE - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET PLACE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('place', gv_to_jsonb (t3)) target_obj, - fk_class target_class, - concat('WGS84: ', lat, '°, ', long, '°') target_label - FROM - information.v_place t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET TIME PRIMITIVE - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('timePrimitive', jsonb_build_object('infTimePrimitive', gv_to_jsonb (t3), 'timePrimitive', json_build_object('duration', t3.duration, 'julianDay', t3.julian_day, 'calendar', t3.calendar))) target_obj, - fk_class target_class, - 'todo' target_label - FROM - information.v_time_primitive t3 - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET DIMENSION - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('dimension',jsonb_build_object('dimension', gv_to_jsonb (t3), 'unitPreview', entity_preview.obj)) target_obj, - fk_class target_class, - concat_ws(' ', t3.numeric_value, entity_preview.entity_label) target_label - FROM - information.v_dimension t3 - LEFT JOIN LATERAL ( SELECT DISTINCT ON (pk_entity) - gv_to_jsonb (e.t4) obj, - e.entity_label - FROM ( - --repo version - SELECT - t4, entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = t3.fk_measurement_unit - AND project_id = 0 - UNION - --project version - SELECT - t4, entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = t3.fk_measurement_unit - AND project_id = _project_id) e) entity_preview ON TRUE - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET ENTITY - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('entity', jsonb_build_object('resource', gv_to_jsonb (t3), 'entityPreview', entity_preview.obj)) target_obj, - fk_class target_class, - entity_preview.entity_label target_label - FROM - information.resource t3 - LEFT JOIN LATERAL ( SELECT DISTINCT ON (pk_entity) - gv_to_jsonb (e.t4) obj, - e.entity_label - FROM ( - --repo version - SELECT - t4, entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = _info_id - AND project_id = 0 - UNION - --project version - SELECT - t4, entity_label - FROM - war.entity_preview t4 - WHERE - t4.pk_entity = _info_id - AND project_id = _project_id) e) entity_preview ON TRUE - WHERE - t3.pk_entity = _info_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET DIGITAL - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('digital', gv_to_jsonb (t3)) target_obj, - 0 target_class, - '' target_label - FROM - data.digital t3 - WHERE - t3.pk_entity = _data_id; - IF FOUND THEN - RETURN; - END IF; - ---------------------------------------------------------------------- - --JOIN STATEMENT'S TARGET CELL - ---------------------------------------------------------------------- - RETURN QUERY - SELECT - jsonb_build_object('cell', gv_to_jsonb (t3)) target_obj, - fk_class target_class, - coalesce(string_value, numeric_value::text) target_label - FROM - tables.cell t3 - WHERE - t3.pk_cell = _tables_cell_id; - IF FOUND THEN - RETURN; - END IF; - - -- Uncomment this block for joining rows and create column row (fk_class) - -- ---------------------------------------------------------------------- - -- --JOIN STATEMENT'S TARGET ROW - -- ---------------------------------------------------------------------- - -- RETURN QUERY - -- SELECT - -- jsonb_build_object('row', gv_to_jsonb (t3)) target_obj, - -- fk_class target_class, - -- 'todo' target_label - -- FROM - -- tables.row t3 - -- WHERE - -- t3.pk_row = _tables_row_id; - -- IF FOUND THEN - -- RETURN; - -- END IF; - ---------------------------------------------------------------------- - --ELSE RETURN 0 ROWS - ---------------------------------------------------------------------- - RETURN; - END - $func$; - - - - - ` - } -} - diff --git a/server/src/components/query/q-alternative-leaf-items.ts b/server/src/components/query/q-alternative-leaf-items.ts index 9a793d61a..234228ee9 100644 --- a/server/src/components/query/q-alternative-leaf-items.ts +++ b/server/src/components/query/q-alternative-leaf-items.ts @@ -144,10 +144,10 @@ export class QAlternativeLeafItems extends SqlBuilderLb4Models { ${this.createSelect('t1', WarEntityPreview.definition)} FROM tw2 - CROSS JOIN war.entity_preview t1 + CROSS JOIN pgwar.entity_preview t1 WHERE tw2.fk_object_info = t1.pk_entity - AND t1.project_id = 0 + AND t1.fk_project = 0 ), -- subject entity_preview tw11 AS ( @@ -155,10 +155,10 @@ export class QAlternativeLeafItems extends SqlBuilderLb4Models { ${this.createSelect('t1', WarEntityPreview.definition)} FROM tw2 - CROSS JOIN war.entity_preview t1 + CROSS JOIN pgwar.entity_preview t1 WHERE tw2.fk_subject_info = t1.pk_entity - AND t1.project_id = 0 + AND t1.fk_project = 0 ), -- measurement unit entity_preview tw12 AS ( @@ -166,10 +166,10 @@ export class QAlternativeLeafItems extends SqlBuilderLb4Models { ${this.createSelect('t1', WarEntityPreview.definition)} FROM tw9 - CROSS JOIN war.entity_preview t1 + CROSS JOIN pgwar.entity_preview t1 WHERE tw9.fk_measurement_unit = t1.pk_entity - AND t1.project_id = 0 + AND t1.fk_project = 0 ), ------------------------------------ --- group parts by model diff --git a/server/src/components/query/q-content-tree.ts b/server/src/components/query/q-content-tree.ts index 288d970b8..183100fc0 100644 --- a/server/src/components/query/q-content-tree.ts +++ b/server/src/components/query/q-content-tree.ts @@ -56,7 +56,7 @@ export class QContentTree extends SqlBuilderLb4Models { ${this.createSelect('t1', WarEntityPreview.definition)}, ${this.createBuildObject('t2', ProInfoProjRel.definition)} proj_rel FROM - war.entity_preview t1 + pgwar.entity_preview t1 JOIN tw0 t3 ON t1.pk_entity = t3.fk_subject_info CROSS JOIN @@ -66,7 +66,7 @@ export class QContentTree extends SqlBuilderLb4Models { AND t2.fk_project = ${this.addParam(fkProject)} ORDER BY t1.pk_entity, - CASE WHEN(t1.project_id = ${this.addParam(fkProject)}) THEN 0 + CASE WHEN(t1.fk_project = ${this.addParam(fkProject)}) THEN 0 ELSE 1 END ), diff --git a/server/src/components/query/q-ram-list.ts b/server/src/components/query/q-ram-list.ts index e25a6494e..d89f58082 100644 --- a/server/src/components/query/q-ram-list.ts +++ b/server/src/components/query/q-ram-list.ts @@ -216,7 +216,7 @@ export class QRamList extends SqlBuilderLb4Models { ${this.createBuildAndAddObject(this.objectWiths.war.entity_preview, {colName: 'o', twName: 'tw1'}, 't1', WarEntityPreviewWithFulltext.definition)} o, ${this.createBuildAndAddObject(this.objectWiths.pro.info_proj_rel, {colName: 'pr', twName: 'tw1'}, 't2', ProInfoProjRel.definition)} pr FROM - war.entity_preview t1 + pgwar.entity_preview t1 JOIN tw0 t3 ON t1.pk_entity = t3.fk_subject_info CROSS JOIN @@ -226,7 +226,7 @@ export class QRamList extends SqlBuilderLb4Models { AND t2.fk_project = ${this.addParam(fkProject)} ORDER BY t1.pk_entity, - CASE WHEN(t1.project_id = ${this.addParam(fkProject)}) THEN 0 + CASE WHEN(t1.fk_project = ${this.addParam(fkProject)}) THEN 0 ELSE 1 END ), @@ -237,7 +237,7 @@ export class QRamList extends SqlBuilderLb4Models { ${this.createBuildAndAddObject(this.objectWiths.war.entity_preview, {colName: 'o', twName: 'tw2'}, 't1', WarEntityPreviewWithFulltext.definition)} o, ${this.createBuildAndAddObject(this.objectWiths.pro.info_proj_rel, {colName: 'pr', twName: 'tw2'}, 't2', ProInfoProjRel.definition)} pr FROM - war.entity_preview t1 + pgwar.entity_preview t1 JOIN tw0 t3 ON t1.pk_entity = t3.fk_object_info CROSS JOIN @@ -247,7 +247,7 @@ export class QRamList extends SqlBuilderLb4Models { AND t2.fk_project = ${this.addParam(fkProject)} ORDER BY t1.pk_entity, - CASE WHEN(t1.project_id = ${this.addParam(fkProject)}) THEN 0 + CASE WHEN(t1.fk_project = ${this.addParam(fkProject)}) THEN 0 ELSE 1 END ), diff --git a/server/src/components/query/q-types-of-project.ts b/server/src/components/query/q-types-of-project.ts index 1b42474c2..e207036c2 100644 --- a/server/src/components/query/q-types-of-project.ts +++ b/server/src/components/query/q-types-of-project.ts @@ -29,17 +29,17 @@ export class QTypesOfProject extends SqlBuilderLb4Models { SELECT pk_entity FROM - war.entity_preview + pgwar.entity_preview WHERE - project_id = ${this.addParam(fkProject)} + fk_project = ${this.addParam(fkProject)} AND parent_classes @> '53'::jsonb UNION SELECT pk_entity FROM - war.entity_preview + pgwar.entity_preview WHERE - project_id = ${this.addParam(fkProject)} + fk_project = ${this.addParam(fkProject)} AND ancestor_classes @> '53'::jsonb ), -- join resource and info_proj_rel diff --git a/server/src/components/query/q-war-search-existing.ts b/server/src/components/query/q-war-search-existing.ts index 76e3c853c..d44932714 100644 --- a/server/src/components/query/q-war-search-existing.ts +++ b/server/src/components/query/q-war-search-existing.ts @@ -58,8 +58,8 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { select * from tw0 t0, - war.entity_preview t1 - WHERE t1.project_id = 0 + pgwar.entity_preview t1 + WHERE t1.fk_project = 0 ${tsSearchString ? ` AND ( t1.ts_vector @@ t0.q @@ -75,8 +75,8 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { select * from tw0 t0, - war.entity_preview t1 - where t1.project_id = ${this.addParam(pkProject)} + pgwar.entity_preview t1 + where t1.fk_project = ${this.addParam(pkProject)} ${tsSearchString ? ` AND ( t1.ts_vector @@ t0.q @@ -91,13 +91,13 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { select t1.* from tw0 t0, - war.entity_preview t1 + pgwar.entity_preview t1 LEFT JOIN projects.info_proj_rel t2 ON t1.pk_entity=t2.fk_entity AND t2.fk_project=${this.addParam(pkProject)} AND t2.is_in_project=true where t2.pk_entity is null --not in project - and t1.project_id = 0 --in community + and t1.fk_project = 0 --in community ${tsSearchString ? ` AND ( t1.ts_vector @@ t0.q @@ -114,7 +114,7 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { this.sql = ` WITH - -- filter the repo versions, add the project_id of given project, if is_in_project + -- filter the repo versions, add the fk_project of given project, if is_in_project -- this ensures we allways search in the full repo full-text (finds more) -- and it includes the information, whether the entity is in project or not tw0 AS ( @@ -130,11 +130,11 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { select distinct on (pk_entity) * FROM te1 - order by pk_entity, project_id desc + order by pk_entity, fk_project desc ), tw1 AS ( SELECT - COALESCE(t2.fk_project, t1.project_id) project_id, + COALESCE(t2.fk_project, t1.fk_project) fk_project, t1.pk_entity, t1.fk_class, t1.entity_label, @@ -154,7 +154,7 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { ), tw2 AS ( select - t1.project_id, + t1.fk_project, t1.pk_entity, t1.fk_class, t1.entity_label, @@ -171,19 +171,19 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { ROW_NUMBER () OVER ( PARTITION BY t1.pk_entity ORDER BY - t1.project_id DESC + t1.fk_project DESC ) as rank FROM tw0 t0, tw1 t1 - ORDER BY project_id, ts_rank(ts_vector, t0.q) DESC, entity_label asc + ORDER BY fk_project, ts_rank(ts_vector, t0.q) DESC, entity_label asc LIMIT ${this.addParam(limit)} OFFSET ${this.addParam(offset)} ), -- take only first ranked preview version of the same entity tw3 AS ( SELECT - t1.project_id, + t1.fk_project, t1.pk_entity, t1.fk_class, t1.entity_label, @@ -220,7 +220,7 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { AND t3.is_in_project = true WHERE rank = 1 GROUP BY - t1.project_id, + t1.fk_project, t1.pk_entity, t1.fk_class, t1.entity_label, @@ -233,7 +233,7 @@ export class QWarEntityPreviewSearchExisiting extends SqlBuilderLb4Models { t1.class_label_headline, t1.entity_label_headline, t1.type_label_headline - ORDER BY project_id desc + ORDER BY fk_project desc ), ------------------------------------ diff --git a/server/src/controllers/ontome.controller.ts b/server/src/controllers/ontome.controller.ts index 3b7bc22c6..c262d7d98 100644 --- a/server/src/controllers/ontome.controller.ts +++ b/server/src/controllers/ontome.controller.ts @@ -462,14 +462,14 @@ export class OntoMeController { ) SELECT DISTINCT 'class' category, t1.pk_class id, t3.identifier_in_namespace, t2.label, t1.number_of_instances, t1.status FROM ctw9 t1 - LEFT JOIN war.v_class_preview t2 + LEFT JOIN pgwar.v_class_preview t2 ON t1.pk_class = t2.fk_class AND t2.fk_project = $1 JOIN ctw2 t3 ON t1.pk_class = t3.pk_class UNION ALL SELECT DISTINCT 'property' category, t1.pk_property id, t3.identifier_in_namespace, t2.label, t1.number_of_instances, t1.status FROM ptw9 t1 - LEFT JOIN war.v_property_preview t2 + LEFT JOIN pgwar.v_property_preview t2 ON t1.pk_property = t2.fk_property AND t2.fk_project = $1 JOIN ptw2 t3 ON t1.pk_property = t3.pk_property; diff --git a/server/src/controllers/project-data/field-change.controller.ts b/server/src/controllers/project-data/field-change.controller.ts index 44ddd00a4..8266c335b 100644 --- a/server/src/controllers/project-data/field-change.controller.ts +++ b/server/src/controllers/project-data/field-change.controller.ts @@ -1,14 +1,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { inject } from '@loopback/core'; -import { repository } from '@loopback/repository'; -import { Subscription } from 'rxjs'; -import { Socket } from 'socket.io'; -import { ws } from '../../decorators/websocket.decorator'; -import { WarFieldChangeAddToStream, WarFieldChangeId } from '../../models/war-field-change-id.model'; -import { WarFieldChange } from '../../models/war-field-change.model'; -import { Streams } from '../../realtime/streams/streams'; -import { WebsocketControllerBase } from '../../realtime/websockets/websocker-controller-base'; -import { WarFieldChangeRepository } from '../../repositories/war-field-change.repository'; +import {inject} from '@loopback/core'; +import {repository} from '@loopback/repository'; +import {Subscription} from 'rxjs'; +import {Socket} from 'socket.io'; +import {ws} from '../../decorators/websocket.decorator'; +import {WarFieldChangeAddToStream, WarFieldChangeId} from '../../models/war-field-change-id.model'; +import {WarFieldChange} from '../../models/war-field-change.model'; +import {Streams} from '../../realtime/streams/streams'; +import {WebsocketControllerBase} from '../../realtime/websockets/websocker-controller-base'; +import {WarFieldChangeRepository} from '../../repositories/war-field-change.repository'; export const IO_FIELD_CHANGE = 'FieldChange' @@ -25,7 +25,7 @@ export class FieldChangeController extends WebsocketControllerBase { logs = false // for caching notifications, to avoid emitting the same modification timestamp more than once - emittedNotifications: { [key: string]: true } = {} + emittedNotifications: {[key: string]: true} = {} constructor( @@ -96,7 +96,6 @@ export class FieldChangeController extends WebsocketControllerBase { const ors: { fk_project: number; fk_property: number; - fk_property_of_property: number; fk_source_info: number; fk_source_tables_cell: number; is_outgoing: boolean; @@ -106,16 +105,15 @@ export class FieldChangeController extends WebsocketControllerBase { .forEach(field => { if (field.fk_project === undefined) return false; if (field.is_outgoing === undefined) return false; - if (field.fk_property === undefined && field.fk_property_of_property === undefined) return false; - if (field.fk_property !== undefined && field.fk_property_of_property !== undefined) return false; + if (field.fk_property === undefined) return false; if (field.fk_source_info === undefined && field.fk_source_tables_cell === undefined) return false; if (field.fk_source_info !== undefined && field.fk_source_tables_cell !== undefined) return false; - const { fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing } = field; - const string = fk_project + '_' + fk_property + '_' + fk_property_of_property + '_' + fk_source_info + '_' + fk_source_tables_cell + '_' + is_outgoing; + const {fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing} = field; + const string = fk_project + '_' + fk_property + '_' + fk_source_info + '_' + fk_source_tables_cell + '_' + is_outgoing; if (!uniq.has(string)) { uniq.set(string, true) - ors.push({ fk_project, fk_property, fk_property_of_property, fk_source_info, fk_source_tables_cell, is_outgoing }) + ors.push({fk_project, fk_property, fk_source_info, fk_source_tables_cell, is_outgoing}) } }) @@ -126,7 +124,7 @@ export class FieldChangeController extends WebsocketControllerBase { } // find the field changes - const fieldChanges = await this.warFieldChangeRepository.find({ where: { or: ors } }) + const fieldChanges = await this.warFieldChangeRepository.find({where: {or: ors}}) // emit them fieldChanges.forEach(i => this.emitFieldChange(i)) @@ -201,8 +199,6 @@ export class FieldChangeController extends WebsocketControllerBase { export function fieldChangeToStringId(i: WarFieldChangeId): string { - - - return `${i.fk_project || 0}_${i.fk_source_info || 0}_${i.fk_property || 0}_${i.fk_property_of_property || 0}_${i.is_outgoing}` + return `${i.fk_project || 0}_${i.fk_source_info || 0}_${i.fk_property || 0}_${i.is_outgoing}` } diff --git a/server/src/controllers/project-data/subfield-page.controller.ts b/server/src/controllers/project-data/subfield-page.controller.ts index 3fc36264c..c1cab5940 100644 --- a/server/src/controllers/project-data/subfield-page.controller.ts +++ b/server/src/controllers/project-data/subfield-page.controller.ts @@ -2,15 +2,10 @@ import {authenticate} from '@loopback/authentication'; import {authorize} from '@loopback/authorization'; import {inject} from '@loopback/core'; import {getModelSchemaRef, post, requestBody} from '@loopback/rest'; -import {concat, mergeDeepWith} from 'ramda'; import {Roles} from '../../components/authorization/keys'; -import {fieldPageReqsToSqlArray} from '../../components/query/fieldpage/fieldPageReqsToSqlArray'; import {registerType} from '../../components/spec-enhancer/model.spec.enhancer'; import {Postgres1DataSource} from '../../datasources'; -import {GvFieldId, GvFieldPage, GvFieldPageReq, GvFieldPageScope, GvPaginationObject, GvSubentitFieldPageReq} from '../../models'; -import {GvSubfieldPageInfo} from '../../models/field-response/GvSubfieldPageInfo'; -import {GvFieldSourceEntity} from '../../models/field/gv-field-source-entity'; -import {SqlBuilderLb4Models} from '../../utils/sql-builders/sql-builder-lb4-models'; +import {GvFieldId, GvFieldPageReq, GvPaginationObject} from '../../models'; export class SubfieldPageController { @@ -51,130 +46,18 @@ export class SubfieldPageController { ) reqs: GvFieldPageReq[], ): Promise { - const pages = await this.queryPagesRecursive(reqs); - return mergePaginationObjects(pages) + const rows: {pages: GvPaginationObject}[] = await this.datasource.execute( + 'SELECT pages FROM commons.get_field_pages($1) AS pages;', + [JSON.stringify(reqs)] + ); - } - - - private async queryPagesRecursive(reqs: GvFieldPageReq[], paginationObjects: GvPaginationObject[] = []): Promise { - - // create request groups - const sqls = fieldPageReqsToSqlArray(reqs); - - if (sqls.length < 1) return [] - - // execute each group - const pagesInGroup: GvPaginationObject = {subfieldPages: []} - for (const sql of sqls) { - const q = new SqlBuilderLb4Models(this.datasource); - q.sql = sql; - const resultingPages = await q.execute(); - pagesInGroup.subfieldPages.push(...resultingPages); - } - paginationObjects.push(pagesInGroup) - - if (paginationObjects.length > 5) { - // max levels of nesting reached - return paginationObjects - } - - // extract nested requests of last object - const lastObject = paginationObjects[paginationObjects.length - 1] - const nestedReqs = nestedRequestsFromPaginationObject(lastObject) - if (nestedReqs.length) { - // nested requests -> query them - - const nestedPaginationObjects = await this.queryPagesRecursive(nestedReqs, paginationObjects) - return nestedPaginationObjects - - } else { - // no nested requests -> return the objects - - return paginationObjects - } + return rows[0].pages; } -} - -registerType(GvFieldId) - -function mergePaginationObjects(results: GvPaginationObject[]) { - let result: GvPaginationObject = {subfieldPages: []}; - for (const obj of results) { - result = mergeDeepWith(concat, result, obj); - } - return result; } -/** - * Extracts nested requests from pagination object and returns - * an array of GvFieldPageReq, with the correct scope - * @param res - * @returns - */ -function nestedRequestsFromPaginationObject(res: GvPaginationObject): GvFieldPageReq[] { - const requests: GvFieldPageReq[] = []; - for (const subfieldPageInfo of res.subfieldPages) { - for (const statementWT of subfieldPageInfo.paginatedStatements) { - const req = subfieldPageInfo.req; - const e = statementWT.target.entity?.resource; - if (e) { - const source: GvFieldSourceEntity = {fkInfo: e.pk_entity}; - const fkClass = e.fk_class; - const targetType = req.targets[fkClass]; - if (targetType?.nestedResource?.length) { - const subreqs = targetType.nestedResource; - const scope = req.page.scope.notInProject ? {inRepo: true} : req.page.scope; - const nestedreqs = nestedRequestsFromNestedResource( - req.pkProject, - source, - subreqs, - scope - ); - requests.push(...nestedreqs); - } - } - } - } - return requests; -} - -export function nestedRequestsFromNestedResource( - pkProject: number, - source: GvFieldSourceEntity, - subReqs: GvSubentitFieldPageReq[], - parentScope: GvFieldPageScope, -): GvFieldPageReq[] { - - // generate the scope of the subpages - let scope: GvFieldPageScope; - if (parentScope.notInProject) - scope = {inRepo: true}; - else - scope = parentScope; - - const results = [] - for (const subReq of subReqs) { - // convert GvLoadSubentitySubfieldPageReq to GvLoadSubfieldPageReq - const page: GvFieldPage = { - ...subReq.page, - scope, - source - }; - const targets = subReq.targets; - const req: GvFieldPageReq = { - page, - targets, - pkProject - } - - results.push(req) - } - return results; - -} +registerType(GvFieldId) diff --git a/server/src/controllers/war-entity-preview.controller.ts b/server/src/controllers/war-entity-preview.controller.ts index e044c4b4f..6c18d94fe 100644 --- a/server/src/controllers/war-entity-preview.controller.ts +++ b/server/src/controllers/war-entity-preview.controller.ts @@ -21,9 +21,8 @@ import {EntitySearchHit} from './EntitySearchHit'; // Fields to include in streamed WarEntityPreviews // see about Lb4 filters: https://loopback.io/doc/en/lb4/Fields-filter.html const includeFieldsForStream: Fields = { - key: true, pk_entity: true, - project_id: true, + fk_project: true, fk_class: true, class_label: true, entity_label: true, @@ -218,14 +217,14 @@ export class WarEntityPreviewController extends WebsocketControllerBase { /** * Queries entity previews that are in the array of keys * - * @param keys array of keys in the form of {project_id}_{pk_entity} + * @param keys array of keys in the form of {fk_project}_{pk_entity} */ private async findByKey(keys: string[]) { - // parse the keys into {project_id, pk_entity] + // parse the keys into {fk_project, pk_entity] const grouped = this.groupByProject(keys); const res: WarEntityPreviewWithFulltext[] = [] - // query the entity previews for each project_id + // query the entity previews for each fk_project for (const key in grouped) { const projectId = parseInt(key); const pkEntities = grouped[key].map(item => item.pk_entity); @@ -233,7 +232,7 @@ export class WarEntityPreviewController extends WebsocketControllerBase { fields: includeFieldsForStream, where: { and: [ - {project_id: projectId}, + {fk_project: projectId}, {pk_entity: {inq: pkEntities}} ] } @@ -250,14 +249,14 @@ export class WarEntityPreviewController extends WebsocketControllerBase { * that are modified at the same time as tsmpLastModification. * * @param tsmpLastModification - * @param keys array of keys in the form of {project_id}_{pk_entity} + * @param keys array of keys in the form of {fk_project}_{pk_entity} */ private async findModifiedSinceTmsp(keys: string[], tsmpLastModification: string) { - // parse the keys into {project_id, pk_entity] + // parse the keys into {fk_project, pk_entity] const grouped = this.groupByProject(keys); const res: WarEntityPreviewWithFulltext[] = [] - // query the entity previews for each project_id + // query the entity previews for each fk_project for (const key in grouped) { const projectId = parseInt(key); const pkEntities = grouped[key].map(item => item.pk_entity); @@ -266,7 +265,7 @@ export class WarEntityPreviewController extends WebsocketControllerBase { where: { and: [ {tmsp_last_modification: {eq: tsmpLastModification}}, - {project_id: projectId}, + {fk_project: projectId}, {pk_entity: {inq: pkEntities}} ] } @@ -281,10 +280,10 @@ export class WarEntityPreviewController extends WebsocketControllerBase { private groupByProject(keys: string[]) { const parsed: WarEntityPreviewId[] = keys.map(k => { const s = k.split('_'); - return {project_id: parseInt(s[0]), pk_entity: parseInt(s[1])}; + return {fk_project: parseInt(s[0]), pk_entity: parseInt(s[1])}; }); - // group the keys by project_id - const grouped = groupBy((item) => item.project_id.toString(), parsed); + // group the keys by fk_project + const grouped = groupBy((item) => item.fk_project.toString(), parsed); return grouped; } @@ -297,7 +296,8 @@ export class WarEntityPreviewController extends WebsocketControllerBase { this.log( this.socket.id + ' emitted entityPreview: ' + - entityPreview.key + + entityPreview.fk_project + '_' + + entityPreview.pk_entity + ' ' + entityPreview.entity_label + ' for project ' + @@ -342,7 +342,7 @@ export class WarEntityPreviewController extends WebsocketControllerBase { ts_headline(entity_label, q) as entity_label_headline, ts_headline(type_label, q) as type_label_headline, count(pk_entity) OVER() AS total_count - from war.entity_preview t1, + from pgwar.entity_preview t1, to_tsquery(${tsSearchString === '' ? "''" : tsSearchString}) q WHERE 1=1 ${tsSearchString @@ -350,8 +350,8 @@ export class WarEntityPreviewController extends WebsocketControllerBase { : '' } ${req.projectId - ? `AND project_id = ${q.addParam(req.projectId)}` - : `AND project_id = 0` + ? `AND fk_project = ${q.addParam(req.projectId)}` + : `AND fk_project = 0` } ${req.entityType ? `AND entity_type = ${q.addParam(req.entityType)}` : ''} ${req.pkClasses?.length @@ -440,20 +440,20 @@ export class WarEntityPreviewController extends WebsocketControllerBase { const q = new SqlBuilderLb4Models(this.dataSource) q.sql = ` WITH tw1 AS ( - SELECT pk_entity, project_id, fk_class, class_label, entity_label, time_span, entity_type - FROM war.entity_preview + SELECT pk_entity, fk_project, fk_class, class_label, entity_label, time_span, entity_type + FROM pgwar.entity_preview WHERE pk_entity IN (${q.addParams(pkEntities)}) - AND project_id = ${q.addParam(pkProject)} + AND fk_project = ${q.addParam(pkProject)} UNION - SELECT pk_entity, project_id, fk_class, class_label, entity_label, time_span, entity_type - FROM war.entity_preview + SELECT pk_entity, fk_project, fk_class, class_label, entity_label, time_span, entity_type + FROM pgwar.entity_preview WHERE pk_entity IN (${q.addParams(pkEntities)}) - AND project_id = 0 + AND fk_project = 0 ), tw2 AS ( SELECT DISTINCT ON (pk_entity) * FROM tw1 - ORDER BY pk_entity, project_id + ORDER BY pk_entity, fk_project ) SELECT * FROM tw2 diff --git a/server/src/models/entity-preview/WarEntityPreviewId.ts b/server/src/models/entity-preview/WarEntityPreviewId.ts index f63d8380e..87eddf859 100644 --- a/server/src/models/entity-preview/WarEntityPreviewId.ts +++ b/server/src/models/entity-preview/WarEntityPreviewId.ts @@ -1,4 +1,4 @@ export interface WarEntityPreviewId { pk_entity: number; - project_id: number; + fk_project: number; } diff --git a/server/src/models/field-response/GvSubfieldPageInfo.ts b/server/src/models/field-response/GvSubfieldPageInfo.ts index 3a7ca7520..1befce4f0 100644 --- a/server/src/models/field-response/GvSubfieldPageInfo.ts +++ b/server/src/models/field-response/GvSubfieldPageInfo.ts @@ -1,11 +1,11 @@ import {model, property} from '@loopback/repository'; -import {GvFieldPageReq} from '../field/gv-field-page-req'; +import {GvFieldPage} from '../field/gv-field-page'; import {StatementWithTarget} from './gv-statement-with-target'; @model() export class GvSubfieldPageInfo { - @property({type: GvFieldPageReq, required: true}) req: GvFieldPageReq; + @property({required: true}) page: GvFieldPage; @property({required: true}) count: number; @property.array(StatementWithTarget, {required: true}) paginatedStatements: StatementWithTarget[]; @property() validFor?: Date; diff --git a/server/src/models/gv-negative-schema-object.model.ts b/server/src/models/gv-negative-schema-object.model.ts index 37c54e03f..220f59c9f 100644 --- a/server/src/models/gv-negative-schema-object.model.ts +++ b/server/src/models/gv-negative-schema-object.model.ts @@ -1,74 +1,74 @@ -import {Entity, model, property} from '@loopback/repository'; -import {ProAnalysis} from './pro-analysis.model'; -import {ProTextProperty} from './pro-text-property.model'; - -@model() -export class PkEntity { - @property() pk_entity: number -} -@model() -export class PkEntityVersion { - @property() pk_entity: number - @property() entity_version: number -} - -@model() -export class FkProjectFkEntity extends Entity { - @property() fk_project: number - @property() fk_entity: number -} - -// @model() -// class ProObject { -// } - -@model() -class DatNegativeObject { - @property.array(PkEntityVersion) digital?: PkEntityVersion[] - @property.array(PkEntity) chunk?: PkEntity[] - @property.array(PkEntity) column?: PkEntity[] - @property.array(PkEntity) class_column_mapping?: PkEntity[] - @property.array(PkEntity) text_property?: PkEntity[] - @property.array(PkEntity) namespace?: PkEntity[] -} - -@model() -class InfNegativeObject { - @property.array(PkEntity) resource?: PkEntity[] - @property.array(PkEntity) statement?: PkEntity[] - @property.array(PkEntity) place?: PkEntity[] - @property.array(PkEntity) language?: PkEntity[] - @property.array(PkEntity) appellation?: PkEntity[] - @property.array(PkEntity) time_primitive?: PkEntity[] - @property.array(PkEntity) text_property?: PkEntity[] - @property.array(PkEntity) lang_string?: PkEntity[] - @property.array(PkEntity) dimension?: PkEntity[] -} - - - - -@model() -class ProNegativeObject { - @property.array(FkProjectFkEntity) info_proj_rel?: FkProjectFkEntity[] - @property.array(ProTextProperty) text_property?: Partial[]; - @property.array(ProAnalysis) analysis?: Partial[]; -} - - -/** - * This model reflects the database schema and acts as a data exchange format - * between geovistory server and geovistory client. - * - * Objects of this model can be easily consumed by geovistory client, which - * puts the individual elements of the object in the Redux store. - * - * Therefor this model is usualy used for the response of an API. - * - */ -@model() -export class GvNegativeSchemaObject { - @property() dat?: DatNegativeObject - @property() inf?: InfNegativeObject - @property() pro?: ProNegativeObject -} +import {Entity, model, property} from '@loopback/repository'; +import {ProAnalysis} from './pro-analysis.model'; +import {ProTextProperty} from './pro-text-property.model'; + +@model() +export class PkEntity { + @property() pk_entity: number +} +@model() +export class PkEntityVersion { + @property() pk_entity: number + @property() entity_version: number +} + +@model() +export class FkProjectFkEntity extends Entity { + @property() fk_project: number + @property() fk_entity: number +} + +// @model() +// class ProObject { +// } + +@model() +class DatNegativeObject { + @property.array(PkEntityVersion) digital?: PkEntityVersion[] + @property.array(PkEntity) chunk?: PkEntity[] + @property.array(PkEntity) column?: PkEntity[] + @property.array(PkEntity) class_column_mapping?: PkEntity[] + @property.array(PkEntity) text_property?: PkEntity[] + @property.array(PkEntity) namespace?: PkEntity[] +} + +@model() +class InfNegativeObject { + @property.array(PkEntity) resource?: PkEntity[] + @property.array(PkEntity) statement?: PkEntity[] + @property.array(PkEntity) place?: PkEntity[] + @property.array(PkEntity) language?: PkEntity[] + @property.array(PkEntity) appellation?: PkEntity[] + @property.array(PkEntity) time_primitive?: PkEntity[] + @property.array(PkEntity) text_property?: PkEntity[] + @property.array(PkEntity) lang_string?: PkEntity[] + @property.array(PkEntity) dimension?: PkEntity[] +} + + + + +@model() +class ProNegativeObject { + @property.array(FkProjectFkEntity) info_proj_rel?: FkProjectFkEntity[] + @property.array(ProTextProperty) text_property?: Partial[]; + @property.array(ProAnalysis) analysis?: Partial[]; +} + + +/** + * This model reflects the database schema and acts as a data exchange format + * between geovistory server and geovistory client. + * + * Objects of this model can be easily consumed by geovistory client, which + * puts the individual elements of the object in the Redux store. + * + * Therefor this model is usualy used for the response of an API. + * + */ +@model() +export class GvNegativeSchemaObject { + @property() dat?: DatNegativeObject + @property() inf?: InfNegativeObject + @property() pro?: ProNegativeObject +} diff --git a/server/src/models/war-class-preview.model.ts b/server/src/models/war-class-preview.model.ts index 508c24d13..f0eaf6006 100644 --- a/server/src/models/war-class-preview.model.ts +++ b/server/src/models/war-class-preview.model.ts @@ -11,7 +11,7 @@ import {Entity, model, property} from '@loopback/repository'; @model({ settings: { forceId: false, - postgresql: {schema: 'war', table: 'class_preview'}, + postgresql: {schema: 'pgwar', table: 'class_preview'}, validateUpsert: true, idInjection: false } diff --git a/server/src/models/war-entity-preview-with-full-text.model.ts b/server/src/models/war-entity-preview-with-full-text.model.ts index c895f33cf..fe66069c7 100644 --- a/server/src/models/war-entity-preview-with-full-text.model.ts +++ b/server/src/models/war-entity-preview-with-full-text.model.ts @@ -5,7 +5,7 @@ import {WarEntityPreview} from './war-entity-preview.model'; settings: { forceId: false, id: ['pk_entity', 'fk_project'], - postgresql: {schema: 'war', table: 'entity_preview'}, + postgresql: {schema: 'pgwar', table: 'entity_preview'}, validateUpsert: true, idInjection: false } diff --git a/server/src/models/war-entity-preview.model.ts b/server/src/models/war-entity-preview.model.ts index 98b842e0b..97a6d452b 100644 --- a/server/src/models/war-entity-preview.model.ts +++ b/server/src/models/war-entity-preview.model.ts @@ -57,15 +57,10 @@ export class WarEntityPreviewTimeSpan { settings: { strict: true, idInjection: false, - postgresql: {schema: 'war', table: 'entity_preview'} + postgresql: {schema: 'pgwar', table: 'entity_preview'} } }) export class WarEntityPreview extends Entity { - @property({ - type: 'string', - id: true, - }) - key?: string; @property({ type: 'number', @@ -77,7 +72,7 @@ export class WarEntityPreview extends Entity { type: 'number', required: true }) - project_id?: number; + fk_project?: number; @property({ type: 'number', diff --git a/server/src/models/war-field-change-id.model.ts b/server/src/models/war-field-change-id.model.ts index c59a6b65f..d586b4817 100644 --- a/server/src/models/war-field-change-id.model.ts +++ b/server/src/models/war-field-change-id.model.ts @@ -29,12 +29,6 @@ export class WarFieldChangeId { }) fk_property: number; - @property({ - type: 'number', - required: true - }) - fk_property_of_property: number; - @property({ type: 'boolean', required: true diff --git a/server/src/models/war-field-change.model.ts b/server/src/models/war-field-change.model.ts index de109562a..48df45d4e 100644 --- a/server/src/models/war-field-change.model.ts +++ b/server/src/models/war-field-change.model.ts @@ -6,7 +6,7 @@ import {registerType} from '../components/spec-enhancer/model.spec.enhancer'; settings: { forceId: false, id: ['fk_project', 'fk_source_info', 'fk_property', 'fk_property_of_property', 'is_outgoing'], - postgresql: {schema: 'war', table: 'field_change'}, + postgresql: {schema: 'pgwar', table: 'field_change'}, validateUpsert: true, idInjection: false } @@ -41,13 +41,6 @@ export class WarFieldChange extends Entity { }) fk_property: number; - @property({ - type: 'number', - required: true, - id: true - }) - fk_property_of_property: number; - @property({ type: 'boolean', required: true, diff --git a/server/src/realtime/db-listeners/postgres-notifications-manager.ts b/server/src/realtime/db-listeners/postgres-notifications-manager.ts index 8c5565aea..8177196a9 100644 --- a/server/src/realtime/db-listeners/postgres-notifications-manager.ts +++ b/server/src/realtime/db-listeners/postgres-notifications-manager.ts @@ -13,18 +13,7 @@ import {getGvDatabaseUrl, getPgSslForPg8} from '../../utils/databaseUrl'; */ export class PostgresNotificationsManager { - warUpdateNeeded = true; - classLabelUpdateNeeded = true; - statementUpdateNeeded = true; - - warUpdating = false; - statementsUpdating = false; - classLabelsUpdating = false; - client: Client; - client2: Client; - - vmStatementUpdated = '1970-01-01 10:08:21.128869+00'; /** * @param lb4App the Application Context to which we bind this manager @@ -84,19 +73,15 @@ export class PostgresNotificationsManager { * Start the manager */ async start() { - // create postgres client for war.updater() queue + // create postgres client to listen to pg_notify() this.client = this.createClient(); - this.client2 = this.createClient(); + // connect client await this.client.connect(); - await this.client2.connect(); - // this.callQueueWorker(); // react to notifications this.reactOnNotifications() - // this.startVmStatementsUpdateJob().catch(e => console.log(e)) - // start listening on pg notifications await this.listenToPgNotifyChannels() @@ -109,34 +94,11 @@ export class PostgresNotificationsManager { // disconnect clients from pg server try { await this.client.end() - await this.client2.end() } catch (e) { console.log(e); throw new Error(e); } } - /** - * Starts a job that periodically updates war.vm_statement - */ - // async startVmStatementsUpdateJob() { - - // const changes = await this.client2.query<{count: number, now: string}>(` - // Select count(*), to_char (now()::timestamp at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') now - // From projects.info_proj_rel t1 - // Where t1.tmsp_last_modification::timestamp >=$1; - // `, [this.vmStatementUpdated]) - - // this.vmStatementUpdated = changes.rows?.[0].now; - - // if (changes.rows?.[0].count > 0) { - // await this.client2.query('REFRESH MATERIALIZED VIEW CONCURRENTLY war.vm_statement;') - // } - - // setTimeout(() => { - // this.startVmStatementsUpdateJob().catch(e => console.log(e)) - // }, 3000) - - // } } diff --git a/server/src/startup/setupPostgresFunctions.ts b/server/src/startup/setupPostgresFunctions.ts index ef3a917cc..806410554 100644 --- a/server/src/startup/setupPostgresFunctions.ts +++ b/server/src/startup/setupPostgresFunctions.ts @@ -1,24 +1,13 @@ import {SqlGvCloneSandboxProject} from '../components/query/pg-functions/gv-clone-sandbox-project-fn'; -import {SqlGvFieldPageIncomingInProject} from '../components/query/pg-functions/gv-field-page-incoming-in-project-fn'; -import {SqlGvFieldPageIncomingInRepo} from '../components/query/pg-functions/gv-field-page-incoming-in-repo-fn'; -import {SqlGvFieldPageIncomingNoConstraint} from '../components/query/pg-functions/gv-field-page-incoming-no-constaint-fn'; -import {SqlGvFieldPageIncomingNotInProject} from '../components/query/pg-functions/gv-field-page-incoming-not-in-project-fn'; -import {SqlGvFieldPageOutgoingInProject} from '../components/query/pg-functions/gv-field-page-outgoing-in-project-fn'; -import {SqlGvFieldPageOutgoingInRepo} from '../components/query/pg-functions/gv-field-page-outgoing-in-repo'; -import {SqlGvFieldPageOutgoingNoConstraint} from '../components/query/pg-functions/gv-field-page-outgoing-no-constraint-fn'; -import {SqlGvFieldPageOutgoingNotInProject} from '../components/query/pg-functions/gv-field-page-outgoing-not-in-project-fn'; import {SqlGvGetIncomingStatementsToAdd} from '../components/query/pg-functions/gv-get-incoming-statements-to-add-fn'; import {SqlGvGetOutgoingStatementsToAdd} from '../components/query/pg-functions/gv-get-outgoing-statements-to-add-fn'; import {SqlGvGetRequiredOntoMeProfiles} from '../components/query/pg-functions/gv-get-required-ontome-profiles'; -import {SqlGvGetStatementTarget} from '../components/query/pg-functions/gv-get-statement-target-fn'; import {SqlGvRowToJsonbFunction} from '../components/query/pg-functions/gv-row-to-jsonb-fn'; import {Postgres1DataSource} from '../datasources/postgres1.datasource'; import {DatDigital, InfAppellation, InfDimension, InfLangString, InfLanguage, InfPlace, InfResource, InfStatement, InfTimePrimitive, ProInfoProjRel, TabCell, TabRow, WarEntityPreview} from '../models'; export async function setupPostgresFunctions(c: Postgres1DataSource) { await createModelToJsonbFunctions(c); - await createGetStatementTargetFunction(c); - await createFieldPageFunctions(c); await createGetRequiredOntoMeProfilesFunction(c); await createGetStatementsToAddFunctions(c); await createCloneSandboxFuntion(c); @@ -39,25 +28,6 @@ async function createGetRequiredOntoMeProfilesFunction(c: Postgres1DataSource) { await s.execute(); } -async function createGetStatementTargetFunction(c: Postgres1DataSource) { - const s = new SqlGvGetStatementTarget(c); - s.generateFunctionSql(); - await s.execute(); -} - -async function createFieldPageFunctions(c: Postgres1DataSource) { - await new SqlGvFieldPageIncomingInProject(c).generateFunctionSql().execute() - await new SqlGvFieldPageIncomingInRepo(c).generateFunctionSql().execute() - await new SqlGvFieldPageIncomingNoConstraint(c).generateFunctionSql().execute() - await new SqlGvFieldPageIncomingNotInProject(c).generateFunctionSql().execute() - await new SqlGvFieldPageOutgoingInProject(c).generateFunctionSql().execute() - await new SqlGvFieldPageOutgoingInRepo(c).generateFunctionSql().execute() - await new SqlGvFieldPageOutgoingNoConstraint(c).generateFunctionSql().execute() - await new SqlGvFieldPageOutgoingNotInProject(c).generateFunctionSql().execute() -} - - - /** * Creates the pg-functions to convert rows to json objects * @param c diff --git a/server/webserver.start.sh b/server/webserver.start.sh deleted file mode 100644 index 545cacd87..000000000 --- a/server/webserver.start.sh +++ /dev/null @@ -1,4 +0,0 @@ -set -e # exit when any command fails -bash ./db-migrate/up.sh # migrate up - -node dist/webserver.js # start server diff --git a/server/webserver.dockerfile b/webserver.dockerfile similarity index 62% rename from server/webserver.dockerfile rename to webserver.dockerfile index 5892515b1..d0954e2e5 100644 --- a/server/webserver.dockerfile +++ b/webserver.dockerfile @@ -6,23 +6,24 @@ WORKDIR /app # Install app dependencies # A wildcard is used to ensure both package.json AND package-lock.json are copied # where available (npm@5+) -COPY package*.json /app/ +COPY server/package*.json /app/server/ # “Ci” will install packages directly from the lock file. -RUN npm ci +RUN npm --prefix server ci # Copy typescript (everything needed to compile) -COPY tsconfig.json /app -COPY src /app/src +COPY server/tsconfig.json /app/server +COPY server/src /app/server/src # Copy migration files -COPY db-migrate /app/db-migrate +COPY database/migrations /app/database/migrations +COPY server/db-migrate /app/server/db-migrate # Copy entrypoint -COPY webserver.start.sh /app +COPY webserver.start.sh /app/ # Compile TypeScript (in workdir) -RUN npm run tsc +RUN npm --prefix server run tsc # If you are building your code for production #RUN npm ci --only=production diff --git a/webserver.start.sh b/webserver.start.sh new file mode 100644 index 000000000..3ac181adb --- /dev/null +++ b/webserver.start.sh @@ -0,0 +1,4 @@ +set -e # exit when any command fails +bash ./server/db-migrate/up.sh # migrate up + +node server/dist/webserver.js # start server