From 80b7b98ec8df49ef5da660d3fe69a10e455d686e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Jun 2021 12:58:10 +0200 Subject: [PATCH] adding trade documents to migration file --- .../51439cf24be8_change_trade_action.py | 80 ++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py b/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py index 5bf3ef54..4f8c87f0 100644 --- a/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py +++ b/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py @@ -83,7 +83,7 @@ def upgrade(): schema=f'{get_inv()}' ) - # ## User + ## User op.add_column('user', sa.Column('active', sa.Boolean(), default=True, nullable=True), schema='common') op.add_column('user', sa.Column('phantom', sa.Boolean(), default=False, nullable=True), @@ -95,9 +95,87 @@ def upgrade(): op.alter_column('user', 'phantom', nullable=False, schema='common') + ## TradeDocument + op.create_table('trade_document', + sa.Column( + 'updated', + sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment='The last time Devicehub recorded a change for \n this thing.\n ' + ), + sa.Column( + 'created', + sa.TIMESTAMP(timezone=True), + server_default=sa.text('CURRENT_TIMESTAMP'), + nullable=False, + comment='When Devicehub created this.' + ), + sa.Column( + 'id', + sa.BigInteger(), + nullable=False, + comment='The identifier of the device for this database. Used only\n internally for software; users should not use this.\n ' + ), + sa.Column( + 'date', + sa.DateTime(), + nullable=True, + comment='The date of document, some documents need to have one date\n ' + ), + sa.Column( + 'id_document', + citext.CIText(), + nullable=True, + comment='The id of one document like invoice so they can be linked.' + ), + sa.Column( + 'description', + citext.CIText(), + nullable=True, + comment='A description of document.' + ), + sa.Column( + 'owner_id', + postgresql.UUID(as_uuid=True), + nullable=False + ), + sa.Column( + 'lot_id', + postgresql.UUID(as_uuid=True), + nullable=False + ), + sa.Column( + 'file_name', + citext.CIText(), + nullable=True, + comment='This is the name of the file when user up the document.' + ), + sa.Column( + 'file_hash', + citext.CIText(), + nullable=True, + comment='This is the hash of the file produced from frontend.' + ), + sa.Column( + 'url', + citext.CIText(), + nullable=True, + comment='This is the url where resides the document.' + ), + sa.ForeignKeyConstraint(['lot_id'], ['lot.id'],), + sa.ForeignKeyConstraint(['owner_id'], ['common.user.id'],), + sa.PrimaryKeyConstraint('id') + ) + op.create_index('document_id', 'trade_document', ['id'], unique=False, postgresql_using='hash') + op.create_index(op.f('ix_trade_document_created'), 'trade_document', ['created'], unique=False) + op.create_index(op.f('ix_trade_document_updated'), 'trade_document', ['updated'], unique=False) + + def downgrade(): op.drop_table('confirm', schema=f'{get_inv()}') op.drop_table('trade', schema=f'{get_inv()}') + op.drop_table('trade', schema=f'{get_inv()}') op.create_table('trade', sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True, comment='When are the devices going to be ready \n \