secajs/scripts/create_invite.sh

31 lines
1.1 KiB
Bash
Raw Normal View History

2025-02-09 19:24:29 +01:00
#!/bin/bash
# Load the .env file from the parent directory
source "$(dirname "$0")/../.env"
# Generate a random UUID for the record
UUID=$(uuidgen)
# Create a fake inviter_npub (using a random string here)
INVITER_NPUB="fake_inviter_${RANDOM}"
# Get the current timestamp for created_at
CREATED_AT=$(date +"%Y-%m-%d %H:%M:%S")
# Get the name of the PostgreSQL container from the docker-compose configuration
POSTGRES_CONTAINER_NAME=$(docker compose ps -q postgres | xargs docker inspect --format '{{.Name}}' | sed 's/\///')
# Connect to the Postgres container and insert the fake record into the app_invite table
docker exec -i "$POSTGRES_CONTAINER_NAME" psql -v -U "$POSTGRES_USER" -d "$POSTGRES_DB" -h localhost -p 5432 -c "
2025-02-11 23:27:51 +01:00
INSERT INTO app_invite_created (uuid, inviter_npub, created_at)
2025-02-09 19:24:29 +01:00
VALUES ('$UUID', '$INVITER_NPUB', '$CREATED_AT')
RETURNING *;
"
# Print the generated values
2025-02-11 23:27:51 +01:00
echo "Inserted app_invite_created Record:"
2025-02-09 19:24:29 +01:00
echo "UUID: $UUID"
echo "Inviter Npub: $INVITER_NPUB"
echo "Created At: $CREATED_AT"
2025-02-09 23:15:37 +01:00
echo "Try it at http://localhost/invite/$UUID"