Rename migrationsDir sqlDir.
This commit is contained in:
parent
4e771345ea
commit
daf3a8dad0
36
README.md
36
README.md
@ -1,4 +1,36 @@
|
||||
DB Migrate
|
||||
==========
|
||||
# DB Migrate
|
||||
|
||||
Small tool(s) to manage database migrations in various languages.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
Usage:
|
||||
db_migrate [options] create <migration-name>
|
||||
db_migrate [options] up [<count>]
|
||||
db_migrate [options] down [<count>]
|
||||
db_migrate [options] init <schema-name>
|
||||
db_migrate (-V | --version)
|
||||
db_migrate (-h | --help)
|
||||
|
||||
Options:
|
||||
-c --config <config-file> Use the given configuration file (defaults to
|
||||
"database.properties").
|
||||
-q --quiet Suppress log information.
|
||||
-v --verbose Print detailed log information.
|
||||
--very-verbose Print very detailed log information.
|
||||
-V --version Print the tools version information.
|
||||
-h --help Print this usage information.
|
||||
```
|
||||
|
||||
|
||||
## Database Config Format
|
||||
|
||||
The database config is formatted as JSON. The following keys are supported by
|
||||
all of the implementations:
|
||||
|
||||
* `sqlDir` -- Directory to store SQL files.
|
||||
|
||||
The following keys are supported by the Nim implementation:
|
||||
|
||||
* `connectionString` --
|
||||
|
@ -42,7 +42,7 @@ Options:
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(DbMigrate)
|
||||
|
||||
Sql sql
|
||||
File migrationsDir
|
||||
File sqlDir
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@ -90,14 +90,14 @@ Options:
|
||||
givenCfg.clear() } }
|
||||
|
||||
// Check for migrations directory
|
||||
File migrationsDir = new File(givenCfg["migrations.dir"] ?: 'migrations')
|
||||
if (!migrationsDir.exists() || !migrationsDir.isDirectory()) {
|
||||
File sqlDir = new File(givenCfg["sqlDir"] ?: 'migrations')
|
||||
if (!sqlDir.exists() || !sqlDir.isDirectory()) {
|
||||
clilog.error("'{}' does not exist or is not a directory.",
|
||||
migrationsDir.canonicalPath)
|
||||
sqlDir.canonicalPath)
|
||||
System.exit(1) }
|
||||
|
||||
// Instantiate the DbMigrate instance
|
||||
DbMigrate dbmigrate = new DbMigrate(migrationsDir: migrationsDir)
|
||||
DbMigrate dbmigrate = new DbMigrate(sqlDir: sqlDir)
|
||||
|
||||
// If we've only been asked to create a new migration, we don't need to
|
||||
// setup the DB connection.
|
||||
@ -112,7 +112,7 @@ Options:
|
||||
|
||||
// Create the datasource.
|
||||
Properties dsProps = new Properties()
|
||||
dsProps.putAll(givenCfg.findAll { it.key != 'migrations.dir' })
|
||||
dsProps.putAll(givenCfg.findAll { it.key != 'sqlDir' })
|
||||
|
||||
HikariDataSource hds = new HikariDataSource(new HikariConfig(dsProps))
|
||||
|
||||
@ -125,8 +125,8 @@ Options:
|
||||
public List<File> createMigration(String migrationName) {
|
||||
String timestamp = sdf.format(new Date())
|
||||
|
||||
File upFile = new File(migrationsDir, "$timestamp-$migrationName-up.sql")
|
||||
File downFile = new File(migrationsDir, "$timestamp-$migrationName-down.sql")
|
||||
File upFile = new File(sqlDir, "$timestamp-$migrationName-up.sql")
|
||||
File downFile = new File(sqlDir, "$timestamp-$migrationName-down.sql")
|
||||
|
||||
upFile.text = "-- UP script for $migrationName ($timestamp)"
|
||||
downFile.text = "-- DOWN script for $migrationName ($timestamp)"
|
||||
@ -140,7 +140,7 @@ Options:
|
||||
CREATE TABLE IF NOT EXISTS migrations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR NOT NULL,
|
||||
run_at TIMESTAMP NOT NULL DEFAULT NOW())''') }
|
||||
run_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW())''') }
|
||||
|
||||
public def diffMigrations() {
|
||||
def results = [notRun: [], missing: []]
|
||||
@ -150,7 +150,7 @@ CREATE TABLE IF NOT EXISTS migrations (
|
||||
.collect { it.name }.sort()
|
||||
|
||||
SortedSet<String> available = new TreeSet<>()
|
||||
available.addAll(migrationsDir
|
||||
available.addAll(sqlDir
|
||||
.listFiles({ d, n -> n ==~ /.+-(up|down).sql$/ } as FilenameFilter)
|
||||
.collect { f -> f.name.replaceAll(/-(up|down).sql$/, '') })
|
||||
|
||||
@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS migrations (
|
||||
|
||||
toRun.each { migrationName ->
|
||||
LOGGER.info(migrationName)
|
||||
File migrationFile = new File(migrationsDir,
|
||||
File migrationFile = new File(sqlDir,
|
||||
"$migrationName-${up ? 'up' : 'down'}.sql")
|
||||
|
||||
if (!migrationFile.exists() || !migrationFile.isFile())
|
||||
|
@ -196,12 +196,15 @@ Usage:
|
||||
db_migrate [options] down [<count>]
|
||||
db_migrate [options] init <schema-name>
|
||||
db_migrate (-V | --version)
|
||||
db_migrate (-h | --help)
|
||||
|
||||
Options:
|
||||
|
||||
-c --config <config-file> Use the given configuration file (defaults to
|
||||
"database.json").
|
||||
|
||||
-h --help Show this usage information.
|
||||
|
||||
-q --quiet Suppress log information.
|
||||
|
||||
-v --verbose Print detailed log information.
|
||||
|
Loading…
x
Reference in New Issue
Block a user