Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating database fails for postgreSQL 9.1 #132

Closed
ebuz opened this issue Aug 17, 2014 · 4 comments
Closed

Creating database fails for postgreSQL 9.1 #132

ebuz opened this issue Aug 17, 2014 · 4 comments

Comments

@ebuz
Copy link
Contributor

ebuz commented Aug 17, 2014

Database table creation fails for postgreSQL. The problem is from specifying a size for the datastring column in the participant model. Text column length is optional for MySQL and SQLite databases but postgreSQL doesn't use (or apparently accept) a length specification. I can initiate a pull request with the fix.

Upshot: Fixes the problem for postgreSQL though I have not looked into how it changes the datastring length upper bound in MySQL databases.

@JSlote
Copy link
Contributor

JSlote commented Aug 18, 2014

@ebuz would it be possible to check the protocol from the config and then modify the pertinent SQLAlchemy stuff based on the protocol? That way we'd be keeping everything safe.

@gureckis
Copy link
Member

@JSlote @ebuz That would be my suggestion as well. I seem to remember specifying the datastring size ended up being important because in MySQL it defaults to something seemingly small and some psiTurk users were reporting data truncation issues (see this commit: 63dcc80).

@ebuz
Copy link
Contributor Author

ebuz commented Aug 19, 2014

@gureckis that's what I was afraid of, looking through the documentation of MySQL it looks like there are actually four different Text types with differing lengths and which SQLalchemy picks to use when building the table seems related to the length parameter, if it isn't specified it likely defaults to one of the smaller of those. Using the SQLalchemy String type instead of Text doesn't work either. The 4294967295 value specified in the current declaration is too large since postgreSQL's character length limit is 10485760. And I think that value is too big for MySQL's varchar limit. Oy.

@JSlote A conditional declaration in models.py can fix it:

if 'postgres' in config.get('Database Parameters', 'database_url'):
  datastring = Column(Text)
else:
  datastring = Column(Text(4294967295))

I just tested it and it works but seems like a hack, though I don't know of any other solutions that aren't equally hackish.

@gureckis
Copy link
Member

although SQLAlchemy aims at DB agnosticism, I think in practice it is nearly impossible to be a purist. given that the current solution of a large text field appears to work for both MySQL and SQLLite, i'm ok with a few conditional statements like this for postgreSQL, if it make things work... happy to merge a pull request to this effect.

This was referenced Aug 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants