Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sea-orm-cli #24

Closed
tyt2y3 opened this issue Jun 19, 2021 · 14 comments · Fixed by #29 or #57
Closed

sea-orm-cli #24

tyt2y3 opened this issue Jun 19, 2021 · 14 comments · Fixed by #29 or #57
Assignees

Comments

@tyt2y3
Copy link
Member

tyt2y3 commented Jun 19, 2021

What should be command line interface?

First, we should read config from .env.

  1. migrate command for schema migration
# to run all migrations
sea-orm-cli migrate
# to run one migration
sea-orm-cli migrate up
# to revert a migration
sea-orm-cli migrate down
  1. generate command for code generation
# to generate entity files
sea-orm-cli generate entity
@tyt2y3 tyt2y3 mentioned this issue Jun 19, 2021
36 tasks
@billy1624
Copy link
Member

Ok, errors will be shown so if we cannot find / read from .env

@billy1624 billy1624 self-assigned this Jun 25, 2021
@tyt2y3 tyt2y3 reopened this Jul 1, 2021
@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 1, 2021

sea-orm-cli$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s                               
     Running `/mnt/c/Users/tyt2y/projects/sea-orm/target/debug/sea-orm-cli`                 
thread 'main' panicked at 'internal error: entered unreachable code: You should never see this message', sea-orm-cli/src/main.rs:18:14                                                  
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace     

We should display a welcome messge

@billy1624
Copy link
Member

billy1624 commented Jul 2, 2021

Will redirect to -h when no subcommand is provided.

See 47bb5b3

sea-orm/sea-orm-cli on  master is 📦 v0.1.0 via 𝗥 v1.53.0 via 🅒 base
➜ cargo r
   Compiling sea-orm-cli v0.1.0 (/Applications/MAMP/htdocs/sea-orm/sea-orm-cli)
    Finished dev [unoptimized + debuginfo] target(s) in 4.61s
     Running `/Applications/MAMP/htdocs/sea-orm/target/debug/sea-orm-cli`
sea-orm 0.1.0

USAGE:
    sea-orm-cli <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    generate    Codegen related commands
    help        Prints this message or the help of the given subcommand(s)

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 25, 2021

For the DATABASE_SCHEMA option, it should be entirely optional (it's useless in MySQL and optional in Postgres).
The default schema for Postgres is actually public
https://www.postgresql.org/docs/current/ddl-schemas.html

I would also suggest using DATABASE_URL and --database-url command line option for the sake of aligning with SQLx cli
https://crates.io/crates/sqlx-cli

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 27, 2021

DATABASE_SCHEMA should be optional

@billy1624
Copy link
Member

Regarding setting DATABASE_SCHEMA to optional. If I understand it correctly, the "schema" in sea-schema is actually the database in mysql connection string.

So, if DATABASE_SCHEMA is not provided, I will use anything after the last slash as the value for DATABASE_SCHEMA.

e.g. connection string mysql://sea:sea@localhost/bakery with DATABASE_SCHEMA: bakery.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 27, 2021

Yes it is the intended behavior. Too bad for the confusion. I definitely think that SeaSchema MySQL should rename that parameter to database.
As per the Postgres discovery, we actually need both database and schema

@billy1624
Copy link
Member

Is this behavior reasonable for MySQL?

So, if DATABASE_SCHEMA is not provided, I will use anything after the last slash as the value for DATABASE_SCHEMA.

e.g. connection string mysql://sea:sea@localhost/bakery with DATABASE_SCHEMA: bakery.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 27, 2021

MySQL does not have a concept of schema. So it's irrelevant.
We should in anycase extract the database from connection string

@billy1624
Copy link
Member

We should in anycase extract the database from connection string

Yes, will do so loll

@billy1624
Copy link
Member

Rename the schema to database? For sea-schema::mysql

@tyt2y3
Copy link
Member Author

tyt2y3 commented Jul 27, 2021

Rename the schema to database? For sea-schema::mysql

Yes please

@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 8, 2021

To clarify, our expected behavior:

  • for MySQL --database-schema is ignored
  • for Postgres --database-schema is optional, defaults to 'public'

Please make the changes to sea-orm-cli and update the docs

@billy1624
Copy link
Member

The new ignore hidden table behavior for sea-orm-cli generate entity:

  • ignore table name starts with "_" (an underscore)
  • add an option --include-hidden-tables to disable this behavior

@tyt2y3 tyt2y3 closed this as completed Aug 23, 2021
SebastienGllmt pushed a commit to dcSpark/sea-orm that referenced this issue Apr 13, 2022
* Correct type from Alias::new("ploygon") to Alias::new("polygon")

Add enum type for writer

* Add  type

* Add support for PostgreSQL types

Fix a few typos I found while digging through the source code

* Add tests for checking the correctness of PostgreSQL enum parsing and processing

* Gate `PgEnum` and its impl block under the `sqlx` feature
to allow the ` #[derive(sqlx::FromRow, Debug)]` to be used
to derive an sqlx row for handling PostgreSQL enums

* Add support for fetching enums

* Move types into types files under postgres::def::Type

Add documentation on types

Output the result by calling `discover_enum` on `SchemaDiscovery`

* Add method to parse a raw SQL create query for enum creation

Add missing documentation for the added types for enum creation

* Test case to discover all the enums in a given database schema

Write into SQL and then parse the raw SQL asserting that all
discovered enums are the same as their raw SQL queries

* Solve issues with github actions not detecting types

* Add feature flag for new enum type and associated functions

* Switch to using re-exported sqlx types within sea-schema

* Fix CI errors

* Support enums with crazy names that include special characters

* Add support for ordered Vecs

* Add tests for discovery of enums

Remove redundant module postgres_enum from the tests dir

* Ensure a custom enum type is dropped first from the database so that CI runs successfully

* Refactoring

* Ensures the writer derives the enum name from the EnumDef

* Refactoring

* Refactoring

* Refactoring

* Testing enum column...

* Refactoring

* Refactoring

* Refactoring

* Fix test

* Refactoring

* Refactoring

* Refactoring

* Cleanup

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants