geovisio 2.11.0__py3-none-any.whl → 2.12.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- geovisio/__init__.py +30 -2
- geovisio/admin_cli/db.py +1 -1
- geovisio/db_migrations.py +2 -2
- geovisio/migrations/20221201_01_wpCGc-initial-schema.rollback.sql +9 -0
- geovisio/migrations/20221201_01_wpCGc-initial-schema.sql +71 -0
- geovisio/migrations/20221201_02_ZG8AR-camera-information.rollback.sql +5 -0
- geovisio/migrations/20221201_02_ZG8AR-camera-information.sql +10 -0
- geovisio/migrations/20221222_01_fsB6f-add-account.rollback.sql +7 -0
- geovisio/migrations/20221222_01_fsB6f-add-account.sql +33 -0
- geovisio/migrations/20230113_01_0co97-rm-metadata-duplicates.rollback.sql +5 -0
- geovisio/migrations/20230113_01_0co97-rm-metadata-duplicates.sql +5 -0
- geovisio/migrations/20230116_01_9PkjZ-add-oauth-provider.rollback.sql +12 -0
- geovisio/migrations/20230116_01_9PkjZ-add-oauth-provider.sql +10 -0
- geovisio/migrations/20230117_01_K71Pd-pictures-ts-index.rollback.sql +4 -0
- geovisio/migrations/20230117_01_K71Pd-pictures-ts-index.sql +4 -0
- geovisio/migrations/20230130_01_VRIv2-sequences-account.rollback.sql +5 -0
- geovisio/migrations/20230130_01_VRIv2-sequences-account.sql +25 -0
- geovisio/migrations/20230324_01_ba9WA-status.rollback.sql +35 -0
- geovisio/migrations/20230324_01_ba9WA-status.sql +11 -0
- geovisio/migrations/20230324_02_efgI6-picture-process.rollback.sql +20 -0
- geovisio/migrations/20230324_02_efgI6-picture-process.sql +44 -0
- geovisio/migrations/20230407_01_wofh1-computed-headings.rollback.sql +6 -0
- geovisio/migrations/20230407_01_wofh1-computed-headings.sql +6 -0
- geovisio/migrations/20230417_01_ZgLMY-add-exif-metadata-column-for-pictures.rollback.sql +4 -0
- geovisio/migrations/20230417_01_ZgLMY-add-exif-metadata-column-for-pictures.sql +4 -0
- geovisio/migrations/20230420_01_elaN3-remove-picture-and-sequence-file-paths.rollback.sql +5 -0
- geovisio/migrations/20230420_01_elaN3-remove-picture-and-sequence-file-paths.sql +5 -0
- geovisio/migrations/20230425_01_gYP77-pictures-edits-triggers.rollback.sql +5 -0
- geovisio/migrations/20230425_01_gYP77-pictures-edits-triggers.sql +64 -0
- geovisio/migrations/20230427_01_k5e5w-timestamps.rollback.sql +10 -0
- geovisio/migrations/20230427_01_k5e5w-timestamps.sql +19 -0
- geovisio/migrations/20230511_01_TdpKo-tokens.rollback.sql +7 -0
- geovisio/migrations/20230511_01_TdpKo-tokens.sql +34 -0
- geovisio/migrations/20230615_01_u7aRf-pic-delete-cascade.rollback.sql +10 -0
- geovisio/migrations/20230615_01_u7aRf-pic-delete-cascade.sql +12 -0
- geovisio/migrations/20230623_01_y1SiQ-pic-deletion-task.rollback.sql +39 -0
- geovisio/migrations/20230623_01_y1SiQ-pic-deletion-task.sql +36 -0
- geovisio/migrations/20230629_01_ZdB3i-compute-heading-0.sql +27 -0
- geovisio/migrations/20230711_01_JGSPB-inserted-at-index.rollback.sql +4 -0
- geovisio/migrations/20230711_01_JGSPB-inserted-at-index.sql +4 -0
- geovisio/migrations/20230720_01_EyQ0e-sequences-summary.rollback.sql +7 -0
- geovisio/migrations/20230720_01_EyQ0e-sequences-summary.sql +26 -0
- geovisio/migrations/20230803_01_aXusm-fix-sequence-computed.rollback.sql +4 -0
- geovisio/migrations/20230803_01_aXusm-fix-sequence-computed.sql +25 -0
- geovisio/migrations/20231018_01_4G3YE-pictures-exiv2.rollback.sql +165 -0
- geovisio/migrations/20231018_01_4G3YE-pictures-exiv2.sql +206 -0
- geovisio/migrations/20231103_01_ZVKEm-update-seq-on-pic-change.rollback.sql +7 -0
- geovisio/migrations/20231103_01_ZVKEm-update-seq-on-pic-change.sql +28 -0
- geovisio/migrations/20231110_01_3p070-jobs-error.rollback.sql +7 -0
- geovisio/migrations/20231110_01_3p070-jobs-error.sql +93 -0
- geovisio/migrations/20231121_01_v6oBF-more-specific-triggers.rollback.sql +36 -0
- geovisio/migrations/20231121_01_v6oBF-more-specific-triggers.sql +40 -0
- geovisio/migrations/20231121_02_1uZXT-deleted-tag.rollback.sql +19 -0
- geovisio/migrations/20231121_02_1uZXT-deleted-tag.sql +13 -0
- geovisio/migrations/20240115_01_FatLR-token-delete-cascade.rollback.sql +6 -0
- geovisio/migrations/20240115_01_FatLR-token-delete-cascade.sql +7 -0
- geovisio/migrations/20240220_01_9wZs0-sequence-current-sort.rollback.sql +6 -0
- geovisio/migrations/20240220_01_9wZs0-sequence-current-sort.sql +15 -0
- geovisio/migrations/20240223_01_LsMHB-remove-binary-fields.sql +80 -0
- geovisio/migrations/20240226_01_8iXl1-track-changes.rollback.sql +13 -0
- geovisio/migrations/20240226_01_8iXl1-track-changes.sql +123 -0
- geovisio/migrations/20240229_01_SgfQY-sequence-geom-multi-linestring.rollback.sql +67 -0
- geovisio/migrations/20240229_01_SgfQY-sequence-geom-multi-linestring.sql +101 -0
- geovisio/migrations/20240308_01_aF0Jb-migrate-sequence-geom-multi-linestring.sql +52 -0
- geovisio/migrations/20240409_01_jnhra-pictures-grid.rollback.sql +3 -0
- geovisio/migrations/20240409_01_jnhra-pictures-grid.sql +21 -0
- geovisio/migrations/20240416_01_FpyGs-pictures-stats-on-sequences.rollback.sql +7 -0
- geovisio/migrations/20240416_01_FpyGs-pictures-stats-on-sequences.sql +9 -0
- geovisio/migrations/20240416_02_A5KzC-fill-pictures-stats-on-sequences.rollback.sql +5 -0
- geovisio/migrations/20240416_02_A5KzC-fill-pictures-stats-on-sequences.sql +84 -0
- geovisio/migrations/20240507_01_eBfqZ-refresh-table.rollback.sql +5 -0
- geovisio/migrations/20240507_01_eBfqZ-refresh-table.sql +9 -0
- geovisio/migrations/20240507_02_dzVET-picture-grid-public.rollback.sql +21 -0
- geovisio/migrations/20240507_02_dzVET-picture-grid-public.sql +26 -0
- geovisio/migrations/20240514_01_IT7DD-picture-delete-cascade.rollback.sql +41 -0
- geovisio/migrations/20240514_01_IT7DD-picture-delete-cascade.sql +42 -0
- geovisio/migrations/20240611_01_jftHn-content-md5.rollback.sql +5 -0
- geovisio/migrations/20240611_01_jftHn-content-md5.sql +7 -0
- geovisio/migrations/20240612_01_yNcuE-upload-set.rollback.sql +6 -0
- geovisio/migrations/20240612_01_yNcuE-upload-set.sql +46 -0
- geovisio/migrations/20240617_01_tKtlx-md5-concurrent-index.rollback.sql +4 -0
- geovisio/migrations/20240617_01_tKtlx-md5-concurrent-index.sql +8 -0
- geovisio/migrations/20240625_01_XMZ24-fix-sequence-stat-on-pic-insertion.rollback.sql +30 -0
- geovisio/migrations/20240625_01_XMZ24-fix-sequence-stat-on-pic-insertion.sql +31 -0
- geovisio/migrations/20240708_01_Xn7IH-job-queue.rollback.sql +31 -0
- geovisio/migrations/20240708_01_Xn7IH-job-queue.sql +104 -0
- geovisio/migrations/20240715_01_Hca9V-upload-set-metadata.rollback.sql +4 -0
- geovisio/migrations/20240715_01_Hca9V-upload-set-metadata.sql +5 -0
- geovisio/migrations/20240723_01_ePGFe-upload-set-files.rollback.sql +7 -0
- geovisio/migrations/20240723_01_ePGFe-upload-set-files.sql +29 -0
- geovisio/migrations/20240729_01_HALjj-upload-set-sort.rollback.sql +18 -0
- geovisio/migrations/20240729_01_HALjj-upload-set-sort.sql +18 -0
- geovisio/migrations/20240730_01_2BaCy-improve-deletion-triggers.rollback.sql +34 -0
- geovisio/migrations/20240730_01_2BaCy-improve-deletion-triggers.sql +53 -0
- geovisio/migrations/20240730_02_aRymN-rejection-status.rollback.sql +10 -0
- geovisio/migrations/20240730_02_aRymN-rejection-status.sql +16 -0
- geovisio/migrations/20240801_01_DOqmf-reports.rollback.sql +11 -0
- geovisio/migrations/20240801_01_DOqmf-reports.sql +100 -0
- geovisio/migrations/20240801_01_uKqPo-remove-files-delete-cascade.rollback.sql +13 -0
- geovisio/migrations/20240801_01_uKqPo-remove-files-delete-cascade.sql +13 -0
- geovisio/migrations/20240813_01_T1XkO-sequences-geom-splits.rollback.sql +42 -0
- geovisio/migrations/20240813_01_T1XkO-sequences-geom-splits.sql +56 -0
- geovisio/migrations/20240820_01_aB2ZK-exclusion-zones.rollback.sql +6 -0
- geovisio/migrations/20240820_01_aB2ZK-exclusion-zones.sql +49 -0
- geovisio/migrations/20240902_01_MDqSj-user-agent.rollback.sql +5 -0
- geovisio/migrations/20240902_01_MDqSj-user-agent.sql +10 -0
- geovisio/migrations/20240904_01_gFjlV-files-rejection-msg.rollback.sql +4 -0
- geovisio/migrations/20240904_01_gFjlV-files-rejection-msg.sql +4 -0
- geovisio/migrations/20240905_01_C8F6U-conflicts.rollback.sql +13 -0
- geovisio/migrations/20240905_01_C8F6U-conflicts.sql +6 -0
- geovisio/migrations/20240905_01_E5Ki0-upload-set-delete.rollback.sql +5 -0
- geovisio/migrations/20240905_01_E5Ki0-upload-set-delete.sql +30 -0
- geovisio/migrations/20240909_01_Muc22-unique-grid-index.rollback.sql +4 -0
- geovisio/migrations/20240909_01_Muc22-unique-grid-index.sql +5 -0
- geovisio/migrations/20240912_01_dAALm-account-index.rollback.sql +4 -0
- geovisio/migrations/20240912_01_dAALm-account-index.sql +4 -0
- geovisio/migrations/20241004_01_d1zfe-pictures-grid-360.rollback.sql +22 -0
- geovisio/migrations/20241004_01_d1zfe-pictures-grid-360.sql +24 -0
- geovisio/migrations/20241011_01_e1j5C-pic-quality.rollback.sql +21 -0
- geovisio/migrations/20241011_01_e1j5C-pic-quality.sql +249 -0
- geovisio/migrations/20241017_01_GuOjF-pic-quality-update.rollback.sql +4 -0
- geovisio/migrations/20241017_01_GuOjF-pic-quality-update.sql +61 -0
- geovisio/migrations/20241017_01_RiFlm-pictures-to-delete.rollback.sql +43 -0
- geovisio/migrations/20241017_01_RiFlm-pictures-to-delete.sql +75 -0
- geovisio/migrations/20241104_01_yhRVu-rejection-details.rollback.sql +4 -0
- geovisio/migrations/20241104_01_yhRVu-rejection-details.sql +4 -0
- geovisio/migrations/20241128_01_ugthx-job-queue-args.rollback.sql +25 -0
- geovisio/migrations/20241128_01_ugthx-job-queue-args.sql +31 -0
- geovisio/migrations/20241224_01_xuN6n-delete-upload-set-on-last-picture-trg-statement.rollback.sql +27 -0
- geovisio/migrations/20241224_01_xuN6n-delete-upload-set-on-last-picture-trg-statement.sql +28 -0
- geovisio/migrations/20250102_01_EElhA-rm-cameras.rollback.sql +126 -0
- geovisio/migrations/20250102_01_EElhA-rm-cameras.sql +30 -0
- geovisio/migrations/20250107_01_EQN9v-tags-tables.rollback.sql +10 -0
- geovisio/migrations/20250107_01_EQN9v-tags-tables.sql +58 -0
- geovisio/migrations/20250109_01_4OOP4-pages.rollback.sql +4 -0
- geovisio/migrations/20250109_01_4OOP4-pages.sql +10 -0
- geovisio/migrations/20250114_01_ABaaL-collaborative-metadata-editing.rollback.sql +7 -0
- geovisio/migrations/20250114_01_ABaaL-collaborative-metadata-editing.sql +16 -0
- geovisio/migrations/20250123_01_Ececu-tos-acceptance.rollback.sql +5 -0
- geovisio/migrations/20250123_01_Ececu-tos-acceptance.sql +5 -0
- geovisio/migrations/20250206_01_PjrEL-annotation-semantics.rollback.sql +14 -0
- geovisio/migrations/20250206_01_PjrEL-annotation-semantics.sql +15 -0
- geovisio/migrations/20250306_01_58oju-semantics-views.rollback.sql +5 -0
- geovisio/migrations/20250306_01_58oju-semantics-views.sql +52 -0
- geovisio/migrations/20250318_01_pANl1-semantics-functions.rollback.sql +5 -0
- geovisio/migrations/20250318_01_pANl1-semantics-functions.sql +41 -0
- geovisio/migrations/20250331_01_kRKjo-store-detections-id.rollback.sql +7 -0
- geovisio/migrations/20250331_01_kRKjo-store-detections-id.sql +25 -0
- geovisio/migrations/20250424_01_RBGXC-semantics-indexes.rollback.sql +6 -0
- geovisio/migrations/20250424_01_RBGXC-semantics-indexes.sql +6 -0
- geovisio/migrations/20250502_01_ZNmkU-job-task-read-metadata.rollback.sql +24 -0
- geovisio/migrations/20250502_01_ZNmkU-job-task-read-metadata.sql +7 -0
- geovisio/migrations/20250509_01_kMatW-deactivate-upload-set-split-dedup.rollback.sql +12 -0
- geovisio/migrations/20250509_01_kMatW-deactivate-upload-set-split-dedup.sql +12 -0
- geovisio/migrations/20250509_01_s3hYk-semantic-delete-cascade.rollback.sql +11 -0
- geovisio/migrations/20250509_01_s3hYk-semantic-delete-cascade.sql +11 -0
- geovisio/migrations/20250513_01_8WkZC-upload-sets-default-config.rollback.sql +7 -0
- geovisio/migrations/20250513_01_8WkZC-upload-sets-default-config.sql +15 -0
- geovisio/migrations/20250523_01_b11eW-picture-update-index.rollback.sql +85 -0
- geovisio/migrations/20250523_01_b11eW-picture-update-index.sql +166 -0
- geovisio/migrations/20250523_02_5ZXXh-update-picture-updated-at.rollback.sql +4 -0
- geovisio/migrations/20250523_02_5ZXXh-update-picture-updated-at.sql +7 -0
- geovisio/migrations/20250624_01_SETp6-job-warnings.rollback.sql +4 -0
- geovisio/migrations/20250624_01_SETp6-job-warnings.sql +4 -0
- geovisio/migrations/20250701_01_kr371-upload-set-semantics.rollback.sql +6 -0
- geovisio/migrations/20250701_01_kr371-upload-set-semantics.sql +15 -0
- geovisio/migrations/20250703_01_p2WVV-sequence-upload-set-link.rollback.sql +4 -0
- geovisio/migrations/20250703_01_p2WVV-sequence-upload-set-link.sql +4 -0
- geovisio/migrations/20250703_02_q0s3D-sequence-upload-set-fill.rollback.sql +4 -0
- geovisio/migrations/20250703_02_q0s3D-sequence-upload-set-fill.sql +26 -0
- geovisio/migrations/20250716_01_f8tcJ-check-empty-annotation-late.rollback.sql +24 -0
- geovisio/migrations/20250716_01_f8tcJ-check-empty-annotation-late.sql +10 -0
- geovisio/migrations/20250728_01_2zgur-upload-set-relative-heading.rollback.sql +4 -0
- geovisio/migrations/20250728_01_2zgur-upload-set-relative-heading.sql +4 -0
- geovisio/migrations/20250825_01_nCgkN-file-deletion-after-delete-no-dup.rollback.sql +20 -0
- geovisio/migrations/20250825_01_nCgkN-file-deletion-after-delete-no-dup.sql +26 -0
- geovisio/migrations/20250902_01_k5UTq-visibility-status.rollback.sql +11 -0
- geovisio/migrations/20250902_01_k5UTq-visibility-status.sql +19 -0
- geovisio/migrations/20250904_01_3uVKX-visibility-functions.rollback.sql +20 -0
- geovisio/migrations/20250904_01_3uVKX-visibility-functions.sql +43 -0
- geovisio/migrations/20251110_01_bWEXo-report-visibility.rollback.sql +30 -0
- geovisio/migrations/20251110_01_bWEXo-report-visibility.sql +30 -0
- geovisio/migrations/20251124_01_0xdqi-page-updates.rollback.sql +6 -0
- geovisio/migrations/20251124_01_0xdqi-page-updates.sql +8 -0
- geovisio/migrations/20251127_01_S6Ci8-pictures-grid-visibility.rollback.sql +24 -0
- geovisio/migrations/20251127_01_S6Ci8-pictures-grid-visibility.sql +36 -0
- geovisio/migrations/20251202_01_Q3g59-pictures-grid-logged-only.rollback.sql +32 -0
- geovisio/migrations/20251202_01_Q3g59-pictures-grid-logged-only.sql +34 -0
- geovisio/templates/main.html +7 -58
- geovisio/templates/viewer.html +8 -15
- geovisio/translations/cy/LC_MESSAGES/messages.mo +0 -0
- geovisio/translations/cy/LC_MESSAGES/messages.po +839 -0
- geovisio/translations/en/LC_MESSAGES/messages.mo +0 -0
- geovisio/translations/en/LC_MESSAGES/messages.po +155 -149
- geovisio/translations/messages.pot +131 -150
- geovisio/utils/cql2.py +22 -17
- geovisio/utils/link.py +13 -3
- geovisio/utils/upload_set.py +42 -2
- geovisio/web/collections.py +80 -40
- geovisio/web/docs.py +1 -1
- geovisio/web/items.py +54 -4
- geovisio/web/upload_set.py +2 -3
- geovisio/web/users.py +1 -1
- {geovisio-2.11.0.dist-info → geovisio-2.12.0.dist-info}/METADATA +6 -26
- geovisio-2.12.0.dist-info/RECORD +305 -0
- geovisio-2.12.0.dist-info/entry_points.txt +3 -0
- geovisio-2.11.0.dist-info/RECORD +0 -117
- {geovisio-2.11.0.dist-info → geovisio-2.12.0.dist-info}/WHEEL +0 -0
- {geovisio-2.11.0.dist-info → geovisio-2.12.0.dist-info}/licenses/LICENSE +0 -0
geovisio/__init__.py
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"""GeoVisio API - Main"""
|
|
2
2
|
|
|
3
|
-
__version__ = "2.
|
|
3
|
+
__version__ = "2.12.0"
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
from flask import Flask, jsonify, stream_template, send_from_directory, redirect, request, url_for
|
|
7
|
-
from flask.cli import with_appcontext
|
|
7
|
+
from flask.cli import with_appcontext, FlaskGroup
|
|
8
8
|
from flask_cors import CORS
|
|
9
9
|
from flask_compress import Compress
|
|
10
10
|
from flask_babel import Babel
|
|
11
11
|
from flasgger import Swagger
|
|
12
|
+
import click
|
|
13
|
+
import atexit
|
|
12
14
|
import logging
|
|
13
15
|
from logging.config import dictConfig
|
|
14
16
|
|
|
@@ -66,6 +68,21 @@ LOGGING_CONFIG = {
|
|
|
66
68
|
dictConfig(LOGGING_CONFIG)
|
|
67
69
|
|
|
68
70
|
|
|
71
|
+
def cleanup_app(app):
|
|
72
|
+
"""Cleanup app before closing it"""
|
|
73
|
+
if not app.pool.closed:
|
|
74
|
+
app.pool.close()
|
|
75
|
+
if not app.long_queries_pool.closed:
|
|
76
|
+
app.long_queries_pool.close()
|
|
77
|
+
app.background_processor.stop()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def on_app_exit(app):
|
|
81
|
+
"""Explicitly cleanup before exiting, to make sure all the database connections are closed, and the background processes stopped
|
|
82
|
+
This is necessary because python 3.13 changed the way the threads bahave at interpreter shutdown"""
|
|
83
|
+
cleanup_app(app)
|
|
84
|
+
|
|
85
|
+
|
|
69
86
|
# Init i18n
|
|
70
87
|
def get_locale():
|
|
71
88
|
try:
|
|
@@ -161,6 +178,8 @@ def create_app(test_config=None, app=None):
|
|
|
161
178
|
|
|
162
179
|
template_vars = {"API_VERSION_MAJOR_MINOR": ".".join(__version__.split(".")[0:2])}
|
|
163
180
|
|
|
181
|
+
atexit.register(on_app_exit, app=app)
|
|
182
|
+
|
|
164
183
|
# Main page
|
|
165
184
|
@app.route("/")
|
|
166
185
|
def index():
|
|
@@ -253,3 +272,12 @@ def createDirNoFailure(directory):
|
|
|
253
272
|
os.makedirs(directory)
|
|
254
273
|
except OSError:
|
|
255
274
|
pass
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@click.group(cls=FlaskGroup, create_app=create_app)
|
|
278
|
+
def cli():
|
|
279
|
+
"""Panoramax backend management commands"""
|
|
280
|
+
# Note: This makes it possible to do:
|
|
281
|
+
# `panoramax_backend db upgrade` instead of `flask --app geovisio db upgrade` (but the later still works)
|
|
282
|
+
# since this `cli` function is used as a project.scripts
|
|
283
|
+
pass
|
geovisio/admin_cli/db.py
CHANGED
|
@@ -20,7 +20,7 @@ def upgrade():
|
|
|
20
20
|
is_flag=True,
|
|
21
21
|
default=False,
|
|
22
22
|
show_default=True,
|
|
23
|
-
help="rollbacks all migrations instead, meaning everything created by
|
|
23
|
+
help="rollbacks all migrations instead, meaning everything created by Panoramax in database is deleted",
|
|
24
24
|
)
|
|
25
25
|
@with_appcontext
|
|
26
26
|
def rollback(all):
|
geovisio/db_migrations.py
CHANGED
|
@@ -67,7 +67,7 @@ ALTER DATABASE {dbName.as_string()} SET TIMEZONE TO 'UTC';"""
|
|
|
67
67
|
# * nor for the tests
|
|
68
68
|
if "db" not in sys.argv and "pytest" not in sys.modules:
|
|
69
69
|
raise Exception(
|
|
70
|
-
f"""
|
|
70
|
+
f"""Panoramax database schema needs an update !
|
|
71
71
|
|
|
72
72
|
The following database migrations are required:
|
|
73
73
|
{migrationNames}
|
|
@@ -105,4 +105,4 @@ def get_yoyo_backend(dbUrl):
|
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
def get_migrations():
|
|
108
|
-
return yoyo.read_migrations(os.path.join(os.path.dirname(__file__), "
|
|
108
|
+
return yoyo.read_migrations(os.path.join(os.path.dirname(__file__), "migrations"))
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- initial schema
|
|
2
|
+
-- depends:
|
|
3
|
+
|
|
4
|
+
DROP TABLE IF EXISTS next_sequences CASCADE;
|
|
5
|
+
DROP TABLE IF EXISTS sequences_pictures CASCADE;
|
|
6
|
+
DROP TABLE IF EXISTS sequences CASCADE;
|
|
7
|
+
DROP TYPE IF EXISTS sequence_status;
|
|
8
|
+
DROP TABLE IF EXISTS pictures CASCADE;
|
|
9
|
+
DROP TYPE IF EXISTS picture_status;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
-- initial schema
|
|
2
|
+
-- depends:
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
--
|
|
6
|
+
-- Script for database setup
|
|
7
|
+
--
|
|
8
|
+
|
|
9
|
+
CREATE EXTENSION IF NOT EXISTS postgis;
|
|
10
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
|
11
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
-- Pictures
|
|
15
|
+
CREATE TYPE picture_status AS ENUM (
|
|
16
|
+
'preparing', -- Default state
|
|
17
|
+
'broken', -- State when an error occured during import/blurring
|
|
18
|
+
'ready', -- State when picture is ready to serve
|
|
19
|
+
'hidden' -- State when admin disabled picture
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
CREATE TABLE pictures(
|
|
23
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
24
|
+
file_path VARCHAR NOT NULL, -- Relative to instance storage path
|
|
25
|
+
status picture_status NOT NULL DEFAULT 'preparing',
|
|
26
|
+
ts TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
27
|
+
heading INT,
|
|
28
|
+
metadata JSONB,
|
|
29
|
+
geom GEOMETRY(Point, 4326) NOT NULL
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CREATE INDEX pictures_geom_idx ON pictures USING GIST(geom);
|
|
33
|
+
CREATE INDEX pictures_status_idx ON pictures(status);
|
|
34
|
+
|
|
35
|
+
-- Sequences
|
|
36
|
+
CREATE TYPE sequence_status AS ENUM (
|
|
37
|
+
'preparing', -- Default state
|
|
38
|
+
'broken', -- State when an error occured during import
|
|
39
|
+
'ready', -- State when sequence is ready to serve
|
|
40
|
+
'hidden' -- State when admin disabled sequence
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
CREATE TABLE sequences(
|
|
44
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
45
|
+
folder_path VARCHAR NOT NULL,
|
|
46
|
+
status sequence_status NOT NULL DEFAULT 'preparing',
|
|
47
|
+
metadata JSONB,
|
|
48
|
+
geom GEOMETRY(LineString, 4326)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE INDEX sequences_geom_idx ON sequences USING GIST(geom);
|
|
52
|
+
CREATE INDEX sequences_status_idx ON sequences(status);
|
|
53
|
+
CREATE INDEX sequences_folder_path_idx ON sequences(folder_path);
|
|
54
|
+
|
|
55
|
+
-- Link between pictures and sequences
|
|
56
|
+
CREATE TABLE sequences_pictures(
|
|
57
|
+
seq_id UUID NOT NULL REFERENCES sequences(id),
|
|
58
|
+
rank BIGINT NOT NULL,
|
|
59
|
+
pic_id UUID NOT NULL REFERENCES pictures(id),
|
|
60
|
+
PRIMARY KEY (seq_id, rank)
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
CREATE INDEX sequences_pictures_pic_id_idx ON sequences_pictures(pic_id);
|
|
64
|
+
|
|
65
|
+
-- Link between sequences
|
|
66
|
+
CREATE TABLE next_sequences(
|
|
67
|
+
seq_id UUID NOT NULL REFERENCES sequences(id),
|
|
68
|
+
rank INT NOT NULL,
|
|
69
|
+
next_seq_id UUID NOT NULL REFERENCES sequences(id),
|
|
70
|
+
PRIMARY KEY (seq_id, rank)
|
|
71
|
+
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- add-account
|
|
2
|
+
-- depends: 20221201_01_wpCGc-initial-schema
|
|
3
|
+
|
|
4
|
+
-- the camera info has been deprecated since versions > 2.7.1__. Newer versions uses data from Geo-picture tag reader directly.
|
|
5
|
+
CREATE TABLE cameras(
|
|
6
|
+
model VARCHAR PRIMARY KEY,
|
|
7
|
+
sensor_width FLOAT NOT NULL
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
CREATE INDEX cameras_model_idx ON cameras USING GIST(model gist_trgm_ops);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- add-account
|
|
2
|
+
-- depends: 20221201_02_ZG8AR-camera-information
|
|
3
|
+
|
|
4
|
+
CREATE TABLE accounts(
|
|
5
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
6
|
+
name VARCHAR NOT NULL,
|
|
7
|
+
is_default BOOLEAN NOT NULL DEFAULT false,
|
|
8
|
+
|
|
9
|
+
CONSTRAINT name_unique UNIQUE (name)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- At most one account can be the default one
|
|
13
|
+
CREATE UNIQUE INDEX at_most_one_default
|
|
14
|
+
ON accounts (is_default) WHERE (is_default);
|
|
15
|
+
|
|
16
|
+
-- Add a link betwen account and picture
|
|
17
|
+
ALTER TABLE pictures ADD COLUMN IF NOT EXISTS account_id UUID;
|
|
18
|
+
ALTER TABLE pictures ADD CONSTRAINT account_fk_id FOREIGN KEY (account_id) REFERENCES accounts (id);
|
|
19
|
+
|
|
20
|
+
-- Create default account and associate existing pictures to default account
|
|
21
|
+
WITH default_account AS (
|
|
22
|
+
INSERT INTO accounts(name, is_default)
|
|
23
|
+
VALUES('Default account', true)
|
|
24
|
+
ON CONFLICT DO NOTHING
|
|
25
|
+
RETURNING id
|
|
26
|
+
)
|
|
27
|
+
UPDATE pictures
|
|
28
|
+
SET account_id = default_account.id
|
|
29
|
+
FROM default_account
|
|
30
|
+
WHERE account_id IS NULL;
|
|
31
|
+
|
|
32
|
+
-- After initial init, set NOT NULL constraint on account_id
|
|
33
|
+
ALTER TABLE pictures ALTER COLUMN account_id SET NOT NULL;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- add-provider-oidc
|
|
2
|
+
-- depends: 20230113_01_0co97-rm-metadata-duplicates
|
|
3
|
+
|
|
4
|
+
DROP INDEX oauth_id_idx;
|
|
5
|
+
|
|
6
|
+
ALTER TABLE accounts
|
|
7
|
+
DROP COLUMN oauth_provider,
|
|
8
|
+
DROP COLUMN oauth_id,
|
|
9
|
+
DROP COLUMN created_at;
|
|
10
|
+
|
|
11
|
+
ALTER TABLE accounts ADD CONSTRAINT name_unique UNIQUE (name);
|
|
12
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- add-provider-oidc
|
|
2
|
+
-- depends: 20230113_01_0co97-rm-metadata-duplicates
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
ALTER TABLE accounts ADD COLUMN IF NOT EXISTS oauth_provider VARCHAR;
|
|
6
|
+
ALTER TABLE accounts ADD COLUMN IF NOT EXISTS oauth_id VARCHAR;
|
|
7
|
+
ALTER TABLE accounts ADD COLUMN IF NOT EXISTS created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
|
8
|
+
ALTER TABLE accounts DROP CONSTRAINT name_unique;
|
|
9
|
+
|
|
10
|
+
CREATE UNIQUE INDEX oauth_id_idx ON accounts (oauth_provider, oauth_id);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- sequences-account
|
|
2
|
+
-- depends: 20230117_01_K71Pd-pictures-ts-index
|
|
3
|
+
|
|
4
|
+
-- Add account column on sequences
|
|
5
|
+
ALTER TABLE sequences ADD COLUMN IF NOT EXISTS account_id UUID;
|
|
6
|
+
ALTER TABLE sequences ADD CONSTRAINT account_fk_id FOREIGN KEY (account_id) REFERENCES accounts (id);
|
|
7
|
+
|
|
8
|
+
-- Try to fill it with sequence's first picture account
|
|
9
|
+
UPDATE sequences
|
|
10
|
+
SET account_id = p.account_id
|
|
11
|
+
FROM (
|
|
12
|
+
SELECT DISTINCT ON (sp.seq_id) sp.seq_id, p.account_id, COUNT(*) as nb
|
|
13
|
+
FROM pictures p
|
|
14
|
+
JOIN sequences_pictures sp on sp.pic_id = p.id
|
|
15
|
+
GROUP BY sp.seq_id, p.account_id
|
|
16
|
+
ORDER BY sp.seq_id, nb DESC
|
|
17
|
+
) p;
|
|
18
|
+
|
|
19
|
+
-- Otherwise, use default account
|
|
20
|
+
UPDATE sequences
|
|
21
|
+
SET account_id = (SELECT id FROM accounts WHERE is_default)
|
|
22
|
+
WHERE account_id IS NULL;
|
|
23
|
+
|
|
24
|
+
-- After initial init, set NOT NULL constraint on account_id
|
|
25
|
+
ALTER TABLE sequences ALTER COLUMN account_id SET NOT NULL;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- status
|
|
2
|
+
-- depends: 20230116_01_9PkjZ-add-oauth-provider 20230130_01_VRIv2-sequences-account
|
|
3
|
+
|
|
4
|
+
UPDATE pictures SET status = 'preparing' WHERE status::text like 'preparing-' OR status = 'waiting-for-process';
|
|
5
|
+
-- Note: PG does not support removing enum values, so we need to rename and replace with another one
|
|
6
|
+
|
|
7
|
+
CREATE TYPE picture_status_new AS ENUM (
|
|
8
|
+
'preparing',
|
|
9
|
+
'broken',
|
|
10
|
+
'ready',
|
|
11
|
+
'hidden'
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
alter table pictures ALTER COLUMN status DROP DEFAULT;
|
|
16
|
+
alter table pictures ALTER COLUMN status TYPE picture_status_new USING status::text::picture_status_new;
|
|
17
|
+
alter table pictures ALTER COLUMN status SET DEFAULT 'preparing';
|
|
18
|
+
DROP TYPE picture_status;
|
|
19
|
+
ALTER TYPE picture_status_new RENAME TO picture_status;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
CREATE TYPE sequence_status_new AS ENUM (
|
|
23
|
+
'preparing',
|
|
24
|
+
'broken',
|
|
25
|
+
'ready',
|
|
26
|
+
'hidden'
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
alter table sequences ALTER COLUMN status DROP DEFAULT;
|
|
31
|
+
alter table sequences ALTER COLUMN status TYPE sequence_status_new USING status::text::sequence_status_new;
|
|
32
|
+
alter table sequences ALTER COLUMN status SET DEFAULT 'preparing';
|
|
33
|
+
|
|
34
|
+
DROP TYPE sequence_status;
|
|
35
|
+
ALTER TYPE sequence_status_new RENAME TO sequence_status;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- status
|
|
2
|
+
-- depends: 20230116_01_9PkjZ-add-oauth-provider 20230130_01_VRIv2-sequences-account
|
|
3
|
+
|
|
4
|
+
-- type cannot be altered in a transaction, so we ask yolo not to create one
|
|
5
|
+
-- transactional: false
|
|
6
|
+
|
|
7
|
+
ALTER TYPE picture_status ADD VALUE 'waiting-for-process';
|
|
8
|
+
ALTER TYPE picture_status ADD VALUE 'preparing-derivates';
|
|
9
|
+
ALTER TYPE picture_status ADD VALUE 'preparing-blur';
|
|
10
|
+
|
|
11
|
+
ALTER TYPE sequence_status ADD VALUE 'waiting-for-process';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- status
|
|
2
|
+
-- depends: 20230324_01_ba9WA-status
|
|
3
|
+
|
|
4
|
+
ALTER TABLE pictures
|
|
5
|
+
DROP COLUMN IF EXISTS inserted_at,
|
|
6
|
+
DROP COLUMN IF EXISTS processed_at,
|
|
7
|
+
DROP COLUMN IF EXISTS nb_errors,
|
|
8
|
+
DROP COLUMN IF EXISTS process_error
|
|
9
|
+
;
|
|
10
|
+
|
|
11
|
+
DROP TABLE pictures_to_process;
|
|
12
|
+
|
|
13
|
+
-- update default from 'waiting-for-process' to 'preparing'
|
|
14
|
+
UPDATE pictures SET status = 'preparing' WHERE status = 'waiting-for-process';
|
|
15
|
+
ALTER TABLE pictures ALTER COLUMN status SET DEFAULT 'preparing';
|
|
16
|
+
|
|
17
|
+
UPDATE sequences SET status = 'preparing' WHERE status = 'waiting-for-process';
|
|
18
|
+
ALTER TABLE sequences ALTER COLUMN status SET DEFAULT 'preparing';
|
|
19
|
+
|
|
20
|
+
DROP FUNCTION picture_insertion CASCADE;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
-- status
|
|
2
|
+
-- depends: 20230324_01_ba9WA-status
|
|
3
|
+
|
|
4
|
+
ALTER TABLE pictures
|
|
5
|
+
ADD COLUMN IF NOT EXISTS inserted_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
6
|
+
ADD COLUMN IF NOT EXISTS processed_at TIMESTAMPTZ,
|
|
7
|
+
ADD COLUMN IF NOT EXISTS nb_errors INT NOT NULL DEFAULT 0,
|
|
8
|
+
ADD COLUMN IF NOT EXISTS process_error VARCHAR
|
|
9
|
+
;
|
|
10
|
+
|
|
11
|
+
CREATE TABLE pictures_to_process(
|
|
12
|
+
picture_id UUID PRIMARY KEY,
|
|
13
|
+
ts TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
14
|
+
);
|
|
15
|
+
ALTER TABLE pictures_to_process ADD CONSTRAINT picture_id_fk FOREIGN KEY (picture_id) REFERENCES pictures (id);
|
|
16
|
+
|
|
17
|
+
CREATE INDEX pictures_to_process_ts_idx ON pictures_to_process(ts);
|
|
18
|
+
|
|
19
|
+
-- update default from 'preparing' to 'waiting-for-process'
|
|
20
|
+
UPDATE pictures SET status = 'waiting-for-process' WHERE status = 'preparing';
|
|
21
|
+
ALTER TABLE pictures ALTER COLUMN status SET DEFAULT 'waiting-for-process';
|
|
22
|
+
|
|
23
|
+
CREATE INDEX pictures_processed_at_idx ON pictures(inserted_at);
|
|
24
|
+
|
|
25
|
+
UPDATE sequences SET status = 'waiting-for-process' WHERE status = 'preparing';
|
|
26
|
+
ALTER TABLE sequences ALTER COLUMN status SET DEFAULT 'waiting-for-process';
|
|
27
|
+
|
|
28
|
+
-- Create Trigger to insert each new picture into pictures_to_process
|
|
29
|
+
CREATE OR REPLACE FUNCTION picture_insertion() RETURNS TRIGGER AS
|
|
30
|
+
$BODY$
|
|
31
|
+
BEGIN
|
|
32
|
+
INSERT INTO
|
|
33
|
+
pictures_to_process(picture_id)
|
|
34
|
+
VALUES
|
|
35
|
+
(new.id);
|
|
36
|
+
RETURN new;
|
|
37
|
+
END;
|
|
38
|
+
$BODY$
|
|
39
|
+
language plpgsql;
|
|
40
|
+
|
|
41
|
+
CREATE TRIGGER trigger_process_picture_insertion
|
|
42
|
+
AFTER INSERT ON pictures
|
|
43
|
+
FOR EACH ROW
|
|
44
|
+
EXECUTE PROCEDURE picture_insertion();
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
-- pictures_edits_triggers
|
|
2
|
+
-- depends: 20230420_01_elaN3-remove-picture-and-sequence-file-paths
|
|
3
|
+
|
|
4
|
+
-- Update sequences geometries on pictures edits
|
|
5
|
+
DROP FUNCTION IF EXISTS pictures_update_sequence CASCADE;
|
|
6
|
+
CREATE FUNCTION pictures_update_sequence() RETURNS trigger AS $$
|
|
7
|
+
BEGIN
|
|
8
|
+
UPDATE sequences
|
|
9
|
+
SET geom = s.geom
|
|
10
|
+
FROM (
|
|
11
|
+
SELECT seq_id, ST_MakeLine(array_agg(geom)) AS geom
|
|
12
|
+
FROM (
|
|
13
|
+
SELECT sp.seq_id, sp.rank, p.geom
|
|
14
|
+
FROM sequences_pictures sp
|
|
15
|
+
JOIN pictures p ON sp.pic_id = p.id
|
|
16
|
+
WHERE sp.seq_id IN (
|
|
17
|
+
SELECT DISTINCT sequences_pictures.seq_id
|
|
18
|
+
FROM old_table
|
|
19
|
+
JOIN new_table USING (id)
|
|
20
|
+
JOIN sequences_pictures ON sequences_pictures.pic_id = new_table.id
|
|
21
|
+
WHERE new_table.status != old_table.status OR NOT ST_Equals(old_table.geom, new_table.geom)
|
|
22
|
+
)
|
|
23
|
+
ORDER BY sp.seq_id, sp.rank
|
|
24
|
+
) sp
|
|
25
|
+
GROUP BY seq_id
|
|
26
|
+
) s
|
|
27
|
+
WHERE sequences.id = s.seq_id;
|
|
28
|
+
RETURN NULL;
|
|
29
|
+
END $$ LANGUAGE plpgsql;
|
|
30
|
+
|
|
31
|
+
CREATE TRIGGER pictures_update_sequences_trg
|
|
32
|
+
AFTER UPDATE ON pictures
|
|
33
|
+
REFERENCING OLD TABLE AS old_table NEW TABLE AS new_table
|
|
34
|
+
FOR EACH STATEMENT EXECUTE FUNCTION pictures_update_sequence();
|
|
35
|
+
|
|
36
|
+
-- Update sequences geometries on sequences_pictures deletions
|
|
37
|
+
DROP FUNCTION IF EXISTS sequences_pictures_delete CASCADE;
|
|
38
|
+
CREATE FUNCTION sequences_pictures_delete() RETURNS trigger AS $$
|
|
39
|
+
BEGIN
|
|
40
|
+
UPDATE sequences
|
|
41
|
+
SET geom = s.geom
|
|
42
|
+
FROM (
|
|
43
|
+
SELECT seq_id, ST_MakeLine(array_agg(geom)) AS geom
|
|
44
|
+
FROM (
|
|
45
|
+
SELECT sp.seq_id, sp.rank, p.geom
|
|
46
|
+
FROM sequences_pictures sp
|
|
47
|
+
JOIN pictures p ON sp.pic_id = p.id
|
|
48
|
+
WHERE sp.seq_id IN (
|
|
49
|
+
SELECT DISTINCT seq_id
|
|
50
|
+
FROM old_table
|
|
51
|
+
)
|
|
52
|
+
ORDER BY sp.seq_id, sp.rank
|
|
53
|
+
) sp
|
|
54
|
+
GROUP BY seq_id
|
|
55
|
+
) s
|
|
56
|
+
WHERE sequences.id = s.seq_id;
|
|
57
|
+
RETURN NULL;
|
|
58
|
+
END $$ LANGUAGE plpgsql;
|
|
59
|
+
|
|
60
|
+
CREATE TRIGGER sequences_pictures_delete_trg
|
|
61
|
+
AFTER DELETE ON sequences_pictures
|
|
62
|
+
REFERENCING OLD TABLE AS old_table
|
|
63
|
+
FOR EACH STATEMENT EXECUTE FUNCTION sequences_pictures_delete();
|
|
64
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- timestamps
|
|
2
|
+
-- depends: 20230425_01_gYP77-pictures-edits-triggers
|
|
3
|
+
|
|
4
|
+
-- Remove trigger & function
|
|
5
|
+
DROP FUNCTION IF EXISTS sequences_update_ts CASCADE;
|
|
6
|
+
|
|
7
|
+
-- Remove timestamps for sequences
|
|
8
|
+
ALTER TABLE sequences
|
|
9
|
+
DROP COLUMN inserted_at,
|
|
10
|
+
DROP COLUMN updated_at;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- timestamps
|
|
2
|
+
-- depends: 20230425_01_gYP77-pictures-edits-triggers
|
|
3
|
+
|
|
4
|
+
-- Creation and update timestamps for sequences
|
|
5
|
+
ALTER TABLE sequences
|
|
6
|
+
ADD COLUMN inserted_at TIMESTAMPTZ DEFAULT current_timestamp,
|
|
7
|
+
ADD COLUMN updated_at TIMESTAMPTZ;
|
|
8
|
+
|
|
9
|
+
-- Trigger for updating sequences last update TS
|
|
10
|
+
DROP FUNCTION IF EXISTS sequences_update_ts CASCADE;
|
|
11
|
+
CREATE FUNCTION sequences_update_ts() RETURNS trigger AS $$
|
|
12
|
+
BEGIN
|
|
13
|
+
NEW.updated_at = current_timestamp;
|
|
14
|
+
RETURN NEW;
|
|
15
|
+
END $$ LANGUAGE plpgsql;
|
|
16
|
+
|
|
17
|
+
CREATE TRIGGER sequences_update_ts_trg
|
|
18
|
+
BEFORE UPDATE ON sequences
|
|
19
|
+
FOR EACH ROW EXECUTE FUNCTION sequences_update_ts();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- tokens
|
|
2
|
+
-- depends: 20230427_01_k5e5w-timestamps
|
|
3
|
+
|
|
4
|
+
CREATE TABLE tokens(
|
|
5
|
+
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
6
|
+
account_id UUID,
|
|
7
|
+
description VARCHAR,
|
|
8
|
+
generated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
ALTER TABLE tokens ADD CONSTRAINT account_fk_id FOREIGN KEY (account_id) REFERENCES accounts (id);
|
|
12
|
+
|
|
13
|
+
-- generate a default token for each existing account
|
|
14
|
+
INSERT INTO tokens (account_id, description)
|
|
15
|
+
SELECT id, 'default token' from accounts;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
-- Also add trigger to generate default token for each new account
|
|
19
|
+
DROP FUNCTION IF EXISTS generate_default_token CASCADE;
|
|
20
|
+
CREATE FUNCTION generate_default_token() RETURNS trigger AS
|
|
21
|
+
$BODY$
|
|
22
|
+
BEGIN
|
|
23
|
+
INSERT INTO
|
|
24
|
+
tokens (account_id, description)
|
|
25
|
+
VALUES
|
|
26
|
+
(NEW.id, 'default token');
|
|
27
|
+
RETURN NEW;
|
|
28
|
+
END;
|
|
29
|
+
$BODY$
|
|
30
|
+
language plpgsql;
|
|
31
|
+
|
|
32
|
+
CREATE TRIGGER generate_default_token_trg
|
|
33
|
+
AFTER INSERT ON accounts
|
|
34
|
+
FOR EACH ROW EXECUTE PROCEDURE generate_default_token();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- pic_delete_cascade
|
|
2
|
+
-- depends: 20230511_01_TdpKo-tokens
|
|
3
|
+
|
|
4
|
+
ALTER TABLE sequences_pictures
|
|
5
|
+
DROP CONSTRAINT sequences_pictures_pic_id_fkey ,
|
|
6
|
+
ADD CONSTRAINT sequences_pictures_pic_id_fkey FOREIGN KEY (pic_id) REFERENCES pictures(id);
|
|
7
|
+
|
|
8
|
+
ALTER TABLE pictures_to_process
|
|
9
|
+
DROP CONSTRAINT picture_id_fk ,
|
|
10
|
+
ADD CONSTRAINT picture_id_fk FOREIGN KEY (picture_id) REFERENCES pictures(id);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- pic_delete_cascade
|
|
2
|
+
-- depends: 20230511_01_TdpKo-tokens
|
|
3
|
+
|
|
4
|
+
-- Add on delete cascade to pic deletion
|
|
5
|
+
|
|
6
|
+
ALTER TABLE sequences_pictures
|
|
7
|
+
DROP CONSTRAINT sequences_pictures_pic_id_fkey ,
|
|
8
|
+
ADD CONSTRAINT sequences_pictures_pic_id_fkey FOREIGN KEY (pic_id) REFERENCES pictures(id) ON DELETE CASCADE;
|
|
9
|
+
|
|
10
|
+
ALTER TABLE pictures_to_process
|
|
11
|
+
DROP CONSTRAINT picture_id_fk ,
|
|
12
|
+
ADD CONSTRAINT picture_id_fk FOREIGN KEY (picture_id) REFERENCES pictures(id) ON DELETE CASCADE;
|