Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
marcio-santos-zocdoc committed Dec 13, 2016
1 parent c011b90 commit 61bda32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 0 additions & 2 deletions model/Command/CreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public void CreateDatabase(string databaseFilesPath)
}

db.CreateDBFromDir(databaseFilesPath, Logger.Log);
Logger.Log(TraceLevel.Info, Environment.NewLine + "Database created successfully.");
}

public void CreateTables(string databaseFilesPath)
Expand All @@ -33,7 +32,6 @@ public void CreateTables(string databaseFilesPath)
}

db.CreateDbObjectsFromDir(databaseFilesPath, Logger.Log);
Logger.Log(TraceLevel.Info, Environment.NewLine + "Database created successfully.");
}
}
}
34 changes: 19 additions & 15 deletions model/Models/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,25 +1486,27 @@ public void CreateDbObjectsFromDir(string databaseFilesPath = null, Action<Trace
ex.Exceptions = errors;
throw ex;
}
}

public void CreateDBFromDir(string databaseFilesPath, Action<TraceLevel, string> log) {
log(TraceLevel.Info, Environment.NewLine + "Database objects created successfully.");
}

public void CreateDBFromDir(string databaseFilesPath, Action<TraceLevel, string> log) {
if (log == null) log = (tl, s) => { };

if (DBHelper.DbExists(Connection)) {
log(TraceLevel.Verbose, "Dropping existing database...");
DBHelper.DropDb(Connection);
log(TraceLevel.Verbose, "Existing database dropped.");
}
log(TraceLevel.Verbose, string.Format("Dropping existing database for {0}", DatabaseName));
DBHelper.DropDb(Connection);
log(TraceLevel.Verbose, string.Format("Existing database dropped for {0}", DatabaseName));
}

log(TraceLevel.Info, "Creating database...");
//create database
DBHelper.CreateDb(Connection, databaseFilesPath);
log(TraceLevel.Info, string.Format("Creating database {0}", DatabaseName));
//create database
DBHelper.CreateDb(Connection, databaseFilesPath);

//run scripts
if (File.Exists(Dir + "/props.sql")) {
log(TraceLevel.Verbose, "Setting database properties...");
try {
log(TraceLevel.Verbose, string.Format("Setting database properties {0}", DatabaseName));
try {
DBHelper.ExecBatchSql(Connection, File.ReadAllText(Dir + "/props.sql"));
} catch (SqlBatchException ex) {
throw new SqlFileException(Dir + "/props.sql", ex);
Expand All @@ -1516,16 +1518,18 @@ public void CreateDBFromDir(string databaseFilesPath, Action<TraceLevel, string>
}

if (File.Exists(Dir + "/schemas.sql")) {
log(TraceLevel.Verbose, "Creating database schemas...");
try {
log(TraceLevel.Verbose, string.Format("Creating database schemas for {0}", DatabaseName));
try {
DBHelper.ExecBatchSql(Connection, File.ReadAllText(Dir + "/schemas.sql"));
} catch (SqlBatchException ex) {
throw new SqlFileException(Dir + "/schemas.sql", ex);
}
}
}

private List<string> GetScripts() {
log(TraceLevel.Info, Environment.NewLine + string.Format("Database {0} created successfully.", DatabaseName));
}

private List<string> GetScripts() {
var scripts = new List<string>();
foreach (
var dirPath in _dirs.Where(dir => dir != "foreign_keys").Select(dir => Dir + "/" + dir).Where(Directory.Exists)) {
Expand Down

0 comments on commit 61bda32

Please sign in to comment.