fumanchu wrote:
Ben Sizer wrote:
> Data is all-important. I should never have to clear a single thing out
> of any database just to make a small change to a model, or when I want
> to remove the "beta" flag from my product and call it a release
> version. I can certainly appreciate that it's hard to get all the
> possibly migration cases from one model.py to another right. But why
> should Turbogears choke just because I added a line like "newCol =
> IntCol()" in there?
Because the intent of a new line like that is ambiguous, exponentially
so if you make more than one change like it at a time. I would also be
extremely worried that a stray keystroke would cause irreparable harm
to a deployed app if such a feature existed. For safety reasons, you
should at least have to run a special "upgrade" command out-of-band
from the normal app execution (like in an admin script, for example).
I'd be happy with that. I tried tg-admin sql upgrade, hoping it would
do such a thing, but if I'd read the docs I'd see that it's just a hook
for SQLObject's upgrade routine, which itself doesn't appear to do
anything without further intervention of some nature.
> One example is an extra table I had to insert in a PHP project earlier
> this year. This consisted of creating the table, searching for joins
> where it would be used, and adding the relevant extra inner join to
> each one. Done in about 30 minutes. Not a single problem. In
> Turbogears/SQLObject? Well, I have to add the table in the model, as
> well as explicitly note backwards references. But that won't propagate
> down to the database, so I have to add the table there too, and hope
> that the declarations map across properly, including any magic name
> mangling SQLObject is doing behind the scenes.
You mean add by hand with SQL? Yuck.
It seems like if I use SQLObject, I have to add the code, then add it
by hand using SQL as well. I can put those SQL statements into a script
if I like but I still have to do the SQL manually. I was hoping to be
proven wrong in this thread but instead people are telling me I'm
asking too much. :)
> Or I can drop the whole
> lot and re-add it, having had to write and execute both export and
> import scripts, which is a large waste of time when 99.9% of the data
> is going right back in exactly the same tables, unchanged.
You mean dump the whole DB? That is truly horrific.
It seems like TurboGears users have learned to adapt to the "tg-admin
sql drop" followed by "tg-admin sql create" idiom, hence the suggestion
above of repopulating the database with test data via Python code.
And indeed,
http://www.sqlobject.org/sqlobject/mysql/mysqlconnection.py.html shows
addColumn and dropColumn methods, at least...
Hopefully, all I have to do is figure out how to get those invoked
based on what's in my model.py.
> Then I still
> have to go through my code and search for all the special cases I had
> to write because SQLObject's 'complex' queries are crippled by design.
> (And since when was "SELECT LibraryUser INNER JOIN Loan INNER JOIN Book
> WHERE Loan.expiry > Now" complex, anyway? Seems that way with
> SQLObject, unless you want the query to run in quadratic time, that is.
Blurg. In Dejavu, you can get that SQL with:
now = datetime.datetime.now()
recall(LibraryUser & Loan & Book, lambda lu, loan, b: loan.expiry >
now)
What does SQLObject's equivalent look like?
No idea to be honest. Maybe something like:
now = datetime.datetime.now()
output = []
users = LibraryUser.select(Loan.q.expiry > now) # only get relevant
users
for user in users:
for loan in user.loans: # at least one of these is overdue
if loan.expiry > now:
output.append(user, loan, loan.book)
Yes, that's a query to get the users and another one to get the loans
for each user. No doubt there's a faster approach somehow, but I'll be
damned if it's obvious how to formulate it.
--
Ben Sizer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---