Skip to content

Feat: Ignore source tables missing in target model #44

@Straightpool

Description

@Straightpool

Thanks a lot for this very helpful script! The following is a feature request to make this even easier to new users.

Issue
When running the migration script with extra tables in the source which are not in the target model the migration script will exit with a fatal error

Expected behavior
The migration script should ignore tables in the source model not needed in the target model

Steps to reproduce

  • Create fresh Grafana sqlite3 db
  • Create fresh Grafana postgre db
  • Add extra tables to Grafana sqlite3 db not existing in postgre schema with some random data
  • Attempt migration

Sample Error:
FATAL[2023-02-06T10:31:14Z] ❌ pq: relation "dashboard_usage_sums" does not exist INSERT INTO "dashboard_usage_sums" VALUES(0,'2022-01-20 03:56:51',0,0,0,0,0,0,0,0,0,0,0,0) - failed to import dump file to Postgres.

Cause
Apparently, Grafana does not create all tables on the first run but some non critical ones at a later time and/or does not clean up obsolete tables when migrating between different Grafana DB versions.

Version info
Grafana v9.3.6 sqlite3 DB migrated over multiple versions of Grafana from version 7.x to 9.3.6

In my sample case to be dropped tables

  • dashboard_usage_by_day
  • dashboard_usage_sums
  • data_source_acl
  • data_source_cache
  • data_source_usage_by_day
  • license_token
  • report
  • report_settings
  • setting
  • team_group
  • user_dashboard_views
  • user_stats

After dropping above tables in my own sqlite3 data file the migration completed without error and everything still work fine as expected, so nothing of value was lost in migration, as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions