Skip to content

Commit

Permalink
feat: save indexer data in db
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Nov 12, 2024
1 parent acb9205 commit a6e85dd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions indexer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ echo "Generated user: $NEW_DB_USER"
# Set PGPASSWORD to handle password prompt
export PGPASSWORD=$DB_PASSWORD

# Fetch metadata and extract service name in one command
service_name=$(aws ecs describe-tasks \
--cluster "$(curl -s http://169.254.170.2/v4/task | jq -r '.Cluster')" \
--tasks "$(curl -s http://169.254.170.2/v4/task | jq -r '.TaskARN' | awk -F'/' '{print $NF}')" \
--query 'tasks[0].group' --output text | sed 's|service:||')

echo "Service Name: $service_name"

# Connect to the database and create the new schema and user
psql -v ON_ERROR_STOP=1 --username "$DB_USER" --dbname "$DB_NAME" --host "$DB_HOST" --port "$DB_PORT" <<-EOSQL
CREATE SCHEMA $NEW_SCHEMA_NAME;
Expand All @@ -32,6 +40,10 @@ psql -v ON_ERROR_STOP=1 --username "$DB_USER" --dbname "$DB_NAME" --host "$DB_HO
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA $NEW_SCHEMA_NAME TO $API_READER_USER;
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $NEW_DB_USER;
ALTER USER $NEW_DB_USER SET search_path TO $NEW_SCHEMA_NAME;
-- Insert a new record into the indexers table
INSERT INTO indexers (service, schema, db_user, created_at)
VALUES ('$service_name', '$NEW_SCHEMA_NAME', '$NEW_DB_USER', NOW());
EOSQL

# Unset PGPASSWORD
Expand Down

0 comments on commit a6e85dd

Please sign in to comment.