-
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.
feat: hide migrations and seeding commands
Those commands should not be visible to lambda users, because seeding is for development and migrations is currently handled for the user. Seeding and migrations have been separated because they don't really fit together. If for a new release, we choose to document and encourage the use of the migrations command, seeding should stay hidden.
- Loading branch information
1 parent
18f6f64
commit f2bbba3
Showing
6 changed files
with
125 additions
and
91 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
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,106 @@ | ||
#!/usr/bin/env lua | ||
|
||
local Migrations = require "kong.tools.migrations" | ||
local constants = require "kong.constants" | ||
local cutils = require "kong.cli.utils" | ||
local IO = require "kong.tools.io" | ||
local lapp = require("lapp") | ||
local args = lapp(string.format([[ | ||
Kong datastore migrations. | ||
Usage: kong migrations <command> [options] | ||
Commands: | ||
<command> (string) where <command> is one of: | ||
list, up, down, reset | ||
Options: | ||
-c,--config (default %s) path to configuration file | ||
]], constants.CLI.GLOBAL_KONG_CONF)) | ||
|
||
-- $ kong migrations | ||
if args.command == "migrations" then | ||
lapp.quit("Missing required <command>.") | ||
end | ||
|
||
local config_path = cutils.get_kong_config_path(args.config) | ||
local _, dao_factory = IO.load_configuration_and_dao(config_path) | ||
local migrations = Migrations(dao_factory, cutils.get_luarocks_install_dir()) | ||
|
||
if args.command == "list" then | ||
|
||
local migrations, err = dao_factory:get_migrations() | ||
if err then | ||
cutils.logger:error_exit(err) | ||
elseif migrations then | ||
cutils.logger:log(string.format( | ||
"Executed migrations for %s on keyspace %s:\n%s", | ||
cutils.colors.yellow(dao_factory.type), | ||
cutils.colors.yellow(dao_factory._properties.keyspace), | ||
table.concat(migrations, ", ") | ||
)) | ||
else | ||
cutils.logger:log(string.format( | ||
"No migrations have been run yet for %s on keyspace: %s", | ||
cutils.colors.yellow(dao_factory.type), | ||
cutils.colors.yellow(dao_factory._properties.keyspace) | ||
)) | ||
end | ||
|
||
elseif args.command == "up" then | ||
|
||
cutils.logger:log(string.format( | ||
"Migrating %s keyspace: %s", | ||
cutils.colors.yellow(dao_factory.type), | ||
cutils.colors.yellow(dao_factory._properties.keyspace)) | ||
) | ||
|
||
migrations:migrate(function(migration, err) | ||
if err then | ||
cutils.logger:error_exit(err) | ||
elseif migration then | ||
cutils.logger:success("Migrated up to: "..cutils.colors.yellow(migration.name)) | ||
else | ||
cutils.logger:success("Schema already up to date") | ||
end | ||
end) | ||
|
||
elseif args.command == "down" then | ||
|
||
cutils.logger:log(string.format( | ||
"Rolling back %s keyspace: %s", | ||
cutils.colors.yellow(dao_factory.type), | ||
cutils.colors.yellow(dao_factory._properties.keyspace) | ||
)) | ||
|
||
migrations:rollback(function(migration, err) | ||
if err then | ||
cutils.logger:error_exit(err) | ||
elseif migration then | ||
cutils.logger:success("Rollbacked to: "..cutils.colors.yellow(migration.name)) | ||
else | ||
cutils.logger:success("No migration to rollback") | ||
end | ||
end) | ||
|
||
elseif args.command == "reset" then | ||
|
||
cutils.logger:log(string.format( | ||
"Reseting %s keyspace: %s", | ||
cutils.colors.yellow(dao_factory.type), | ||
cutils.colors.yellow(dao_factory._properties.keyspace)) | ||
) | ||
|
||
migrations:reset(function(migration, err) | ||
if err then | ||
cutils.logger:error_exit(err) | ||
elseif migration then | ||
cutils.logger:success("Rollbacked: "..cutils.colors.yellow(migration.name)) | ||
else | ||
cutils.logger:success("Schema reseted") | ||
end | ||
end) | ||
|
||
else | ||
lapp.quit("Invalid command: "..args.command) | ||
end |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env lua | ||
|
||
local cutils = require "kong.cli.utils" | ||
local infos = cutils.get_infos() | ||
local infos = cutils.get_kong_infos() | ||
|
||
cutils.logger:log(string.format("Kong version: %s", infos.version)) |