Skip to main content

update_pipelines.go

017_update_pipelines.go - Overview

  1. Overview This file defines a SQL migration to update the pipelines table by adding org_id, updated_by, and updated_at columns. It also backfills the org_id column if there's only one organization.

  2. Detailed Documentation

type updatePipelines

  • Purpose: Represents the SQL migration for updating the pipelines table.
  • Fields:
    • store (sqlstore.SQLStore): SQL store instance.

func NewUpdatePipelines

  • Purpose: Creates a new updatePipelines factory.
  • Parameters:
    • sqlstore (sqlstore.SQLStore): The SQL store to use.
  • Returns: factory.ProviderFactory[SQLMigration, Config] A factory that can create updatePipelines instances.

func newUpdatePipelines

  • Purpose: Creates a new updatePipelines instance.
  • Parameters:
    • _ (context.Context): Context (not used).
    • _ (factory.ProviderSettings): Provider settings (not used).
    • _ (Config): Configuration (not used).
    • store (sqlstore.SQLStore): SQL store instance.
  • Returns: (SQLMigration, error): The new updatePipelines instance and an error, if any.

func (*updatePipelines) Register

  • Purpose: Registers the Up and Down migration functions.
  • Parameters:
    • migrations (*migrate.Migrations): The migrations to register with.
  • Returns: error: An error, if any.

func (*updatePipelines) Up

  • Purpose: Implements the "up" migration, adding columns to the pipelines table.
  • Parameters:
    • ctx (context.Context): Context for the operation.
    • db (*bun.DB): The database connection.
  • Returns: error: An error, if any.
    • It checks if org_id, updated_by, and updated_at columns exist in the pipelines table.
    • If a column doesn't exist, it adds the column.
    • If there is only one organization, it sets the org_id for all pipelines where org_id is NULL.

func (*updatePipelines) Down

  • Purpose: Implements the "down" migration (currently empty).
  • Parameters:
    • ctx (context.Context): Context for the operation.
    • db (*bun.DB): The database connection.
  • Returns: error: Always returns nil.
  1. Code Examples N/A

  2. Clarity and Accuracy The documentation is based on the code and aims to be precise.

  3. Markdown & MDX Perfection All markdown is valid.

  4. Edge Cases To Avoid Breaking MDX No MDX errors.

  5. Getting Started Relevance Include in Getting Started: NO