Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ba3253c
allow db schema to be set in config
jgautsch May 25, 2022
95746d0
allow custom types via config
jgautsch May 25, 2022
7140e20
Merge pull request #1 from jgautsch/add-schema-support
jgautsch May 25, 2022
f8db86b
Merge pull request #2 from jgautsch/allow-custom-types-via-config
jgautsch May 25, 2022
fd56bb3
singularize ecto schema and file names
jgautsch May 25, 2022
523ec6c
declare schema prefix in generated files
jgautsch May 25, 2022
3e9c07e
allow custom types via config
jgautsch May 25, 2022
529a538
Merge pull request #3 from jgautsch/add-schema-support
jgautsch May 25, 2022
abc1700
Merge branch 'master' into allow-custom-types-via-config
jgautsch May 25, 2022
517433c
Merge pull request #4 from jgautsch/allow-custom-types-via-config
jgautsch May 25, 2022
1e3ce9a
Merge pull request #5 from jgautsch/singularize-schema
jgautsch May 25, 2022
580be33
fix uuid type handling
jgautsch May 25, 2022
5a48a17
Merge pull request #6 from jgautsch/allow-custom-types-via-config
jgautsch May 25, 2022
8698b6a
Add features
saleyn Oct 1, 2022
3647f65
Add features
saleyn Oct 1, 2022
cd97c46
Document new options
saleyn Oct 3, 2022
30c7792
Add features
saleyn Oct 1, 2022
ee30104
Add support for compound primary keys
saleyn Oct 3, 2022
537e7d4
Ensure the creation of destination directory
saleyn Oct 5, 2022
8bea042
Apply
saleyn Oct 5, 2022
0ffb5ff
Update myxql version
saleyn Nov 16, 2022
a630c0e
Add automatic detection of DB connectivity options
saleyn Dec 24, 2022
d32576d
Update default time type
saleyn Dec 25, 2022
c46f50d
Rename mix task to
saleyn Dec 25, 2022
2a1681f
Add module doc
saleyn Dec 25, 2022
b121a33
Add impl
saleyn Dec 25, 2022
dc50343
Fix help
saleyn Dec 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ plasm.configs
Plsm.configs
.vscode

lib/test_temp/schemas/*.ex
test/schemas/*.ex
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Serge Aleynikov <saleyn at gmail dot com>
- Added many enhancements to the schema generator and config options
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Plsm (Formerly Plasm)- Ecto model generation

Plsm generates Ecto models based on existing database tables in your database. Currently, Ecto only allows the ability to create migrations that creates new tables/schemas. If you have an existing project that you want to add Ecto support for you would have to hand code the models. This can be tedious for tables that have many columns.
Plsm generates Ecto models based on existing database tables in your database. Currently, Ecto only allows the ability to create migrations that creates new tables/schemas. If you have an existing project that you want to add Ecto support for you would have to hand code the models. This can be tedious for tables that have many columns.

## Getting Plsm

You can add
You can add

`{:plsm, "~> 2.3.2"}`

Expand All @@ -19,27 +19,34 @@ First, in order to run plsm, you need to generate a config file. You do this by

This will create a skeleton config file to the given config file. If you don't specify a config.exs file the config will then be appended to the "config/config.exs" file. If you are using another structure, such as Phoenix, then you need to pass in your dev.exs, since this is a dev only process. You will need to make changes to the generated Plsm configs in the config file in order to allow Plsm to function correctly.

Once you have your config file generated then you are ready to run plsm. You do this by running
Once you have your config file generated then you are ready to run plsm. You do this by running

`mix plsm`
`mix ecto.gen.schema [-t|--table Table]`

You are able to change the location of the model file output in the configuration file
You are able to change the location of the model file output in the configuration file. If
`-t|--table Table` argument is given, the schemas will be generated only for the specified
table(s).


## Configuration Options

* module_name -> This is the name of the module that the models will be placed under
* destination -> The output location for the generated models. If this is not provided then the models will go in the directory that you ran plsm in
* server -> this is the name of the server that you are connecting to. It can be a DNS name or an IP Address. This needs to be filled in as there are no defaults
* port -> The port that the database server is listening on. This needs to be provided as there may not be a default for your server
* database_name -> the name of the database that you are connecting to. This is required.
* username -> The username that is used to connect. Make sure that there is sufficient privileges to be able to connect, query tables as well as query information schemas on the database. The schema information is used to find the index/keys on each table
* password -> This is necessary as there is no default nor is there any handling of a blank password currently.
* type -> This dictates which database vendor you are using. We currently support PostgreSQL and MySQL. If no value is entered then it will default to MySQL. Accepted values: `:mysql` or `:postgres`. **Do note that this is an atom and not a string**
By default Plsm will try to guess the database connectivity settings by reading the current
project's application and `:ecto_repos` setting. If it cannot find that setting, it will use
the following configuration options:

* `:module_name` -> This is the name of the module that the models will be placed under
* `:destination` -> The output location for the generated models. If this is not provided then the models will go in the directory that you ran plsm in
* `:hostname` -> this is the name of the server that you are connecting to. It can be a DNS name or an IP Address. This needs to be filled in as there are no defaults
* `:port` -> The port that the database server is listening on. This needs to be provided as there may not be a default for your server
* `:database` -> the name of the database that you are connecting to. This is required.
* `:username` -> The username that is used to connect. Make sure that there is sufficient privileges to be able to connect, query tables as well as query information schemas on the database. The schema information is used to find the index/keys on each table
* `:password` -> This is necessary as there is no default nor is there any handling of a blank password currently.
* `:type` -> This dictates which database vendor you are using. We currently support PostgreSQL and MySQL. If no value is entered then it will default to MySQL. Accepted values: `:mysql`, `:postgres`, `Ecto.Adapters.MyXQL`, `Ecto.Adapters.Postgres`. **Do note that this is an atom and not a string**
* `:typed_schema` -> When `true`, will generate code for using `:typed_ecto_schema` application dependency.


## Supported Databases

We currently support the following databases:

* MySQL
Expand Down
20 changes: 7 additions & 13 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
Expand All @@ -21,20 +21,12 @@ use Mix.Config
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"

# Plsm configs are used to drive the extraction process. Below are what each field means:
# * module_name -> This is the name of the module that the models will be placed under
# * destination -> The output location for the generated models
# * server -> this is the name of the server that you are connecting to. It can be a DNS name or an IP Address. This needs to be filled in as there are no defaults
# * port -> The port that the database server is listening on. This needs to be provided as there may not be a default for your server
# * database_name -> the name of the database that you are connecting to. This is required.
# * database -> the name of the database that you are connecting to. This is required.
# * username -> The username that is used to connect. Make sure that there is sufficient privileges to be able to connect, query tables as well as query information schemas on the database. The schema information is used to find the index/keys on each table
# * password -> This is necessary as there is no default nor is there any handling of a blank password currently.
# * type -> This dictates which database vendor you are using. We currently support PostgreSQL and MySQL. If no value is entered then it will default to MySQL. Accepted values: :mysql or :postgres. Do note that this is an atom and not a string
Expand All @@ -43,8 +35,10 @@ config :plsm,
module_name: "module name",
destination: "output path",
server: "localhost",
port: "3306",
database_name: "name of database",
port: 5432,
database: "name of database",
username: "username",
password: "password",
type: :mysql
type: :postgres

File.exists?("config/#{config_env()}.exs") && import_config "#{config_env()}.exs"
20 changes: 20 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
import Config

config :plsm,
module_name: "PlsmTest",
destination: "test/schemas",
server: "localhost",
port: 5432,
database: System.get_env("DB_NAME", "db"),
username: System.get_env("DB_USER", "postgres"),
password: System.get_env("DB_PASS", "postgres"),
type: :postgres,
typed_schema: false
# overwrite: false

#config :tmp_app, TmpApp.Repo,
# database: System.get_env("DB_NAME", "db"),
# username: System.get_env("DB_USER", "postgres"),
# password: System.get_env("DB_PASS", "postgres")
13 changes: 5 additions & 8 deletions doc/.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ Mix.Tasks.Plasm.Config.html
Mix.Tasks.Plasm.html
Mix.Tasks.Plsm.Config.html
Mix.Tasks.Plsm.html
Plsm.Common.Configs.html
Plsm.Config.Config.html
Plsm.Configs.Database.html
Plsm.Configs.Project.html
Plsm.Configs.html
Plsm.Config.Project.html
Plsm.Config.html
Plsm.Database.Column.html
Plsm.Database.Common.html
Plsm.Database.Factory.html
Plsm.Database.MySql.html
Plsm.Database.PostgreSQL.html
Plsm.Database.Table.html
Expand All @@ -23,7 +20,7 @@ dist/html/fonts/icomoon.eot
dist/html/fonts/icomoon.svg
dist/html/fonts/icomoon.ttf
dist/html/fonts/icomoon.woff
dist/search_items-e2b7e1e7c4.js
dist/sidebar_items-67ec123bbf.js
dist/search_items-47eb325acf.js
dist/sidebar_items-abdb5749aa.js
index.html
search.html
4 changes: 2 additions & 2 deletions doc/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<title>404 — plsm v2.4.0</title>
<link rel="stylesheet" href="dist/elixir-9f91ebe876dc01d67920.css" />

<link rel="canonical" href="https://hexdocs.pm/plsm/404.html" />

<script src="dist/sidebar_items-304a1cc72b.js"></script>

<script src="docs_config.js"></script>

<script async src="dist/app-60a0c9f10e9e52eae31f.js"></script>


</head>
<body data-type="extras">
<script>try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }</script>
Expand Down Expand Up @@ -119,5 +118,6 @@ <h2>Page not found</h2>
</section>
</div>


</body>
</html>
4 changes: 2 additions & 2 deletions doc/Mix.Tasks.Plasm.Config.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<title>mix plasm.config — plsm v2.4.0</title>
<link rel="stylesheet" href="dist/elixir-9f91ebe876dc01d67920.css" />

<link rel="canonical" href="https://hexdocs.pm/plsm/Mix.Tasks.Plasm.Config.html" />

<script src="dist/sidebar_items-304a1cc72b.js"></script>

<script src="docs_config.js"></script>

<script async src="dist/app-60a0c9f10e9e52eae31f.js"></script>


</head>
<body data-type="tasks">
<script>try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }</script>
Expand Down Expand Up @@ -176,5 +175,6 @@ <h1 class="signature">run(params)</h1>
</section>
</div>


</body>
</html>
4 changes: 2 additions & 2 deletions doc/Mix.Tasks.Plasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<title>mix plasm — plsm v2.4.0</title>
<link rel="stylesheet" href="dist/elixir-9f91ebe876dc01d67920.css" />

<link rel="canonical" href="https://hexdocs.pm/plsm/Mix.Tasks.Plasm.html" />

<script src="dist/sidebar_items-304a1cc72b.js"></script>

<script src="docs_config.js"></script>

<script async src="dist/app-60a0c9f10e9e52eae31f.js"></script>


</head>
<body data-type="tasks">
<script>try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }</script>
Expand Down Expand Up @@ -176,5 +175,6 @@ <h1 class="signature">run(_)</h1>
</section>
</div>


</body>
</html>
4 changes: 2 additions & 2 deletions doc/Mix.Tasks.Plsm.Config.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<title>mix plsm.config — plsm v2.4.0</title>
<link rel="stylesheet" href="dist/elixir-9f91ebe876dc01d67920.css" />

<link rel="canonical" href="https://hexdocs.pm/plsm/Mix.Tasks.Plsm.Config.html" />

<script src="dist/sidebar_items-304a1cc72b.js"></script>

<script src="docs_config.js"></script>

<script async src="dist/app-60a0c9f10e9e52eae31f.js"></script>


</head>
<body data-type="tasks">
<script>try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }</script>
Expand Down Expand Up @@ -176,5 +175,6 @@ <h1 class="signature">run(params)</h1>
</section>
</div>


</body>
</html>
8 changes: 4 additions & 4 deletions doc/Mix.Tasks.Plsm.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
<title>mix plsm — plsm v2.4.0</title>
<link rel="stylesheet" href="dist/elixir-9f91ebe876dc01d67920.css" />

<link rel="canonical" href="https://hexdocs.pm/plsm/Mix.Tasks.Plsm.html" />

<script src="dist/sidebar_items-304a1cc72b.js"></script>

<script src="docs_config.js"></script>

<script async src="dist/app-60a0c9f10e9e52eae31f.js"></script>


</head>
<body data-type="tasks">
<script>try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }</script>
Expand Down Expand Up @@ -97,7 +96,7 @@ <h2>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#run/1">run(_)</a>
<a href="#run/1">run(params)</a>

</div>

Expand Down Expand Up @@ -126,7 +125,7 @@ <h1 class="section-heading">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<h1 class="signature">run(_)</h1>
<h1 class="signature">run(params)</h1>


</div>
Expand Down Expand Up @@ -176,5 +175,6 @@ <h1 class="signature">run(_)</h1>
</section>
</div>


</body>
</html>
Loading