1 import dispatch
2 from turbogears import config
3 from turbogears.util import get_model
4 try:
5 from sqlalchemy import MetaData, exceptions, Table
6 from sqlalchemy import String, Unicode, Text, UnicodeText
7 from turbogears.database import metadata, get_engine
8 except ImportError:
9 pass
10
11 [dispatch.generic()]
14
15 [sacommand.when("command == 'help'")]
16 -def help(command, args):
17 print """TurboGears SQLAlchemy Helper
18
19 tg-admin sql command [options]
20
21 Available commands:
22 create Create tables
23 execute Execute SQL statements
24 help Show help
25 list List tables that appear in the model
26 status Show differences between model and database
27 """
28
29 [sacommand.when("command == 'create'")]
35
36 [sacommand.when("command == 'list'")]
41
42 [sacommand.when("command == 'execute'")]
52
53 [sacommand.when("command == 'status'")]
62
64 return [' ' + l for l in ls]
65
79
97
99 rc = []
100 pyt, dbt = pyc.type, dbc.type
101
102
103 if isinstance(pyt, Unicode):
104 pyt = String(pyt.length)
105 elif isinstance(pyt, UnicodeText):
106 pyt = Text(pyt.length)
107
108
109 if not isinstance(dbt, pyt.__class__):
110 rc.append('Change type to ' + pyt.__class__.__name__)
111
112
113 else:
114 if isinstance(pyt, String):
115 if pyt.length != dbt.length:
116 rc.append('Change length to ' + str(pyt.length))
117
118
119 if any_pkey and dbc.primary_key != pyc.primary_key:
120 rc.append(pyc.primary_key and 'Make primary key' or 'Remove primary key')
121
122
123
124
125 if dbc.default is not None and dbc.default != pyc.default:
126 rc.append('Change default to ' + str(pyc.default.arg))
127
128
129 if dbc.index is not None and dbc.index != pyc.index:
130 rc.append(pyc.index and 'Add index' or 'Remove index')
131
132 return rc
133