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

feat: Implement compileTables missing method #868

Merged
merged 7 commits into from
Jul 31, 2024

Conversation

ErDiabIo
Copy link
Contributor

Hi,

This pr is for implemente the missing method compileTables from laravel

compileTables

i write the following query for get all table from database

SELECT all_tab_comments.table_name AS "name"
FROM all_tab_comments
         JOIN all_tables ON all_tab_comments.table_name = all_tables.table_name
WHERE all_tab_comments.owner = '{owner}'
  AND all_tab_comments.table_type IN ('TABLE')
ORDER BY all_tab_comments.table_name;

Luca Zangheri added 3 commits July 15, 2024 14:34
A new method 'compileTables' has been added to OracleGrammar.php. This addition allows the query to be compiled to determine the tables for a database. Accompanying tests for this feature were also added in Oci8SchemaGrammarTest.php.
@yajra yajra changed the title Implement compileTables missing method feat: Implement compileTables missing method Jul 20, 2024
@yajra
Copy link
Owner

yajra commented Jul 20, 2024

Thank you for the PR, the initial review looks good with a test.

I will review this further as soon as I can.

@yajra yajra self-requested a review July 20, 2024 08:06
Copy link
Owner

@yajra yajra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running on local, Schema::getTables() returns duplicates and other fields are null.

    [
      "name" => "JOBS",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "JOBS",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "JOB_BATCHES",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "JOB_BATCHES",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "JOB_BATCHES",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "JOB_BATCHES",
      "schema" => null,
      "size" => null,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],

Using SQLite:

    [
      "name" => "job_batches",
      "schema" => null,
      "size" => 8192,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],
    [
      "name" => "jobs",
      "schema" => null,
      "size" => 16384,
      "comment" => null,
      "collation" => null,
      "engine" => null,
    ],

@yajra
Copy link
Owner

yajra commented Jul 20, 2024

Maybe MySQL would return more values, I suggest we try to match it. Thanks!

The OracleGrammar.php and associated test file have been updated. These modifications provide additional information, such as the schema, size, comments, and collation when compiling table data. Now, the user will have a more detailed view of their database tables.
Copy link
Contributor Author

@ErDiabIo ErDiabIo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I've updated the query to remove duplicates and add the missing information.

the new query

SELECT ALL_TAB_COMMENTS.TABLE_NAME                                              AS "NAME",
       ALL_TABLES.OWNER                                                         AS "SCHEMA",
       COALESCE(ROUND(SUM(USER_SEGMENTS.BYTES) / 1024 / 1024, 2), 0)            AS "SIZE",
       ALL_TAB_COMMENTS.COMMENTS                                                AS "COMMENTS",
       (SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_SORT') AS "COLLATION"
FROM ALL_TABLES
         JOIN ALL_TAB_COMMENTS ON ALL_TAB_COMMENTS.TABLE_NAME = ALL_TABLES.TABLE_NAME
         LEFT JOIN USER_SEGMENTS ON USER_SEGMENTS.SEGMENT_NAME = ALL_TABLES.TABLE_NAME
WHERE ALL_TABLES.OWNER = '{OWNER}'
  AND ALL_TAB_COMMENTS.OWNER = '{OWNER}'
  AND ALL_TAB_COMMENTS.TABLE_TYPE IN ('TABLE')
GROUP BY ALL_TAB_COMMENTS.TABLE_NAME, ALL_TABLES.OWNER, ALL_TABLES.NUM_ROWS, ALL_TABLES.AVG_ROW_LEN, ALL_TABLES.BLOCKS,
         ALL_TAB_COMMENTS.COMMENTS
order by all_tab_comments.table_name;

@ErDiabIo ErDiabIo requested a review from yajra July 22, 2024 19:12
@yajra
Copy link
Owner

yajra commented Jul 26, 2024

Thanks for the updates, will review this again as soon as I can.

ErDiabIo and others added 3 commits July 30, 2024 09:04
Co-authored-by: Arjay Angeles <aqangeles@gmail.com>
Lowercased table names, schema, and collation parameters to ensure consistency. Also simplified the size calculation by removing the rounding and conversion to megabytes.
@yajra yajra merged commit 0fe8b7e into yajra:master Jul 31, 2024
2 checks passed
@yajra
Copy link
Owner

yajra commented Jul 31, 2024

Release on https://github.com/yajra/laravel-oci8/releases/tag/v11.5.0 🚀 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants