-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scripts improvements + refactor for lua_cliargs
- Unified scripts in db.lua - Friendly error reporting - Now using cli_args - Silence flag, on for dev, off for travis
- Loading branch information
1 parent
23ae818
commit 17c100a
Showing
12 changed files
with
171 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,4 @@ install: | |
- sudo make install | ||
- make dev | ||
|
||
script: "make test-all" | ||
script: "make test-all SILENT_FLAG=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env lua | ||
|
||
local cli = require "cliargs" | ||
local utils = require "kong.tools.utils" | ||
local Migrations = require "kong.tools.migrations" | ||
|
||
cli:set_name("db.lua") | ||
cli:add_argument("COMMAND", "<create|migrate|rollback|reset|seed|drop>") | ||
cli:add_option("-n, --name=NAME", "If <create>, sets a name to the migration", "new_migration") | ||
cli:add_flag("-r, --random", "If seeding, also seed random entities (1000 for each collection by default)") | ||
cli:add_flag("-s, --silent", "No output") | ||
cli:optarg("CONFIGURATION", "configuration path", "config.dev/kong.yaml") | ||
|
||
local args = cli:parse(arg) | ||
if not args then | ||
os.exit(1) | ||
end | ||
|
||
local logger = utils.logger:new(args.silent) | ||
local configuration, dao = utils.load_configuration_and_dao(args.CONFIGURATION) | ||
|
||
if args.COMMAND == "create" then | ||
|
||
Migrations.create(configuration, args.name, function(interface, file_path, file_name) | ||
os.execute("mkdir -p "..file_path) | ||
|
||
local file = file_path.."/"..file_name..".lua" | ||
utils.write_to_file(file, interface) | ||
logger:success("New migration: "..file) | ||
end) | ||
|
||
elseif args.COMMAND == "migrate" then | ||
|
||
logger:log("Migrating "..utils.yellow(dao.type)) | ||
|
||
dao:migrate(function(migration, err) | ||
if err then | ||
logger:error(err) | ||
else | ||
logger:success("Migrated up to: "..utils.yellow(migration.name)) | ||
end | ||
end) | ||
|
||
elseif args.COMMAND == "rollback" then | ||
|
||
logger:log("Rolling back "..utils.yellow(dao.type)) | ||
|
||
dao:rollback(function(migration, err) | ||
if err then | ||
logger:error(err) | ||
else | ||
logger:success("Rollbacked to: "..utils.yellow(migration.name)) | ||
end | ||
end) | ||
|
||
elseif args.COMMAND == "reset" then | ||
|
||
logger:log("Resetting "..utils.yellow(dao.type)) | ||
|
||
dao:reset(function(migration, err) | ||
if err then | ||
logger:error(err) | ||
else | ||
logger:success("Rollbacked: "..utils.yellow(migration.name)) | ||
end | ||
end) | ||
|
||
elseif args.COMMAND == "seed" then | ||
|
||
-- Drop if exists | ||
local err = dao:drop() | ||
if err then | ||
logger:error(err) | ||
end | ||
|
||
local err = dao:prepare() | ||
if err then | ||
logger:error(err) | ||
end | ||
|
||
dao:seed(args.random) | ||
logger:success("Populated") | ||
|
||
elseif args.COMMAND == "drop" then | ||
|
||
dao:drop() | ||
logger:success("Dropped") | ||
|
||
else | ||
print("Invalid command: "..args.COMMAND) | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.