Manlio Perillo wrote:
> When writing this code I found some problems with SQLAlchemy:
>
> 1) There is no support for SQL Schema at all.
>
>    It is ok, for me, if there is no direct support for SQL Schema in
>    SQLAlchemy, but this is a standard feature, so SQLALchemy dialects
>    should:
>
>    * define a `supports_schemas` attribute, as a boolean
>    * define a `has_schema` method, to check is a schema exists
>
>    Can I fill a ticket with this feature request?

can you describe this for me ?   We support schemas from the perspective
that you can define a table that is in a particular schema, so i dont
understand the statement "no support for SQL schema at all".

While the approach you have to issue CREATE SCHEMA and DROP SCHEMA
commands are fine for your own usage, the intended method of creating
these was meant to be the techniques described at:

http://www.sqlalchemy.org/docs/reference/ext/compiler.html
http://www.sqlalchemy.org/docs/metadata.html#customizing-ddl

`has_schema()` is a totally fine method for which we'd accept a patch to
the Inspector class as well as dialects.


>
> 2) I would like to emulate SQL Schema support in SQLite, using secondary
>    databases, attached to the main database.
>
>    However, I noted that SQLAlchemy executes the following query:
>
>      BEGIN
>      PRAGMA "test".table_info("test")
>      ()
>      ROLLBACK
>
>    for a table named "test" in a schema named "test"
>    (to be precise, the previous query is exected two times).
>
>    It seems that SQLAlchemy assumes that the schema refers to a
>    secondary database.
>
>    The problem is that SQLAlchemy executes these queries **before** my
>    DDL listener is called, so the query fails because I don't have yet
>    attached the secondary database.

if your database requires special configuration in order for "schemas" to
be present, you would do that before issuing anything with metadata
creation.   I'd advise using a PoolListener to handle this configuration. 
It should not be the job of "create_all" to attach to a particular schema,
since "create_all" is not a "configure the database" command - many
applications don't ever call "create_all" but still may be using sqlite
schemas.


>    I think that this behaviour is incorrect.
>    The "before-create" listeners of a MetaData object should be called
>    before checking if the tables exist.

I can see the awkardness here but the current contract of "before-create"
is that it means "before I create this list of Tables that I have found
need creation, and here they are".    Its something we may have to revisit
if there's really a reason for a "before I do anything" hook - but I don't
buy the case of "I need to attach schemas in the create_all()" as a
necessary use case.   an app would need to call that regardless of
create_all() being called or not.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to