@@ -449,8 +449,128 @@ def upgrade() -> None:
449449 unique = True ,
450450 )
451451
452+ # --- navigation_sessions ---
453+ op .create_table (
454+ "navigation_sessions" ,
455+ sa .Column (
456+ "id" ,
457+ sa .UUID (),
458+ server_default = sa .text ("gen_random_uuid()" ),
459+ nullable = False ,
460+ ),
461+ sa .Column ("host_id" , sa .UUID (), nullable = False ),
462+ sa .Column (
463+ "status" ,
464+ sa .String (length = 20 ),
465+ server_default = "active" ,
466+ nullable = False ,
467+ comment = "active | completed | cancelled" ,
468+ ),
469+ sa .Column ("destination_name" , sa .String (length = 500 ), nullable = False ),
470+ sa .Column ("destination_lat" , sa .Float (), nullable = False ),
471+ sa .Column ("destination_lng" , sa .Float (), nullable = False ),
472+ sa .Column ("origin_lat" , sa .Float (), nullable = False ),
473+ sa .Column ("origin_lng" , sa .Float (), nullable = False ),
474+ sa .Column (
475+ "route_data" ,
476+ postgresql .JSONB (astext_type = sa .Text ()),
477+ server_default = sa .text ("'{}'::jsonb" ),
478+ nullable = False ,
479+ ),
480+ sa .Column (
481+ "current_step_index" ,
482+ sa .Integer (),
483+ server_default = sa .text ("0" ),
484+ nullable = False ,
485+ ),
486+ sa .Column (
487+ "created_at" ,
488+ sa .DateTime (timezone = True ),
489+ server_default = sa .text ("now()" ),
490+ nullable = False ,
491+ ),
492+ sa .Column ("completed_at" , sa .DateTime (timezone = True ), nullable = True ),
493+ sa .ForeignKeyConstraint (
494+ ["host_id" ],
495+ ["users.id" ],
496+ name = op .f ("fk_navigation_sessions_host_id_users" ),
497+ ondelete = "CASCADE" ,
498+ ),
499+ sa .PrimaryKeyConstraint ("id" , name = op .f ("pk_navigation_sessions" )),
500+ )
501+ op .create_index (
502+ "ix_navigation_sessions_host_id" ,
503+ "navigation_sessions" ,
504+ ["host_id" ],
505+ unique = False ,
506+ )
507+ op .create_index (
508+ "ix_navigation_sessions_status" ,
509+ "navigation_sessions" ,
510+ ["status" ],
511+ unique = False ,
512+ )
513+
514+ # --- location_waypoints ---
515+ op .create_table (
516+ "location_waypoints" ,
517+ sa .Column (
518+ "id" ,
519+ sa .UUID (),
520+ server_default = sa .text ("gen_random_uuid()" ),
521+ nullable = False ,
522+ ),
523+ sa .Column ("host_id" , sa .UUID (), nullable = False ),
524+ sa .Column ("session_id" , sa .UUID (), nullable = True ),
525+ sa .Column ("lat" , sa .Float (), nullable = False ),
526+ sa .Column ("lng" , sa .Float (), nullable = False ),
527+ sa .Column ("altitude" , sa .Float (), nullable = True ),
528+ sa .Column ("accuracy" , sa .Float (), nullable = True ),
529+ sa .Column ("speed" , sa .Float (), nullable = True ),
530+ sa .Column ("heading" , sa .Float (), nullable = True ),
531+ sa .Column (
532+ "created_at" ,
533+ sa .DateTime (timezone = True ),
534+ server_default = sa .text ("now()" ),
535+ nullable = False ,
536+ ),
537+ sa .ForeignKeyConstraint (
538+ ["host_id" ],
539+ ["users.id" ],
540+ name = op .f ("fk_location_waypoints_host_id_users" ),
541+ ondelete = "CASCADE" ,
542+ ),
543+ sa .ForeignKeyConstraint (
544+ ["session_id" ],
545+ ["navigation_sessions.id" ],
546+ name = op .f ("fk_location_waypoints_session_id_navigation_sessions" ),
547+ ondelete = "SET NULL" ,
548+ ),
549+ sa .PrimaryKeyConstraint ("id" , name = op .f ("pk_location_waypoints" )),
550+ )
551+ op .create_index (
552+ "ix_location_waypoints_host_id_created_at" ,
553+ "location_waypoints" ,
554+ ["host_id" , "created_at" ],
555+ unique = False ,
556+ )
557+ op .create_index (
558+ "ix_location_waypoints_session_id" ,
559+ "location_waypoints" ,
560+ ["session_id" ],
561+ unique = False ,
562+ )
563+
452564
453565def downgrade () -> None :
566+ op .drop_index ("ix_location_waypoints_session_id" , table_name = "location_waypoints" )
567+ op .drop_index (
568+ "ix_location_waypoints_host_id_created_at" , table_name = "location_waypoints"
569+ )
570+ op .drop_table ("location_waypoints" )
571+ op .drop_index ("ix_navigation_sessions_status" , table_name = "navigation_sessions" )
572+ op .drop_index ("ix_navigation_sessions_host_id" , table_name = "navigation_sessions" )
573+ op .drop_table ("navigation_sessions" )
454574 op .drop_index (op .f ("ix_device_tokens_token" ), table_name = "device_tokens" )
455575 op .drop_index ("ix_device_tokens_user_id" , table_name = "device_tokens" )
456576 op .drop_table ("device_tokens" )
0 commit comments