Jira (PDB-5109) Improve delete-reports scripts for upgrades to 2019.8

10 views
Skip to first unread message

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:14:04 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt created an issue
 
PuppetDB / Improvement PDB-5109
Improve delete-reports scripts for upgrades to 2019.8
Issue Type: Improvement Improvement
Assignee: Unassigned
Created: 2021/04/20 11:13 AM
Priority: Normal Normal
Reporter: Austin Blatt

Replace the old scripts in PE 2019.8 upgrade cautions with these new ones.

Before 2019.3.0

BEGIN TRANSACTION;
DO $$ DECLARE
  db_schema_version integer;
BEGIN
  if exists (select from information_schema.tables
               where table_schema = 'public'
                 and table_name = 'schema_migrations')
  then
    select max(version) into db_schema_version from schema_migrations;
    case
      when db_schema_version > 72 then
        raise exception
          'This version of the delete-reports.sql is for versions of PuppetDB
           before migration 73, your database is on migration % which is too
           new for this version of PuppetDB.', db_schema_version
          USING HINT = 'You may already be upgraded, or you may need a different
           version of the script.';
 
      else
        ALTER TABLE certnames DROP CONSTRAINT IF EXISTS certnames_reports_id_fkey;
        UPDATE certnames SET latest_report_id = NULL;
        TRUNCATE TABLE reports CASCADE;
 
        ALTER TABLE certnames
          ADD CONSTRAINT certnames_reports_id_fkey
          FOREIGN KEY (latest_report_id) REFERENCES reports(id) ON DELETE SET NULL;
    end case;
  else
    raise exception
      'Could not find puppetdb schema_migrations table';
  end if;
 
end $$;
 
COMMIT TRANSACTION;

2019.3.0 through 2019.6.0

BEGIN TRANSACTION;
DO $$ DECLARE
  db_schema_version integer;
  r RECORD;
BEGIN
  if exists (select from information_schema.tables
               where table_schema = 'public'
                 and table_name = 'schema_migrations')
  then
    select max(version) into db_schema_version from schema_migrations;
    case
      when db_schema_version != 73 then
        raise exception
          'This version of the delete-reports.sql is for versions of PuppetDB
           on migration 73, your database is on migration %', db_schema_version
          USING HINT =
          'You may already be upgraded, or you may need a different
           version of the script.';
 
      else
        ALTER TABLE certnames DROP CONSTRAINT IF EXISTS certnames_reports_id_fkey;
        UPDATE certnames SET latest_report_id = NULL;
 
        FOR r IN (SELECT tablename FROM pg_tables WHERE tablename LIKE 'resource_events_%') LOOP
          EXECUTE 'DROP TABLE ' || quote_ident(r.tablename);
        END LOOP;
 
        TRUNCATE TABLE reports CASCADE;
 
        ALTER TABLE certnames
          ADD CONSTRAINT certnames_reports_id_fkey
          FOREIGN KEY (latest_report_id) REFERENCES reports(id) ON DELETE SET NULL;
    end case;
  else
    raise exception
      'Could not find puppetdb schema_migrations table';
  end if;
 
end $$;
 
COMMIT TRANSACTION;

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:17:02 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt assigned an issue to Austin Blatt
Change By: Austin Blatt
Acceptance Criteria: - Make a docs ticket once the scripts are tested/approved
Release Notes: Not Needed
Release Notes Summary: docs ticket
Sprint: HA 2020-04-21
Team: HA
Assignee: Austin Blatt

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:18:02 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt updated an issue
Replace the old scripts in PE 2019.8 upgrade cautions (https://puppet.com/docs/pe/2019.8/upgrading_pe.html) with these new ones.

Before 2019.3.0
{code}
{code}

2019.3.0 through 2019.6.0
{code}
{code}

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:20:02 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt updated an issue
Replace the old scripts in PE 2019.8 upgrade cautions (https://puppet.com/docs/pe/2019.8/upgrading_pe.html) with these new ones.

Before 2019.3.0
{code :SQL }

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:21:01 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt updated an issue
Replace the old scripts in PE 2019.8 upgrade cautions (https://puppet.com/docs/pe/2019.8/upgrading_pe.html) with these new ones.

Before 2019.3.0
{code: SQL sql }

Austin Blatt (Jira)

unread,
Apr 20, 2021, 2:21:01 PM4/20/21
to puppe...@googlegroups.com
Austin Blatt updated an issue
Replace the old scripts in PE 2019.8 upgrade cautions (https://puppet.com/docs/pe/2019.8/upgrading_pe.html) with these new ones.

Before 2019.3.0
{code:sql}
{code :sql }

BEGIN TRANSACTION;
DO $$ DECLARE
  db_schema_version integer;
Reply all
Reply to author
Forward
0 new messages