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

Moving database connection stuff to a dedicated db module #757

Merged
merged 5 commits into from
Oct 14, 2015
Merged

Conversation

hallvors
Copy link
Contributor

I propose we collect the code to create a db session in one place, for example like this.

(This may not be The Best Way To Do It - would be good with a review from for example @karlcow )

@karlcow
Copy link
Member

karlcow commented Oct 11, 2015

@hallvors

  • Where is the issue this pull request depends on?
  • What was the discussion about it?

db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
from db import db_session, engine

This comment was marked as abuse.

@miketaylr
Copy link
Member

In spirit this seems fine. But do we want to be adding other tables and data to the "session.db"? Or do we want to create new databases for different things, i.e. issues? I don't actually have an answer, curious what others think.

(If we keep it all in a single db, we should probably rename it to not be session.db)

@karlcow
Copy link
Member

karlcow commented Oct 12, 2015

I have a hunch that it should be a separate db, for at least one reason, that it is easier to un-mess things if we need to fully drop it because it has been polluted. On the other hand, we probably want to keep the bugs data if any in the future.

@miketaylr
Copy link
Member

I also tend to like the idea of separate databases. And right now I can't think of any relationships between user_id/session and a table of issues... On the other hand, at some point we will probably want a relationship between issues and usernames for dashboard stuff. But we don't store usernames in our session table.

@hallvors can you refactor this so we're creating two databases, one for session and one for issues?

@hallvors
Copy link
Contributor Author

@karlcow This is a little refactoring that is meant to make the fix for #165 easier and cleaner. Is it mandatory to have an Issue and a Pull Request even for small fixes? IMHO a PR is a good place to discuss things ;)

@miketaylr Sure, will change this to have two data files.

I also forgot to do the pep8 thing..

@miketaylr
Copy link
Member

Is it mandatory to have an Issue and a Pull Request even for small fixes?

Probably not mandatory, usually when I do this kind of refactoring I'm already inside a branch working on a feature (that has an issue). So it would just be a single commit like Issue NNN. Move database connection stuff to a dedicated db module (or something).

I would say for simple fixes a PR is fine, but for stuff that would benefit from discussion Issues are a good thing™ (even though yes there are comment boxes in this PR :P).

@hallvors
Copy link
Contributor Author

I've fixed the variable names to be session_db and session_engine, so whenever other parts import those it should be pretty clear what DB we're using. When we need other files and tables we can add them in db/__init.py__ . OK this way?

@hallvors
Copy link
Contributor Author

Hm.. not sure why the Travis build fails now, this runs OK locally as far as I can tell.

@miketaylr
Copy link
Member

Hm.. not sure why the Travis build fails now, this runs OK locally as far as I can tell.

It looks like some unrelated label test failures. Somehow a label got left on the test issue, so everything that expects it to not have a label fails.

Those tests have been flaky in the past, so I wouldn't worry about it. Hopefully once #712 lands, we'll be less affected by these kinds of failures.

@miketaylr
Copy link
Member

OK this way?

Looks good to me. In a perfect world the commit messages would start with Issue #165., since these commits get you closer to solving that issue.

(Also that way they are cross-linked in the issue and make it easier to track down the commits/history in the CHANGELOG (we list PR and Issue)).

But I'll take the contribution over perfection. ^_^

miketaylr pushed a commit that referenced this pull request Oct 14, 2015
Issue #165. Moving database connection stuff to a dedicated db module
@miketaylr miketaylr merged commit c679f75 into master Oct 14, 2015
@miketaylr miketaylr deleted the db_work branch October 14, 2015 17:42
@miketaylr
Copy link
Member

I deployed this to staging and logging in and out still works, so that's good. 🎈

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 this pull request may close these issues.

3 participants