From bde668c467ad657534e6111855f9b4fd2aa4f66f Mon Sep 17 00:00:00 2001 From: Igor Shishkin Date: Wed, 27 Nov 2024 01:37:12 +0300 Subject: [PATCH] Add check constraints for container.version_ttl_seconds and blobs.size (#268) To ensure data integrity Ref: #196 Signed-off-by: Igor Shishkin --- ...re_containers_versions_ttl_and_blobs_size.down.sql | 11 +++++++++++ ...sure_containers_versions_ttl_and_blobs_size.up.sql | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.down.sql create mode 100644 repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.up.sql diff --git a/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.down.sql b/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.down.sql new file mode 100644 index 0000000..23e322e --- /dev/null +++ b/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.down.sql @@ -0,0 +1,11 @@ +BEGIN; + +ALTER TABLE blobs + DROP CONSTRAINT size_range +; + +ALTER TABLE containers + DROP CONSTRAINT version_ttl_seconds_range +; + +COMMIT; diff --git a/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.up.sql b/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.up.sql new file mode 100644 index 0000000..c3835ba --- /dev/null +++ b/repositories/metadata/postgresql/migrations/sql/0007_ensure_containers_versions_ttl_and_blobs_size.up.sql @@ -0,0 +1,11 @@ +BEGIN; + +ALTER TABLE blobs + ADD CONSTRAINT size_range CHECK (size >= 0) +; + +ALTER TABLE containers + ADD CONSTRAINT version_ttl_seconds_range CHECK (version_ttl_seconds >= -1) +; + +COMMIT;