Postgresql database schema

323 views
Skip to first unread message

Massimiliano

unread,
May 30, 2011, 6:14:44 AM5/30/11
to web...@googlegroups.com
Hi all,

I've a legacy enterprise application that use postgresql as database.

Existing tables are divided on different database schemas (not only public).

Now I want to rewrite a single application that use existing tables on schema "xyz".

Does web2py support that?

Thank you
--
Massimiliano

Johann Spies

unread,
May 30, 2011, 8:04:06 AM5/30/11
to web...@googlegroups.com
On 30 May 2011 12:14, Massimiliano <mbel...@gmail.com> wrote:
 
Existing tables are divided on different database schemas (not only public).

Now I want to rewrite a single application that use existing tables on schema "xyz".

Does web2py support that?


I could not get DAL to work with that(different schemas) type of setup and would also like to know whether that  can be done.

I had so much trouble using a legacy mysql database that I in the end decided to rebuild the total database in the end.  I will not easily try the legacy usage of Web2py in future.

Regards
Johann 
--
 May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord!  His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence.
                                                    2 Pet. 1:2b,3a

Mathew Grabau

unread,
May 30, 2011, 9:50:42 PM5/30/11
to web2py-users
You could always change the schema before executing the db commands:

db.executesql("set search_path to 'schemaname,public';")

If you could determine the name of the schema first that would be
feasible.

Massimiliano

unread,
May 31, 2011, 3:47:49 AM5/31/11
to web...@googlegroups.com
Sure... That is the way I'm follow...
Fortunately I haven't tables with the same name...

Ciao
--
Massimiliano

Mathew Grabau

unread,
May 31, 2011, 12:00:44 PM5/31/11
to web2py-users
You could always do the db.define_table calls specific to the tables
that are in the schema:

def define_schema1():
db.define_table("table1")
# and so forth

def define_schema1():
db.define_table("tablea")
# and so forth

# later on... (after changing the schema)

if current_schema == "schema1":
define_schema1()
elif current_schema == "schema2":
define_schema2()


You would have to be very careful then to only make the right calls
given the schema otherwise you would end up with an error.

Also be careful with the schema changing - be on the lookout for SQL
injection.
Reply all
Reply to author
Forward
0 new messages