about summary refs log tree commit diff stats
path: root/scripts/mkdb.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mkdb.sh')
-rwxr-xr-xscripts/mkdb.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/mkdb.sh b/scripts/mkdb.sh
new file mode 100755
index 0000000..c9895f8
--- /dev/null
+++ b/scripts/mkdb.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env sh
+
+# rocie - An enterprise grocery management system
+#
+# Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Rocie.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+root="$(dirname "$0")/.."
+db="${DATABASE_URL#sqlite://}"
+
+[ -f "$db" ] && rm "$db"
+[ -d "$root/target" ] || mkdir "$root/target"
+
+fd . "$root/crates/yt/src/storage/migrate/sql" | while read -r sql_file; do
+    echo "Applying sql migration file: $(basename "$sql_file").."
+    {
+        # NOTE(@bpeetz): The wrapping in a transaction is needed to simulate the rust code. <2025-05-07>
+        echo "BEGIN TRANSACTION;"
+        cat "$sql_file"
+        echo "COMMIT TRANSACTION;"
+    } | sqlite3 "$db"
+done
+
+# vim: ft=sh