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

Entity Generation Fails to Skip Ignored Tables #2089

Open
cxgreat2014 opened this issue Jan 30, 2024 · 3 comments
Open

Entity Generation Fails to Skip Ignored Tables #2089

cxgreat2014 opened this issue Jan 30, 2024 · 3 comments

Comments

@cxgreat2014
Copy link

Description

Encountering an issue (refer to GitHub issue #123), I aimed to exclude specific tables during entity generation. However, despite utilizing the --ignore-tables flag, the entity generation process failed without skipping the specified tables.

Steps to Reproduce

Execute the following command:

sea-orm-cli generate entity --ignore-tables django_apscheduler_djangojob,django_apscheduler_djangojobexecution -v

Check the log for details:

2024-01-30T15:32:35.334322Z DEBUG sqlx::query: PRAGMA foreign_key_list('django_apscheduler_djangojob') - elapsed=15.2µs
2024-01-30T15:32:35.334558Z DEBUG sqlx::query: PRAGMA table_info('django_apscheduler_djangojob') - elapsed=86.6µs
2024-01-30T15:32:35.334833Z DEBUG sqlx::query: PRAGMA index_list('django_apscheduler_djangojob') - elapsed=84.5µs
2024-01-30T15:32:35.335242Z DEBUG sqlx::query: SELECT ? FROM "sqlite_master" ... - elapsed=108.5µs
2024-01-30T15:32:35.335519Z DEBUG sqlx::query: PRAGMA foreign_key_list('django_apscheduler_djangojobexecution') - elapsed=80.1µs
2024-01-30T15:32:35.335822Z DEBUG sqlx::query: PRAGMA table_info('django_apscheduler_djangojobexecution') - elapsed=104.8µs
thread 'main' panicked at C:\Users\rustdev\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-schema-0.14.2\src\sqlite\def\types.rs:62:42:
index out of bounds: the len is 1 but the index is 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

Actual Behavior

Reproduces How Often

Workarounds

Reproducible Example

Versions

@cxgreat2014
Copy link
Author

Fix method:

sea-schema/src/sqlite/discovery.rs:23:

    pub async fn discover(&self, ignore_tables: Vec<String>) -> DiscoveryResult<Schema> {
        let get_tables = SelectStatement::new()
            .column(Alias::new("name"))
            .from(SqliteMaster)
            .and_where(Expr::col(Alias::new("type")).eq("table"))
            .and_where(Expr::col(Alias::new("name")).ne("sqlite_sequence"))
            .and_where(Expr::col(Alias::new("name")).is_not_in(ignore_tables))
            .to_owned();

sea-orm-cli/src/commands/generate.rs:78

            let ignore_tables_clone = ignore_tables.clone();
            let filter_skip_tables = |table: &String| -> bool { !ignore_tables_clone.contains(table) };

sea-orm-cli/src/commands/generate.rs:139

let schema = schema_discovery.discover(ignore_tables).await?;

@tyt2y3
Copy link
Member

tyt2y3 commented Mar 2, 2024

Thank you for your report. Seems like you have a proposed fix. Can you open a PR?

@cxgreat2014
Copy link
Author

cxgreat2014 commented Mar 2, 2024

My fixes are superficial and not fully tested, and in the case of non-sqlite database branches there is no compatibility processing. The current code logic changes will significantly lower the current code quality. I hope that some sea-orm members can understand the problem more quickly and know a dirty hack fix based on the information I provided above. Then make a good design and submit clean fix code and test files to solve this problem,(which means a lot of work and takes a lot of time and I can't do it at present), so I hope there are more kind people like you to do this PR

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

No branches or pull requests

2 participants