From acec2f2cf09d4db223cb81c5dd3c12bab61fa6de Mon Sep 17 00:00:00 2001 From: Davron Date: Sun, 25 Jul 2021 17:10:05 +0500 Subject: [PATCH 1/2] feat: add foreign key param on column creation --- README.md | 11 +++++++++++ src/lib/PostgresMetaColumns.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6fb78170..e24760da 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries (and more). +### Environment variables +```shell +PG_META_DB_HOST = ${PG_META_DB_HOST} +PG_META_DB_NAME = ${PG_META_DB_NAME} +PG_META_DB_USER = ${PG_META_DB_USER} +PG_META_DB_PASSWORD = ${PG_META_DB_PASSWORD} +PG_META_DB_PORT = ${PG_META_DB_PORT} +PG_META_PORT = ${PG_META_PORT} +``` + + ## Documentation https://supabase.github.io/postgres-meta/ diff --git a/src/lib/PostgresMetaColumns.ts b/src/lib/PostgresMetaColumns.ts index 0a10b815..c1a56dab 100644 --- a/src/lib/PostgresMetaColumns.ts +++ b/src/lib/PostgresMetaColumns.ts @@ -91,7 +91,8 @@ export default class PostgresMetaColumns { is_unique = false, comment, check, - }: { + foreign_table, + }: { table_id: number name: string type: string @@ -103,6 +104,7 @@ export default class PostgresMetaColumns { is_primary_key?: boolean is_unique?: boolean comment?: string + foreign_table?: string check?: string }): Promise> { const { data, error } = await this.metaTables.retrieve({ id: table_id }) @@ -126,6 +128,7 @@ export default class PostgresMetaColumns { } const isPrimaryKeyClause = is_primary_key ? 'PRIMARY KEY' : '' const isUniqueClause = is_unique ? 'UNIQUE' : '' + const foreignClause = foreign_table ? `references ${ident(foreign_table)}` : ''; const checkSql = check === undefined ? '' : `CHECK (${check})` const commentSql = comment === undefined @@ -140,7 +143,8 @@ BEGIN; ${isNullableClause} ${isPrimaryKeyClause} ${isUniqueClause} - ${checkSql}; + ${checkSql} + ${foreignClause}; ${commentSql}; COMMIT;` { From ffdcefbda10ff74e247c39b0ca7bb2c4faf577e7 Mon Sep 17 00:00:00 2001 From: Davron Date: Sun, 25 Jul 2021 17:53:29 +0500 Subject: [PATCH 2/2] chore: Disable tests/docs ci, change github action deployment to dockerhub --- .github/workflows/ci.yml | 43 -------------- .github/workflows/docs.yml | 44 -------------- .github/workflows/release.yml | 109 +++++++++++++++++----------------- 3 files changed, 54 insertions(+), 142 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 9091173a..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: CI - -on: - pull_request: - push: - branches: - - master - workflow_dispatch: - -jobs: - test: - name: Test / OS ${{ matrix.platform }} / Node ${{ matrix.node }} - strategy: - fail-fast: false - matrix: - platform: [ubuntu-latest] - node: ['12'] - - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v2 - - - name: Set up DB - run: docker-compose up -d - - - uses: actions/cache@v1 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Set up Node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - - run: | - npm ci - npm run dev & - sleep 30 - npm test diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 338d6d1c..00000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Docs - -on: - push: - branches: - - master - workflow_dispatch: - -jobs: - docs: - name: Publish docs / OS ${{ matrix.os }} / Node ${{ matrix.node }} - strategy: - matrix: - os: - - ubuntu-latest - node: - - '12' - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - - - run: | - npm ci - npm run docs:export - - - name: Generate Swagger UI - uses: Legion2/swagger-ui-action@v1 - with: - output: docs - spec-file: openapi.json - - - name: Publish - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: docs - force_orphan: true - commit_message: 'docs: update' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c7011b97..786c9064 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,16 +28,16 @@ jobs: npm run build - name: Get version before - run: echo "VERSION_BEFORE=$(curl -s https://api.github.com/repos/supabase/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV + run: echo "VERSION_BEFORE=$(curl -s https://api.github.com/repos/DavraYoung/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV - - name: Release on GitHub - run: npx semantic-release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} +# - name: Release on GitHub +# run: npx semantic-release +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Get version after - run: echo "VERSION_AFTER=$(curl -s https://api.github.com/repos/supabase/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV + run: echo "VERSION_AFTER=$(curl -s https://api.github.com/repos/DavraYoung/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV - name: Check version difference run: | @@ -89,60 +89,59 @@ jobs: with: node-version: ${{ matrix.node }} - - name: Prepare release - if: env.HAS_NEW_RELEASE == 1 - run: | - npm ci - npm run pkg - tar -czvf postgres-meta-linux.tar.gz -C ./bin postgres-meta-linux - tar -czvf postgres-meta-macos.tar.gz -C ./bin postgres-meta-macos - tar -czvf postgres-meta-windows.tar.gz -C ./bin postgres-meta-win.exe - - - name: Get upload url - if: env.HAS_NEW_RELEASE == 1 - run: echo "UPLOAD_URL=$(curl -s https://api.github.com/repos/supabase/postgres-meta/releases/latest | jq .upload_url -r)" >> $GITHUB_ENV - - - name: Upload linux release asset - if: env.HAS_NEW_RELEASE == 1 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ env.UPLOAD_URL }} - asset_path: ./postgres-meta-linux.tar.gz - asset_name: postgres-meta-linux.tar.gz - asset_content_type: application/gzip - - - name: Upload macos release asset - if: env.HAS_NEW_RELEASE == 1 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ env.UPLOAD_URL }} - asset_path: ./postgres-meta-macos.tar.gz - asset_name: postgres-meta-macos.tar.gz - asset_content_type: application/gzip - - - name: Upload windows release asset - if: env.HAS_NEW_RELEASE == 1 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ env.UPLOAD_URL }} - asset_path: ./postgres-meta-windows.tar.gz - asset_name: postgres-meta-windows.tar.gz - asset_content_type: application/gzip +# - name: Prepare release +# if: env.HAS_NEW_RELEASE == 1 +# run: | +# npm ci +# npm run pkg +# tar -czvf postgres-meta-linux.tar.gz -C ./bin postgres-meta-linux +# tar -czvf postgres-meta-macos.tar.gz -C ./bin postgres-meta-macos +# tar -czvf postgres-meta-windows.tar.gz -C ./bin postgres-meta-win.exe + +# - name: Get upload url +# if: env.HAS_NEW_RELEASE == 1 +# run: echo "UPLOAD_URL=$(curl -s https://api.github.com/repos/DavraYoung/postgres-meta/releases/latest | jq .upload_url -r)" >> $GITHUB_ENV +# +# - name: Upload linux release asset +# if: env.HAS_NEW_RELEASE == 1 +# uses: actions/upload-release-asset@v1 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# with: +# upload_url: ${{ env.UPLOAD_URL }} +# asset_path: ./postgres-meta-linux.tar.gz +# asset_name: postgres-meta-linux.tar.gz +# asset_content_type: application/gzip +# +# - name: Upload macos release asset +# if: env.HAS_NEW_RELEASE == 1 +# uses: actions/upload-release-asset@v1 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# with: +# upload_url: ${{ env.UPLOAD_URL }} +# asset_path: ./postgres-meta-macos.tar.gz +# asset_name: postgres-meta-macos.tar.gz +# asset_content_type: application/gzip +# +# - name: Upload windows release asset +# if: env.HAS_NEW_RELEASE == 1 +# uses: actions/upload-release-asset@v1 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# with: +# upload_url: ${{ env.UPLOAD_URL }} +# asset_path: ./postgres-meta-windows.tar.gz +# asset_name: postgres-meta-windows.tar.gz +# asset_content_type: application/gzip - name: Get version - run: echo "VERSION=$(curl -s https://api.github.com/repos/supabase/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV + run: echo "VERSION=$(curl -s https://api.github.com/repos/DavraYoung/postgres-meta/releases/latest | jq .name -r)" >> $GITHUB_ENV - name: Upload image to Docker Hub - if: env.HAS_NEW_RELEASE == 1 uses: docker/build-push-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - repository: supabase/postgres-meta + repository: davronsherbaev/jidoca-meta tags: latest,${{ env.VERSION }}