diff --git a/.github/workflows/scripts/create-orm-update-pull-request b/.github/workflows/scripts/create-orm-update-pull-request index dce3e017..19ce2ffc 100755 --- a/.github/workflows/scripts/create-orm-update-pull-request +++ b/.github/workflows/scripts/create-orm-update-pull-request @@ -7,16 +7,8 @@ git config credential.helper "store --file=.git/credentials" echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials echo -echo "##[section]Installing github cli" -pushd .. >/dev/null -wget -nv https://github.com/github/hub/releases/download/v2.6.0/hub-linux-amd64-2.6.0.tgz -O - | tar xz -export PATH=$(pwd)/hub-linux-amd64-2.6.0/bin/:${PATH} -popd >/dev/null -hub --version -echo - echo "##[section]Check for existing pull request" -hub pr list -b main -f '%H%n' | grep "^orm-update$" && { +echo $( gh pr list -B ${BRANCH} -H orm-update ) | grep orm-update && { echo Pull request already exists. Stopping here. exit } || { @@ -39,8 +31,7 @@ echo echo "##[section]Creating pull request" git push -f --set-upstream origin orm-update -HUB_VERBOSE=1 hub pull-request -b main -f -m "ISPyB ORM schema update v${DATABASE_SCHEMA} - +gh pr create -B ${BRANCH} -H orm-update -t "ISPyB ORM schema update v${DATABASE_SCHEMA}" -b " This is an automated pull request to update the ISPyB ORM schema. Before merging this pull request you may want to diff --git a/.github/workflows/test-and-publish.yml b/.github/workflows/test-and-publish.yml index 8f173e49..0c1dcf90 100644 --- a/.github/workflows/test-and-publish.yml +++ b/.github/workflows/test-and-publish.yml @@ -76,6 +76,9 @@ jobs: update_ORM: name: Call orm update workflow + permissions: + contents: write + pull-requests: write needs: - build - get-env-vars diff --git a/.github/workflows/update-orm.yml b/.github/workflows/update-orm.yml index bb52ecdc..9f8a1b9d 100644 --- a/.github/workflows/update-orm.yml +++ b/.github/workflows/update-orm.yml @@ -11,17 +11,21 @@ jobs: orm-update: name: Update ORM runs-on: ubuntu-latest - container: mariadb + permissions: + contents: write + pull-requests: write + services: mariadb: image: mariadb:10.6 env: - MYSQL_DATABASE: ispybtest - MYSQL_ROOT_PASSWORD: mysql_root_pwd + MARIADB_DATABASE: ispybtest + MARIADB_ROOT_PASSWORD: mariadb_root_pwd ports: - 3306:3306 + options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 outputs: - output1: ${{ steps.checkUpdate.needsUpdate }} + needsUpdate: ${{ steps.checkUpdate.outputs.needsUpdate }} steps: - uses: actions/checkout@v4 @@ -45,42 +49,43 @@ jobs: working-directory: ./src/ispyb/sqlalchemy - name: Install sqlacodegen - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} run: | set -eux pip install -r requirements_orm.txt pip install pre-commit - name: Get database schema - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} uses: actions/download-artifact@v4 with: - name: ispyb-database.tar.gz + name: package-distributions path: dist/ + - uses: shogo82148/actions-setup-mysql@v1 + with: + distribution: 'mariadb' + mysql-version: '10.6' + auto-start: false + - name: Set up reference database schema - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} run: | set -eu - cat >~/.my.cnf < .my.cnf </dev/null; do printf '.'; sleep 0.5; done + until mariadb --defaults-file=.my.cnf -e "SHOW DATABASES" >/dev/null; do printf '.'; sleep 0.5; done printf '\n' echo "Installing reference database" @@ -88,14 +93,13 @@ jobs: echo echo "Installed tables:" - mysql -D ispyb_build -e "SHOW TABLES" - working-directory: dist + mariadb --defaults-file=.my.cnf -D ispyb_build -e "SHOW TABLES" - name: Generate ORM - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} run: | set -eux - sqlacodegen mysql+mysqlconnector://root:mysql_root_pwd@127.0.0.1/ispyb_build --noinflect --nojoined --outfile _auto_db_schema.py.in + sqlacodegen mysql+mysqlconnector://root:mariadb_root_pwd@127.0.0.1/ispyb_build --noinflect --nojoined --outfile _auto_db_schema.py.in # This code produces false positives due to non-deterministic ordering. # Add an identifier to the file, and only update/PR the changes when the # identifier indicates the file is out of date. @@ -105,18 +109,20 @@ jobs: working-directory: ./src/ispyb/sqlalchemy - name: Show differences - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} run: git diff - name: Store artifact - if: ${{ steps.checkUpdate.needsUpdate == 'true' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} uses: actions/upload-artifact@v4 with: name: ORM path: ./src/ispyb/sqlalchemy/_auto_db_schema.py - name: Create ORM pull request - if: ${{ steps.checkUpdate.needsUpdate == 'true' && github.ref_name == 'main' }} + if: ${{ steps.checkUpdate.outputs.needsUpdate == 'true' }} run: .github/workflows/scripts/create-orm-update-pull-request env: GITHUB_TOKEN: ${{ github.token }} + DATABASE_SCHEMA: ${{ inputs.DATABASE_SCHEMA }} + BRANCH: ${{ github.ref_name }} diff --git a/src/ispyb/sqlalchemy/_auto_db_schema.py b/src/ispyb/sqlalchemy/_auto_db_schema.py index 92c7633e..d6e41f26 100644 --- a/src/ispyb/sqlalchemy/_auto_db_schema.py +++ b/src/ispyb/sqlalchemy/_auto_db_schema.py @@ -1,4 +1,4 @@ -__schema_version__ = "4.2.0" +__schema_version__ = "4.2.1" # coding: utf-8 from sqlalchemy import ( BINARY, @@ -1697,8 +1697,8 @@ class DiffractionPlan(Base): class LabContact(Base): __tablename__ = "LabContact" __table_args__ = ( - Index("personAndProposal", "personId", "proposalId", unique=True), Index("cardNameAndProposal", "cardName", "proposalId", unique=True), + Index("personAndProposal", "personId", "proposalId", unique=True), ) labContactId = Column(INTEGER(10), primary_key=True)