Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add meta_{create,update}_date fields to bib_organismes #99

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
*********


unreleased (2024-05-xx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unreleased (2024-05-xx)
3.0.2 (unreleased)

------------------

**🚀 Nouveautés**

- Ajout des champs `meta_create_date` et `meta_update_date` à la table `bib_organismes` (#96).


3.0.1 (2024-11-29)
------------------

Expand Down Expand Up @@ -35,13 +44,13 @@ auth_manager.init_app(app,providers_declaration=providers_config)
```



2.1.5 (2024-05-23)
------------------

**🚀 Nouveautés**

- Mise à jour de dépendances critiques : `requests`, `jinja2`, `werkzeug` (#102)
- Ajout des champs `meta_create_date` et `meta_update_date` à la table `bib_organismes` (#96).

2.1.4 (2024-04-23)
------------------
Expand Down
2 changes: 2 additions & 0 deletions src/pypnusershub/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ class Organisme(db.Model):
db.Integer, db.ForeignKey("utilisateurs.bib_organismes.id_organisme")
)
additional_data = db.Column(JSONB, nullable=True, server_default="{}")
meta_create_date = db.Column(db.DateTime)
meta_update_date = db.Column(db.DateTime)
members = db.relationship(User, backref="organisme")

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""Add meta create/insert date to biborganismes

Revision ID: cf38131bc247
Revises: f9d3b95946cd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Revises: f9d3b95946cd
Revises: b7c98935d9e8

Create Date: 2024-05-20 10:45:25.067157

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "cf38131bc247"
down_revision = "f9d3b95946cd"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
down_revision = "f9d3b95946cd"
down_revision = "b7c98935d9e8"

branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"bib_organismes",
sa.Column("meta_create_date", sa.TIMESTAMP, server_default=sa.func.now()),
schema="utilisateurs",
)
op.add_column(
"bib_organismes",
sa.Column("meta_update_date", sa.TIMESTAMP, server_default=sa.func.now()),
schema="utilisateurs",
)
op.execute(
"""
CREATE FUNCTION utilisateurs.fct_trg_meta_dates_change() RETURNS trigger
LANGUAGE plpgsql
AS
$$
begin
if(TG_OP = 'INSERT') THEN
NEW.meta_create_date = NOW();
ELSIF(TG_OP = 'UPDATE') THEN
NEW.meta_update_date = NOW();
if(NEW.meta_create_date IS NULL) THEN
NEW.meta_create_date = NOW();
END IF;
end IF;
return NEW;
end;
$$;

CREATE TRIGGER tri_meta_dates_change_organisms
BEFORE INSERT OR UPDATE
ON utilisateurs.bib_organismes
FOR EACH ROW
EXECUTE PROCEDURE utilisateurs.fct_trg_meta_dates_change();
"""
)


def downgrade():
op.drop_column(
table_name="bib_organismes",
column_name="meta_create_date",
schema="utilisateurs",
)
op.drop_column(
table_name="bib_organismes",
column_name="meta_update_date",
schema="utilisateurs",
)
op.execute(
"""
DROP TRIGGER tri_meta_dates_change_organisms ON utilisateurs.bib_organismes;
DROP FUNCTION utilisateurs.fct_trg_meta_dates_change();
"""
)
Loading