Skip to content

Commit

Permalink
Simplify the source code parsing
Browse files Browse the repository at this point in the history
- Add tests
- Check circular dependencies
- fix a bug on the parsed files

Signed-off-by: Gabriel de Maeztu <[email protected]>
  • Loading branch information
merqurio committed Aug 25, 2024
1 parent de6fdee commit 77a94c1
Show file tree
Hide file tree
Showing 7 changed files with 697 additions and 508 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ env_logger = "0.8.4"
indexmap = "1.9.3"
log = "0.4"
sqlparser = { version = "0.50.0", features = ["visitor"] }
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "mysql", "sqlite", "tls-rustls-ring"] }
sqlx = { version = "0.8", features = [
"runtime-tokio",
"postgres",
"mysql",
"sqlite",
"tls-rustls-ring",
] }
tokio = { version = "1.0", features = ["full"] }
walkdir = "2.3"

[dev-dependencies]
tempfile = "3.2"

[[bin]]
name = "oxigration"
path = "src/main.rs"
path = "src/main.rs"
2 changes: 1 addition & 1 deletion src/deploy_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::env;
use std::error::Error;
use std::sync::atomic::Ordering;

use crate::relational_object::DatabaseObject;
use crate::source_code::DatabaseObject;
use crate::utils::{format_query_with_schema, SCHEMA_SUPPORT};

/// This function initializes the deploy log and the configuration settings in the database.
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod deploy_log;
mod reference;
mod relational_object;
mod source_code;
mod utils;

use deploy_log::{init_deploy_log, read_deploy_log};
use log::{error, info};
use reference::reference;
use relational_object::DatabaseObject;
use source_code::read_source_code;
use sqlx::{query_scalar, AnyPool};
use std::env;
use std::path::Path;
Expand Down Expand Up @@ -205,7 +203,7 @@ pub async fn migrate(
// This step involves parsing the SQL files, processing them, and storing the information in memory. It parses the SQL inside each file and builds a graph representation of each database object, its modifications over time, and other dependencies.
// The information from the AST tree is used to build a graph where all the other database objects that have a dependency on that object are stated with a relationship.
// TODO: With table CREATE statements, it rewrites the initial schema based on all the ALTERS that the table might have along all the files, creating a new CREATE statement that includes all the changes.
let _reference_source_code = reference(base_dir)?;
let _reference_source_code = read_source_code(base_dir)?;

// Step 1: Read changes from the deploy log in the target database
// This step involves reading the deploy log to understand the current state of the environment.
Expand Down
Loading

0 comments on commit 77a94c1

Please sign in to comment.