summaryrefslogtreecommitdiff
path: root/psql
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-23 10:39:16 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-23 10:39:16 -0500
commitde9cae795f93d03e68d965c59af4b21d96df4ec7 (patch)
treead4f903c04630b3b92e2b9b5d06d5b8647d299bb /psql
parentlicense (diff)
downloadcrimson-de9cae795f93d03e68d965c59af4b21d96df4ec7.tar.gz
crimson-de9cae795f93d03e68d965c59af4b21d96df4ec7.tar.bz2
crimson-de9cae795f93d03e68d965c59af4b21d96df4ec7.zip
initial
Diffstat (limited to 'psql')
-rwxr-xr-xpsql45
1 files changed, 45 insertions, 0 deletions
diff --git a/psql b/psql
new file mode 100755
index 0000000..71071a4
--- /dev/null
+++ b/psql
@@ -0,0 +1,45 @@
+#!/bin/sh
+### CRIMSON --- A simple PHP framework.
+### Copyright © 2024 Freya Murphy <contact@freyacat.org>
+###
+### This file is part of CRIMSON.
+###
+### CRIMSON is free software; you can redistribute it and/or modify it
+### under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 3 of the License, or (at
+### your option) any later version.
+###
+### CRIMSON is distributed in the hope that it will be useful, but
+### WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>.
+
+# `psql`
+# This is an alias for running
+# $ `compose` exec postgres psql -U $POSTGRES_USER $POSTGRES_DB.
+#
+# When working on a crimson project, you will likely have to lurk within the
+# database at times. This makes it nicer enter it since you dont have to type
+# the full command. :)
+
+# ================================================================ CONSTANTS ==
+# ROOT: This is the folder the crimson project is located in. ROOT is used to
+# load the crimson environment. We need this since that is where POSTGRES_USER
+# and POSTGRES_DB are stored.
+# CALL_ROOT: This is the folder that the user who called `compose` is currently
+# in. For crimson to work this must be the folder that your project using
+# crimson is. This is because crimson loads `.env` here to load any user
+# specified environment. `.env` is needed in cause you override POSTGRES_USER
+# and/or POSTGRES_DB.
+ROOT="$(dirname "$0")"
+CALL_ROOT="$(pwd)"
+
+# ================================================================ BOOTSTRAP ==
+# Load `base.env` and `.env`, then launch psql in docker.
+
+source "$ROOT/base.env"
+source "$CALL_ROOT/.env"
+$ROOT/compose exec postgres psql -U "${POSTGRES_USER}" "${POSTGRES_DB}"