func (tm *TableManager) MatchSource(ctx context.Context, db dbh, rowSource *TableSource) error {
	metricTable := tm.table(rowSource.Name())
	var tagTable *tableState
	if tm.TagsAsForeignKeys {
		tagTable = tm.table(metricTable.name + tm.TagTableSuffix)

		missingCols, err := tm.EnsureStructure(
			ctx,
			db,
			tagTable,
			rowSource.TagTableColumns(),
			tm.TagTableCreateTemplates,
			tm.TagTableAddColumnTemplates,
			metricTable,
			tagTable,
		)
		if err != nil {
			return err
		}

		if len(missingCols) > 0 {
			colDefs := make([]string, len(missingCols))
			for i, col := range missingCols {
				if err := rowSource.DropColumn(col); err != nil {
					return fmt.Errorf("metric/table mismatch: Unable to omit field/column from \"%s\": %w", tagTable.name, err)
				}
				colDefs[i] = col.Name + " " + col.Type
			}
			tm.Logger.Errorf("table '%s' is missing tag columns (dropping metrics): %s",
				tagTable.name,
				strings.Join(colDefs, ", "))
		}
	}

	missingCols, err := tm.EnsureStructure(
		ctx,
		db,
		metricTable,
		rowSource.MetricTableColumns(),
		tm.CreateTemplates,
		tm.AddColumnTemplates,
		metricTable,
		tagTable,
	)
	if err != nil {
		return err
	}

	if len(missingCols) > 0 {
		colDefs := make([]string, len(missingCols))
		for i, col := range missingCols {
			if err := rowSource.DropColumn(col); err != nil {
				return fmt.Errorf("metric/table mismatch: Unable to omit field/column from \"%s\": %w", metricTable.name, err)
			}
			colDefs[i] = col.Name + " " + col.Type
		}
		tm.Logger.Errorf("table \"%s\" is missing columns (omitting fields): %s",
			metricTable.name,
			strings.Join(colDefs, ", "))
	}

	return nil
}
// MatchSource scans through the metrics, determining what columns are needed for inserting, and ensuring the DB schema matches.
//
// If the schema does not match, and schema updates are disabled:
// If a field missing from the DB, the field is omitted.
// If a tag is missing from the DB, the metric is dropped.
MatchSource scans through the metrics, determining what columns are needed for inserting, and ensuring the DB schema matches.

If the schema does not match, and schema updates are disabled:
If a field missing from the DB, the field is omitted.
If a tag is missing from the DB, the metric is dropped.
// MatchSource scans through the metrics determining what columns are needed for inserting and ensuring the DB schema matches . // // If the schema does not match and schema updates are disabled : // If a field missing from the DB the field is omitted . // If a tag is missing from the DB the metric is dropped .
func (tm *TableManager) MatchSource(ctx context.Context, db dbh, rowSource *TableSource) error {
	metricTable := tm.table(rowSource.Name())
	var tagTable *tableState
	if tm.TagsAsForeignKeys {
		tagTable = tm.table(metricTable.name + tm.TagTableSuffix)
		missingCols, err := tm.EnsureStructure(
			ctx,
			db,
			tagTable,
			rowSource.TagTableColumns(),
			tm.TagTableCreateTemplates,
			tm.TagTableAddColumnTemplates,
			metricTable,
			tagTable,
		)
		if err != nil {
			return err
		}
		if len(missingCols) > 0 {
			colDefs := make([]string, len(missingCols))
			for i, col := range missingCols {
				if err := rowSource.DropColumn(col); err != nil {
					return fmt.Errorf("metric/table mismatch: Unable to omit field/column from \"%s\": %w", tagTable.name, err)
				}
				colDefs[i] = col.Name + " " + col.Type
			}
			tm.Logger.Errorf("table '%s' is missing tag columns (dropping metrics): %s",
				tagTable.name,
				strings.Join(colDefs, ", "))
		}
	}
	missingCols, err := tm.EnsureStructure(
		ctx,
		db,
		metricTable,
		rowSource.MetricTableColumns(),
		tm.CreateTemplates,
		tm.AddColumnTemplates,
		metricTable,
		tagTable,
	)
	if err != nil {
		return err
	}
	if len(missingCols) > 0 {
		colDefs := make([]string, len(missingCols))
		for i, col := range missingCols {
			if err := rowSource.DropColumn(col); err != nil {
				return fmt.Errorf("metric/table mismatch: Unable to omit field/column from \"%s\": %w", metricTable.name, err)
			}
			colDefs[i] = col.Name + " " + col.Type
		}
		tm.Logger.Errorf("table \"%s\" is missing columns (omitting fields): %s",
			metricTable.name,
			strings.Join(colDefs, ", "))
	}
	return nil
}
func ( tm * TableManager ) MatchSource ( ctx context . Context , db dbh , rowSource * TableSource ) error { metricTable := tm . table ( rowSource . Name ( ) ) var tagTable * tableState if tm . TagsAsForeignKeys { tagTable = tm . table ( metricTable . name + tm . TagTableSuffix ) missingCols , err := tm . EnsureStructure ( ctx , db , tagTable , rowSource . TagTableColumns ( ) , tm . TagTableCreateTemplates , tm . TagTableAddColumnTemplates , metricTable , tagTable , ) if err != nil { return err } if len ( missingCols ) > 0 { colDefs := make ( [ ] string , len ( missingCols ) ) for i , col := range missingCols { if err := rowSource . DropColumn ( col ) ; err != nil { return fmt . Errorf ( " \" \" " , tagTable . name , err ) } colDefs [ i ] = col . Name + " " + col . Type } tm . Logger . Errorf ( " " , tagTable . name , strings . Join ( colDefs , " " ) ) } } missingCols , err := tm . EnsureStructure ( ctx , db , metricTable , rowSource . MetricTableColumns ( ) , tm . CreateTemplates , tm . AddColumnTemplates , metricTable , tagTable , ) if err != nil { return err } if len ( missingCols ) > 0 { colDefs := make ( [ ] string , len ( missingCols ) ) for i , col := range missingCols { if err := rowSource . DropColumn ( col ) ; err != nil { return fmt . Errorf ( " \" \" " , metricTable . name , err ) } colDefs [ i ] = col . Name + " " + col . Type } tm . Logger . Errorf ( " \" \" " , metricTable . name , strings . Join ( colDefs , " " ) ) } return nil }
MatchSource scans through the metrics, determining what columns are needed for inserting, and ensuring the DB schema matches.
MatchSource scans through the metrics determining what columns are needed for inserting and ensuring the DB schema matches .