| 6 | |
| 7 | #[tokio::test] |
| 8 | async fn test_datetime_trigger_creation() { |
| 9 | let server = setup_test_server().await; |
| 10 | let client = &server.client; |
| 11 | |
| 12 | // Debug logging is already initialized by the test server |
| 13 | |
| 14 | // Create table with datetime columns |
| 15 | client.execute( |
| 16 | "CREATE TABLE trigger_test ( |
| 17 | id INTEGER PRIMARY KEY, |
| 18 | date_col DATE, |
| 19 | time_col TIME, |
| 20 | timestamp_col TIMESTAMP |
| 21 | )", |
| 22 | &[] |
| 23 | ).await.unwrap(); |
| 24 | |
| 25 | // Check that datetime triggers are NOT created (we use InsertTranslator instead) |
| 26 | let trigger_check = client.query( |
| 27 | "SELECT name, sql FROM sqlite_master WHERE type = 'trigger' AND name LIKE '__pgsqlite_datetime%'", |
| 28 | &[] |
| 29 | ).await.unwrap(); |
| 30 | |
| 31 | assert!(trigger_check.is_empty(), "Datetime triggers should not be created anymore"); |
| 32 | |
| 33 | // Check __pgsqlite_schema for datetime columns |
| 34 | let schema_check = client.query( |
| 35 | "SELECT column_name, pg_type, sqlite_type FROM __pgsqlite_schema |
| 36 | WHERE table_name = 'trigger_test' AND pg_type IN ('date', 'time', 'timestamp')", |
| 37 | &[] |
| 38 | ).await.unwrap(); |
| 39 | |
| 40 | println!("\nDatetime columns in schema:"); |
| 41 | for row in &schema_check { |
| 42 | let col: String = row.get(0); |
| 43 | let pg_type: String = row.get(1); |
| 44 | let sqlite_type: String = row.get(2); |
| 45 | println!(" {col} -> pg: {pg_type}, sqlite: {sqlite_type}"); |
| 46 | } |
| 47 | |
| 48 | // Test INSERT with datetime literals |
| 49 | client.execute( |
| 50 | "INSERT INTO trigger_test VALUES (1, '2024-01-15', '14:30:00', '2024-01-15 14:30:00')", |
| 51 | &[] |
| 52 | ).await.unwrap(); |
| 53 | |
| 54 | // Small delay to let triggers execute |
| 55 | tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; |
| 56 | |
| 57 | // Check storage types |
| 58 | let type_check = client.query( |
| 59 | "SELECT typeof(date_col), typeof(time_col), typeof(timestamp_col) |
| 60 | FROM trigger_test WHERE id = 1", |
| 61 | &[] |
| 62 | ).await.unwrap(); |
| 63 | |
| 64 | if !type_check.is_empty() { |
| 65 | let row = &type_check[0]; |