diff --git a/.github/workflows/sync-staging-db.yml b/.github/workflows/sync-staging-db.yml index 32d18e9f23..a32252d592 100644 --- a/.github/workflows/sync-staging-db.yml +++ b/.github/workflows/sync-staging-db.yml @@ -19,6 +19,11 @@ jobs: working-directory: infrastructure/application env: PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }} + - run: | + echo "PG_URL=$(pulumi stack output --stack staging --show-secrets dbRootUrl)" >> $GITHUB_ENV + working-directory: infrastructure/data + env: + PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }} - uses: actions/setup-node@v2 with: node-version: ${{ env.NODE_VERSION }} diff --git a/api.planx.uk/helpers.ts b/api.planx.uk/helpers.ts index 1a4307f76c..4fca1dab86 100644 --- a/api.planx.uk/helpers.ts +++ b/api.planx.uk/helpers.ts @@ -25,7 +25,7 @@ const getMostRecentPublishedFlow = async (id: string) => { ` query GetMostRecentPublishedFlow($id: uuid!) { flows_by_pk(id: $id) { - published_flows(limit: 1, order_by: { created_at: desc }) { + published_flows(limit: 1, order_by: { id: desc }) { data } } diff --git a/docker-compose.yml b/docker-compose.yml index dafa38b85f..d3e63cfe71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -114,6 +114,7 @@ services: HASURA_GRAPHQL_URL: http://hasura-proxy:7000/v1/graphql HASURA_GRAPHQL_ENDPOINT: http://hasura-proxy:7000/ PRODUCTION_GRAPHQL_URL: 'https://hasura.editor.planx.uk/v1/graphql' + PG_URL: postgres://${PG_USERNAME}:${PG_PASSWORD}@postgres/${PG_DATABASE} api: restart: unless-stopped build: diff --git a/scripts/seed-database/Dockerfile b/scripts/seed-database/Dockerfile index de52a5b616..0da605616e 100644 --- a/scripts/seed-database/Dockerfile +++ b/scripts/seed-database/Dockerfile @@ -4,6 +4,7 @@ RUN npm install -g hasura-cli WORKDIR /scripts/ RUN npm install -g pnpm@7.8.0 COPY pnpm-lock.yaml . +RUN apk add postgresql-client RUN pnpm fetch --prod ADD . . diff --git a/scripts/seed-database/fix_id_sequence.sql b/scripts/seed-database/fix_id_sequence.sql new file mode 100644 index 0000000000..39ab3744cd --- /dev/null +++ b/scripts/seed-database/fix_id_sequence.sql @@ -0,0 +1 @@ +SELECT setval('published_flows_id_seq', max(id)) FROM published_flows; diff --git a/scripts/seed-database/seed-db.sh b/scripts/seed-database/seed-db.sh index 891565017f..4dad588d8e 100644 --- a/scripts/seed-database/seed-db.sh +++ b/scripts/seed-database/seed-db.sh @@ -4,4 +4,7 @@ hasura seeds apply cd /scripts/ -pnpm upsert-flows \ No newline at end of file +pnpm upsert-flows + +echo "Fixing published_flows id sequence" +psql "${PG_URL}" < "./fix_id_sequence.sql" \ No newline at end of file