-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathscaffold-db
More file actions
executable file
·46 lines (38 loc) · 1.48 KB
/
scaffold-db
File metadata and controls
executable file
·46 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env nix-shell
#! nix-shell -i nix -p nix
#! nix shell nixpkgs#bash nixpkgs#dotnet-ef nixpkgs#postgresql nixpkgs#nodejs nixpkgs#dos2unix --command bash
set -ex
rm -rfv Models/Spacebar.Models.Db
# prep temporary db
# - Update collation version for template1 just incase!
psql -U postgres -c 'ALTER DATABASE template1 REFRESH COLLATION VERSION;'
dropdb -U postgres sb-server-scaffold --if-exists --force || true
createdb -U postgres sb-server-scaffold
# - Build spacebar-ts and apply it's migrations
pushd ../..
npm run build:src:tsgo
DATABASE=postgres://postgres@127.0.0.1/sb-server-scaffold npm run apply:migrations
popd
# Create new project
pushd Models
dotnet new classlib --no-restore -o Spacebar.Models.Db
pushd Spacebar.Models.Db
rm Class1.cs
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL -n -f net9.0
dotnet add package Microsoft.EntityFrameworkCore.Design -n -f net9.0
dotnet restore
dotnet-ef dbcontext scaffold "Host=127.0.0.1; Username=postgres; Database=sb-server-scaffold" \
Npgsql.EntityFrameworkCore.PostgreSQL \
-o Models \
-c SpacebarDbContext \
--context-dir Contexts \
--force \
--no-onconfiguring \
--data-annotations
for f in **/*.cs; do
dos2unix --verbose --keepdate "$f"
done
for patch in ../db-patches/*.patch; do
patch --verbose -p2 < $patch
done
echo 'Scaffolded database and applied patches. Dont forget to generate new patches with `cd Models && git diff --relative Spacebar.Models.Db/path/xyz > db-patches/001-your-patch-name.patch!`'