lapis-annotate
is a Lapis extension that lets you
annotate your model files with their schema.
$ luarocks install lapis-annotate
$ lapis annotate help
Usage: lapis annotate [-h] [--preload-module <name>]
[--format {sql,table,generate_enum_comments}] [--print]
<files> [<files>] ...
Extract schema information from model's table to comment model
Arguments:
files Paths to model classes to annotate (eg. models/first.moon models/second.moon ...)
Options:
-h, --help Show this help message and exit.
--preload-module <name>
Module to require before annotating a model
--format {sql,table,generate_enum_comments}
What dump format to use (default: sql)
--print, -p Print the output instead of editing the model files
Example annotating a single model:
$ lapis annotate models/my_model.moon
Before:
import Model from require "lapis.db.model"
class UserIpAddresses extends Model
@timestamp: true
@primary_key: {"user_id", "ip"}
After:
import Model from require "lapis.db.model"
-- Generated schema dump: (do not edit)
--
-- CREATE TABLE user_ip_addresses (
-- user_id integer NOT NULL,
-- ip character varying(255) NOT NULL,
-- created_at timestamp without time zone NOT NULL,
-- updated_at timestamp without time zone NOT NULL
-- );
-- ALTER TABLE ONLY user_ip_addresses
-- ADD CONSTRAINT user_ip_addresses_pkey PRIMARY KEY (user_id, ip);
-- CREATE INDEX user_ip_addresses_ip_idx ON user_ip_addresses USING btree (ip);
--
class UserIpAddresses extends Model
@timestamp: true
@primary_key: {"user_id", "ip"}
--preload-module=MODULE_NAME
: load the named module withrequire
before initializing config
Only supports MoonScript and PostgreSQL at the moment
- 2021-03-15
1.2.1
Don't include the defaultpublic
table shema in output - 2018-04-03
1.2.0
Strip anySELECT
lines from the output - 2017-06-14
1.1.0
Add support for db user/password (Skiouros), add shell escaping - 2016-01-23
1.0.0
Initial release