Files
threshold/internal/db/sqltest/tests/domain/immutable_table.sql
T
Michael Gaffney b97dc07bb0 feat(sql): Add history tables for host catalogs
This adds history tables for `static_host_catalog` and
`host_plugin_catalog`. This also adds a base table for the host catalog
history tables and an immutable table with one row for when a target has
a direct address assigned to it.

This also adds a reusable trigger function for tables that are
immutable.
2023-05-31 12:18:16 +00:00

33 lines
783 B
PL/PgSQL

-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: MPL-2.0
begin;
select plan(5);
create table test_t1 (
id text
);
insert into test_t1 (id) values ('one');
create trigger immutable_table before insert or update or delete
on test_t1 for each row execute procedure immutable_table();
select is(count(*), 1::bigint) from test_t1;
prepare insert_fail as insert into test_t1 (id) values ('two');
select throws_ok('insert_fail', '23603');
prepare update_fail as
update test_t1
set id = 'two'
where id = 'one';
select throws_ok('update_fail', '23603');
prepare delete_fail as delete from test_t1;
select throws_ok('delete_fail', '23603');
select is(count(*), 1::bigint) from test_t1;
select * from finish();
rollback;