-
Notifications
You must be signed in to change notification settings - Fork 26
/
dbdoc-ci.sh
executable file
·73 lines (59 loc) · 2.01 KB
/
dbdoc-ci.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## Prerequisites:
## - IaSQL running locally
## - Added a db called iasql using organization credentials
#!/bin/bash
# Fail on error
set -e
# IaSQL db connect
echo "\Connecting an iasql db..."
psql postgres://postgres:test@localhost:5432/iasql_metadata -c "SELECT * FROM iasql_connect('iasql');"
# Setup Account
echo "\nInstalling aws_account..."
psql postgres://postgres:test@localhost:5432/iasql -c "
select iasql_install(
'aws_account'
);
";
echo "\nAttaching credentials..."
psql postgres://postgres:test@localhost:5432/iasql -c "
INSERT INTO aws_credentials (access_key_id, secret_access_key)
VALUES ('${AWS_ACCESS_KEY_ID}', '${AWS_SECRET_ACCESS_KEY}');
";
psql postgres://postgres:test@localhost:5432/iasql -c "
SELECT * FROM default_aws_region('${AWS_REGION}');
";
# TODO how to install all and get latest engine version?
echo "\nInstalling all modules in iasql db..."
psql postgres://postgres:test@localhost:5432/iasql -c "
select iasql_install(
variadic array(select module_name from iasql_modules_list() where module_name != 'aws_account' and module_name not like 'iasql_%')
);
";
echo "\nSet working directory to examples/ecs-fargate/prisma/infra"
cd examples/ecs-fargate/prisma/infra
# Install npm modules
echo "\nInstall npm modules"
npm install
npm install -D prisma-dbml-generator
echo "\nCreate a basic schema.prisma file"
mkdir prisma
echo 'datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator dbml {
provider = "prisma-dbml-generator"
outputName = "iasql.dbml"
projectName = "IaSQL"
projectDatabaseType = "PostgreSQL"
projectNote = "https://iasql.com"
}' > prisma/schema.prisma
echo "\nIntrospect schema"
npx prisma db pull
echo "\nReplace unsupported types"
cat prisma/schema.prisma | sed 's/Unsupported..cidr../String/g' > prisma/out.prisma
rm prisma/schema.prisma; mv prisma/out.prisma prisma/schema.prisma
echo "\nGenerate dbml from prisma schema"
npx prisma generate
echo "\nUploading new dbml to dbdocs..."
dbdocs build prisma/dbml/iasql.dbml --project=iasql