Use Pony ORM to create tables.
With the release of Pony 0.8, we will have migration capabilities.
This commit is contained in:
58
lib/dbConfig.py
Normal file
58
lib/dbConfig.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from datetime import date, datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from pony.orm import (
|
||||
Database,
|
||||
LongStr,
|
||||
Optional,
|
||||
PrimaryKey,
|
||||
Required,
|
||||
Set,
|
||||
set_sql_debug,
|
||||
)
|
||||
|
||||
db = Database
|
||||
|
||||
db = Database()
|
||||
|
||||
|
||||
class Cases(db.Entity):
|
||||
case_id = PrimaryKey(int, auto=True)
|
||||
docket_id = Required(str)
|
||||
petitioners = Required(str)
|
||||
respondents = Optional(str)
|
||||
date = Required(date)
|
||||
active = Required(bool)
|
||||
entries = Set("Entries")
|
||||
lhs_id = Set('Cases', column='lhs')
|
||||
rhs_id = Set('Cases', column='rhs')
|
||||
|
||||
class Entries(db.Entity):
|
||||
entry_id = PrimaryKey(int, auto=True)
|
||||
case_id = Required(Cases)
|
||||
date = Required(date)
|
||||
text = Required(LongStr)
|
||||
documents = Set('Documents')
|
||||
|
||||
class Documents(db.Entity):
|
||||
document_id = PrimaryKey(int, auto=True)
|
||||
entry_id = Required(Entries)
|
||||
name = Required(str)
|
||||
url = Required(LongStr)
|
||||
|
||||
class History(db.Entity):
|
||||
history_id = PrimaryKey(int, auto=True)
|
||||
year = Required(str, max_len=3)
|
||||
edocket = Required(bool)
|
||||
number = Required(int)
|
||||
|
||||
set_sql_debug(True)
|
||||
db.bind(
|
||||
provider="mysql",
|
||||
user="scotus",
|
||||
host="ceph5",
|
||||
database="scotus",
|
||||
password="lechOtvirf8Om/",
|
||||
)
|
||||
db.generate_mapping(create_tables=True)
|
||||
db.disconnect()
|
||||
Reference in New Issue
Block a user