From ae56bfee7abdbd776cbdc689980e0168416af904 Mon Sep 17 00:00:00 2001 From: Andrew Seales Date: Tue, 24 Aug 2021 11:37:15 +0100 Subject: [PATCH] Increase the column width of the subscription role column (#103) --- Dockerfile | 2 +- README.md | 21 ++++++++++------- nbexchange/alembic.ini | 2 +- nbexchange/alembic/README | 1 - nbexchange/alembic/README.md | 15 ++++++++++++ ...-24-21_change_subscription_column_width.py | 23 +++++++++++++++++++ nbexchange/models/subscriptions.py | 11 +++++++-- 7 files changed, 62 insertions(+), 13 deletions(-) delete mode 100644 nbexchange/alembic/README create mode 100644 nbexchange/alembic/README.md create mode 100644 nbexchange/alembic/versions/2021-08-20-15-24-21_change_subscription_column_width.py diff --git a/Dockerfile b/Dockerfile index 56add6b2..f7b9ac26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ LABEL commit=${COMMIT} WORKDIR /usr/src/app # Sqlite for testing -RUN apt update && apt install sqlite -y && rm -rf /var/lib/apt/lists/* +RUN apt update && apt install sqlite3 -y && rm -rf /var/lib/apt/lists/* # Supervisord RUN pip install supervisor diff --git a/README.md b/README.md index b027321f..6a0e10d0 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,20 @@ Documentation currently in [docs/](docs/) - should be in readthedocs # Installing -Nbexchange can be installed as a Helm chart +Nbexchange can be installed as a Helm chart or as a pip dependency: -## Configuration + +``` +helm install --name nbexchange --namespace default ./chart -f myconfiguration.yaml +``` + +or + +``` +pip install . +``` + +## Helm Configuration | Parameter | Description | Default | | ---------- | -------------- | ------- | @@ -87,12 +98,6 @@ Nbexchange can be installed as a Helm chart | `nodeSelector` | Pod node selector for deployment | `{}` | -## How to - -``` -helm install --name nbexchange --namespace default ./chart -f myconfiguration.yaml -``` - # Contributing See [Contributing.md](CONTRIBUTING.md) diff --git a/nbexchange/alembic.ini b/nbexchange/alembic.ini index a4d2ce87..bd32a720 100644 --- a/nbexchange/alembic.ini +++ b/nbexchange/alembic.ini @@ -6,7 +6,7 @@ script_location = {alembic_dir} sqlalchemy.url = {db_url} # template used to generate migration files -# file_template = %%(rev)s_%%(slug)s +file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d-%%(minute).2d-%%(second).2d_%%(slug)s # timezone to use when rendering the date # within the migration file as well as the filename. diff --git a/nbexchange/alembic/README b/nbexchange/alembic/README deleted file mode 100644 index 98e4f9c4..00000000 --- a/nbexchange/alembic/README +++ /dev/null @@ -1 +0,0 @@ -Generic single-database configuration. \ No newline at end of file diff --git a/nbexchange/alembic/README.md b/nbexchange/alembic/README.md new file mode 100644 index 00000000..17a028f6 --- /dev/null +++ b/nbexchange/alembic/README.md @@ -0,0 +1,15 @@ +# Generic single-database configuration. + +## Building migrations: + +Build a fresh database + +`NBEX_DB_URL="sqlite:///test.db" nbexchange` + +Create a migration: + +`NBEX_DB_URL="sqlite:///test.db" python -m nbexchange.dbutil alembic revision --autogenerate -m "Change subscription column width"` + +Apply a migration: + +`NBEX_DB_URL="sqlite:///test.db" python -m nbexchange.dbutil alembic upgrade head` diff --git a/nbexchange/alembic/versions/2021-08-20-15-24-21_change_subscription_column_width.py b/nbexchange/alembic/versions/2021-08-20-15-24-21_change_subscription_column_width.py new file mode 100644 index 00000000..c6e78862 --- /dev/null +++ b/nbexchange/alembic/versions/2021-08-20-15-24-21_change_subscription_column_width.py @@ -0,0 +1,23 @@ +"""Change subscription column width + +Revision ID: 2540572282f2 +Revises: bfe19408f64f +Create Date: 2021-08-20 15:24:21.878350 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "2540572282f2" +down_revision = "bfe19408f64f" +branch_labels = None +depends_on = None + + +def upgrade(): + op.execute("ALTER TABLE subscription ALTER COLUMN role TYPE Text") + + +def downgrade(): + op.execute("ALTER TABLE subscription ALTER COLUMN role TYPE VARCHAR(50)") diff --git a/nbexchange/models/subscriptions.py b/nbexchange/models/subscriptions.py index c6aeacbc..1fccfc05 100644 --- a/nbexchange/models/subscriptions.py +++ b/nbexchange/models/subscriptions.py @@ -1,4 +1,11 @@ -from sqlalchemy import Column, ForeignKey, Integer, Unicode, UniqueConstraint +from sqlalchemy import ( + Column, + ForeignKey, + Integer, + Unicode, + UniqueConstraint, + UnicodeText, +) from sqlalchemy.orm import relationship from nbexchange.models import Base @@ -25,7 +32,7 @@ class Subscription(Base): id = Column(Integer, primary_key=True, autoincrement=True) user_id = Column(Integer, ForeignKey("user.id", ondelete="CASCADE"), index=True) course_id = Column(Integer, ForeignKey("course.id", ondelete="CASCADE"), index=True) - role = Column(Unicode(50), nullable=False) + role = Column(UnicodeText, nullable=False) # These are the relationship handles: a specific subscription has a single user to a single course user = relationship("User", back_populates="courses")