Skip to content
Open
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
58 changes: 25 additions & 33 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,57 +75,49 @@ jobs:

- name: Install TimescaleDB on Windows
run: |
# Download the official TimescaleDB installer for PostgreSQL 14.
Invoke-WebRequest -Uri "https://github.com/timescale/timescaledb/releases/latest/download/timescaledb-postgresql-14-windows-amd64.zip" -OutFile "timescaledb.zip"
# Create a dedicated folder for the installer.
# Download TimescaleDB for PostgreSQL 14 (not 17)
Invoke-WebRequest -Uri "https://github.com/timescale/timescaledb/releases/download/2.19.0/timescaledb-postgresql-14-windows-amd64.zip" -OutFile "timescaledb.zip"

# Create a folder for extraction
New-Item -ItemType Directory -Force -Path "C:\timescaledb"

# Extract the ZIP into C:\timescaledb.
Expand-Archive -Path "timescaledb.zip" -DestinationPath "C:\timescaledb"
# Find the setup.exe file in the extracted folder.

# Locate setup.exe
$setupPath = Get-ChildItem -Path "C:\timescaledb" -Recurse -Filter "setup.exe" | Select-Object -First 1 | ForEach-Object { $_.FullName }
Write-Host "Found setup executable at: $setupPath"

# Unblock the setup executable so it can run.
Write-Host "Unblocking setup.exe..."

# Unblock and set up environment
Unblock-File -Path $setupPath
Set-ExecutionPolicy Bypass -Scope Process -Force

# Setup working directory
$setupDir = Split-Path -Path $setupPath
Write-Host "Setting working directory to: $setupDir"
Set-Location -Path $setupDir

# PostgreSQL paths
# Run the installer first (before editing postgresql.conf)
Start-Process -FilePath $setupPath -ArgumentList "/S --yes" -WorkingDirectory $setupDir -Wait -NoNewWindow

# Modify postgresql.conf now that DLLs are installed
$pgDataDir = "D:\a\_temp\pgdata"
$env:PGPASSWORD="${{ env.pgpass }}"
$pgConfigPath = "D:/a/_temp/pgdata/postgresql.conf"

# Modify postgresql.conf to preload TimescaleDB before installation
Write-Host "Preload TimescaleDB..."
(Get-Content $pgConfigPath) -replace "^#?\s*shared_preload_libraries\s*=.*", "shared_preload_libraries = 'timescaledb'" | Set-Content $pgConfigPath

Write-Host "Restarting PostgreSQL to apply new settings..."
pg_ctl -D $pgDataDir restart
Start-Sleep -Seconds 5

# Run the installer
Write-Host "Running setup.exe..."
Start-Process -FilePath $setupPath -ArgumentList "/S --yes" -WorkingDirectory $setupDir -Wait -NoNewWindow

# Restart PostgreSQL again to apply TimescaleDB settings

# Restart PostgreSQL to load TimescaleDB
Write-Host "Restarting PostgreSQL after installation..."
pg_ctl -D $pgDataDir restart
Start-Sleep -Seconds 5

# Enable the TimescaleDB extension in PostgreSQL.
Write-Host "Configuring PostgreSQL authentication..."

# Enable extension
$env:PGPASSWORD="${{ env.pgpass }}"
Write-Host "Create TimescaleDB extension for database..."
psql -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS timescaledb;"
shell: pwsh
# Enable extension
- name: Verify TimescaleDB Extension
run: |
$env:PGPASSWORD="${{ env.pgpass }}"
psql -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS timescaledb;"

# Verify that the TimescaleDB extension is loaded
Write-Host "Verifying TimescaleDB extension is installed..."
psql -U postgres -d postgres -c "SELECT * FROM pg_extension WHERE extname = 'timescaledb';"

- name: Create Python Virtual Environment and Install Dependencies
run: |
Expand Down
10 changes: 5 additions & 5 deletions aisdb_lib/src/csvreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn sqlite_decodemsgs_ee_csv(
own_vessel: true,
station: Station::BaseStation,
ais_type: AisClass::Unknown,
mmsi: row.get(0).unwrap().parse().unwrap(),
mmsi: row.get(0).unwrap().parse::<u32>().unwrap_or(0),
nav_status: NavigationStatus::NotDefined,
rot: row.get(25).unwrap().parse::<f64>().ok(),
rot_direction: None,
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn sqlite_decodemsgs_ee_csv(
let payload = VesselStaticData {
own_vessel: true,
ais_type: AisClass::Unknown,
mmsi: row.get(0).unwrap().parse().unwrap(),
mmsi: row.get(0).unwrap().parse::<u32>().unwrap_or(0),
ais_version_indicator: row.get(23).unwrap().parse().unwrap_or_default(),
imo_number: row.get(15).unwrap().parse().ok(),
call_sign: row.get(14).unwrap().parse().ok(),
Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn postgres_decodemsgs_ee_csv(
let payload = VesselStaticData {
own_vessel: true,
ais_type: AisClass::Unknown,
mmsi: row.get(0).unwrap().parse().unwrap(),
mmsi: row.get(0).unwrap().parse::<u32>().unwrap_or(0),
ais_version_indicator: row.get(23).unwrap().parse().unwrap_or_default(),
imo_number: row.get(15).unwrap().parse().ok(),
call_sign: row.get(14).unwrap().parse().ok(),
Expand Down Expand Up @@ -762,8 +762,8 @@ MMSI,Message_ID,Repeat_indicator,Time,Millisecond,Region,Country,Base_station,On
let fpath = std::path::PathBuf::from("testdata/testingdata.csv");

let _ = sqlite_decodemsgs_ee_csv(
&std::path::Path::new("testdata/test.db").to_path_buf(),
&fpath,
std::path::Path::new("testdata/test.db").to_path_buf(),
fpath,
"TESTDATA",
true,
);
Expand Down
6 changes: 4 additions & 2 deletions aisdb_lib/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ mod tests {
#[test]
fn test_create_statictable() -> SqliteResult<()> {
let mstr = "00test00";
let mut conn = get_db_conn(Path::new(":memory:")).expect("getting db conn");
let path = Path::new(":memory:").to_path_buf();
let mut conn = get_db_conn(path).expect("getting db conn");

println!("/* creating table */");
let tx = conn.transaction().expect("begin transaction");
Expand All @@ -403,7 +404,8 @@ mod tests {
#[test]
fn test_create_dynamictable() -> SqliteResult<()> {
let mstr = "00test00";
let mut conn = get_db_conn(Path::new(":memory:")).expect("getting db conn");
let path = Path::new(":memory:").to_path_buf();
let mut conn = get_db_conn(path).expect("getting db conn");

println!("/* creating table */");
let tx = conn.transaction().expect("begin transaction");
Expand Down
4 changes: 2 additions & 2 deletions aisdb_lib/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ pub mod tests {
let fpaths = glob_dir(std::path::PathBuf::from("testdata/"), "nm4").expect("globbing");
for filepath in fpaths {
parser = sqlite_decode_insert_msgs(
&std::path::Path::new("testdata/test.db").to_path_buf(),
&std::path::Path::new(&filepath).to_path_buf(),
std::path::Path::new("testdata/test.db").to_path_buf(),
std::path::Path::new(&filepath).to_path_buf(),
"TESTING",
parser,
true,
Expand Down
Loading