-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[CLI] implement regex filtering #1914
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
Closed
Closed
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a87d73b
implement regex filtering
KeenS 1990fdc
use absolute path for backward compatibility
KeenS 0839c42
fmt with 1.26.1
KeenS cbb3a20
Merge branch 'master' into filter-regex
KeenS ddef0ee
implement for CLI
KeenS ed8ebc6
Merge branch 'master' into filter-regex
KeenS 05f14aa
Merge branch 'master' into filter-regex
KeenS fbc9fee
compile pass
KeenS 4277f07
fix typo
KeenS c4ccdd9
fmt
KeenS 570f620
force rerun ci
KeenS 8fa5cf9
Merge remote-tracking branch 'origin/master' into filter-regex
KeenS e103a2b
show user friendly message
KeenS c5999da
Merge remote-tracking branch 'origin' into filter-regex
KeenS 2ff2f37
Merge branch 'master' into filter-regex
KeenS edc54d4
remove old flags and rename -regexes flags
KeenS 4c6f7e9
update changelog
KeenS c7ad968
update test
KeenS f72c48b
cleanup flags
KeenS 62331a7
syntax and fmt
KeenS 543855e
fix typo
KeenS 4c85583
force ci rerun
KeenS da78072
Merge remote-tracking branch 'origin/master' into filter-regex
KeenS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ extern crate dotenv; | |
| extern crate migrations_internals; | ||
| #[macro_use] | ||
| extern crate serde; | ||
| extern crate regex; | ||
| extern crate serde_regex; | ||
| extern crate tempfile; | ||
| extern crate toml; | ||
| #[cfg(feature = "url")] | ||
|
|
@@ -45,6 +47,7 @@ mod query_helper; | |
| use chrono::*; | ||
| use clap::{ArgMatches, Shell}; | ||
| use migrations_internals::{self as migrations, MigrationConnection}; | ||
| use regex::Regex; | ||
| use std::any::Any; | ||
| use std::error::Error; | ||
| use std::io::stdout; | ||
|
|
@@ -368,6 +371,12 @@ fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<Error>> { | |
| }) | ||
| .collect(); | ||
|
|
||
| let filter_regex = matches | ||
| .values_of("table-name-regexpes") | ||
| .unwrap_or_default() | ||
| .map(|table_name_regex| Regex::new(table_name_regex).unwrap().into()) | ||
|
||
| .collect(); | ||
|
|
||
| if matches.is_present("whitelist") { | ||
| eprintln!("The `whitelist` option has been deprecated and renamed to `only-tables`."); | ||
| } | ||
|
|
@@ -378,8 +387,12 @@ fn run_infer_schema(matches: &ArgMatches) -> Result<(), Box<Error>> { | |
|
|
||
| if matches.is_present("only-tables") || matches.is_present("whitelist") { | ||
| config.filter = Filtering::OnlyTables(filter) | ||
| } else if matches.is_present("only-table-regexes") { | ||
| config.filter = Filtering::OnlyTableRegexes(filter_regex) | ||
| } else if matches.is_present("except-tables") || matches.is_present("blacklist") { | ||
| config.filter = Filtering::ExceptTables(filter) | ||
| } else if matches.is_present("except-table-regexes") { | ||
| config.filter = Filtering::ExceptTableRegexes(filter_regex) | ||
| } | ||
|
|
||
| if matches.is_present("with-docs") { | ||
|
|
||
This file contains hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
diesel_cli/tests/print_schema/print_schema_except_table_regexes/diesel.toml
This file contains hidden or 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,4 @@ | ||
| [print_schema] | ||
| file = "src/schema.rs" | ||
| with_docs = true | ||
| filter = { except_table_regexes = [".*1"] } |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_except_table_regexes/mysql/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users2` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users2 (id) { | ||
| /// The `id` column of the `users2` table. | ||
| /// | ||
| /// Its SQL type is `Integer`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Integer, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_except_table_regexes/mysql/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id INTEGER PRIMARY KEY); | ||
| CREATE TABLE users2 (id INTEGER PRIMARY KEY); |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_except_table_regexes/postgres/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users2` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users2 (id) { | ||
| /// The `id` column of the `users2` table. | ||
| /// | ||
| /// Its SQL type is `Int4`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Int4, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_except_table_regexes/postgres/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id SERIAL PRIMARY KEY); | ||
| CREATE TABLE users2 (id SERIAL PRIMARY KEY); |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_except_table_regexes/sqlite/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users2` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users2 (id) { | ||
| /// The `id` column of the `users2` table. | ||
| /// | ||
| /// Its SQL type is `Nullable<Integer>`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Nullable<Integer>, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_except_table_regexes/sqlite/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id INTEGER PRIMARY KEY); | ||
| CREATE TABLE users2 (id INTEGER PRIMARY KEY); |
4 changes: 4 additions & 0 deletions
4
diesel_cli/tests/print_schema/print_schema_only_table_regexes/diesel.toml
This file contains hidden or 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,4 @@ | ||
| [print_schema] | ||
| file = "src/schema.rs" | ||
| with_docs = true | ||
| filter = { only_table_regexes = [".*1"] } |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_only_table_regexes/mysql/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users1` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users1 (id) { | ||
| /// The `id` column of the `users1` table. | ||
| /// | ||
| /// Its SQL type is `Integer`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Integer, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_only_table_regexes/mysql/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id INTEGER PRIMARY KEY); | ||
| CREATE TABLE users2 (id INTEGER PRIMARY KEY); |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_only_table_regexes/postgres/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users1` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users1 (id) { | ||
| /// The `id` column of the `users1` table. | ||
| /// | ||
| /// Its SQL type is `Int4`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Int4, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_only_table_regexes/postgres/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id SERIAL PRIMARY KEY); | ||
| CREATE TABLE users2 (id SERIAL PRIMARY KEY); |
13 changes: 13 additions & 0 deletions
13
diesel_cli/tests/print_schema/print_schema_only_table_regexes/sqlite/expected.rs
This file contains hidden or 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,13 @@ | ||
| table! { | ||
| /// Representation of the `users1` table. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| users1 (id) { | ||
| /// The `id` column of the `users1` table. | ||
| /// | ||
| /// Its SQL type is `Nullable<Integer>`. | ||
| /// | ||
| /// (Automatically generated by Diesel.) | ||
| id -> Nullable<Integer>, | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
diesel_cli/tests/print_schema/print_schema_only_table_regexes/sqlite/schema.sql
This file contains hidden or 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,2 @@ | ||
| CREATE TABLE users1 (id INTEGER PRIMARY KEY); | ||
| CREATE TABLE users2 (id INTEGER PRIMARY KEY); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next release will be 2.0 so we can make a breaking change here. Therefore I would prefer to just introduce this functionality under the old flags.
cc @diesel-rs/core as information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the old flags mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of just replacing the old flag (
only-tables) with the regex filtering.