Subversion Repositories SmartDukaan

Rev

Rev 7987 | Rev 9300 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 28-Apr-2010

@author: ashish
'''

from elixir import *
from elixir.entity import Entity
from elixir.fields import Field
from sqlalchemy import create_engine
from sqlalchemy.types import Integer
from elixir.relationships import OneToMany, ManyToOne
import datetime
import elixir

class Address(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    line_1 = Field(String(100))
    line_2 = Field(String(100))
    landmark = Field(String(100))
    city = Field(String(100))
    state = Field(String(100))
    pin = Field(String(10))
    country = Field(String(100))
    enabled = Field(Boolean)
    type = Field(Integer)
    added_on = Field(DateTime)
    name = Field(String(100))
    phone = Field(String(20))
    user = ManyToOne("User")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
        
class User(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    email = Field(String(100))
    password = Field(String(50))
    name = Field(String(150))
    default_address_id = Field(Integer)
    communication_email = Field(String(100))
    active_cart = ManyToOne("Cart")
    jsession_id = Field(String(64))
    is_anonymous = Field(Boolean)
    date_of_birth = Field(String(20))
    sex = Field(Integer)
    mobile_number = Field(String(20))
    source = Field(String(200))
    source_start_time = Field(DateTime)
    trust_level = Field(Float)
    last_login = Field(DateTime)
    last_logout = Field(DateTime)
    active_since = Field(DateTime)
    fbusers = OneToMany("FacebookUser")
    addresses = OneToMany("Address")
    sources = OneToMany("UserSource")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class FacebookUser(Entity):
    user = ManyToOne("User", primary_key=True)
    facebook_access_token = Field(String(200))
    facebook_id = Field(String(50))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class UserSource(Entity):
    user = ManyToOne("User", primary_key=True)
    source_id = Field(Integer)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Line(Entity):
    cart = ManyToOne("Cart", primary_key=True)
    item_id = Field(Integer, primary_key=True, autoincrement=False)
    quantity = Field(Float)
    line_status = Field(Integer)
    estimate = Field(Integer)
    created_on = Field(DateTime)
    updated_on = Field(DateTime)
    actual_price = Field(Float)
    discounted_price = Field(Float)
    discounts = OneToMany('Discount')
    insurer = Field(Integer)
    insuranceAmount = Field(Float)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
class Cart(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    cart_status = Field(Integer)
    address_id = Field(Integer)
    pickupStoreId = Field(Integer)
    checked_out_on = Field(DateTime)
    created_on = Field(DateTime)
    updated_on = Field(DateTime)
    lines = OneToMany("Line")
    total_price = Field(Float)
    discounted_price = Field(Float)
    coupon_code = Field(String(20))
    user = OneToMany("User")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Discount(Entity):
    line = ManyToOne("Line", primary_key=True)
    discount = Field(Float, primary_key = True)
    quantity = Field(Float)
    using_options(shortnames = True)
    using_table_options(mysql_engine = 'InnoDB')

#===============================================================================
# Entity generated from Promotion Service
#===============================================================================
class Promotion(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    name = Field(String(200))
    rule_execution_src = Field(String(100))
    start_on = Field(DateTime)
    end_on = Field(DateTime)
    coupons = OneToMany("Coupon")
    created_on = Field(DateTime)
    type = Field(Integer)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class Coupon(Entity):
    coupon_code = Field(String(20))
    promotion = ManyToOne("Promotion")
    arguments = Field(String(200))
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class PromotionTracker(Entity):
    coupon_code = Field(String(20))
    transaction_id = Field(Integer)
    user_id = Field(Integer)
    applied_on = Field(DateTime)
    promotion_id = Field(Integer)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

class RechargeVoucher(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    voucherCode = Field(String(30))
    voucherType = Field(Integer)
    amount = Field(Numeric(precision=8, scale=2, asdecimal=False))
    available = Field(Boolean)
    issuedOn = Field(DateTime)
    expiredOn = Field(DateTime)
    redeemed = Field(Boolean)
    redeemedOn = Field(DateTime)
    email = Field(String(100))
    userId = Field(Integer)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")
    
#===============================================================================
# Entity generated from Contact Us form
#===============================================================================
class UserCommunication(Entity):
    id = Field(Integer, primary_key = True, autoincrement = True)
    user_id = Field(Integer)
    communication_type = Field(Integer)
    order_id = Field(Integer)
    airwaybill_no = Field(String(50))
    reply_to = Field(String(50))
    product_name = Field(String(200))
    subject = Field(String(200))
    message = Field(String(600))
    communication_timestamp = Field(DateTime)
    using_options(shortnames = True)
    using_table_options(mysql_engine = "InnoDB")

#===============================================================================
# Different entities for the Widget service
#===============================================================================

class UserWidgetItem(Entity):
    userId = Field(Integer, primary_key=True)
    widgetId = Field(Integer, primary_key=True)
    itemId = Field(Integer, primary_key=True)
    addedOn = Field(DateTime)
    using_options(shortnames=True)    
    using_table_options(mysql_engine="InnoDB")

class MasterAffiliate(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(100), unique=True)
    added_on = Field(DateTime)
    affiliates = OneToMany("Affiliate")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Affiliate(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    master_affiliate = ManyToOne("MasterAffiliate")
    name = Field(String(100), unique=True)
    url = Field(String(200))
    added_on = Field(DateTime)
    tracklogs = OneToMany("TrackLog")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Tracker(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    affiliate_id = Field(Integer)
    added_on = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class TrackLog(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    added_on = Field(DateTime)
    affiliate = ManyToOne("Affiliate")
    user_id = Field(Integer)
    event = Field(String(100))
    event_id = Field(Integer)
    url = Field(String(200))
    data = Field(String(200))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class InsuranceDetails(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    addressId = Field(Integer)
    dob = Field(String(64))
    guardianName = Field(String(255))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

def initialize(dbname='user', db_hostname="localhost"):
    #metadata.bind = "sqlite:///user.sqlite" #need to read it from configserver.
    engine = create_engine('mysql://root:shop2020@' + db_hostname + '/' + dbname, pool_recycle=7200, max_overflow=20)
    metadata.bind = engine
    metadata.bind.echo = True
    setup_all(True)

if __name__=="__main__":
    initialize()