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

Option unwrap in CLI #270

Closed
fenhl opened this issue Oct 23, 2021 · 2 comments
Closed

Option unwrap in CLI #270

fenhl opened this issue Oct 23, 2021 · 2 comments

Comments

@fenhl
Copy link

fenhl commented Oct 23, 2021

Making a new issue since #153 got repurposed. With the --verbose flag introduced there, this is the output I'm getting:

[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery::executor::real] SELECT "table_name", "user_defined_type_schema", "user_defined_type_name" FROM "information_schema"."tables" WHERE "table_schema" = $1 AND "table_type" = $2, Values([String(Some("public")), String(Some("BASE TABLE"))])
[2021-10-23T16:43:23Z INFO  sqlx::query] /* SQLx ping */; rows: 0, elapsed: 140.301µs
[2021-10-23T16:43:23Z INFO  sqlx::query] SELECT "table_name", "user_defined_type_schema", "user_defined_type_name" …; rows: 1, elapsed: 4.604ms

    SELECT
      "table_name",
      "user_defined_type_schema",
      "user_defined_type_name"
    FROM
      "information_schema"."tables"
    WHERE
      "table_schema" = $1
      AND "table_type" = $2

[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableQueryResult { table_name: "people", user_defined_type_schema: None, user_defined_type_name: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableInfo { name: "people", of_type: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery::executor::real] SELECT "column_name", "data_type", "column_default", "generation_expression", "is_nullable", "is_identity", "numeric_precision", "numeric_precision_radix", "numeric_scale", "character_maximum_length", "character_octet_length", "datetime_precision", "interval_type", "interval_precision" FROM "information_schema"."columns" WHERE "table_schema" = $1 AND "table_name" = $2, Values([String(Some("public")), String(Some("people"))])
[2021-10-23T16:43:23Z INFO  sqlx::query] /* SQLx ping */; rows: 0, elapsed: 208.231µs
[2021-10-23T16:43:23Z INFO  sqlx::query] SELECT "column_name", "data_type", "column_default", …; rows: 8, elapsed: 15.731ms

    SELECT
      "column_name",
      "data_type",
      "column_default",
      "generation_expression",
      "is_nullable",
      "is_identity",
      "numeric_precision",
      "numeric_precision_radix",
      "numeric_scale",
      "character_maximum_length",
      "character_octet_length",
      "datetime_precision",
      "interval_type",
      "interval_precision"
    FROM
      "information_schema"."columns"
    WHERE
      "table_schema" = $1
      AND "table_name" = $2

[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "id", column_type: "integer", column_default: Some("nextval('people_id_seq'::regclass)"), column_generated: None, is_nullable: "NO", is_identity: "NO", numeric_precision: Some(32), numeric_precision_radix: Some(2), numeric_scale: Some(0), character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "id", col_type: Integer, default: Some(ColumnExpression("nextval('people_id_seq'::regclass)")), generated: None, not_null: Some(NotNull), is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "wmbid", column_type: "character varying", column_default: None, column_generated: None, is_nullable: "YES", is_identity: "NO", numeric_precision: None, numeric_precision_radix: None, numeric_scale: None, character_maximum_length: Some(16), character_octet_length: Some(64), datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "wmbid", col_type: Varchar(StringAttr { length: Some(16) }), default: None, generated: None, not_null: None, is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "snowflake", column_type: "bigint", column_default: None, column_generated: None, is_nullable: "YES", is_identity: "NO", numeric_precision: Some(64), numeric_precision_radix: Some(2), numeric_scale: Some(0), character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "snowflake", col_type: BigInt, default: None, generated: None, not_null: None, is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "active", column_type: "boolean", column_default: None, column_generated: None, is_nullable: "NO", is_identity: "NO", numeric_precision: None, numeric_precision_radix: None, numeric_scale: None, character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "active", col_type: Boolean, default: None, generated: None, not_null: Some(NotNull), is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "data", column_type: "jsonb", column_default: None, column_generated: None, is_nullable: "YES", is_identity: "NO", numeric_precision: None, numeric_precision_radix: None, numeric_scale: None, character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "data", col_type: Unknown("jsonb"), default: None, generated: None, not_null: None, is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "version", column_type: "integer", column_default: None, column_generated: None, is_nullable: "NO", is_identity: "NO", numeric_precision: Some(32), numeric_precision_radix: Some(2), numeric_scale: Some(0), character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "version", col_type: Integer, default: None, generated: None, not_null: Some(NotNull), is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "apikey", column_type: "character varying", column_default: None, column_generated: None, is_nullable: "YES", is_identity: "NO", numeric_precision: None, numeric_precision_radix: None, numeric_scale: None, character_maximum_length: Some(25), character_octet_length: Some(100), datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "apikey", col_type: Varchar(StringAttr { length: Some(25) }), default: None, generated: None, not_null: None, is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnQueryResult { column_name: "discorddata", column_type: "jsonb", column_default: None, column_generated: None, is_nullable: "YES", is_identity: "NO", numeric_precision: None, numeric_precision_radix: None, numeric_scale: None, character_maximum_length: None, character_octet_length: None, datetime_precision: None, interval_type: None, interval_precision: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] ColumnInfo { name: "discorddata", col_type: Unknown("jsonb"), default: None, generated: None, not_null: None, is_identity: false }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery::executor::real] SELECT "table_constraints"."constraint_schema", "table_constraints"."constraint_name", "table_constraints"."table_schema", "table_constraints"."table_name", "table_constraints"."constraint_type", "table_constraints"."is_deferrable", "table_constraints"."initially_deferred", "check_constraints"."check_clause", "key_column_usage"."column_name", "key_column_usage"."ordinal_position", "key_column_usage"."position_in_unique_constraint", "referential_constraints_subquery"."unique_constraint_schema", "referential_constraints_subquery"."unique_constraint_name", "referential_constraints_subquery"."match_option", "referential_constraints_subquery"."update_rule", "referential_constraints_subquery"."delete_rule", "referential_constraints_subquery"."table_name", "referential_constraints_subquery"."column_name" FROM "information_schema"."table_constraints" LEFT JOIN "information_schema"."check_constraints" ON "table_constraints"."constraint_name" = "check_constraints"."constraint_name" LEFT JOIN "information_schema"."key_column_usage" ON "table_constraints"."constraint_name" = "key_column_usage"."constraint_name" LEFT JOIN (SELECT "referential_constraints"."constraint_name", "referential_constraints"."unique_constraint_schema", "referential_constraints"."unique_constraint_name", "referential_constraints"."match_option", "referential_constraints"."update_rule", "referential_constraints"."delete_rule", "key_column_usage"."table_name", "key_column_usage"."column_name" FROM "information_schema"."referential_constraints" LEFT JOIN "information_schema"."key_column_usage" ON "referential_constraints"."unique_constraint_name" = "key_column_usage"."constraint_name") AS "referential_constraints_subquery" ON "table_constraints"."constraint_name" = "referential_constraints_subquery"."constraint_name" WHERE "table_constraints"."table_schema" = $1 AND "table_constraints"."table_name" = $2 ORDER BY "table_constraints"."constraint_name" ASC, "key_column_usage"."ordinal_position" ASC, "referential_constraints_subquery"."unique_constraint_name" ASC, "referential_constraints_subquery"."constraint_name" ASC, Values([String(Some("public")), String(Some("people"))])
[2021-10-23T16:43:23Z INFO  sqlx::query] /* SQLx ping */; rows: 0, elapsed: 490.332µs
[2021-10-23T16:43:23Z INFO  sqlx::query] /* SQLx ping */; rows: 0, elapsed: 188.771µs
[2021-10-23T16:43:23Z INFO  sqlx::query] SELECT "table_constraints"."constraint_schema", "table_constraints"."constraint_name", "table_constraints"."table_schema", …; rows: 4, elapsed: 11.477ms

    SELECT
      "table_constraints"."constraint_schema",
      "table_constraints"."constraint_name",
      "table_constraints"."table_schema",
      "table_constraints"."table_name",
      "table_constraints"."constraint_type",
      "table_constraints"."is_deferrable",
      "table_constraints"."initially_deferred",
      "check_constraints"."check_clause",
      "key_column_usage"."column_name",
      "key_column_usage"."ordinal_position",
      "key_column_usage"."position_in_unique_constraint",
      "referential_constraints_subquery"."unique_constraint_schema",
      "referential_constraints_subquery"."unique_constraint_name",
      "referential_constraints_subquery"."match_option",
      "referential_constraints_subquery"."update_rule",
      "referential_constraints_subquery"."delete_rule",
      "referential_constraints_subquery"."table_name",
      "referential_constraints_subquery"."column_name"
    FROM
      "information_schema"."table_constraints"
      LEFT JOIN "information_schema"."check_constraints" ON "table_constraints"."constraint_name" = "check_constraints"."constraint_name"
      LEFT JOIN "information_schema"."key_column_usage" ON "table_constraints"."constraint_name" = "key_column_usage"."constraint_name"
      LEFT JOIN (
        SELECT
          "referential_constraints"."constraint_name",
          "referential_constraints"."unique_constraint_schema",
          "referential_constraints"."unique_constraint_name",
          "referential_constraints"."match_option",
          "referential_constraints"."update_rule",
          "referential_constraints"."delete_rule",
          "key_column_usage"."table_name",
          "key_column_usage"."column_name"
        FROM
          "information_schema"."referential_constraints"
          LEFT JOIN "information_schema"."key_column_usage" ON "referential_constraints"."unique_constraint_name" = "key_column_usage"."constraint_name"
      ) AS "referential_constraints_subquery" ON "table_constraints"."constraint_name" = "referential_constraints_subquery"."constraint_name"
    WHERE
      "table_constraints"."table_schema" = $1
      AND "table_constraints"."table_name" = $2
    ORDER BY
      "table_constraints"."constraint_name" ASC,
      "key_column_usage"."ordinal_position" ASC,
      "referential_constraints_subquery"."unique_constraint_name" ASC,
      "referential_constraints_subquery"."constraint_name" ASC

[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_1_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
[2021-10-23T16:43:23Z INFO  sqlx::query] /* SQLx ping */; rows: 0, elapsed: 142.150µs
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_4_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_6_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "people_pkey", table_schema: "public", table_name: "people", constraint_type: "PRIMARY KEY", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: Some("id"), ordinal_position: Some(1), position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/fenhl/.cargo/registry/src/github.com-1ecc6299db9ec823/sea-schema-0.2.9/src/postgres/parser/table_constraints.rs:39:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@billy1624
Copy link
Member

billy1624 commented Oct 25, 2021

Thanks @fenhl, if you look closely into...

[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_1_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_4_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }
[2021-10-23T16:43:23Z DEBUG sea_schema::postgres::discovery] TableConstraintsQueryResult { constraint_schema: "public", constraint_name: "2200_16389_6_not_null", table_schema: "public", table_name: "people", constraint_type: "CHECK", is_deferrable: "NO", initially_deferred: "NO", check_clause: None, column_name: None, ordinal_position: None, position_in_unique_constraint: None, unique_constraint_schema: None, unique_constraint_name: None, match_option: None, update_rule: None, delete_rule: None, referential_key_table_name: None, referential_key_column_name: None }

You could see these three CHECK constraints don't have a check_clause and this is why it panic.

May I know the meta of these CHECK constraints with name...

  • 2200_16389_1_not_null
  • 2200_16389_4_not_null
  • 2200_16389_6_not_null

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 15, 2021

Please reopen if you still have problems

@tyt2y3 tyt2y3 closed this as completed Nov 15, 2021
arpancodes pushed a commit to arpancodes/sea-orm that referenced this issue Apr 8, 2022
Allow for trailing commas in any and all macros
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

3 participants