diff --git a/data/location-import-template.xlsx b/data/location-import-template.xlsx new file mode 100644 index 0000000..a824b3b Binary files /dev/null and b/data/location-import-template.xlsx differ diff --git a/sql/cleardown-all-tables.sql b/sql/cleardown-all-tables.sql new file mode 100644 index 0000000..aa352c9 --- /dev/null +++ b/sql/cleardown-all-tables.sql @@ -0,0 +1,23 @@ +DELETE FROM SIGHTING; +DELETE FROM REGISTRATION_HISTORY; +DELETE FROM VOYAGE_EVENT; +DELETE FROM VOYAGE; +DELETE FROM PORT; +DELETE FROM VESSEL; +DELETE FROM COUNTRY; +DELETE FROM JOB_STATUS; +DELETE FROM LOCATION; +DELETE FROM OPERATOR; +DELETE FROM VESSEL_TYPE; + +DELETE FROM SQLITE_SEQUENCE WHERE NAME='SIGHTING'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='REGISTRATION_HISTORY'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='VOYAGE_EVENT'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='VOYAGE'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='PORT'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='VESSEL'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='COUNTRY'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='JOB_STATUS'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='LOCATION'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='OPERATOR'; +DELETE FROM SQLITE_SEQUENCE WHERE NAME='VESSEL_TYPE'; diff --git a/sql/cleardown-operators.sql b/sql/cleardown-operators.sql new file mode 100644 index 0000000..b1413b6 --- /dev/null +++ b/sql/cleardown-operators.sql @@ -0,0 +1,2 @@ +DELETE FROM OPERATOR; +DELETE FROM SQLITE_SEQUENCE WHERE name='OPERATOR'; diff --git a/sql/create-test-voyage.sql b/sql/create-test-voyage.sql new file mode 100644 index 0000000..bc634e1 --- /dev/null +++ b/sql/create-test-voyage.sql @@ -0,0 +1,22 @@ +SELECT * FROM PORT WHERE Code IN ( 'GBSOU', 'BEZEE' ); +/* +6901 22 BEZEE Zeebrugge +59315 235 GBSOU Southampton +*/ +SELECT * FROM OPERATOR WHERE Name LIKE 'P&O%'; +/* +310 P&O Cruises +311 P&O Cruises Australia +*/ +SELECT v.* +FROM VESSEL v +INNER JOIN REGISTRATION_HISTORY rh ON rh.Vessel_Id = v.Id +WHERE rh.Name = 'Arcadia'; +-- 3 9226906 2005 8.2 285 33 +INSERT INTO VOYAGE ( Operator_Id, Vessel_ID, Number ) VALUES ( 310, 3, 'I413' ); +SELECT * FROM VOYAGE WHERE Number = 'I413'; +-- 1 I413 310 3 +INSERT INTO VOYAGE_EVENT ( Voyage_Id, Event_Type, Port_Id, Date ) VALUES ( 1, 0, 59315, '2024-05-14 00:00:00' ); +INSERT INTO VOYAGE_EVENT ( Voyage_Id, Event_Type, Port_Id, Date ) VALUES ( 1, 1, 6901, '2024-05-15 00:00:00' ); +INSERT INTO VOYAGE_EVENT ( Voyage_Id, Event_Type, Port_Id, Date ) VALUES ( 1, 0, 6901, '2024-05-15 00:00:00' ); +INSERT INTO VOYAGE_EVENT ( Voyage_Id, Event_Type, Port_Id, Date ) VALUES ( 1, 1, 59315, '2024-05-17 00:00:00' ); diff --git a/src/ShippingRecorder.BusinessLogic/Config/ManagerCommandLineParser.cs b/src/ShippingRecorder.BusinessLogic/Config/ManagerCommandLineParser.cs index bba982d..34722a1 100644 --- a/src/ShippingRecorder.BusinessLogic/Config/ManagerCommandLineParser.cs +++ b/src/ShippingRecorder.BusinessLogic/Config/ManagerCommandLineParser.cs @@ -10,6 +10,7 @@ public ManagerCommandLineParser(IHelpGenerator generator) : base(generator) Add(CommandLineOptionType.Help, false, "--help", "-h", "Show command line help", 0, 0); Add(CommandLineOptionType.Update, false, "--update", "-u", "Apply the latest database migrations", 0, 0); Add(CommandLineOptionType.ImportCountries, false, "--import-countries", "-ic", "Import countries from a CSV file", 1, 1); + Add(CommandLineOptionType.ImportLocations, false, "--import-locations", "-il", "Import locations from a CSV file", 1, 1); Add(CommandLineOptionType.ImportOperators, false, "--import-operators", "-io", "Import operators from a CSV file", 1, 1); Add(CommandLineOptionType.ImportVesselTypes, false, "--import-vessel-types", "-ivt", "Import vessel types from a CSV file", 1, 1); Add(CommandLineOptionType.ImportVessels, false, "--import-vessels", "-iv", "Import vessels from a CSV file", 1, 1); diff --git a/src/ShippingRecorder.Entities/Config/CommandLineOptionType.cs b/src/ShippingRecorder.Entities/Config/CommandLineOptionType.cs index 372d5a8..1fd5a63 100644 --- a/src/ShippingRecorder.Entities/Config/CommandLineOptionType.cs +++ b/src/ShippingRecorder.Entities/Config/CommandLineOptionType.cs @@ -12,6 +12,7 @@ public enum CommandLineOptionType ExportVesselTypes, Help, ImportCountries, + ImportLocations, ImportOperators, ImportPorts, ImportSightings, diff --git a/src/ShippingRecorder.Manager/Logic/ImportHandler.cs b/src/ShippingRecorder.Manager/Logic/ImportHandler.cs index f0e5916..c8f7ee9 100644 --- a/src/ShippingRecorder.Manager/Logic/ImportHandler.cs +++ b/src/ShippingRecorder.Manager/Logic/ImportHandler.cs @@ -68,6 +68,14 @@ private async Task HandleImport(CommandLineOptionType type, string pattern public async Task HandleCountryImportAsync() => await HandleImport(CommandLineOptionType.ImportCountries, ExportableCountry.CsvRecordPattern); + + /// + /// Handle the locations import command + /// + /// + public async Task HandleLocationImportAsync() + => await HandleImport(CommandLineOptionType.ImportLocations, ExportableLocation.CsvRecordPattern); + /// /// Handle the operators import command /// diff --git a/src/ShippingRecorder.Manager/Program.cs b/src/ShippingRecorder.Manager/Program.cs index 90e45f7..d7bc620 100644 --- a/src/ShippingRecorder.Manager/Program.cs +++ b/src/ShippingRecorder.Manager/Program.cs @@ -69,6 +69,12 @@ public static async Task Main(string[] args) await new ImportHandler(settings, parser, factory).HandleCountryImportAsync(); } + // If a CSV file containing locations details has been supplied, import it + if (parser.IsPresent(CommandLineOptionType.ImportLocations)) + { + await new ImportHandler(settings, parser, factory).HandleLocationImportAsync(); + } + // If a CSV file containing operator details has been supplied, import it if (parser.IsPresent(CommandLineOptionType.ImportOperators)) {