| 115 | } |
| 116 | |
| 117 | func makeMigrateFS(version string) (fs.FS, error) { |
| 118 | // Export the migrations from the requested version to a zip archive |
| 119 | out, err := exec.Command("git", "archive", "--format=zip", version, "coderd/database/migrations").CombinedOutput() |
| 120 | if err != nil { |
| 121 | return nil, xerrors.Errorf("git archive: %s\n", out) |
| 122 | } |
| 123 | // Make a zip.Reader on top of it. This implements fs.fs! |
| 124 | zr, err := zip.NewReader(bytes.NewReader(out), int64(len(out))) |
| 125 | if err != nil { |
| 126 | return nil, xerrors.Errorf("create zip reader: %w", err) |
| 127 | } |
| 128 | // Sub-FS to it's rooted at migrations dir. |
| 129 | subbed, err := fs.Sub(zr, "coderd/database/migrations") |
| 130 | if err != nil { |
| 131 | return nil, xerrors.Errorf("sub fs: %w", err) |
| 132 | } |
| 133 | return subbed, nil |
| 134 | } |
| 135 | |
| 136 | func gitShow(path, version string) ([]byte, error) { |
| 137 | out, err := exec.Command("git", "show", version+":"+path).CombinedOutput() //nolint:gosec |