From 09438c12ee61c9245cf3ddd5015d522772959dd7 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 4 Apr 2017 14:52:07 -0700 Subject: [PATCH 1/2] Autoincrement trove classifier id. This should allow to not have to bother about getting the id right when inserting new. Legacy PyPI does a : ```python cursor = st.get_cursor() cursor.execute("select max(id) from trove_classifiers") id = cursor.fetchone()[0] if id: id = int(id) + 1 else: id = 1 ``` Then insert, which IIUC is subject to race conditions. --- ...b5d_autoincrement_trove_classifiers_ids.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 warehouse/migrations/versions/ad81a3452b5d_autoincrement_trove_classifiers_ids.py diff --git a/warehouse/migrations/versions/ad81a3452b5d_autoincrement_trove_classifiers_ids.py b/warehouse/migrations/versions/ad81a3452b5d_autoincrement_trove_classifiers_ids.py new file mode 100644 index 000000000000..7c545d5ef25d --- /dev/null +++ b/warehouse/migrations/versions/ad81a3452b5d_autoincrement_trove_classifiers_ids.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Autoincrement trove classifier id when inserting (if id not given). + +Revision ID: ad81a3452b5d +Revises: 5b3f9e687d94 +Create Date: 2017-04-04 21:00:25.205245 +""" + +from alembic import op + +revision = 'ad81a3452b5d' +down_revision = '5b3f9e687d94' + +def upgrade(): + """ + Autoincrement the trove classifier ID when a new one get inserted. + """ + op.execute( + """CREATE SEQUENCE trove_classifiers_seq; + SELECT setval('trove_classifiers_seq', + (SELECT max(id) from trove_classifiers) + ); + ALTER TABLE trove_classifiers + ALTER COLUMN id + SET DEFAULT nextval('trove_classifiers_seq'); + ALTER SEQUENCE trove_classifiers_seq + OWNED BY trove_classifiers.id; + """) + + +def downgrade(): + op.execute( + """ALTER TABLE trove_classifiers + ALTER COLUMN id SET DEFAULT 1; + DROP SEQUENCE trove_classifiers_seq; + """) From 3f465459158b1a34469c2bf521006f7fc48dbfbc Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 6 Apr 2017 15:23:29 -0700 Subject: [PATCH 2/2] Create `Framework :: Jupyter` trove classifier AS requested in https://github.com/pypa/pypi-legacy/issues/210 --- ..._add_framework_jupyter_trove_classifier.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 warehouse/migrations/versions/1430c9aefcd7_add_framework_jupyter_trove_classifier.py diff --git a/warehouse/migrations/versions/1430c9aefcd7_add_framework_jupyter_trove_classifier.py b/warehouse/migrations/versions/1430c9aefcd7_add_framework_jupyter_trove_classifier.py new file mode 100644 index 000000000000..bbe62e4a1afe --- /dev/null +++ b/warehouse/migrations/versions/1430c9aefcd7_add_framework_jupyter_trove_classifier.py @@ -0,0 +1,45 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +""" +Create `Framework::Jupyter` as required on pypi-legace issue 210 + +Revision ID: 1430c9aefcd7 +Revises: ad81a3452b5d +Create Date: 2017-04-06 22:03:40.917628 +""" + +from alembic import op +import sqlalchemy as sa + + +revision = '1430c9aefcd7' +down_revision = 'ad81a3452b5d' +classifier = "Framework :: Jupyter" + +def upgrade(): + op.execute( + """ + INSERT into trove_classifiers (classifier, l2, l3, l4, l5) VALUES ('{classifier}', 0, 0, 0, 0); + UPDATE trove_classifiers set l2=id where classifier='{classifier}'; + """.format(classifier=classifier) + ) + + pass + + +def downgrade(): + op.execute( + """ + DELETE from release_classifiers where trove_id=(SELECT id from trove_classifiers where classifier='{classifier}'); + DELETE FROM trove_classifiers where classifier='{classifier}'; + """.format(classifier=classifier) + )