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 858B

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