-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to create dbml file (#1421)
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Create dbml from database | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update_dbdocs: | ||
name: Create trs.dbml | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:15 | ||
env: | ||
POSTGRES_PASSWORD: trs | ||
POSTGRES_DB: trs | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: extractions/setup-just@v2 | ||
|
||
- name: Install postgresql-client | ||
run: | | ||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null | ||
sudo apt update | ||
sudo apt install postgresql-client-15 -y | ||
- name: Update DB schema | ||
run: dotnet run --project TeachingRecordSystem/src/TeachingRecordSystem.Cli -- migrate-db --connection-string "Host=localhost;Username=postgres;Password=trs;Database=trs" | ||
|
||
- name: Dump database | ||
run: | | ||
export PGHOST="localhost" | ||
export PGDATABASE="trs" | ||
export PGUSER="postgres" | ||
export PGPASSWORD="trs" | ||
psql -c '\dt' | sed '1,3d' | head -n -2 | sed 's/ //g' | cut -d'|' -f 2 | tr '\n' ' ' | xargs printf -- ' -t %s' | xargs pg_dump --schema-only >trs.dump | ||
- name: Create dbml file | ||
run: npx -p @dbml/cli sql2dbml trs.dump --postgres -o trs.dbml | ||
|
||
- name: Publish dbml file | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: trs.dbml | ||
path: trs.dbml | ||
if-no-files-found: error |