first commit
This commit is contained in:
34
calcom/scripts/auto-grant.sql
Normal file
34
calcom/scripts/auto-grant.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Create or replace the function to automatically grant permissions to a user when a table is created.
|
||||
CREATE OR REPLACE
|
||||
FUNCTION auto_grant_func()
|
||||
RETURNS event_trigger AS $$
|
||||
|
||||
BEGIN
|
||||
GRANT ALL ON ALL TABLES IN SCHEMA public TO REPLACE_ME_WITH_USERNAME;
|
||||
GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO REPLACE_ME_WITH_USERNAME;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO REPLACE_ME_WITH_USERNAME;
|
||||
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO REPLACE_ME_WITH_USERNAME;
|
||||
END;
|
||||
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- Create event trigger for auto_grant_func
|
||||
CREATE EVENT TRIGGER auto_grant_trigger
|
||||
ON
|
||||
ddl_command_end
|
||||
WHEN TAG IN ('CREATE TABLE', 'CREATE TABLE AS')
|
||||
EXECUTE PROCEDURE auto_grant_func();
|
||||
|
||||
-- Check if auto_grant_func exists
|
||||
SELECT
|
||||
prosrc
|
||||
FROM
|
||||
pg_proc
|
||||
WHERE
|
||||
proname = 'auto_grant_func';
|
||||
|
||||
-- List event triggers
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
pg_event_trigger;
|
||||
24
calcom/scripts/connection-activity.sql
Normal file
24
calcom/scripts/connection-activity.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
-- Check all connection activity
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
pg_stat_activity;
|
||||
|
||||
-- Clear idle connections older than 15 minutes
|
||||
SELECT
|
||||
pg_terminate_backend(pid)
|
||||
FROM
|
||||
pg_stat_activity
|
||||
WHERE
|
||||
state = 'idle'
|
||||
AND
|
||||
state_change < now() - '15min'::INTERVAL;
|
||||
|
||||
-- Check connections by user
|
||||
SELECT
|
||||
usename,
|
||||
count(*)
|
||||
FROM
|
||||
pg_stat_activity
|
||||
GROUP BY
|
||||
usename;
|
||||
18
calcom/scripts/delete-empty-google-credentials.sql
Normal file
18
calcom/scripts/delete-empty-google-credentials.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- Count how many empty google credentials are in the database
|
||||
SELECT
|
||||
count(*)
|
||||
FROM
|
||||
"Credential" c
|
||||
WHERE
|
||||
"key" = '""'
|
||||
AND "type" = 'google_calendar'
|
||||
|
||||
-- Delete empty google credentials
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
"Credential" c
|
||||
DELETE FROM "Credential" c
|
||||
WHERE
|
||||
"key" = '""'
|
||||
AND "type" = 'google_calendar' RETURNING *
|
||||
13
calcom/scripts/find-email-case-insensitive-duplicates.sql
Normal file
13
calcom/scripts/find-email-case-insensitive-duplicates.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Find users with uppercase characters in email
|
||||
SELECT * FROM users u WHERE u.email ~ '[[:upper:]]';
|
||||
|
||||
-- Find emails with case insensitive duplicates
|
||||
SELECT lower(email) FROM users GROUP BY lower(email) HAVING count(*) > 1;
|
||||
|
||||
-- List emails with their case insensitive duplicates
|
||||
SELECT * FROM users u WHERE LOWER(u.email) IN (
|
||||
SELECT lower(email) FROM users GROUP BY lower(email) HAVING count(*) > 1
|
||||
);
|
||||
|
||||
-- Lowercase all user emails (This will fail if there are case insensitive duplicates)
|
||||
UPDATE users SET email = lower(email) WHERE email ~ '[[:upper:]]';
|
||||
22
calcom/scripts/get-table-storage-sizes.sql
Normal file
22
calcom/scripts/get-table-storage-sizes.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
SELECT
|
||||
table_name,
|
||||
pg_size_pretty (table_size) AS table_size,
|
||||
pg_size_pretty (indexes_size) AS indexes_size,
|
||||
pg_size_pretty (total_size) AS total_size
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
table_name,
|
||||
pg_table_size (table_name) AS table_size,
|
||||
pg_indexes_size (table_name) AS indexes_size,
|
||||
pg_total_relation_size (table_name) AS total_size
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
('"' || table_schema || '"."' || table_name || '"') AS table_name
|
||||
FROM
|
||||
information_schema.tables
|
||||
) AS all_tables
|
||||
ORDER BY
|
||||
total_size DESC
|
||||
) AS pretty_sizes;
|
||||
15
calcom/scripts/staging-deploy.sh
Executable file
15
calcom/scripts/staging-deploy.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "VERCEL_GIT_COMMIT_REF: $VERCEL_GIT_COMMIT_REF"
|
||||
|
||||
if [[ "$VERCEL_GIT_COMMIT_REF" == "staging" ]] ; then
|
||||
# Proceed with the build
|
||||
echo "✅ - Build can proceed"
|
||||
./vercel.sh
|
||||
exit 1;
|
||||
|
||||
else
|
||||
# Don't build
|
||||
echo "🛑 - Build cancelled"
|
||||
exit 0;
|
||||
fi
|
||||
76
calcom/scripts/vercel.sh
Executable file
76
calcom/scripts/vercel.sh
Executable file
@@ -0,0 +1,76 @@
|
||||
# We only branch if it's not main or production
|
||||
if [[ ("$VERCEL_GIT_COMMIT_REF" == "main") || ("$VERCEL_GIT_COMMIT_REF" == "production") ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# We don't have snaplet installed on the CI, so we use this script to get it temporarily.
|
||||
curl -sL https://app.snaplet.dev/get-cli/ | bash &>/dev/null
|
||||
export PATH=/vercel/.local/bin/:$PATH
|
||||
|
||||
if [ "$VERCEL_GIT_COMMIT_SHA" == "" ]; then
|
||||
echo "Error: VERCEL_GIT_COMMIT_SHA is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$VERCEL_TOKEN" == "" ]; then
|
||||
echo "Error: VERCEL_TOKEN is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$VERCEL_PROJECT_ID" == "" ]; then
|
||||
echo "Error: VERCEL_PROJECT_ID is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$SNAPLET_ACCESS_TOKEN" == "" ]; then
|
||||
echo "Error: SNAPLET_ACCESS_TOKEN is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$SNAPLET_PROJECT_ID" == "" ]; then
|
||||
echo "Error: SNAPLET_PROJECT_ID is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# stop execution on error - don't let it build if something goes wrong
|
||||
set -e
|
||||
|
||||
# Create new snaplet instant db for this branch
|
||||
snaplet db create --git --latest
|
||||
|
||||
# Save the new snaplet instant db url
|
||||
NEW_DATABASE_URL=$(snaplet db url --git)
|
||||
|
||||
if [ "$NEW_DATABASE_URL" == "" ]; then
|
||||
echo "Error: NEW_DATABASE_URL is empty"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$VERCEL_ORG_ID" == "" ]; then
|
||||
# Use this for personal projects
|
||||
VERCEL_PROJECT_ENDPOINT=$(echo "https://api.vercel.com/v1/projects/$VERCEL_PROJECT_ID/env")
|
||||
else
|
||||
# Use this for team projects
|
||||
VERCEL_PROJECT_ENDPOINT=$(echo "https://api.vercel.com/v1/projects/$VERCEL_PROJECT_ID/env?teamId=$VERCEL_ORG_ID")
|
||||
fi
|
||||
|
||||
echo "calling... $VERCEL_PROJECT_ENDPOINT"
|
||||
# We update DATABASE_URL using Vercel API
|
||||
curl -f -sS -o /dev/null -X POST "$VERCEL_PROJECT_ENDPOINT" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H "Authorization: Bearer $VERCEL_TOKEN" \
|
||||
--data-raw '{
|
||||
"target": "preview",
|
||||
"gitBranch": "'$VERCEL_GIT_COMMIT_REF'",
|
||||
"type": "encrypted",
|
||||
"key": "DATABASE_URL",
|
||||
"value": "'$NEW_DATABASE_URL'"
|
||||
}'
|
||||
res=$?
|
||||
if test "$res" != "0"; then
|
||||
echo "the curl command failed with: $res"
|
||||
exit 0
|
||||
else
|
||||
echo "Successfully updated DATABASE_URL"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user