Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feat/id source #242

Merged
merged 6 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions backend/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TImports(ModelCruvedAutorization):
__table_args__ = {"schema": "gn_imports", "extend_existing": True}

id_import = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
id_source_synthese = DB.Column(DB.Integer, ForeignKey("gn_synthese.t_sources.id_source"), nullable=True)
format_source_file = DB.Column(DB.Unicode, nullable=True)
srid = DB.Column(DB.Integer, nullable=True)
separator = DB.Column(DB.Unicode, nullable=True)
Expand Down Expand Up @@ -94,16 +95,7 @@ def to_dict(self, user=None, user_cruved=None):
import_as_dict["dataset_name"] = import_as_dict["dataset"]["dataset_name"]
import_as_dict.pop("dataset")
import_as_dict["errors"] = import_as_dict.get("errors", [])
name_source = "Import(id=" + str(self.id_import) + ")"
id_source = None
source = (
DB.session.query(TSources.id_source)
.filter(TSources.name_source == name_source)
.first()
)
if source:
id_source = source[0]
import_as_dict["id_source"] = id_source
import_as_dict["id_source"] = self.id_source_synthese
return import_as_dict


Expand Down
6 changes: 5 additions & 1 deletion backend/routes/download_to_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from ..db.models import TImports, TMappings

from ..db.queries.save_mapping import get_selected_columns
from ..db.queries.load_to_synthese import insert_into_t_sources, check_id_source
from ..db.queries.load_to_synthese import (insert_into_t_sources,
check_id_source,
get_id_source)
from ..db.queries.user_table_queries import (
set_imports_table_name,
get_table_name,
Expand Down Expand Up @@ -182,6 +184,8 @@ def finalize_import(id_import, table_name, total_columns):
import_obj.is_finished = True
import_obj.processing = False
import_obj.in_error = False
# Get id_source from t_sources table
import_obj.id_source_synthese = get_id_source(id_import)

logger.info("-> t_imports updated on final step")

Expand Down
3 changes: 3 additions & 0 deletions data/import_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ ALTER TABLE ONLY cor_role_import
ALTER TABLE ONLY cor_role_import
ADD CONSTRAINT fk_cor_role_import_import FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE ON DELETE CASCADE;

ALTER table gn_imports.t_imports add column id_source_synthese int4 default null;
ALTER TABLE only gn_imports.t_imports
ADD CONSTRAINT fk_gn_imports_t_import_id_source_synthese FOREIGN KEY (id_source_synthese) REFERENCES gn_synthese.t_sources(id_source) ON UPDATE SET NULL ON DELETE CASCADE;
---------------------
--OTHER CONSTRAINTS--
---------------------
Expand Down
10 changes: 10 additions & 0 deletions data/migration/1.1.2toDev.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-----------------------
-- Add id_source column
-----------------------
ALTER TABLE only gn_imports.t_imports
ADD CONSTRAINT fk_gn_imports_t_import_id_source_synthese FOREIGN KEY (id_source_synthese) REFERENCES gn_synthese.t_sources(id_source) ON UPDATE CASCADE ON DELETE CASCADE;
-- Populate id_source column
UPDATE gn_imports.t_imports
SET id_source_synthese = s.id_source
FROM gn_synthese.t_sources s
WHERE s.name_source='Import(id='||id_import||')'