@@ -26,18 +26,18 @@ import (
2626 "github.com/spf13/viper"
2727)
2828
29- type (
30- DiffEntry struct {
31- Type string `json:"type"`
32- Title string `json:"title"`
33- Status string `json:"status"`
34- SourceDdl string `json:"source_ddl "`
35- TargetDdl string `json:"target_ddl "`
36- DiffDdl string `json:"diff_ddl"`
37- GroupName string `json:"group_name"`
38- SourceSchemaName * string `json:"source_schema_name "`
39- }
40- )
29+ type DiffDependencies struct {
30+ Type string `json:"type"`
31+ }
32+
33+ type DiffEntry struct {
34+ Type string `json:"type "`
35+ Status string `json:"status "`
36+ DiffDdl string `json:"diff_ddl"`
37+ GroupName string `json:"group_name"`
38+ Dependencies [] DiffDependencies `json:"dependencies "`
39+ SourceSchemaName * string `json:"source_schema_name"`
40+ }
4141
4242const (
4343 ShadowDbName = "supabase_shadow"
@@ -281,16 +281,6 @@ func GetGitRoot() (*string, error) {
281281 }
282282}
283283
284- func IsSchemaIgnoredFromDump (schema string ) bool {
285- ignoredSchemas := []string {"auth" , "extensions" , "pgbouncer" , "storage" }
286- for _ , s := range ignoredSchemas {
287- if s == schema {
288- return true
289- }
290- }
291- return false
292- }
293-
294284type (
295285 StatusMsg string
296286 ProgressMsg * float64
@@ -391,7 +381,66 @@ func ProcessDiffOutput(p *tea.Program, out io.Reader) ([]byte, error) {
391381 // TODO: Remove when https://github.com/supabase/pgadmin4/issues/24 is fixed.
392382 diffBytes := bytes .TrimPrefix (diffBytesBuf .Bytes (), []byte ("NOTE: Configuring authentication for DESKTOP mode.\n " ))
393383
394- return diffBytes , nil
384+ return filterDiffOutput (diffBytes )
385+ }
386+
387+ func filterDiffOutput (diffBytes []byte ) ([]byte , error ) {
388+ var diffJson []DiffEntry
389+ if err := json .Unmarshal (diffBytes , & diffJson ); err != nil {
390+ return nil , err
391+ }
392+
393+ filteredDiffDdls := []string {`-- This script was generated by the Schema Diff utility in pgAdmin 4
394+ -- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
395+ -- and may require manual changes to the script to ensure changes are applied in the correct order.
396+ -- Please report an issue for any failure with the reproduction steps.` }
397+
398+ for _ , diffEntry := range diffJson {
399+ if diffEntry .Status == "Identical" || diffEntry .DiffDdl == "" {
400+ continue
401+ }
402+
403+ switch diffEntry .Type {
404+ case "function" , "mview" , "table" , "trigger_function" , "type" , "view" :
405+ // skip
406+ default :
407+ continue
408+ }
409+
410+ {
411+ doContinue := false
412+ for _ , dep := range diffEntry .Dependencies {
413+ if dep .Type == "extension" {
414+ doContinue = true
415+ break
416+ }
417+ }
418+
419+ if doContinue {
420+ continue
421+ }
422+ }
423+
424+ if isSchemaIgnored (diffEntry .GroupName ) ||
425+ // Needed at least for trigger_function
426+ (diffEntry .SourceSchemaName != nil && isSchemaIgnored (* diffEntry .SourceSchemaName )) {
427+ continue
428+ }
429+
430+ filteredDiffDdls = append (filteredDiffDdls , strings .TrimSpace (diffEntry .DiffDdl ))
431+ }
432+
433+ return []byte (strings .Join (filteredDiffDdls , "\n \n " ) + "\n " ), nil
434+ }
435+
436+ func isSchemaIgnored (schema string ) bool {
437+ ignoredSchemas := []string {"auth" , "extensions" , "pgbouncer" , "realtime" , "storage" , "supabase_migrations" }
438+ for _ , s := range ignoredSchemas {
439+ if s == schema {
440+ return true
441+ }
442+ }
443+ return false
395444}
396445
397446func ProcessPsqlOutput (out io.Reader , p * tea.Program ) error {
0 commit comments