diff --git a/.gitignore b/.gitignore index 6e283cf..f2e6c3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ /venv/ /instance/ +/.idea/inspectionProfiles/profiles_settings.xml +/.idea/inspectionProfiles/Project_Default.xml +/.idea/.gitignore +/.idea/misc.xml +/.idea/modules.xml +/.idea/rifalto.iml +/.idea/vcs.xml diff --git a/migrations/versions/78f324ae4f45_add_timestamps.py b/migrations/versions/78f324ae4f45_add_timestamps.py new file mode 100644 index 0000000..d4af459 --- /dev/null +++ b/migrations/versions/78f324ae4f45_add_timestamps.py @@ -0,0 +1,38 @@ +"""add timestamps + +Revision ID: 78f324ae4f45 +Revises: 45281a94fd78 +Create Date: 2023-06-14 17:54:40.318023 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '78f324ae4f45' +down_revision = '45281a94fd78' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('purchases', schema=None) as batch_op: + batch_op.add_column(sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True)) + + with op.batch_alter_table('tickets', schema=None) as batch_op: + batch_op.add_column(sa.Column('timestamp', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('tickets', schema=None) as batch_op: + batch_op.drop_column('timestamp') + + with op.batch_alter_table('purchases', schema=None) as batch_op: + batch_op.drop_column('timestamp') + + # ### end Alembic commands ### diff --git a/rifaserver/app.py b/rifaserver/app.py index e3a1f66..8d43ed3 100644 --- a/rifaserver/app.py +++ b/rifaserver/app.py @@ -189,7 +189,7 @@ def numbers_screen(purchase_id): @login_required def seller_purchases(): seller_id = current_user.id - purchases = Purchase.query.filter_by(seller_id=seller_id).order_by(Purchase.id.desc()).all() + purchases = Purchase.query.filter_by(seller_id=seller_id).order_by(Purchase.timestamp.desc(), Purchase.id.desc()) return render_template('seller_purchases.html', purchases=purchases) @@ -253,10 +253,3 @@ def change_password(usuario, nova_senha): db.session.commit() click.echo(f"Senha para {usuario} foi atualizada.") - - -@app.cli.command('apply_migrations') -@with_appcontext -def apply_migrations_command(): - """Apply database migrations.""" - upgrade() diff --git a/rifaserver/models.py b/rifaserver/models.py index 26a6052..c6c7c72 100644 --- a/rifaserver/models.py +++ b/rifaserver/models.py @@ -2,7 +2,7 @@ from flask_login import UserMixin from flask_sqlalchemy import SQLAlchemy from sqlalchemy.orm import relationship from werkzeug.security import generate_password_hash, check_password_hash -from sqlalchemy import UniqueConstraint +from sqlalchemy import UniqueConstraint, func import hashlib import os @@ -31,7 +31,7 @@ class Purchase(db.Model): total_numbers = db.Column(db.Integer, default=0) numbers_left = db.Column(db.Integer, default=0) remarks = db.Column(db.Text) -# timestamp = db.Column(db.DateTime) + timestamp = db.Column(db.DateTime, server_default=func.now()) def generate_id(self): self.id = hashlib.sha256(os.urandom(60)).hexdigest() @@ -59,6 +59,7 @@ class Ticket(db.Model): buyer_name = db.Column(db.String(64)) buyer_contact = db.Column(db.String(64)) chosen_number = db.Column(db.Integer) + timestamp = db.Column(db.DateTime, server_default=func.now()) raffle = relationship(Raffle) diff --git a/start.sh b/start.sh index a209bc2..261277e 100644 --- a/start.sh +++ b/start.sh @@ -1,4 +1,5 @@ #!/bin/bash export PYTHONUNBUFFERED=1 +flask --app $FLASK_APP db upgrade exec gunicorn -b $GUNICORN_BIND --access-logfile - --error-logfile - $FLASK_APP:app # exec /bin/bash