-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Diego Caspi <[email protected]>
- Loading branch information
1 parent
8e12938
commit 94455b8
Showing
11 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
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
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
63 changes: 63 additions & 0 deletions
63
migrations/versions/f2bde8be828c_product_history_locked_stock.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,63 @@ | ||
"""product history locked stock | ||
Revision ID: f2bde8be828c | ||
Revises: c9ce5d5552a5 | ||
Create Date: 2024-06-23 09:48:43.589979 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f2bde8be828c' | ||
down_revision = 'c9ce5d5552a5' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
create_trigger_fun = """ | ||
CREATE OR REPLACE FUNCTION update_product_history() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
INSERT INTO product_history(product_id, sequence, price, currency, stock, locked_stock, deleted_at) | ||
VALUES (NEW.id, NEW.current_sequence, NEW.current_price, NEW.current_currency, NEW.current_stock, NEW.current_locked_stock, NEW.deleted_at); | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
""" | ||
|
||
create_trigger = """ | ||
CREATE OR REPLACE TRIGGER after_update_product_history | ||
AFTER INSERT OR UPDATE OF current_price, current_currency, current_stock, current_locked_stock, deleted_at ON products | ||
FOR EACH ROW EXECUTE FUNCTION update_product_history(); | ||
""" | ||
|
||
drop_trigger = """ | ||
DROP TRIGGER after_update_product_history ON products; | ||
""" | ||
|
||
drop_trigger_fun = """ | ||
DROP FUNCTION update_product_history; | ||
""" | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('product_history', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('locked_stock', sa.Integer(), nullable=False)) | ||
|
||
op.execute(create_trigger_fun) | ||
op.execute(create_trigger) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('product_history', schema=None) as batch_op: | ||
batch_op.drop_column('locked_stock') | ||
|
||
op.execute(drop_trigger) | ||
op.execute(drop_trigger_fun) | ||
# ### end Alembic commands ### |