widgetworks_schema.py :  » Database » PyTable » pytable-0.8.20a » pytable » examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » PyTable 
PyTable » pytable 0.8.20a » pytable » examples » widgetworks_schema.py
from pytable.schemabuilder import *

schema = database(
  name = "widgetworks",
  comment = """A Widget-seller's database""",
  tables = [
    table(
      "customer",
      fields = [
        field( 
          "customer_id", "serial", 0, """Unique id for the customer""",
          constraints = [ primary(), notNull() ],
        ),
        field(
          "customer_name", "varchar", 0, """Human-friendly name of the customer""",
          constraints = [ notNull() ],
        ),
      ],
      defaultRecords = [
        { 'customer_name': "Ricky's Dept. Store" },
        { 'customer_name': "Vicky Valencourt Inc." },
        { 'customer_name': "James Joyce Bars" },
        { 'customer_name': "Regal Regalia" },
        { 'customer_name': "Bitter Biters" },
      ],
    ),
    table(
      "widget",
      comment ="""Base table for a saleable product""",
      fields = [
        field(
          "widget_id", "serial", 0, """Unique id for the widget""",
          constraints = [ primary(), notNull() ],
        ),
        field(
          "widget_name", "varchar", 0, """Human-friendly name for the widget""",
          constraints = [ notNull() ],
        ),
        field(
          "widget_cost", "number", 0, """Decimal description of a widget's base cost""",
          constraints = [ notNull() ],
        ),
        field(
          "product_id", "varchar", 8, """8-Character product ID for external reference""",
          constraints = [ notNull() ],
        ),
      ],
      indices = [
        index( unique=1, primary=0, fields=('product_id',)),
      ],
      defaultRecords = [
        { 'widget_name': 'Vipo Vapour Grommit', "widget_cost": 32.33, "product_id": "AABBCCDD"},
        { 'widget_name': 'Vegan Verdana',"widget_cost": 59.99, "product_id": "AABBCCDE"},
        { 'widget_name': 'Wisconsin Whippet',"widget_cost": 34.00, "product_id": "AABBCCDF"},
        { 'widget_name': 'Magic Merdana',"widget_cost": 55.98, "product_id": "AABBCCDG"},
        { 'widget_name': 'Loputuk Latkes',"widget_cost": 29.32, "product_id": "AABBCCDH"},
        { 'widget_name': 'Galaxy Ginseng Garter',"widget_cost": 55.30, "product_id": "AABBCCDI"},
      ],
    ),
    table(
      "order",
      comment = """Overall order from a customer from some set of widgets""",
      fields = [
        field(
          "order_id", "serial", 0, """Unique id for the order""",
          constraints = [ primary(), notNull() ],
        ),
        field(
          "order_date", "timestamp", 0, """Date the order was submitted""",
          defaultValue = 'CURRENT_TIMESTAMP',
        ),
        field(
          "delivery_date", "timestamp", 0, """Date the order is to be delivered""",
        ),
        field(
          "customer_id", "integer", 0, """The customer that placed the order""",
          constraints = [
            foreignKey(
              "customer", # uses primary key by default...
              onDelete = "CASCADE",
              onUpdate = "CASCADE",
            ),
            notNull(),
          ],
        ),
      ],
    ),
    table(
      "order_widgets",
      comment = """Widgets expected for a given order""",
      fields = [
        field(
          "order_id", "integer", 0, """The order being described""",
          constraints = [
            foreignKey(
              "order", # uses primary key by default...
              onDelete = "CASCADE",
              onUpdate = "CASCADE",
            ),
            notNull(),
          ],
        ),
        field(
          "widget_id", "integer", 0, """The widgets being ordered""",
          constraints = [
            foreignKey(
              "widget", # uses primary key by default...
              onDelete = "CASCADE",
              onUpdate = "CASCADE",
            ),
            notNull(),
          ],
        ),
        field(
          "widgets_ordered", "integer", 0, """Number of widgets ordered""",
          defaultValue = 0,
          constraints = [
            notNull(),
          ],
        ),
        field(
          "widgets_reserved", "integer", 0, """Number of widgets already reserved from inventory""",
          defaultValue = 0,
          constraints = [
            notNull(),
          ],
        ),
      ],
      indices = [
        index( unique=1, primary=0, fields=('order_id','widget_id'), ),
      ],
    ),
    table(
      "inventory",
      comment = """Widgets currently on hand""",
      fields = [
        field(
          "widget_id", "integer", 0, """The widgets being stored""",
          constraints = [
            foreignKey(
              "widget", # uses primary key by default...
              onDelete = "CASCADE",
              onUpdate = "CASCADE",
            ),
            notNull(),
          ],
        ),
        field(
          "widgets_onhand", "integer", 0, """Number of widgets currently on-hand""",
          defaultValue = 0,
          constraints = [
            notNull(),
          ],
        ),
        field(
          "widgets_reserved", "integer", 0, """Number of widgets currently reserved (already allocated to orders)""",
          defaultValue = 0,
          constraints = [
            notNull(),
          ],
        ),
      ],
    ),
  ],
)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.