From 0b60c5716ecef878bbed7678086afdfd9ad1d31a Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 5 Aug 2019 18:58:02 +0100 Subject: [PATCH] Separate cover items and stamps into their own models --- houdini.sql | 30 ++++++++++++++++++++++++------ houdini/data/stamp.py | 15 +++++++++++++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/houdini.sql b/houdini.sql index ed27b8d..bdd9368 100644 --- a/houdini.sql +++ b/houdini.sql @@ -746,28 +746,46 @@ DROP TABLE IF EXISTS cover_stamp; CREATE TABLE cover_stamp ( penguin_id INT NOT NULL, stamp_id INT NOT NULL, - item_id INT NOT NULL, x SMALLINT NOT NULL DEFAULT 0, y SMALLINT NOT NULL DEFAULT 0, - type SMALLINT NOT NULL DEFAULT 0, rotation SMALLINT NOT NULL DEFAULT 0, depth SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (penguin_id, stamp_id), CONSTRAINT cover_stamp_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT cover_stamp_ibfk_2 FOREIGN KEY (stamp_id) REFERENCES stamp (id) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT cover_stamp_ibfk_3 FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT cover_stamp_ibfk_2 FOREIGN KEY (stamp_id) REFERENCES stamp (id) ON DELETE CASCADE ON UPDATE CASCADE ); COMMENT ON TABLE cover_stamp IS 'Stamps placed on book cover'; COMMENT ON COLUMN cover_stamp.penguin_id IS 'Unique penguin ID'; -COMMENT ON COLUMN cover_stamp.stamp_id IS 'Cover stamp or item ID'; +COMMENT ON COLUMN cover_stamp.stamp_id IS 'Cover stamp ID'; COMMENT ON COLUMN cover_stamp.x IS 'Cover X position'; COMMENT ON COLUMN cover_stamp.y IS 'Cover Y position'; -COMMENT ON COLUMN cover_stamp.type IS 'Cover item type'; COMMENT ON COLUMN cover_stamp.rotation IS 'Stamp cover rotation'; COMMENT ON COLUMN cover_stamp.depth IS 'Stamp cover depth'; +DROP TABLE IF EXISTS cover_item; +CREATE TABLE cover_item ( + penguin_id INT NOT NULL, + item_id INT NOT NULL, + x SMALLINT NOT NULL DEFAULT 0, + y SMALLINT NOT NULL DEFAULT 0, + rotation SMALLINT NOT NULL DEFAULT 0, + depth SMALLINT NOT NULL DEFAULT 0, + PRIMARY KEY (penguin_id, item_id), + CONSTRAINT cover_item_ibfk_1 FOREIGN KEY (penguin_id) REFERENCES penguin (id) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT cover_item_ibfk_2 FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE ON UPDATE CASCADE +); + +COMMENT ON TABLE cover_item IS 'Items placed on book cover'; + +COMMENT ON COLUMN cover_item.penguin_id IS 'Unique penguin ID'; +COMMENT ON COLUMN cover_item.item_id IS 'Cover item ID'; +COMMENT ON COLUMN cover_item.x IS 'Cover X position'; +COMMENT ON COLUMN cover_item.y IS 'Cover Y position'; +COMMENT ON COLUMN cover_item.rotation IS 'Stamp cover rotation'; +COMMENT ON COLUMN cover_item.depth IS 'Stamp cover depth'; + DROP TABLE IF EXISTS penguin_card; CREATE TABLE penguin_card ( penguin_id INT NOT NULL, diff --git a/houdini/data/stamp.py b/houdini/data/stamp.py index b90661a..b2dba05 100644 --- a/houdini/data/stamp.py +++ b/houdini/data/stamp.py @@ -27,10 +27,21 @@ class CoverStamp(db.Model): nullable=False) stamp_id = db.Column(db.ForeignKey('stamp.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, nullable=False) - item_id = db.Column(db.ForeignKey('item.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False) x = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) y = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) - type = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + rotation = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + depth = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + + +class CoverItem(db.Model): + __tablename__ = 'cover_item' + + penguin_id = db.Column(db.ForeignKey('penguin.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, + nullable=False) + item_id = db.Column(db.ForeignKey('item.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, + nullable=False) + x = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) + y = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) rotation = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) depth = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0"))