Skip to main content

update_dashboards_savedviews.go

015_update_dashboards_savedviews.go - Overview

  1. Overview

This file defines a SQL migration to update the dashboards and saved_views tables by adding an org_id column as a foreign key referencing the organizations table. It also populates this column with the existing organization ID if only one exists.

  1. Detailed Documentation

type updateDashboardAndSavedViews struct

  • Purpose: Represents the migration to update the dashboards and saved views tables.
  • Fields:
    • store: An instance of sqlstore.SQLStore used for database interactions.

func NewUpdateDashboardAndSavedViewsFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config]

  • Purpose: Creates a new factory for the updateDashboardAndSavedViews migration.
  • Parameters:
    • sqlstore: The sqlstore.SQLStore instance to be used by the migration.
  • Returns: A factory.ProviderFactory that creates SQLMigration instances.

func newUpdateDashboardAndSavedViews(_ context.Context, _ factory.ProviderSettings, _ Config, store sqlstore.SQLStore) (SQLMigration, error)

  • Purpose: Creates a new instance of the updateDashboardAndSavedViews migration.
  • Parameters:
    • _: A context.Context (not used).
    • _: factory.ProviderSettings (not used).
    • _: Config (not used).
    • store: The sqlstore.SQLStore instance to be used by the migration.
  • Returns: A new SQLMigration instance and an error, if any.

func (migration *updateDashboardAndSavedViews) Register(migrations *migrate.Migrations) error

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

func (migration *updateDashboardAndSavedViews) Up(ctx context.Context, db *bun.DB) error

  • Purpose: Implements the "Up" migration logic, adding the org_id column to the dashboards and saved_views tables and populating it with the existing organization ID if only one exists.
  • Parameters:
    • ctx: The context for the operation.
    • db: The bun.DB instance to use for database operations.
  • Returns: An error, if any.

func (migration *updateDashboardAndSavedViews) Down(ctx context.Context, db *bun.DB) error

  • Purpose: Implements the "Down" migration logic (reverting the "Up" migration). Currently, it does nothing and returns nil.
  • Parameters:
    • ctx: The context for the operation.
    • db: The bun.DB instance to use for database operations.
  • Returns: nil.
  1. Code Examples

No examples are needed.

  1. Clarity and Accuracy

The documentation reflects the code accurately.

  1. Markdown & MDX Perfection

The markdown is correctly formatted.

  1. Edge Cases To Avoid Breaking MDX:

All potential MDX issues have been avoided.

  1. Getting Started Relevance

Include in Getting Started: NO