Skip to content

Commit

Permalink
Feat: workshop drop t_exportlogs (#135)
Browse files Browse the repository at this point in the history
* Suppression de t_exports_logs
  • Loading branch information
amandine-sahl authored Jun 2, 2023
1 parent 192b7d0 commit d79d79e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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;
"""
)
26 changes: 0 additions & 26 deletions backend/gn_module_export/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion backend/gn_module_export/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit d79d79e

Please sign in to comment.