Skip to content

Commit 7acc730

Browse files
Merge pull request #5021 from hashicorp/backport/louis-org-policy/lightly-helping-werewolf
This pull request was automerged via backport-assistant
2 parents 57dfbba + f66fc79 commit 7acc730

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

internal/db/schema/migrations/oss/postgres/82/01_storage_policies.up.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ begin;
66
create table policy (
77
public_id wt_public_id primary key,
88
scope_id wt_scope_id not null
9+
-- constraints replaced in internal/db/schema/migrations/postgres/91/01_storage_policies.up.sql
910
constraint policy_scope_id_fkey
1011
references iam_scope(public_id)
1112
on delete restrict
@@ -17,6 +18,7 @@ comment on table policy is
1718
create table policy_storage_policy (
1819
public_id wt_public_id primary key,
1920
scope_id wt_scope_id not null
21+
-- constraints replaced in internal/db/schema/migrations/postgres/91/01_storage_policies.up.sql
2022
constraint policy_storage_policy_scope_id_fkey
2123
references iam_scope(public_id)
2224
on delete restrict
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Copyright (c) HashiCorp, Inc.
2+
-- SPDX-License-Identifier: BUSL-1.1
3+
4+
begin;
5+
6+
-- replaces constraints from internal/db/schema/migrations/postgres/82/01_storage_policies.up.sql
7+
alter table policy
8+
drop constraint policy_scope_id_fkey;
9+
alter table policy
10+
add constraint policy_scope_id_fkey
11+
foreign key (scope_id)
12+
references iam_scope(public_id)
13+
on delete cascade
14+
on update cascade;
15+
16+
alter table policy_storage_policy
17+
drop constraint policy_storage_policy_scope_id_fkey;
18+
alter table policy_storage_policy
19+
add constraint policy_storage_policy_scope_id_fkey
20+
foreign key (scope_id)
21+
references iam_scope(public_id)
22+
on delete cascade
23+
on update cascade;
24+
25+
commit;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Copyright (c) HashiCorp, Inc.
2+
-- SPDX-License-Identifier: BUSL-1.1
3+
4+
begin;
5+
6+
select plan(6);
7+
8+
-- create a storage policy
9+
prepare insert_policy as
10+
insert into policy_storage_policy
11+
(public_id, scope_id, retain_for_days, delete_after_days)
12+
values
13+
('pst_test1234', 'o__foodtruck', 1, 0);
14+
select lives_ok('insert_policy');
15+
16+
select is(count(*), 1::bigint) from policy_storage_policy where public_id = 'pst_test1234';
17+
select is(count(*), 1::bigint) from policy where public_id = 'pst_test1234';
18+
19+
-- deleting org should also delete the storage policy creating in that org
20+
prepare delete_org as
21+
delete from iam_scope
22+
where type = 'org'
23+
and public_id = 'o__foodtruck';
24+
25+
select lives_ok('delete_org');
26+
27+
select is(count(*), 0::bigint) from policy_storage_policy where public_id = 'pst_test1234';
28+
select is(count(*), 0::bigint) from policy where public_id = 'pst_test1234';
29+
30+
rollback;

0 commit comments

Comments
 (0)