diff --git a/backend/gn_module_export/migrations/bcee745e5647_drop_table_texportslog.py b/backend/gn_module_export/migrations/bcee745e5647_drop_table_texportslog.py new file mode 100644 index 0000000..06a679c --- /dev/null +++ b/backend/gn_module_export/migrations/bcee745e5647_drop_table_texportslog.py @@ -0,0 +1,68 @@ +"""drop table gn_exports.t_exports_logs + +Revision ID: bcee745e5647 +Revises: c2d02e345a06 +Create Date: 2023-05-10 10:43:45.661554 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "bcee745e5647" +down_revision = "fe1347f4805f" +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute( + """ + DROP VIEW gn_exports.v_exports_logs; + DROP TABLE gn_exports.t_exports_logs; + """ + ) + + +def downgrade(): + op.execute( + """ + CREATE TABLE gn_exports.t_exports_logs + ( + id SERIAL NOT NULL PRIMARY KEY, + id_role integer NOT NULL, + id_export integer, + format character varying(10) NOT NULL, + start_time TIMESTAMP NOT NULL, + end_time TIMESTAMP, + status numeric DEFAULT '-2'::integer, + log text, + CONSTRAINT fk_export FOREIGN KEY (id_export) + REFERENCES gn_exports.t_exports (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION, + CONSTRAINT fk_user FOREIGN KEY (id_role) + REFERENCES utilisateurs.t_roles (id_role) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + ); + + COMMENT ON TABLE gn_exports.t_exports_logs IS 'This table is used to log all the realised exports.'; + COMMENT ON COLUMN gn_exports.t_exports_logs.id_role IS 'Role who realize export'; + COMMENT ON COLUMN gn_exports.t_exports_logs.id_export IS 'Export type'; + COMMENT ON COLUMN gn_exports.t_exports_logs.format IS 'The exported format (csv, json, shp, geojson)'; + COMMENT ON COLUMN gn_exports.t_exports_logs.start_time IS 'When the export process start'; + COMMENT ON COLUMN gn_exports.t_exports_logs.end_time IS 'When the export process finish'; + COMMENT ON COLUMN gn_exports.t_exports_logs.status IS 'Status of the process : 1 ok: -2 error'; + COMMENT ON COLUMN gn_exports.t_exports_logs.log IS 'Holds export failure message'; + + -- View to list Exports LOGS with users names and exports labels + CREATE VIEW gn_exports.v_exports_logs AS + SELECT r.nom_role ||' '||r.prenom_role AS utilisateur, e.label, l.format, l.start_time, l.end_time, l.status, l.log + FROM gn_exports.t_exports_logs l + JOIN utilisateurs.t_roles r ON r.id_role = l.id_role + JOIN gn_exports.t_exports e ON e.id = l.id_export + ORDER BY start_time; + """ + ) diff --git a/backend/gn_module_export/models.py b/backend/gn_module_export/models.py index 16535de..fde89fa 100644 --- a/backend/gn_module_export/models.py +++ b/backend/gn_module_export/models.py @@ -153,32 +153,6 @@ def get_view_query(self, limit, offset, filters=None): ) -@serializable -class ExportLog(DB.Model): - __tablename__ = "t_exports_logs" - __table_args__ = {"schema": "gn_exports"} - id = DB.Column(DB.Integer, primary_key=True, nullable=False) # noqa: A003 - id_role = DB.Column(DB.Integer, DB.ForeignKey(User.id_role)) - role = DB.relationship("User", foreign_keys=[id_role], lazy="joined") - id_export = DB.Column(DB.Integer(), DB.ForeignKey(Export.id)) - export = DB.relationship("Export", lazy="joined") - format = DB.Column(DB.String(10), nullable=False) # noqa: A003 - start_time = DB.Column(DB.DateTime, nullable=False) - end_time = DB.Column(DB.DateTime) - status = DB.Column(DB.Integer, default=-2) - log = DB.Column(DB.Text) - - @classmethod - def record(cls, adict): - try: - exportLog = cls() - exportLog.from_dict(adict) - DB.session.add(exportLog) - DB.session.commit() - except Exception as e: - DB.session.rollback() - - class ExportSchedules(DB.Model): __tablename__ = "t_export_schedules" __table_args__ = {"schema": "gn_exports"} diff --git a/backend/gn_module_export/repositories.py b/backend/gn_module_export/repositories.py index acabe24..521bb18 100644 --- a/backend/gn_module_export/repositories.py +++ b/backend/gn_module_export/repositories.py @@ -7,7 +7,7 @@ from utils_flask_sqla_geo.generic import GenericTableGeo -from .models import Export, ExportLog, ExportSchedules +from .models import Export, ExportSchedules SWAGGER_TYPE_COR = {