sql initial data files

1 view
Skip to first unread message

jacek....@gmail.com

unread,
Jun 12, 2006, 11:08:57 AM6/12/06
to Django developers
Hi,

I'm using postgresql for my django app
and I want to have a trigger to be created for one of my django models

I hoped that the sqlinitialdata feature would do the job for me but it
failed.

Problems:
1) '%' in statments (psycopg is trying to format a string)
2) multiline "create function" statment

I think it would be nice if one could put some
more complicated code than just the inserts in
sqlinitialdata files.

I'm also thinking about having some
<model>.upgrade.<from-ver>.<to-ver>.sql files
and putting there all nesessery "alter table add column", etc

django could check the schema version saved into some
table in database, and if it is too old try to run those upgrade files

What do you think?

Jacek Rembisz
PS
That's my first django app.
I realy, realy liked this framework. It saves my time.
Thank you very much.

PS2
This patch works for me but it is just a hack
and breaks support for other database backends.

--- django/core/management.py (revision 3065)
+++ django/core/management.py (working copy)
@@ -344,10 +344,11 @@
for sql_file in sql_files:
if os.path.exists(sql_file):
fp = open(sql_file)
- output.extend(sql_expr.findall(fp.read()))
+# output.extend(sql_expr.findall(fp.read()))
+ output.append(fp.read())
fp.close()

- return output
+ return [l.replace('%', '%%') for l in output]

def get_sql_initial_data(app):
"Returns a list of the initial INSERT SQL statements for the given
app."

Reply all
Reply to author
Forward
0 new messages