Liking cljdoc? Tell your friends :D
Clojure only.

puppetlabs.puppetdb.scf.migrate

Schema migrations

The initialize-schema function can be used to prepare the database, applying all the pending migrations to the database, in ascending order of schema version. Pending is defined as having a schema version greater than the current version in the database.

A migration is specified by defining a function of arity 0 and adding it to the migrations map, along with its schema version. To apply the migration, the migration function will be invoked, and the schema version and current time will be recorded in the schema_migrations table.

A migration function can return a map with ::vacuum-analyze to indicate what tables need to be analyzed post-migration.

NOTE: in order to support bug-fix schema changes to older branches without breaking the ability to upgrade, it is possible to define a sequence of migrations with non-sequential integers. e.g., if the 1.0.x branch contains migrations 1-5, and the 2.0.x branch contains schema migrations 1-10, and then a bugfix schema change (such as creating or adding an index) is identified, this migration can be defined as #11 in both branches. Code in the 1.0.x branch should happily apply #11 even though it does not have a definition for 6-10. Then when a 1.0.x user upgrades to 2.0.x, migrations 6-10 will be applied, and 11 will be skipped because it's already been run. Because of this, it is crucial to be extremely careful about numbering new migrations if they are going into multiple branches. It's also crucial to be absolutely certain that the schema change in question is compatible with both branches and that the migrations missing from the earlier branch can reasonably and safely be applied after the bugfix migration, because that is what will happen for upgrading users.

In short, here are some guidelines re: applying schema changes to multiple branches:

  1. If at all possible, avoid it.
  2. Seriously, are you sure you need to do this? :)
  3. OK, if you really must do it, make sure that the schema change in question is as independent as humanly possible. For example, things like creating or dropping an index on a table should be fairly self-contained. You should think long and hard about any change more complex than that.
  4. Determine what the latest version of the schema is in each of the two branches.
  5. Examine every migration that exists in the newer branch but not the older branch, and make sure that your new schema change will not conflict with any of those migrations. Your change must be able to execute successfully regardless of whether it is applied BEFORE all of those migrations or AFTER them.
  6. If you're certain you've met the conditions described above, choose the next available integer from the newer branch and add your migration to both branches using this integer. This will result in a gap between the integers in the migrations array in the old branch, but that is not a problem.

TODO: consider using multimethods for migration funcs

Schema migrations

 The `initialize-schema` function can be used to prepare the
database, applying all the pending migrations to the database, in
ascending order of schema version. Pending is defined as having a
schema version greater than the current version in the database.

 A migration is specified by defining a function of arity 0 and adding it to
 the `migrations` map, along with its schema version. To apply the migration,
 the migration function will be invoked, and the schema version and current
 time will be recorded in the schema_migrations table.

 A migration function can return a map with ::vacuum-analyze to indicate what tables
 need to be analyzed post-migration.

 NOTE: in order to support bug-fix schema changes to older branches without
 breaking the ability to upgrade, it is possible to define a sequence of
 migrations with non-sequential integers.  e.g., if the 1.0.x branch
 contains migrations 1-5, and the 2.0.x branch contains schema migrations
 1-10, and then a bugfix schema change (such as creating or adding an index)
 is identified, this migration can be defined as #11 in both branches.  Code
 in the 1.0.x branch should happily apply #11 even though it does not have
 a definition for 6-10.  Then when a 1.0.x user upgrades to 2.0.x, migrations
 6-10 will be applied, and 11 will be skipped because it's already been run.
 Because of this, it is crucial to be extremely careful about numbering new
 migrations if they are going into multiple branches.  It's also crucial to
 be absolutely certain that the schema change in question is compatible
 with both branches and that the migrations missing from the earlier branch
 can reasonably and safely be applied *after* the bugfix migration, because
 that is what will happen for upgrading users.

 In short, here are some guidelines re: applying schema changes to multiple
 branches:

 1. If at all possible, avoid it.
 2. Seriously, are you sure you need to do this? :)
 3. OK, if you really must do it, make sure that the schema change in question
    is as independent as humanly possible.  For example, things like creating
    or dropping an index on a table should be fairly self-contained.  You should
    think long and hard about any change more complex than that.
 4. Determine what the latest version of the schema is in each of the two branches.
 5. Examine every migration that exists in the newer branch but not the older
    branch, and make sure that your new schema change will not conflict with
    *any* of those migrations.  Your change must be able to execute successfully
    regardless of whether it is applied BEFORE all of those migrations or AFTER
    them.
 6. If you're certain you've met the conditions described above, choose the next
    available integer from the *newer* branch and add your migration to both
    branches using this integer.  This will result in a gap between the integers
    in the migrations array in the old branch, but that is not a problem.

 _TODO: consider using multimethods for migration funcs_
raw docstring

add-catalog-inputs-hashclj

(add-catalog-inputs-hash)
source

add-catalog-inputs-pkeyclj

(add-catalog-inputs-pkey)
source

add-catalog-uuid-to-reports-and-catalogsclj

(add-catalog-uuid-to-reports-and-catalogs)
source

add-certname-id-to-certnamesclj

(add-certname-id-to-certnames)
source

add-certname-id-to-resource-eventsclj

(add-certname-id-to-resource-events)
source

add-code-id-to-catalogsclj

(add-code-id-to-catalogs)
source

add-corrective-change-columnsclj

(add-corrective-change-columns)
source

add-corrective-change-indexclj

(add-corrective-change-index)
source

add-expired-to-certnamesclj

(add-expired-to-certnames)

Add a 'expired' column to the 'certnames' table, to track which nodes have been automatically expired because of inactivity.

Add a 'expired' column to the 'certnames' table, to track
which nodes have been automatically expired because of inactivity.
sourceraw docstring

add-expression-indexes-for-bytea-queriesclj

(add-expression-indexes-for-bytea-queries)
source

add-gin-index-on-resource-params-cacheclj

(add-gin-index-on-resource-params-cache)
source

add-indexes-for-reports-summary-queryclj

(add-indexes-for-reports-summary-query)

This aggregate and function is used by PE, not puppetdb

This aggregate and function is used by PE, not puppetdb
sourceraw docstring

add-job-idclj

(add-job-id)
source

add-jsonb-columns-for-metrics-and-logsclj

(add-jsonb-columns-for-metrics-and-logs)
source

add-latest-report-timestamp-to-certnamesclj

(add-latest-report-timestamp-to-certnames)
source

add-noop-pending-to-reportsclj

(add-noop-pending-to-reports)
source

add-package-tablesclj

(add-package-tables)
source

add-producer-timestamp-to-reportsclj

(add-producer-timestamp-to-reports)
source

add-producer-to-reports-catalogs-and-factsetsclj

(add-producer-to-reports-catalogs-and-factsets)
source

add-report-partition-indexes-on-certname-end-timeclj

(add-report-partition-indexes-on-certname-end-time)
source

add-report-partition-indexes-on-idclj

(add-report-partition-indexes-on-id)
source

add-report-type-to-reportsclj

(add-report-type-to-reports)

Add a 'report_type' column to the 'reports' table, to indicate the source of the report. Valid values at the time of this migration are 'agent' or 'plan'.

Add a 'report_type' column to the 'reports' table, to indicate the
source of the report. Valid values at the time of this migration are
'agent' or 'plan'.
sourceraw docstring

add-support-for-catalog-inputsclj

(add-support-for-catalog-inputs)
source

add-support-for-historical-catalogsclj

(add-support-for-historical-catalogs)
source

add-workspaces-tablesclj

(add-workspaces-tables)
source

analyze-if-existsclj

(analyze-if-exists tables)
source

applied-migrationsclj

(applied-migrations)

Returns a collection of migrations that have been run against this database already, ordered from oldest to latest.

Returns a collection of migrations that have been run against this database
already, ordered from oldest to latest.
sourceraw docstring

autovacuum-vacuum-scale-factor-factsets-catalogs-certnamesclj

(autovacuum-vacuum-scale-factor-factsets-catalogs-certnames)
source

call-with-connections-blocked-during-migrationclj

(call-with-connections-blocked-during-migration db-name users f)
(call-with-connections-blocked-during-migration db-name [user & others] users f)
source

coalesce-fact-valuesclj

(coalesce-fact-values)
source

coalesce-valuesclj

(coalesce-values value-keys row)
source

create-original-partitionclj

(create-original-partition base-table date-column date constraint-fn index-fn)

Inputs: [base-table :- s/Str date-column :- s/Str date :- (s/cond-pre LocalDate LocalDateTime ZonedDateTime Instant java.sql.Timestamp) constraint-fn :- (s/fn-schema (s/fn :- [s/Str] [_iso-year-week :- s/Str])) index-fn :- (s/fn-schema (s/fn :- [s/Str] [_full-table-name :- s/Str _iso-year-week :- s/Str]))]

Creates an inheritance partition for the historical state of migrations #73 and #74

Inputs: [base-table :- s/Str date-column :- s/Str date :- (s/cond-pre LocalDate LocalDateTime ZonedDateTime Instant java.sql.Timestamp) constraint-fn :- (s/fn-schema (s/fn :- [s/Str] [_iso-year-week :- s/Str])) index-fn :- (s/fn-schema (s/fn :- [s/Str] [_full-table-name :- s/Str _iso-year-week :- s/Str]))]

Creates an inheritance partition for the historical state of migrations #73 and #74
sourceraw docstring

create-original-reports-partitionclj

(create-original-reports-partition date)

Creates an inheritance partition in the reports table for migration #74

Creates an inheritance partition in the reports table for migration #74
sourceraw docstring

create-original-resource-events-partitionclj

(create-original-resource-events-partition date)

Creates an inheritance partition in the resource_events table for migration #73

Creates an inheritance partition in the resource_events table for migration #73
sourceraw docstring

desired-schema-versionclj

(desired-schema-version)

The newest migration this PuppetDB instance knows about. Anything newer is considered invalid as far as this instance is concerned.

The newest migration this PuppetDB instance knows about.  Anything
newer is considered invalid as far as this instance is concerned.
sourceraw docstring

drop-certnames-latest-id-indexclj

(drop-certnames-latest-id-index)
source

drop-child-partition-constraintsclj

(drop-child-partition-constraints date-column child-table-maps)

Drops the redundant constraints previously placed on the child tables that were enforcing the partitioning for the inheritance partitions.

Drops the redundant constraints previously placed on the child tables that
were enforcing the partitioning for the inheritance partitions.
sourceraw docstring

drop-foreign-key-constraintsclj

(drop-foreign-key-constraints child-table-maps)

Drops the foreign keys previously placed on the child tables

Drops the foreign keys previously placed on the child tables
sourceraw docstring

drop-resource-events-resource-type-idxclj

(drop-resource-events-resource-type-idx)
source

fact-values-value-to-jsonbclj

(fact-values-value-to-jsonb)
source

factset-hash-field-not-nullableclj

(factset-hash-field-not-nullable)
source

fix-bytea-expression-indexes-to-use-encodeclj

(fix-bytea-expression-indexes-to-use-encode)
source

fix-missing-edges-fk-constraintclj

(fix-missing-edges-fk-constraint)
source

improve-facts-factset-id-indexclj

(improve-facts-factset-id-index)
source

index-certnames-latest-report-idclj

(index-certnames-latest-report-id)
source

index-certnames-unique-latest-report-idclj

(index-certnames-unique-latest-report-id)
source

init-through-2-3-8clj

(init-through-2-3-8)
source

initialize-schemaclj

(initialize-schema)
(initialize-schema write-user read-user db-name)

Ensures the database is migrated to the latest version, and returns true if and only if migrations were run. Assumes the database status, version, etc. have already been validated.

Ensures the database is migrated to the latest version, and returns
true if and only if migrations were run.  Assumes the database
status, version, etc. have already been validated.
sourceraw docstring

jsonb-factsclj

(jsonb-facts)
source

maybe-parse-jsonclj

(maybe-parse-json s)
source

merge-fact-values-into-factsclj

(merge-fact-values-into-facts)
source

migrate-md5-to-sha1-hashesclj

(migrate-md5-to-sha1-hashes)
source

migrate-reports-to-declarative-partitioningclj

(migrate-reports-to-declarative-partitioning)
source

migrate-resource-events-to-declarative-partitioningclj

(migrate-resource-events-to-declarative-partitioning)
source

migrate-through-appclj

(migrate-through-app table1 table2 column-list munge-fn)
source

migration-69-stubclj

(migration-69-stub)
source

migrationsclj

The available migrations, as a map from migration version to migration function.

The available migrations, as a map from migration version to migration function.
sourceraw docstring

note-migrations-finishedclj

(note-migrations-finished)

Currently just a hook used during testing.

Currently just a hook used during testing.
sourceraw docstring

pending-migrationsclj

(pending-migrations)

Returns a collection of pending migrations, ordered from oldest to latest.

Returns a collection of pending migrations, ordered from oldest to latest.
sourceraw docstring

prevent-duplicate-catalogsclj

(prevent-duplicate-catalogs)
source

reattach-partitionsclj

(reattach-partitions table child-table-maps)

Detaches partition children from PostgreSQL inheritance and attaches them to the new partition table (under its placeholder name).

Detaches partition children from PostgreSQL inheritance and attaches them to
the new partition table (under its placeholder name).
sourceraw docstring

record-migration!clj

(record-migration! version)

Records a migration by storing its version in the schema_migrations table, along with the time at which the migration was performed.

Records a migration by storing its version in the schema_migrations table,
along with the time at which the migration was performed.
sourceraw docstring

rededuplicate-factsclj

(rededuplicate-facts)
source

remove-catalog-resources-file-trgm-indexclj

(remove-catalog-resources-file-trgm-index)

Drops the expensive catalog_resources_file_trgm index, and resets the catalog_resources autovacuum_analyze_scale_factor storage parameter to default.

Drops the expensive catalog_resources_file_trgm index, and resets the
catalog_resources autovacuum_analyze_scale_factor storage parameter to
default.
sourceraw docstring

remove-historical-catalogsclj

(remove-historical-catalogs)
source

rename-environments-name-to-environmentclj

(rename-environments-name-to-environment)
source

reports-partial-indicesclj

(reports-partial-indices)
source

reports-partitioningclj

(reports-partitioning)
source

require-previously-optional-trigram-indexesclj

(require-previously-optional-trigram-indexes)

Create trgm indexes if they do not currently exist.

Create trgm indexes if they do not currently exist.
sourceraw docstring

require-schema-migrations-tableclj

(require-schema-migrations-table)
source

require-valid-schemaclj

(require-valid-schema)

Returns true if the database is ready for use, otherwise throws.

Returns true if the database is ready for use, otherwise throws.
sourceraw docstring

resource-events-partitioningclj

(resource-events-partitioning)
(resource-events-partitioning batch-size)
source

resource-params-cache-parameters-to-jsonbclj

(resource-params-cache-parameters-to-jsonb)
source

run-migrationsclj

(run-migrations migrations)

Runs the requested migrations. Returns a set of tables that should be analyzed if there were any migrations.

Runs the requested migrations.  Returns a set of tables that should
be analyzed if there were any migrations.
sourceraw docstring

split-certnames-tableclj

(split-certnames-table)

Split the certnames table. Avoid dirtying buffer cache pages for critical deactivated/expired informaton.

Split the certnames table. Avoid dirtying buffer cache pages for critical
deactivated/expired informaton.
sourceraw docstring

store-latest-events-separatelyclj

(store-latest-events-separately)
source

store-latest-reports-separatelyclj

(store-latest-reports-separately)
source

support-fact-expiration-configurationclj

(support-fact-expiration-configuration)
source

unrecognized-migrationsclj

(unrecognized-migrations applied-migrations)

Returns a set of migrations, likely created by a future version of PuppetDB

Returns a set of migrations, likely created by a future version of
PuppetDB
sourceraw docstring

update-schemaclj

(update-schema write-user read-user db-name)
source

update-value-jsonclj

(update-value-json {:keys [id value]})
source

varchar-columns-to-textclj

(varchar-columns-to-text)
source

version-2yz-to-300-migrationclj

(version-2yz-to-300-migration)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close