diff --git a/internal/db/schema/migrations/oss/postgres/82/06_storage_policy_max_days.up.sql b/internal/db/schema/migrations/oss/postgres/82/06_storage_policy_max_days.up.sql new file mode 100644 index 0000000000..f34ab64bc4 --- /dev/null +++ b/internal/db/schema/migrations/oss/postgres/82/06_storage_policy_max_days.up.sql @@ -0,0 +1,12 @@ +-- Copyright (c) HashiCorp, Inc. +-- SPDX-License-Identifier: BUSL-1.1 + +begin; + + alter table policy_storage_policy + add constraint delete_after_days_less_than_100_years + check(delete_after_days <= 36525), + add constraint retain_for_days_less_than_100_years + check(retain_for_days <= 36525); + +commit; diff --git a/internal/db/sqltest/tests/policy/policy_storage_policy.sql b/internal/db/sqltest/tests/policy/policy_storage_policy.sql index 676bd15cda..d2bf08d5a4 100644 --- a/internal/db/sqltest/tests/policy/policy_storage_policy.sql +++ b/internal/db/sqltest/tests/policy/policy_storage_policy.sql @@ -3,7 +3,7 @@ begin; - select plan(8); + select plan(12); -- helper statements for resetting test env prepare delete_policy_storage_policy_resource as @@ -44,4 +44,20 @@ begin; select throws_ok('insert_policy_delete_after_less_than_retain', 23514, null, 'delete_after must be greater than or equal to retain_for'); select lives_ok('delete_policy_storage_policy_resource', 'policy_storage_policy cleanup'); + prepare retain_for_days_max as + insert into policy_storage_policy + (public_id, scope_id, retain_for_days, delete_after_days) + values + ('pst__bcolors', 'global', 40000, 0); + select throws_ok('retain_for_days_max', 23514); + select lives_ok('delete_policy_storage_policy_resource', 'policy_storage_policy cleanup'); + + prepare delete_after_days_max as + insert into policy_storage_policy + (public_id, scope_id, retain_for_days, delete_after_days) + values + ('pst__bcolors', 'global', 0, 40000); + select throws_ok('delete_after_days_max', 23514); + select lives_ok('delete_policy_storage_policy_resource', 'policy_storage_policy cleanup'); + rollback;