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

database changes to fix 969 #2071

Merged
merged 5 commits into from
Feb 6, 2017
Merged

Conversation

antgonza
Copy link
Member

@antgonza antgonza commented Feb 3, 2017

These are the DB changes so we can add the tagging system to Qiita. Note that I decided to keep track of which user adds which tag so we can allow users to add tags and still catch any abuse.

Copy link
Contributor

@josenavas josenavas left a comment

Choose a reason for hiding this comment

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

Few comments - thanks @antgonza


Parameters
----------
tag_ids : list of int
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we provide the list of tags rather than the list of tag ids? We have been removing the exposure of DB ids for these types of thins as much as we could, so I would like not to re-add some of them back

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Just FYI: We (@josenavas and me) decided via offline chat that it was fine to leave as is because that way we can link the ids in the templates and the text can be escaped in the templates, which makes our live easier.

return qdb.sql_connection.TRN.execute_fetchindex()

@tags.setter
def tags(self, tag_ids):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not setting the tags correctly. If a tag has been removed from the list it doesn't get removed from the DB.

Would it be more useful to add a couple of functions add_tags and remove_tags?

The study tags
"""
with qdb.sql_connection.TRN:
sql = """SELECT study_tag_id, study_tag
Copy link
Contributor

Choose a reason for hiding this comment

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

Just return the "study_tag" (not the id)


# assigning the tags to study
study = qdb.study.Study(1)
study.tags = [tig for tig, tag in obs]
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a:

self.asertEqual(study.tags, [])

before this line

study = qdb.study.Study(1)
study.tags = [tig for tig, tag in obs]
# and checking that everything went fine
self.assertEqual(exp, study.tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add another case in which a tag is removed from the list.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 91.555% when pulling 751d4ad on antgonza:fix-969-db into 6360675 on biocore:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 91.555% when pulling 65a86df on antgonza:fix-969-db into 6360675 on biocore:master.


Parameters
----------
tag_ids : list of int
Copy link
Member

Choose a reason for hiding this comment

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

👍

qdb.sql_connection.TRN.execute()

if tag_ids:
sql = """INSERT INTO qiita.per_study_tags
Copy link
Member

Choose a reason for hiding this comment

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

If something goes wrong when this query is executed, we will have lost the tags 😱. IIRC the API should allow you to only execute at the very end of this function, such that if something fails the whole transaction is rolled back.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, deleting this execute

)"""
sql_args = [[tid, self._id, tid, self._id] for tid in tag_ids]
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
return qdb.sql_connection.TRN.execute()
Copy link
Member

Choose a reason for hiding this comment

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

What's being returned here? ... should anything be returned at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, removing the return

CREATE TABLE qiita.study_tags (
study_tag_id bigserial NOT NULL,
email varchar NOT NULL,
study_tag varchar NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

Can/should we guarantee unique tags?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, 1 line below: CONSTRAINT pk_study_tag UNIQUE ( study_tag_id ),

Copy link
Member Author

@antgonza antgonza left a comment

Choose a reason for hiding this comment

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

thanks submitting changes in a few secs


Parameters
----------
tag_ids : list of int
Copy link
Member Author

Choose a reason for hiding this comment

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

Just FYI: We (@josenavas and me) decided via offline chat that it was fine to leave as is because that way we can link the ids in the templates and the text can be escaped in the templates, which makes our live easier.

qdb.sql_connection.TRN.execute()

if tag_ids:
sql = """INSERT INTO qiita.per_study_tags
Copy link
Member Author

Choose a reason for hiding this comment

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

good point, deleting this execute

)"""
sql_args = [[tid, self._id, tid, self._id] for tid in tag_ids]
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
return qdb.sql_connection.TRN.execute()
Copy link
Member Author

Choose a reason for hiding this comment

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

good point, removing the return

CREATE TABLE qiita.study_tags (
study_tag_id bigserial NOT NULL,
email varchar NOT NULL,
study_tag varchar NOT NULL,
Copy link
Member Author

Choose a reason for hiding this comment

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

yes, 1 line below: CONSTRAINT pk_study_tag UNIQUE ( study_tag_id ),

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 91.555% when pulling 18d77e1 on antgonza:fix-969-db into 6360675 on biocore:master.

@josenavas josenavas merged commit 01c656c into qiita-spots:master Feb 6, 2017
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.

None yet

4 participants