Changeset 450

Show
Ignore:
Timestamp:
Tue Jun 17 01:00:48 2008
Author:
Brian
Message:

Change the meta-model to match the code in ORM.py. Open a text window to display the generated SQL.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • scripts/trunk/Object Role Modeling/Install ORM Meta-Model Reports.py

    r448 r450  
    192 192 #       =             pu           U            inor         s         =                        xor  
    193 193 #       - Operator ['Preferred', 'Unique', 'InclusiveOr', 'Subset', 'Equality', 'Exclusion', 'ExclusiveOr', 'Ring', 'Value']  
    194   #       - Modality ['a', 'd']  
      194 ##       - Modality ['a', 'd']  
      195 #       - Deontic [True, False]  
    195 196 #       - Location ['internal', 'extermal']    # all in same fact, cross facts  
    196 197 #       - ORMPathID  
     
    198 199  
    199 200     rt = { 'Name': 'ORM Constraint', 'TableA': 'ORMConstraint', 'TableB': None, 'Also': None, 'AllOrEach': 'each',  
    200              'SuggestedColumns': ',ID;,Type;,Alethic;,DateAdded' }  
      201            'SuggestedColumns': ',ID;,Type;,Modality;,DateAdded' }  
    200 201     ct = [  
    201 202     { 'Name': 'ProjectID',     'Label': 'Project\nID',    'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 50  },  
     
    204 205     { 'Name': 'ID',            'Label': None,             'DataType': 'i', 'AccessType': 'd', 'T': 'A', 'Edit': False, 'Width': 35  },  
    205 206     { 'Name': 'Operator',          'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
    206       { 'Name': 'Modality',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      207 #    { 'Name': 'Modality',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
      208     { 'Name': 'Deontic',       'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
    207 209     { 'Name': 'Location',      'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
    208 210 #    { 'Name': 'Prefered',      'Label': None,             'DataType': 't', 'AccessType': 'd', 'T': 'A', 'Edit': True,  'Width': 35  },  
  • scripts/trunk/Object Role Modeling/Generate SQL.py

    r444 r450  
    11 11 def Generate(project):  
    12 12  
    13       print "create schema %s;" % project.Name  
    14       print  
      13     text = []  
      14     def printx(line):  
      15         text.append(line)  
      16  
      17     printx("create schema %s;" % project.Name)  
      18     printx("")  
    15 19      
    16 20     tables = project.GetList('RelationalTable')  
    17 21     for table in tables:  
    18 22         if table.InUse:  
    19               print "create table %s (" % table.Name  
      23             printx("create table %s (" % table.Name)  
    19 23             columns = table.GetList('RelationalColumn')  
    20 24             for column in columns:  
    21 25                 if column.InUse:  
    22                       print "  %s  %s  %s," % (  
      26                     printx("  %s  %s  %s," % (  
    22 26                         column.Name or "",  
    23 27                         column.DataType or "",  
    24 28                         column.PrimaryKey or "",  
    25                           )  
    26               print ");"  
      29                         ))  
      30             printx(");")  
      31     return "\n".join(text)  
    27 32  
    28 33 def Do(self):  
     
    37 42     report = db.GetObject('Report',rid)  
    38 43  
    39       Generate( report.Project )  
      44     text = Generate( report.Project )  
      45  
      46     dlg = wx.lib.dialogs.ScrolledMessageDialog(self, text, "Generate SQL")  
      47     dlg.Show()  
    40 48  
    41 49 #    Data.SetUndo('Baseline Rmap')  
  • scripts/trunk/Object Role Modeling/Generate SQL Deltas.py

    r444 r450  
    11 11 def GenerateDeltas(project):  
    12 12  
    13       print '''  
      13     text = []  
      14     def printx(line):  
      15         text.append(line)  
      16  
      17     printx('''  
    14 18 This delta is generated as a starting point for data conversion.  
    15 19 Do not use as is. Be sure to review and alter it as necessary for  
     
    17 21  
    18 22 ---- Adds and alters to migrate database from baseline to current ----  
    19   '''  
      23 ''')  
    19 23     tables = project.GetList('RelationalTable')  
    20 24     for table in tables:  
    21 25         if table.InUse and not table.InBase:  
    22               print "create table %s (" % table.Name  
      26             printx("create table %s (" % table.Name)  
    22 26             columns = table.GetList('RelationalColumn')  
    23 27             for column in columns:  
    24 28                 if column.InUse:  
    25                       print "  %s  %s  %s," % (  
      29                     printx("  %s  %s  %s," % (  
    25 29                         column.Name or "",  
    26 30                         column.DataType or "",  
    27 31                         column.PrimaryKey or "",  
    28                           )  
    29               print ");"  
      32                         ))  
      33             printx(");")  
    30 34         elif table.InUse:  # generate table alter adds  
    31 35             columns = table.GetList('RelationalColumn')  
    32 36             for column in columns:  
    33 37                 if column.InUse and not column.InBase:  
    34                       print "alter table %s (" % table.Name  
    35                       print "  add column  %s  %s  %s," % (  
      38                     printx("alter table %s (" % table.Name)  
      39                     printx("  add column  %s  %s  %s," % (  
    36 40                         column.Name or "",  
    37 41                         column.DataType or "",  
    38 42                         column.PrimaryKey or "",  
    39                           )  
    40                       print ");"  
      43                         ))  
      44                     printx(");")  
    41 45                 # should handle names here  
    42 46                 # changed columns should be created here with new name  
     
    49 53                       column.DataType != column.BaseDataType or  
    50 54                       column.PrimaryKey != column.BasePrimaryKey):  
    51                       print "alter table %s (" % table.Name  
    52                       print "  alter column  %s  %s  %s  %s," % (  
      55                     printx("alter table %s (" % table.Name)  
      56                     printx("  alter column  %s  %s  %s  %s," % (  
    53 57                         column.BaseName or "",  
    54 58                         column.Name or "",  
    55 59                         column.DataType or "",  
    56 60                         column.PrimaryKey or "",  
    57                           )  
    58                       print ");"  
      61                         ))  
      62                     printx(");")  
    59 63  
    60       print '''  
      64     printx('''  
    60 64 ---- End of adds and alters ----  
    61 65  
     
    65 69  
    66 70 ---- Beginning of drops ----  
    67   '''  
      71 ''')  
    67 71  
    68 72     for table in tables:  
    69 73         if not table.InUse and table.InBase:  
    70               print "drop table %s; " % table.BaseName  
      74             printx("drop table %s; " % table.BaseName)  
    70 74         elif table.InUse:  # generate table alter adds  
    71 75             columns = table.GetList('RelationalColumn')  
    72 76             for column in columns:  
    73 77                 if not column.InUse and not column.InBase:  
    74                       print "alter table %s" % table.Name  
    75                       print "  drop column  %s;" % (  
      78                     printx("alter table %s" % table.Name)  
      79                     printx("  drop column  %s;" % (  
    76 80                         column.BaseName or "",  
    77                           )  
    78       print '''  
      81                         ))  
      82     printx('''  
    79 83 ---- End of drops ----  
    80 84  
    81 85 End of SQL Deltas  
    82   '''  
      86 ''')  
      87     return "\n".join(text)  
    83 88  
    84 89 def Do(self):  
     
    93 98     report = db.GetObject('Report',rid)  
    94 99  
    95       GenerateDeltas( report.Project )  
      100     text = GenerateDeltas( report.Project )  
      101  
      102     dlg = wx.lib.dialogs.ScrolledMessageDialog(self, text, "Generate SQL Deltas")  
      103     dlg.Show()  
    96 104  
    97 105 ##    Data.SetUndo('Baseline Rmap')