You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

schemas_dynamic.go 930B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. //go:build !bindata
  5. package migration
  6. import (
  7. "io"
  8. "net/url"
  9. "os"
  10. "path"
  11. "path/filepath"
  12. )
  13. func openSchema(s string) (io.ReadCloser, error) {
  14. u, err := url.Parse(s)
  15. if err != nil {
  16. return nil, err
  17. }
  18. basename := path.Base(u.Path)
  19. filename := basename
  20. //
  21. // Schema reference each other within the schemas directory but
  22. // the tests run in the parent directory.
  23. //
  24. if _, err := os.Stat(filename); os.IsNotExist(err) {
  25. filename = filepath.Join("schemas", basename)
  26. //
  27. // Integration tests run from the git root directory, not the
  28. // directory in which the test source is located.
  29. //
  30. if _, err := os.Stat(filename); os.IsNotExist(err) {
  31. filename = filepath.Join("modules/migration/schemas", basename)
  32. }
  33. }
  34. return os.Open(filename)
  35. }