From 6fabb98d18f46887911f4b5531980194d810bbb9 Mon Sep 17 00:00:00 2001
From: Gusev Anton <gusev_aa@groupbwt.com>
Date: Mon, 17 Jun 2019 14:59:48 +0300
Subject: [PATCH] Change book model, add index, nullable attribute

---
 src/database/models/Book.py                      |  8 ++++----
 ...ble.py => 08bb7bfd9fd6_create_books_table.py} | 16 ++++++----------
 2 files changed, 10 insertions(+), 14 deletions(-)
 rename src/database/versions/{e19a8f6d44a2_create_books_table.py => 08bb7bfd9fd6_create_books_table.py} (81%)

diff --git a/src/database/models/Book.py b/src/database/models/Book.py
index db587ee..91de2c2 100644
--- a/src/database/models/Book.py
+++ b/src/database/models/Book.py
@@ -9,7 +9,7 @@ Base = declarative_base()
 class Book(Base, Model):
     __tablename__ = 'books'
     id = Column(Integer, primary_key=True)
-    url = Column(String(255))
+    url = Column(String(255), index=True, nullable=False)
 
     title = Column(String(255), nullable=False, index=True)
     description = Column(Text)
@@ -18,9 +18,9 @@ class Book(Base, Model):
 
     upc = Column(String(32), unique=True)
     product_type = Column(String(32), index=True)
-    price_excl_tax = Column(Numeric(6, 2), index=True)
-    price_incl_tax = Column(Numeric(6, 2), index=True)
-    tax = Column(Numeric(6, 2), index=True)
+    price_excl_tax = Column(Numeric(6, 2))
+    price_incl_tax = Column(Numeric(6, 2))
+    tax = Column(Numeric(6, 2))
     in_stock = Column(Integer, index=True)
     count_reviews = Column(Integer, index=True)
 
diff --git a/src/database/versions/e19a8f6d44a2_create_books_table.py b/src/database/versions/08bb7bfd9fd6_create_books_table.py
similarity index 81%
rename from src/database/versions/e19a8f6d44a2_create_books_table.py
rename to src/database/versions/08bb7bfd9fd6_create_books_table.py
index 9e02b82..950079e 100644
--- a/src/database/versions/e19a8f6d44a2_create_books_table.py
+++ b/src/database/versions/08bb7bfd9fd6_create_books_table.py
@@ -1,8 +1,8 @@
 """create books table
 
-Revision ID: e19a8f6d44a2
+Revision ID: 08bb7bfd9fd6
 Revises: 
-Create Date: 2019-06-17 13:21:39.815414
+Create Date: 2019-06-17 14:24:34.157665
 
 """
 from alembic import op
@@ -10,7 +10,7 @@ import sqlalchemy as sa
 
 
 # revision identifiers, used by Alembic.
-revision = 'e19a8f6d44a2'
+revision = '08bb7bfd9fd6'
 down_revision = None
 branch_labels = None
 depends_on = None
@@ -20,7 +20,7 @@ def upgrade():
     # ### commands auto generated by Alembic - please adjust! ###
     op.create_table('books',
     sa.Column('id', sa.Integer(), nullable=False),
-    sa.Column('url', sa.String(length=255), nullable=True),
+    sa.Column('url', sa.String(length=255), nullable=False),
     sa.Column('title', sa.String(length=255), nullable=False),
     sa.Column('description', sa.Text(), nullable=True),
     sa.Column('image_path', sa.String(length=255), nullable=True),
@@ -43,23 +43,19 @@ def upgrade():
     op.create_index(op.f('ix_books_count_reviews'), 'books', ['count_reviews'], unique=False)
     op.create_index(op.f('ix_books_currency_type'), 'books', ['currency_type'], unique=False)
     op.create_index(op.f('ix_books_in_stock'), 'books', ['in_stock'], unique=False)
-    op.create_index(op.f('ix_books_price_excl_tax'), 'books', ['price_excl_tax'], unique=False)
-    op.create_index(op.f('ix_books_price_incl_tax'), 'books', ['price_incl_tax'], unique=False)
     op.create_index(op.f('ix_books_product_type'), 'books', ['product_type'], unique=False)
     op.create_index(op.f('ix_books_rating'), 'books', ['rating'], unique=False)
-    op.create_index(op.f('ix_books_tax'), 'books', ['tax'], unique=False)
     op.create_index(op.f('ix_books_title'), 'books', ['title'], unique=False)
+    op.create_index(op.f('ix_books_url'), 'books', ['url'], unique=False)
     # ### end Alembic commands ###
 
 
 def downgrade():
     # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_index(op.f('ix_books_url'), table_name='books')
     op.drop_index(op.f('ix_books_title'), table_name='books')
-    op.drop_index(op.f('ix_books_tax'), table_name='books')
     op.drop_index(op.f('ix_books_rating'), table_name='books')
     op.drop_index(op.f('ix_books_product_type'), table_name='books')
-    op.drop_index(op.f('ix_books_price_incl_tax'), table_name='books')
-    op.drop_index(op.f('ix_books_price_excl_tax'), table_name='books')
     op.drop_index(op.f('ix_books_in_stock'), table_name='books')
     op.drop_index(op.f('ix_books_currency_type'), table_name='books')
     op.drop_index(op.f('ix_books_count_reviews'), table_name='books')
-- 
GitLab