(template string, args []string, interactive bool)
| 144 | } |
| 145 | |
| 146 | func (p *plugin) migrateCreateHandler(template string, args []string, interactive bool) (string, error) { |
| 147 | if len(args) < 1 { |
| 148 | return "", errors.New("missing migration file name") |
| 149 | } |
| 150 | |
| 151 | name := args[0] |
| 152 | dir := p.config.Dir |
| 153 | |
| 154 | filename := fmt.Sprintf("%d_%s.%s", time.Now().Unix(), inflector.Snakecase(name), p.config.TemplateLang) |
| 155 | |
| 156 | resultFilePath := path.Join(dir, filename) |
| 157 | |
| 158 | if interactive { |
| 159 | confirm := osutils.YesNoPrompt(fmt.Sprintf("Do you really want to create migration %q?", resultFilePath), false) |
| 160 | if !confirm { |
| 161 | fmt.Println("The command has been cancelled") |
| 162 | return "", nil |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // get default create template |
| 167 | if template == "" { |
| 168 | var templateErr error |
| 169 | if p.config.TemplateLang == TemplateLangJS { |
| 170 | template, templateErr = p.jsBlankTemplate() |
| 171 | } else { |
| 172 | template, templateErr = p.goBlankTemplate() |
| 173 | } |
| 174 | if templateErr != nil { |
| 175 | return "", fmt.Errorf("failed to resolve create template: %v", templateErr) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | // ensure that the migrations dir exist |
| 180 | if err := os.MkdirAll(dir, os.ModePerm); err != nil { |
| 181 | return "", err |
| 182 | } |
| 183 | |
| 184 | // save the migration file |
| 185 | if err := os.WriteFile(resultFilePath, []byte(template), 0644); err != nil { |
| 186 | return "", fmt.Errorf("failed to save migration file %q: %v", resultFilePath, err) |
| 187 | } |
| 188 | |
| 189 | if interactive { |
| 190 | fmt.Printf("Successfully created file %q\n", resultFilePath) |
| 191 | } |
| 192 | |
| 193 | return filename, nil |
| 194 | } |
| 195 | |
| 196 | func (p *plugin) migrateCollectionsHandler(args []string, interactive bool) (string, error) { |
| 197 | createArgs := []string{"collections_snapshot"} |
no test coverage detected