()
| 64 | } |
| 65 | |
| 66 | func (c *CreateOptions) Create() error { |
| 67 | var op errors.Op = "cmd.CreateOptions.Create" |
| 68 | path := filepath.Join(c.Directory, fmt.Sprintf("%s_%s", c.Version, c.Name)) |
| 69 | err := os.MkdirAll(path, os.ModePerm) |
| 70 | if err != nil { |
| 71 | return errors.E(op, err) |
| 72 | } |
| 73 | |
| 74 | // Check if data has been set in one of the files |
| 75 | if c.SQLUp == nil && c.SQLDown == nil { |
| 76 | return errors.E(op, "none of the files has been set with data") |
| 77 | } |
| 78 | |
| 79 | if c.SQLUp != nil { |
| 80 | // Create SQLUp |
| 81 | err = createFile(filepath.Join(path, "up.sql"), c.SQLUp) |
| 82 | if err != nil { |
| 83 | return errors.E(op, err) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if c.SQLDown != nil { |
| 88 | // Create SQLDown |
| 89 | err = createFile(filepath.Join(path, "down.sql"), c.SQLDown) |
| 90 | if err != nil { |
| 91 | return errors.E(op, err) |
| 92 | } |
| 93 | } |
| 94 | return nil |
| 95 | } |
| 96 | |
| 97 | func (c *CreateOptions) Delete() error { |
| 98 | var op errors.Op = "cmd.CreateOptions.Delete" |
no test coverage detected