Skip to content

Commit

Permalink
Separate settings for extraction and insertion file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
vieirandre committed Jul 6, 2020
1 parent e54d2f0 commit 7c7bb9e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static class Config
public static int TargetPort => int.TryParse(Configuration.GetSection("TargetPort").Value, out int targetPort) ? targetPort : Cassandra.ProtocolOptions.DefaultPort;
public static string TargetKeyspace => Configuration.GetSection("TargetKeyspace").Value;
public static string TargetTable => Configuration.GetSection("TargetTable").Value;
public static string FilePath => Configuration.GetSection("FilePath").Value;
public static string InsertionFilePath => Configuration.GetSection("InsertionFilePath").Value;
public static string ExtractionFilePath => Configuration.GetSection("ExtractionFilePath").Value;
public static int InsertionBatch => int.TryParse(Configuration.GetSection("InsertionBatch").Value, out int insertionBatch) ? insertionBatch : 100000;

private static readonly IConfigurationRoot Configuration = new ConfigurationBuilder()
Expand Down
4 changes: 2 additions & 2 deletions Models/Extraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private static void ProcessRows(RowSet rows)
{
Logger.Info("Processing rows...");

_ = Directory.CreateDirectory(Path.GetDirectoryName(Config.FilePath));
using var fileWriter = new StreamWriter(Config.FilePath);
_ = Directory.CreateDirectory(Path.GetDirectoryName(Config.ExtractionFilePath));
using var fileWriter = new StreamWriter(Config.ExtractionFilePath);

string columnNames = string.Join(',', rows.Columns.Select(c => c.Name));
fileWriter.WriteLine(columnNames);
Expand Down
4 changes: 2 additions & 2 deletions Models/Insertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal override void Execute()

BuildTargetClusterAndSession();

if (!File.Exists(Config.FilePath))
if (!File.Exists(Config.InsertionFilePath))
throw new FileNotFoundException("The file either does not exist or there is a lack of permissions to read it. Check the path provided.");

IEnumerable<dynamic> records = ReadRecordsFromFile();
Expand All @@ -52,7 +52,7 @@ private static IEnumerable<dynamic> ReadRecordsFromFile()
{
Logger.Info("Reading data from file...");

var reader = new StreamReader(Config.FilePath);
var reader = new StreamReader(Config.InsertionFilePath);
var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture);

ConfigureCsvReader(csvReader);
Expand Down
3 changes: 2 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"TargetPort": "",
"TargetKeyspace": "",
"TargetTable": "",
"FilePath": "data/migration.csv",
"ExtractionFilePath": "data/extract.csv",
"InsertionFilePath": "data/insert.csv",
"InsertionBatch": "100000"
}

0 comments on commit 7c7bb9e

Please sign in to comment.