(ctx context.Context, request *v1pb.DiffSchemaRequest)
| 758 | } |
| 759 | |
| 760 | func (s *DatabaseService) getSourceDBMetadata(ctx context.Context, request *v1pb.DiffSchemaRequest) (*model.DatabaseMetadata, error) { |
| 761 | if strings.Contains(request.Name, common.ChangelogPrefix) { |
| 762 | instanceID, databaseName, changelogID, err := common.GetInstanceDatabaseChangelogID(request.Name) |
| 763 | if err != nil { |
| 764 | return nil, err |
| 765 | } |
| 766 | |
| 767 | changelog, err := s.store.GetChangelog(ctx, &store.FindChangelogMessage{ |
| 768 | InstanceID: instanceID, |
| 769 | ResourceID: &changelogID, |
| 770 | }) |
| 771 | if err != nil { |
| 772 | return nil, err |
| 773 | } |
| 774 | if changelog == nil { |
| 775 | return nil, errors.Errorf("changelog %q not found", changelogID) |
| 776 | } |
| 777 | |
| 778 | // Use SyncHistory to get historical metadata |
| 779 | if changelog.SyncHistory != nil { |
| 780 | syncHistory, err := s.store.GetSyncHistory(ctx, *changelog.SyncHistory) |
| 781 | if err != nil { |
| 782 | return nil, err |
| 783 | } |
| 784 | if syncHistory == nil { |
| 785 | return nil, errors.Errorf("sync history %s not found", *changelog.SyncHistory) |
| 786 | } |
| 787 | |
| 788 | // Get instance to determine engine and case sensitivity |
| 789 | instance, err := s.store.GetInstance(ctx, &store.FindInstanceMessage{ |
| 790 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 791 | ResourceID: &instanceID, |
| 792 | }) |
| 793 | if err != nil { |
| 794 | return nil, err |
| 795 | } |
| 796 | if instance == nil { |
| 797 | return nil, errors.Errorf("instance %s not found", instanceID) |
| 798 | } |
| 799 | |
| 800 | return model.NewDatabaseMetadata( |
| 801 | syncHistory.Metadata, |
| 802 | []byte(syncHistory.Schema), |
| 803 | &storepb.DatabaseConfig{}, |
| 804 | instance.Metadata.GetEngine(), |
| 805 | store.IsObjectCaseSensitive(instance), |
| 806 | ), nil |
| 807 | } |
| 808 | |
| 809 | // Fallback to current database schema if no sync history |
| 810 | dbMetadata, err := s.store.GetDBSchema(ctx, &store.FindDBSchemaMessage{ |
| 811 | Workspace: common.GetWorkspaceIDFromContext(ctx), |
| 812 | InstanceID: instanceID, |
| 813 | DatabaseName: databaseName, |
| 814 | }) |
| 815 | if err != nil { |
| 816 | return nil, err |
| 817 | } |
no test coverage detected