(ctx context.Context, request *v1pb.DiffSchemaRequest)
| 841 | } |
| 842 | |
| 843 | func (s *DatabaseService) getTargetDBMetadata(ctx context.Context, request *v1pb.DiffSchemaRequest) (*model.DatabaseMetadata, error) { |
| 844 | changeHistoryID := request.GetChangelog() |
| 845 | |
| 846 | // If the change history id is set, use the schema of the change history as the target. |
| 847 | if changeHistoryID != "" { |
| 848 | instanceID, databaseName, changelogID, err := common.GetInstanceDatabaseChangelogID(changeHistoryID) |
| 849 | if err != nil { |
| 850 | return nil, err |
| 851 | } |
| 852 | |
| 853 | changelog, err := s.store.GetChangelog(ctx, &store.FindChangelogMessage{ |
| 854 | InstanceID: instanceID, |
| 855 | ResourceID: &changelogID, |
| 856 | }) |
| 857 | if err != nil { |
| 858 | return nil, err |
| 859 | } |
| 860 | if changelog == nil { |
| 861 | return nil, errors.Errorf("changelog %q not found", changelogID) |
| 862 | } |
| 863 | |
| 864 | // Use SyncHistory to get historical metadata |
| 865 | if changelog.SyncHistory != nil { |
| 866 | syncHistory, err := s.store.GetSyncHistory(ctx, *changelog.SyncHistory) |
| 867 | if err != nil { |
| 868 | return nil, err |
| 869 | } |
| 870 | if syncHistory == nil { |
| 871 | return nil, errors.Errorf("sync history %s not found", *changelog.SyncHistory) |
| 872 | } |
| 873 | |
| 874 | // Get instance to determine engine and case sensitivity |
| 875 | instance, err := s.store.GetInstance(ctx, &store.FindInstanceMessage{ |
| 876 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 877 | ResourceID: &instanceID, |
| 878 | }) |
| 879 | if err != nil { |
| 880 | return nil, err |
| 881 | } |
| 882 | if instance == nil { |
| 883 | return nil, errors.Errorf("instance %s not found", instanceID) |
| 884 | } |
| 885 | |
| 886 | return model.NewDatabaseMetadata( |
| 887 | syncHistory.Metadata, |
| 888 | []byte(syncHistory.Schema), |
| 889 | &storepb.DatabaseConfig{}, |
| 890 | instance.Metadata.GetEngine(), |
| 891 | store.IsObjectCaseSensitive(instance), |
| 892 | ), nil |
| 893 | } |
| 894 | |
| 895 | // Fallback to current database schema if no sync history |
| 896 | dbMetadata, err := s.store.GetDBSchema(ctx, &store.FindDBSchemaMessage{ |
| 897 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 898 | InstanceID: instanceID, |
| 899 | DatabaseName: databaseName, |
| 900 | }) |
no test coverage detected