Update SQL queries to use more descriptive column aliases

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-07-22 22:24:00 -06:00
parent d295dda6b3
commit cb4f69884a
8 changed files with 17 additions and 16 deletions

View File

@@ -1,6 +1,6 @@
-- name: DatabasesServiceGetDatabase :one
SELECT
*,
pgp_sym_decrypt(connection_string::bytea, @encryption_key) AS connection_string
pgp_sym_decrypt(connection_string::bytea, @encryption_key) AS decrypted_connection_string
FROM databases
WHERE id = @id;

View File

@@ -4,7 +4,7 @@ SELECT COUNT(*) FROM databases;
-- name: DatabasesServicePaginateDatabases :many
SELECT
*,
pgp_sym_decrypt(connection_string::bytea, @encryption_key) AS connection_string
pgp_sym_decrypt(connection_string::bytea, @encryption_key) AS decrypted_connection_string
FROM databases
ORDER BY created_at DESC
LIMIT sqlc.arg('limit') OFFSET sqlc.arg('offset');

View File

@@ -1,7 +1,7 @@
-- name: DestinationsServiceGetDestination :one
SELECT
*,
pgp_sym_decrypt(access_key::bytea, @encryption_key) AS access_key,
pgp_sym_decrypt(secret_key::bytea, @encryption_key) AS secret_key
pgp_sym_decrypt(access_key::bytea, @encryption_key) AS decrypted_access_key,
pgp_sym_decrypt(secret_key::bytea, @encryption_key) AS decrypted_secret_key
FROM destinations
WHERE id = @id;

View File

@@ -4,8 +4,8 @@ SELECT COUNT(*) FROM destinations;
-- name: DestinationsServicePaginateDestinations :many
SELECT
*,
pgp_sym_decrypt(access_key::bytea, @encryption_key) AS access_key,
pgp_sym_decrypt(secret_key::bytea, @encryption_key) AS secret_key
pgp_sym_decrypt(access_key::bytea, @encryption_key) AS decrypted_access_key,
pgp_sym_decrypt(secret_key::bytea, @encryption_key) AS decrypted_secret_key
FROM destinations
ORDER BY created_at DESC
LIMIT sqlc.arg('limit') OFFSET sqlc.arg('offset');

View File

@@ -50,7 +50,7 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
})
}
err = s.ints.PGDumpClient.Ping(pgVersion, back.DatabaseConnectionString)
err = s.ints.PGDumpClient.Ping(pgVersion, back.DecryptedDatabaseConnectionString)
if err != nil {
return updateExec(dbgen.ExecutionsServiceUpdateExecutionParams{
ID: ex.ID,
@@ -61,7 +61,7 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
}
dumpBytes, err := s.ints.PGDumpClient.DumpZip(
pgVersion, back.DatabaseConnectionString, pgdump.DumpParams{
pgVersion, back.DecryptedDatabaseConnectionString, pgdump.DumpParams{
DataOnly: back.BackupOptDataOnly,
SchemaOnly: back.BackupOptSchemaOnly,
Clean: back.BackupOptClean,
@@ -88,8 +88,9 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
path := strutil.CreatePath(false, back.BackupDestDir, date, file)
_, err = s.ints.S3Client.Upload(
back.DestinationAccessKey, back.DestinationSecretKey, back.DestinationRegion,
back.DestinationEndpoint, back.DestinationBucketName, path, dumpBytes,
back.DecryptedDestinationAccessKey, back.DecryptedDestinationSecretKey,
back.DestinationRegion, back.DestinationEndpoint, back.DestinationBucketName,
path, dumpBytes,
)
if err != nil {
return updateExec(dbgen.ExecutionsServiceUpdateExecutionParams{

View File

@@ -11,7 +11,7 @@ SELECT
pgp_sym_decrypt(
databases.connection_string::bytea, @encryption_key
) AS database_connection_string,
) AS decrypted_database_connection_string,
databases.pg_version as database_pg_version,
destinations.bucket_name as destination_bucket_name,
@@ -19,10 +19,10 @@ SELECT
destinations.endpoint as destination_endpoint,
pgp_sym_decrypt(
destinations.access_key::bytea, @encryption_key
) AS destination_access_key,
) AS decrypted_destination_access_key,
pgp_sym_decrypt(
destinations.secret_key::bytea, @encryption_key
) AS destination_secret_key
) AS decrypted_destination_secret_key
FROM backups
JOIN databases ON backups.database_id = databases.id
JOIN destinations ON backups.destination_id = destinations.id

View File

@@ -27,7 +27,7 @@ func (s *Service) SoftDeleteExecution(
if execution.ExecutionPath.Valid {
err := s.ints.S3Client.Delete(
execution.DestinationAccessKey, execution.DestinationSecretKey,
execution.DecryptedDestinationAccessKey, execution.DecryptedDestinationSecretKey,
execution.DestinationRegion, execution.DestinationEndpoint,
execution.DestinationBucketName, execution.ExecutionPath.String,
)

View File

@@ -10,10 +10,10 @@ SELECT
destinations.endpoint as destination_endpoint,
pgp_sym_decrypt(
destinations.access_key::bytea, @encryption_key
) AS destination_access_key,
) AS decrypted_destination_access_key,
pgp_sym_decrypt(
destinations.secret_key::bytea, @encryption_key
) AS destination_secret_key
) AS decrypted_destination_secret_key
FROM executions
JOIN backups ON backups.id = executions.backup_id
JOIN destinations ON destinations.id = backups.destination_id