Skip to content

Commit

Permalink
Correct schema handling, fixes #486 and #487
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Dec 28, 2014
1 parent 279e54a commit b5a5688
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions playhouse/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ def get_database_name(self):
return self.metadata.database.database

def get_database_kwargs(self):
return self.metadata.database.connect_kwargs
database_kwargs = dict(self.metadata.database.connect_kwargs)
if self.schema:
database_kwargs.update(schema=self.schema)
return database_kwargs

def make_model_name(self, table):
model = re.sub('[^\w]+', '', table)
Expand All @@ -381,7 +384,11 @@ def make_column_name(self, column):

def introspect(self, table_names=None):
# Retrieve all the tables in the database.
tables = self.metadata.database.get_tables()
if self.schema:
tables = self.metadata.database.get_tables(schema=self.schema)
else:
tables = self.metadata.database.get_tables()

if table_names is not None:
tables = [table for table in tables if table in table_names]

Expand Down

3 comments on commit b5a5688

@dkorduban
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it fixes the problem. You will get something like

from peewee import *

database = PostgresqlDatabase('db_name', **{'schema': 'schema_name', ...})

class UnknownField(object):
    pass

class BaseModel(Model):
    class Meta:
        database = database

when you probably want

from peewee import *

database = PostgresqlDatabase('db_name', **{...})

class UnknownField(object):
    pass

class BaseModel(Model):
    class Meta:
        database = database
        schema = 'schema_name'

instead.

Database.__init__ doesn't support schema argument ATM and I don't see why it should. Schema is something table-level, not db-level.

@coleifer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right...derp. I never use schemas myself so I'm not that familiar with them.

@coleifer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 05d2c29 and 3f2d22b

Please sign in to comment.