-
Notifications
You must be signed in to change notification settings - Fork 31
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
Suppression de la suppression logique des médias #538
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
apptax/migrations/versions/44447746cacc_drop_t_medias_supprime_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""drop t_medias.supprime column | ||
|
||
Revision ID: 44447746cacc | ||
Revises: 0db13d65cb27 | ||
Create Date: 2023-08-04 14:04:28.235799 | ||
|
||
""" | ||
|
||
import os | ||
import shutil | ||
from pathlib import Path | ||
from flask import current_app | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.sql import false | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "44447746cacc" | ||
down_revision = "0db13d65cb27" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# Suppression des fichiers médias | ||
conn = op.get_bind() | ||
res = conn.execute( | ||
"""SELECT id_media, chemin | ||
FROM taxonomie.t_medias | ||
WHERE NOT NULLIF(chemin , '') IS NULL AND supprime = TRUE;""" | ||
) | ||
|
||
media_path = Path(current_app.config["MEDIA_FOLDER"], "taxhub").absolute() | ||
|
||
for m in res: | ||
# Fichier principal | ||
try: | ||
os.remove(media_path / Path(m[1])) | ||
except FileNotFoundError: | ||
pass | ||
# Thumbnail | ||
try: | ||
shutil.rmtree(f"{media_path}/thumb/{m[0]}") | ||
except FileNotFoundError: | ||
pass | ||
|
||
# Suppression des enregistrements médias supprimés logiquement | ||
op.execute("DELETE FROM taxonomie.t_medias AS tm WHERE supprime = TRUE;") | ||
op.drop_column(table_name="t_medias", column_name="supprime", schema="taxonomie") | ||
|
||
|
||
def downgrade(): | ||
op.add_column( | ||
table_name="t_medias", | ||
column=sa.Column("supprime", sa.Boolean, nullable=False, server_default=false()), | ||
schema="taxonomie", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
si les gens passe la migration avant d'avoir changer le paramètre
UPLOAD_FOLDER
enMEDIA_FOLDER
ça va pas marcher ?Et le
/taxhub
ne marche pas dans le contexte de taxhub standalone ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que c'est bon
Pour MEDIA_FOLDER c'est géré par défaut avec le schema toml.
Pour /taxhub même dans standalone le chemin est MEDIA_FOLDER/taxhub