114 lines
3.4 KiB
Rust
114 lines
3.4 KiB
Rust
use scylla::{Session, SessionBuilder};
|
|
use std::sync::Arc;
|
|
|
|
pub async fn initialize_schema(session: &Session) -> Result<(), Box<dyn std::error::Error>> {
|
|
// Create keyspace
|
|
session
|
|
.query(
|
|
"CREATE KEYSPACE IF NOT EXISTS map_data WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
// Create table for OSM nodes (points)
|
|
// Partition by tile coordinates (zoom, x, y) for efficient retrieval
|
|
// This is a simplified schema. Real OSM data is more complex.
|
|
session
|
|
.query(
|
|
"CREATE TABLE IF NOT EXISTS map_data.nodes (
|
|
zoom int,
|
|
tile_x int,
|
|
tile_y int,
|
|
id bigint,
|
|
lat double,
|
|
lon double,
|
|
tags map<text, text>,
|
|
PRIMARY KEY ((zoom, tile_x, tile_y), id)
|
|
)",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
session
|
|
.query(
|
|
"CREATE TABLE IF NOT EXISTS map_data.ways (
|
|
zoom int,
|
|
tile_x int,
|
|
tile_y int,
|
|
id bigint,
|
|
tags map<text, text>,
|
|
points blob,
|
|
PRIMARY KEY ((zoom, tile_x, tile_y), id)
|
|
)",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
session
|
|
.query(
|
|
"CREATE TABLE IF NOT EXISTS map_data.buildings (
|
|
zoom int,
|
|
tile_x int,
|
|
tile_y int,
|
|
id bigint,
|
|
tags map<text, text>,
|
|
points blob,
|
|
PRIMARY KEY ((zoom, tile_x, tile_y), id)
|
|
)",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
session
|
|
.query(
|
|
"CREATE TABLE IF NOT EXISTS map_data.landuse (
|
|
zoom int,
|
|
tile_x int,
|
|
tile_y int,
|
|
id bigint,
|
|
tags map<text, text>,
|
|
points blob,
|
|
PRIMARY KEY ((zoom, tile_x, tile_y), id)
|
|
)",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
session
|
|
.query(
|
|
"CREATE TABLE IF NOT EXISTS map_data.water (
|
|
zoom int,
|
|
tile_x int,
|
|
tile_y int,
|
|
id bigint,
|
|
tags map<text, text>,
|
|
points blob,
|
|
PRIMARY KEY ((zoom, tile_x, tile_y), id)
|
|
)",
|
|
&[],
|
|
)
|
|
.await?;
|
|
|
|
println!("Schema initialized.");
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn seed_data(session: &Session) -> Result<(), Box<dyn std::error::Error>> {
|
|
// Insert some dummy data for Munich (approx lat/lon)
|
|
// Munich is roughly at lat 48.1351, lon 11.5820
|
|
// At zoom 10, this falls into a specific tile.
|
|
// For simplicity, we'll just use a fixed tile coordinate for testing: 10/500/500 (not accurate, just for ID)
|
|
|
|
let insert_stmt = "INSERT INTO map_data.nodes (zoom, tile_x, tile_y, id, lat, lon, tags) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
let prepared = session.prepare(insert_stmt).await?;
|
|
|
|
// Point 1: Marienplatz
|
|
session.execute(&prepared, (10, 500, 500, 1_i64, 48.137, 11.575, std::collections::HashMap::from([("name".to_string(), "Marienplatz".to_string())]))).await?;
|
|
|
|
// Point 2: English Garden
|
|
session.execute(&prepared, (10, 500, 500, 2_i64, 48.150, 11.590, std::collections::HashMap::from([("name".to_string(), "English Garden".to_string())]))).await?;
|
|
|
|
println!("Test data seeded.");
|
|
Ok(())
|
|
}
|