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

Added order on dump fields #211

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/lib/database_drivers/maria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl DatabaseDriver for MariaDBDriver {
let fut = async move {
let schema = r#"
--
-- Maria SQL Schema dump automatic generated by geni
-- MySQL SQL Schema dump automatic generated by geni
--


Expand All @@ -217,7 +217,9 @@ impl DatabaseDriver for MariaDBDriver {
' ', COLUMN_NAME, ' ', COLUMN_TYPE,
IF(IS_NULLABLE = 'NO', ' NOT NULL', ''),
IF(COLUMN_DEFAULT IS NOT NULL, CONCAT(' DEFAULT ', COLUMN_DEFAULT), '')
) SEPARATOR', \n'
)
ORDER BY COLUMN_NAME ASC
SEPARATOR', \n'
),
'\n);'
) AS create_table_stmt
Expand Down Expand Up @@ -258,7 +260,8 @@ impl DatabaseDriver for MariaDBDriver {
FROM
INFORMATION_SCHEMA.VIEWS
WHERE
TABLE_SCHEMA = ?;
TABLE_SCHEMA = ?
ORDER BY TABLE_SCHEMA asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -294,7 +297,8 @@ impl DatabaseDriver for MariaDBDriver {
ELSE ')'
END,
';'
) AS create_constraint_stmt
) AS create_constraint_stmt,
TABLE_NAME
FROM
(
SELECT
Expand Down Expand Up @@ -335,9 +339,10 @@ impl DatabaseDriver for MariaDBDriver {
WHERE
TABLE_SCHEMA = ?
AND REFERENCED_TABLE_NAME IS NOT NULL
ORDER BY COLUMN_NAME asc
) AS constraints
ORDER BY
TABLE_NAME;
TABLE_NAME asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -374,7 +379,7 @@ impl DatabaseDriver for MariaDBDriver {
GROUP BY
TABLE_NAME, INDEX_NAME, COLUMN_NAME
ORDER BY
TABLE_NAME;
TABLE_NAME, COLUMN_NAME asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -410,7 +415,8 @@ impl DatabaseDriver for MariaDBDriver {
SELECT TABLE_NAME, NULL, COLUMN_NAME, COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ? AND (COLUMN_COMMENT IS NOT NULL OR COLUMN_COMMENT != '')
) AS comments;
) AS comments
ORDER BY TABLE_NAME, COLUMN_NAME
"#,
)
.bind(&self.db_name)
Expand Down
15 changes: 10 additions & 5 deletions src/lib/database_drivers/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ impl DatabaseDriver for MySQLDriver {
' ', COLUMN_NAME, ' ', COLUMN_TYPE,
IF(IS_NULLABLE = 'NO', ' NOT NULL', ''),
IF(COLUMN_DEFAULT IS NOT NULL, CONCAT(' DEFAULT ', COLUMN_DEFAULT), '')
) SEPARATOR', \n'
)
ORDER BY COLUMN_NAME ASC
SEPARATOR', \n'
),
'\n);'
) AS create_table_stmt
Expand Down Expand Up @@ -258,7 +260,8 @@ impl DatabaseDriver for MySQLDriver {
FROM
INFORMATION_SCHEMA.VIEWS
WHERE
TABLE_SCHEMA = ?;
TABLE_SCHEMA = ?
ORDER BY TABLE_SCHEMA asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -336,9 +339,10 @@ impl DatabaseDriver for MySQLDriver {
WHERE
TABLE_SCHEMA = ?
AND REFERENCED_TABLE_NAME IS NOT NULL
ORDER BY COLUMN_NAME asc
) AS constraints
ORDER BY
TABLE_NAME;
TABLE_NAME asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -375,7 +379,7 @@ impl DatabaseDriver for MySQLDriver {
GROUP BY
TABLE_NAME, INDEX_NAME, COLUMN_NAME
ORDER BY
TABLE_NAME;
TABLE_NAME, COLUMN_NAME asc
"#,
)
.bind(&self.db_name)
Expand Down Expand Up @@ -411,7 +415,8 @@ impl DatabaseDriver for MySQLDriver {
SELECT TABLE_NAME, NULL, COLUMN_NAME, COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ? AND (COLUMN_COMMENT IS NOT NULL OR COLUMN_COMMENT != '')
) AS comments;
) AS comments
ORDER BY TABLE_NAME, COLUMN_NAME
"#,
)
.bind(&self.db_name)
Expand Down
11 changes: 6 additions & 5 deletions src/lib/database_drivers/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ impl DatabaseDriver for PostgresDriver {
FROM
pg_extension
WHERE
(SELECT nspname FROM pg_namespace WHERE oid = extnamespace) = 'public';
(SELECT nspname FROM pg_namespace WHERE oid = extnamespace) = 'public'
ORDER BY extname ASC
"#,
)
.map(|row: PgRow| row.get("sql"))
Expand All @@ -233,7 +234,7 @@ impl DatabaseDriver for PostgresDriver {
THEN '(' || c.character_maximum_length || ')'
ELSE '' END) ||
(CASE WHEN c.is_nullable = 'NO' THEN ' NOT NULL' ELSE '' END),
E',\n ') ||
E',\n ' ORDER BY c.column_name ASC) ||
E'\n);' AS sql
FROM
information_schema.columns c
Expand Down Expand Up @@ -269,7 +270,7 @@ impl DatabaseDriver for PostgresDriver {
WHERE
table_schema = 'public'
ORDER BY
table_name;
table_name ASC
"#,
)
.map(|row: PgRow| row.get("sql"))
Expand Down Expand Up @@ -344,7 +345,7 @@ impl DatabaseDriver for PostgresDriver {
WHERE
schemaname = 'public'
ORDER BY
indexname;
indexname ASC;
"#,
)
.map(|row: PgRow| row.get("sql"))
Expand Down Expand Up @@ -374,7 +375,7 @@ impl DatabaseDriver for PostgresDriver {
WHERE
sequence_schema = 'public'
ORDER BY
sequence_name;
sequence_name ASC;
"#,
)
.map(|row: PgRow| row.get("sql"))
Expand Down
Loading