Skip to content

Commit

Permalink
Update db migration script to support pg_partman 5 (#3942)
Browse files Browse the repository at this point in the history
Closes #3931

Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
  • Loading branch information
tegioz authored Jul 15, 2024
1 parent 3cf7813 commit f65d8ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
6 changes: 0 additions & 6 deletions database/migrations/schema/032_packages_views.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
create extension pg_partman;

create table if not exists package_views (
package_id uuid not null references package on delete cascade,
version text not null,
Expand All @@ -8,10 +6,6 @@ create table if not exists package_views (
unique (package_id, version, day)
) partition by range (day);

select create_parent('public.package_views', 'day', 'native', 'monthly', p_start_partition := current_date::text);

---- create above / drop below ----

drop table if exists package_views;
drop table template_public_package_views;
delete from part_config where parent_table = 'public.package_views';
34 changes: 34 additions & 0 deletions database/migrations/schema/034_partman.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
create schema partman;
create extension pg_partman schema partman;

do language plpgsql $$
declare
v_pg_partman_version text;
begin
select extversion from pg_extension where extname = 'pg_partman' into v_pg_partman_version;
case
when starts_with(v_pg_partman_version, '4.') then
perform partman.create_parent(
'public.package_views',
'day',
'native',
'monthly',
p_start_partition := current_date::text
);
when starts_with(v_pg_partman_version, '5.') then
perform partman.create_parent(
'public.package_views',
'day',
'1 month',
p_start_partition := current_date::text
);
else
raise exception 'pg_partman version not supported';
end case;
end
$$;

---- create above / drop below ----

drop extension pg_partman;
drop schema partman cascade;
12 changes: 0 additions & 12 deletions database/migrations/schema/034_partman_schema.sql

This file was deleted.

0 comments on commit f65d8ac

Please sign in to comment.