This works for me. :-)

As for you point 1), if there is no tg_init_database, then the behaviour
is exactly as before and SQLObject users will not be confused.  That is
to say, I have to do an explicit act to get the new behaviour and so I
will know what will happen.

As for point 2), I am thinking that a counterpart method like
tg_clear_database or something would be nice so that old data can be
torn down.  And alternative would be to make your tg_init_database,
check for the existence of any data you are trying to insert.

Further a reset or rebuild method is a simple as tg_clear_database();
tg_init_database().  If that is useful.

And then there is the blue-sky-on-mars <wink> thinking that this could
be the base for model versioning with upgrade functions in each model to
that can migrate old data structures to new ones. I think this is a bit
far off, though. (Can you tell I have been played with Zope and
Twisted?) :-)

Krys

Fabian Neumann wrote:

>Krys Wilken wrote:
>  
>
>>I think both ideas are of value.  An exec command for running scripts,
>>and a special module-level function in model.py that is run
>>automatically by sql create.
>>    
>>
>
>I might like it, too.  What do you think of this:
>
>Index: turbogears/quickstart/projectname/model.py.source
>===================================================================
>--- turbogears/quickstart/projectname/model.py.source   (Revision 43)
>+++ turbogears/quickstart/projectname/model.py.source   (Arbeitskopie)
>@@ -6,3 +6,6 @@
>
> # class YourDataClass(SQLObject):
> #     pass
>+
>+# def tg_init_database():
>+#     pass
>Index: turbogears/command/__init__.py
>===================================================================
>--- turbogears/command/__init__.py      (Revision 43)
>+++ turbogears/command/__init__.py      (Arbeitskopie)
>@@ -104,6 +104,12 @@
>
>         from sqlobject.manager import command
>         command.the_runner.run(sys.argv)
>+        if sqlobjcommand == "create":
>+            mod = self.get_model()
>+            if hasattr(mod, 'tg_init_database'):
>+                print 'Filling database'
>+                mod.tg_init_database()
>+
>
>     def fix_egginfo(self, eggname):
>         print """
>
>
>Two issues with that:
>1. This behaviour may be unexpected by people who are familiar with
>   "sqlobject-admin create".
>2. If you run "sql create" twice or more, those init values are doubled.
>
>  
>
>>An alternative to a single module-level function would be a special
>>method on each model that is responsible for populating itself, perhaps
>>"post_create(self)" or something.  Sql create could just call that
>>method of each model after all the tables have been created.
>>    
>>
>
>I don't think this granularity is useful, as you can only create all
>models at once (I think).
>
>Fabian
>
>
>  
>

Reply via email to