• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / migrations / 847

01 Jan 2026 09:03PM UTC coverage: 79.903% (-1.0%) from 80.917%
847

push

github

web-flow
Merge pull request #490 from hazendaz/master

[mvn] Add hsqldb method class names back to maven.config

679 of 986 branches covered (68.86%)

1813 of 2269 relevant lines covered (79.9%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/main/java/org/apache/ibatis/migration/commands/NewCommand.java
1
/*
2
 *    Copyright 2010-2023 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.apache.ibatis.migration.commands;
17

18
import java.io.File;
19
import java.util.HashMap;
20
import java.util.Map;
21
import java.util.Properties;
22

23
import org.apache.ibatis.migration.MigrationException;
24
import org.apache.ibatis.migration.hook.MigrationHook;
25
import org.apache.ibatis.migration.hook.NewHookContext;
26
import org.apache.ibatis.migration.options.SelectedOptions;
27
import org.apache.ibatis.migration.utils.Util;
28

29
public final class NewCommand extends BaseCommand {
30

31
  private static final String CUSTOM_NEW_COMMAND_TEMPLATE_PROPERTY = "new_command.template";
32

33
  public NewCommand(SelectedOptions options) {
34
    super(options);
1✔
35
  }
1✔
36

37
  @Override
38
  public void execute(String... params) {
39
    if (paramsEmpty(params)) {
1!
40
      throw new MigrationException("No description specified for new migration.");
×
41
    }
42
    String description = params[0];
1✔
43
    Properties variables = new Properties();
1✔
44
    variables.setProperty("description", description);
1✔
45
    existingEnvironmentFile();
1✔
46
    String filename = getNextIDAsString() + '_' + description.replace(' ', '_') + ".sql";
1✔
47

48
    Map<String, Object> hookBindings = new HashMap<>();
1✔
49
    MigrationHook hook = createNewHook();
1✔
50
    if (hook != null) {
1✔
51
      hookBindings.put(MigrationHook.HOOK_CONTEXT, new NewHookContext(description, filename));
1✔
52
      hook.before(hookBindings);
1✔
53
    }
54

55
    if (options.getTemplate() != null) {
1✔
56
      copyExternalResourceTo(options.getTemplate(), Util.file(paths.getScriptPath(), filename), variables);
1✔
57
    } else {
58
      String customConfiguredTemplate = Util.getPropertyOption(CUSTOM_NEW_COMMAND_TEMPLATE_PROPERTY);
1✔
59
      if (customConfiguredTemplate != null && !customConfiguredTemplate.isEmpty()) {
1!
60
        copyExternalResourceTo(Util.migrationsHome() + File.separator + customConfiguredTemplate,
×
61
            Util.file(paths.getScriptPath(), filename), variables);
×
62
      } else {
63
        printStream
1✔
64
            .append("Your migrations configuration did not find your custom template.  Using the default template.");
1✔
65
        copyDefaultTemplate(variables, filename);
1✔
66
      }
67
      if (hook != null) {
1✔
68
        hookBindings.put(MigrationHook.HOOK_CONTEXT, new NewHookContext(description, filename));
1✔
69
        hook.after(hookBindings);
1✔
70
      }
71
    }
72
    printStream.println("Done!");
1✔
73
    printStream.println();
1✔
74
  }
1✔
75

76
  private void copyDefaultTemplate(Properties variables, String filename) {
77
    copyResourceTo("org/apache/ibatis/migration/template_migration.sql", Util.file(paths.getScriptPath(), filename),
1✔
78
        variables);
79
  }
1✔
80

81
  private MigrationHook createNewHook() {
82
    String before = environment().getHookBeforeNew();
1✔
83
    String after = environment().getHookAfterNew();
1✔
84
    if (before == null && after == null) {
1!
85
      return null;
1✔
86
    }
87
    return createFileMigrationHook(before, null, null, after);
1✔
88
  }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc