Author: Kevin Schoon [me@kevinschoon.com]
Hash: b88993d283a49b0b95db82e3621e36f751ebfc3d
Timestamp: Sun, 14 Apr 2024 09:39:59 +0000 (3 months ago)

+24 -35 +/-7 browse
improve development scripts for database creation
improve development scripts for database creation

This standardizes the creation of sqlite databases for use in testing and
the compilation process.

Prior to compiling each component you need to:

Usage:

scripts/ensure-db.sh $COMPONENT
1diff --git a/.env b/.env
2deleted file mode 100644
3index 3144d47..0000000
4--- a/.env
5+++ /dev/null
6 @@ -1 +0,0 @@
7- DATABASE_URL=sqlite://db/ayllu.db
8 diff --git a/ayllu-build/.env b/ayllu-build/.env
9index 454b3de..eab74de 100644
10--- a/ayllu-build/.env
11+++ b/ayllu-build/.env
12 @@ -1 +1 @@
13- DATABASE_URL=sqlite://ayllu-build/db/ayllu-build.db
14+ DATABASE_URL=sqlite://./db/ayllu-build.db
15 diff --git a/ayllu-xmpp/.env b/ayllu-xmpp/.env
16index e4a88c4..5f37ab5 100644
17--- a/ayllu-xmpp/.env
18+++ b/ayllu-xmpp/.env
19 @@ -1 +1 @@
20- DATABASE_URL=sqlite://ayllu-xmpp/db/ayllu-xmpp.db
21+ DATABASE_URL=sqlite://./db/ayllu-xmpp.db
22 diff --git a/ayllu/.env b/ayllu/.env
23new file mode 100644
24index 0000000..62858e4
25--- /dev/null
26+++ b/ayllu/.env
27 @@ -0,0 +1 @@
28+ DATABASE_URL=sqlite://./db/ayllu.db
29 diff --git a/db/.gitkeep b/db/.gitkeep
30deleted file mode 100644
31index e69de29..0000000
32--- a/db/.gitkeep
33+++ /dev/null
34 diff --git a/scripts/ensure_database.sh b/scripts/ensure_database.sh
35new file mode 100755
36index 0000000..8e344f6
37--- /dev/null
38+++ b/scripts/ensure_database.sh
39 @@ -0,0 +1,21 @@
40+ #!/bin/sh
41+ set -e
42+ # initialize a local database for builds and testing assuming the package
43+ # has database support.
44+
45+ COMPONENT="$1"
46+
47+ if [ ! -n "$COMPONENT" ] ; then
48+ COMPONENT="ayllu"
49+ fi
50+
51+ DB_PATH="db/$COMPONENT.db"
52+ DB_URL="sqlite://${DB_PATH}"
53+
54+ mkdir -p "$(dirname "${DB_PATH}")"
55+
56+ if [ ! -f ${DB_PATH} ]; then
57+ sqlx database create --database-url "${DB_URL}"
58+ fi
59+
60+ sqlx migrate run --source "$COMPONENT/migrations" --database-url "${DB_URL}"
61 diff --git a/scripts/init_db_if_missing.sh b/scripts/init_db_if_missing.sh
62deleted file mode 100755
63index 93e125b..0000000
64--- a/scripts/init_db_if_missing.sh
65+++ /dev/null
66 @@ -1,32 +0,0 @@
67- #!/bin/sh
68-
69- DB_PATH="db/ayllu.db"
70- DB_URL="sqlite://${DB_PATH}"
71-
72- mkdir -p "$(dirname "${DB_PATH}")"
73-
74- if [ ! -f ${DB_PATH} ]; then
75- sqlx database create --database-url "${DB_URL}"
76- sqlx migrate run --database-url "${DB_URL}"
77- fi
78-
79- DB_PATH="ayllu-xmpp/db/ayllu-xmpp.db"
80- DB_URL="sqlite://${DB_PATH}"
81-
82- mkdir -p "$(dirname "${DB_PATH}")"
83-
84- if [ ! -f "${DB_PATH}" ]; then
85- sqlx database create --database-url "${DB_URL}"
86- sqlx migrate run --source ayllu-xmpp/migrations --database-url "${DB_URL}"
87- fi
88-
89-
90- DB_PATH="ayllu-build/db/ayllu-build.db"
91- DB_URL="sqlite://${DB_PATH}"
92-
93- mkdir -p "$(dirname "${DB_PATH}")"
94-
95- if [ ! -f "${DB_PATH}" ]; then
96- sqlx database create --database-url "${DB_URL}"
97- sqlx migrate run --source ayllu-build/migrations --database-url "${DB_URL}"
98- fi