diff --git a/server/assets/postgres/baseline.json b/server/assets/postgres/baseline.json index 12dddea08..1c3901e46 100644 --- a/server/assets/postgres/baseline.json +++ b/server/assets/postgres/baseline.json @@ -1,5 +1,5 @@ { - "through": "Migration20200101046360_a_new_install_starts_with_more_addons_on", + "through": "Migration20200101046440_a_trip_owns_its_tags", "migrations": [ "Migration20200101000000_baseline_schema", "Migration20200101000100_users_add_unsplash_api_key", @@ -333,6 +333,14 @@ "Migration20200101046330_an_object_no_row_names_is_marked_before_it_goes", "Migration20200101046340_a_released_object_outlasts_every_undo_before_it_goes", "Migration20200101046350_a_place_lies_on_the_real_world", - "Migration20200101046360_a_new_install_starts_with_more_addons_on" + "Migration20200101046360_a_new_install_starts_with_more_addons_on", + "Migration20200101046370_a_deleted_chat_message_keeps_no_text", + "Migration20200101046380_ireland_gained_its_counties", + "Migration20200101046390_a_trip_can_keep_its_costs_as_totals_only", + "Migration20200101046400_a_booked_flight_shows_where_it_is", + "Migration20200101046410_a_forwarded_booking_mail_lands_in_its_trip", + "Migration20200101046420_a_visit_keeps_its_own_stay", + "Migration20200101046430_a_paused_mail_import_can_tell_its_address_holders", + "Migration20200101046440_a_trip_owns_its_tags" ] } diff --git a/server/assets/postgres/baseline.sql b/server/assets/postgres/baseline.sql index 97eabc300..0a2d0e254 100644 --- a/server/assets/postgres/baseline.sql +++ b/server/assets/postgres/baseline.sql @@ -6,8 +6,11 @@ create table "document_providers" ("id" text null, "name" text not null, "descri create table "document_provider_fields" ("id" bigserial primary key, "provider_id" text not null, "field_key" text not null, "label" text not null, "input_type" text not null default 'text', "placeholder" text null, "hint" text null, "required" bigint null default 0, "secret" bigint null default 0, "sort_order" bigint null default 0); alter table "document_provider_fields" add constraint "document_provider_fields_provider_id_field_key_unique" unique ("provider_id", "field_key"); create table "ferrata_tiles" ("tile_key" text not null, "payload" text not null, "fetched_at" bigint not null, primary key ("tile_key")); +create table "flight_live_states" ("callsign" text not null, "service_date" text not null, "origin" text not null, "destination" text not null, "phase" text not null default 'scheduled', "departed_at" text null, "landed_at" text null, "lat" double precision null, "lng" double precision null, "altitude_ft" double precision null, "ground_speed_kt" double precision null, "track_deg" double precision null, "vertical_rate_fpm" double precision null, "on_ground" bigint null, "registration" text null, "aircraft_type" text null, "source" text null, "first_seen_at" text null, "last_seen_at" text null, "fetched_at" text null, "next_poll_at" text null, "fail_count" bigint not null default 0, "departed_notified" bigint not null default 0, "landed_notified" bigint not null default 0, "delay_notified" bigint not null default 0, primary key ("callsign", "service_date", "origin", "destination")); create table "google_api_usage" ("day" text null, "calls" bigint not null default 0, primary key ("day")); create table "google_place_photo_meta" ("place_id" text null, "attribution" text null, "fetched_at" bigint not null, "error_at" bigint null, primary key ("place_id")); +create table "mail_ingest_cursor" ("id" bigserial primary key, "transport" text not null, "mailbox" text not null, "uid_validity" bigint null, "last_uid" bigint null, "last_ok_at" text null, "last_error" text null, "lease_owner" text null, "lease_until" text null); +alter table "mail_ingest_cursor" add constraint "mail_ingest_cursor_transport_mailbox_unique" unique ("transport", "mailbox"); create table "migrations" ("id" bigserial primary key, "timestamp" bigint not null, "name" varchar(255) not null); create table "paddle_region_requests" ("region_id" text not null, "name" text not null, "reason" text not null, "bytes" bigint null, "requested_by" text null, "requested_at" text not null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "declined_at" text null, primary key ("region_id")); alter table "paddle_region_requests" add constraint "paddle_region_requests_reason_check" check ("reason" in ('ask', 'too_large', 'limit')); @@ -75,10 +78,11 @@ alter table "users" add constraint "users_username_unique" unique ("username"); CREATE UNIQUE INDEX idx_users_email_lower ON users (lower(email)); create table "user_notice_dismissals" ("user_id" bigint not null, "notice_id" text not null, "dismissed_at" bigint not null, "dismissed_app_version" text null, primary key ("user_id", "notice_id")); alter table "user_notice_dismissals" add constraint "user_notice_dismissals_user_id_notice_id_unique" unique ("user_id", "notice_id"); -create table "trips" ("id" bigserial primary key, "user_id" bigint not null, "title" text not null, "description" text null, "start_date" text null, "end_date" text null, "currency" text null default 'EUR', "cover_image" text null, "is_archived" bigint null default 0, "reminder_days" bigint null default 3, "feed_token" text null, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "updated_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "reminder_sent_for" text null); +create table "trips" ("id" bigserial primary key, "user_id" bigint not null, "title" text not null, "description" text null, "start_date" text null, "end_date" text null, "currency" text null default 'EUR', "cover_image" text null, "is_archived" bigint null default 0, "reminder_days" bigint null default 3, "feed_token" text null, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "updated_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "reminder_sent_for" text null, "costs_mode" text not null default 'split'); create index "idx_trips_user_id" on "trips" ("user_id"); create index "idx_trips_created_at" on "trips" ("created_at"); create unique index "idx_trips_feed_token" on "trips" ("feed_token") where feed_token IS NOT NULL; +alter table "trips" add constraint "trips_costs_mode_check" check ("costs_mode" in ('split', 'totals')); create table "roadtrip_preferences" ("trip_id" bigint not null, "key" text not null, "value" text not null, primary key ("trip_id", "key")); alter table "roadtrip_preferences" add constraint "roadtrip_preferences_trip_id_key_unique" unique ("trip_id", "key"); create table "days" ("id" bigserial primary key, "trip_id" bigint not null, "day_number" bigint not null, "date" text null, "notes" text null, "title" text null, "default_transport_mode" text null); @@ -129,8 +133,9 @@ create index "idx_todo_items_assigned_user_id" on "todo_items" ("assigned_user_i create table "todo_category_assignees" ("id" bigserial primary key, "trip_id" bigint not null, "category_name" text not null, "user_id" bigint not null); create index "idx_todo_category_assignees_user_id" on "todo_category_assignees" ("user_id"); alter table "todo_category_assignees" add constraint "todo_category_assignees_trip_id_category_name_user_id_unique" unique ("trip_id", "category_name", "user_id"); -create table "tags" ("id" bigserial primary key, "user_id" bigint not null, "name" text not null, "color" text null default '#10b981', "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS')); +create table "tags" ("id" bigserial primary key, "user_id" bigint not null, "name" text not null, "color" text null default '#10b981', "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "trip_id" bigint null); create index "idx_tags_user_id" on "tags" ("user_id"); +create index "idx_tags_trip_id" on "tags" ("trip_id"); create table "share_tokens" ("id" bigserial primary key, "trip_id" bigint not null, "token" text not null, "share_map" bigint null default 1, "share_bookings" bigint null default 1, "share_packing" bigint null default 0, "share_budget" bigint null default 0, "share_collab" bigint null default 0, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "expires_at" text null, "share_travel_only" bigint not null default 0, "share_hide_images" bigint not null default 0, "created_by" bigint not null); create index "idx_share_tokens_trip_id" on "share_tokens" ("trip_id"); create index "idx_share_tokens_token" on "share_tokens" ("token"); @@ -192,6 +197,23 @@ alter table "notification_channel_preferences" add constraint "notification_chan create table "mcp_tokens" ("id" bigserial primary key, "user_id" bigint not null, "name" text not null, "token_hash" text not null, "token_prefix" text not null, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "last_used_at" text null, "kind" text not null default 'mcp', "scope_mode" text not null default 'all', "api_scopes" text null); create index "idx_mcp_tokens_user_id" on "mcp_tokens" ("user_id"); alter table "mcp_tokens" add constraint "idx_mcp_tokens_hash" unique ("token_hash"); +create table "mail_ingest_prefs" ("id" bigserial primary key, "user_id" bigint not null, "enabled" bigint not null default 1, "ai_enabled" bigint not null default 1, "auto_add" bigint not null default 1); +alter table "mail_ingest_prefs" add constraint "mail_ingest_prefs_user_id_unique" unique ("user_id"); +create table "mail_ingest_addresses" ("id" bigserial primary key, "token_hash" text not null, "token_enc" text not null, "user_id" bigint not null, "trip_id" bigint null, "created_at" text not null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "revoked_at" text null, "last_used_at" text null); +create index "idx_mail_ingest_addresses_trip" on "mail_ingest_addresses" ("trip_id"); +create index "idx_mail_ingest_addresses_user" on "mail_ingest_addresses" ("user_id", "trip_id"); +alter table "mail_ingest_addresses" add constraint "mail_ingest_addresses_token_hash_unique" unique ("token_hash"); +create table "mail_ingest_messages" ("id" bigserial primary key, "transport" text not null, "message_id_hdr" text null, "dedupe_hash" text not null, "address_id" bigint null, "user_id" bigint not null, "trip_id" bigint null, "from_addr" text null, "from_verified" bigint not null default 0, "auth_results" text null, "subject" text null, "received_at" text not null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "size" bigint not null, "raw_eml_enc" text null, "raw_purged_at" text null, "status" text not null default 'queued', "reason" text null, "hints" text null, "attachments" text null, "forwarding_code" text null, "attempts" bigint not null default 0, "next_attempt_at" text not null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "lease_until" text null, "ai_used" bigint not null default 0, "processed_at" text null); +create index "idx_mail_ingest_messages_trip" on "mail_ingest_messages" ("trip_id"); +create index "idx_mail_ingest_messages_address" on "mail_ingest_messages" ("address_id", "received_at"); +create index "idx_mail_ingest_messages_user" on "mail_ingest_messages" ("user_id", "received_at"); +create index "idx_mail_ingest_messages_due" on "mail_ingest_messages" ("status", "next_attempt_at"); +alter table "mail_ingest_messages" add constraint "mail_ingest_messages_dedupe_hash_unique" unique ("dedupe_hash"); +create table "mail_ingest_candidates" ("id" bigserial primary key, "message_id" bigint not null, "user_id" bigint not null, "position" bigint not null default 0, "item_json" text null, "source" text null, "checks_json" text null, "uncertain_fields" text null, "match_json" text null, "suggested_trip_id" bigint null, "dedupe_key" text null, "content_hash" text null, "resolution" text not null default 'pending', "reason" text null, "resolved_trip_id" bigint null, "created_ids_json" text null, "attach_error" text null, "resolved_by" bigint null, "resolved_at" text null, "undo_until" text null, "created_at" text not null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS')); +create index "idx_mail_ingest_candidates_suggested" on "mail_ingest_candidates" ("suggested_trip_id"); +create index "idx_mail_ingest_candidates_resolved" on "mail_ingest_candidates" ("resolved_trip_id", "content_hash"); +create index "idx_mail_ingest_candidates_user" on "mail_ingest_candidates" ("user_id", "resolution"); +create index "idx_mail_ingest_candidates_message" on "mail_ingest_candidates" ("message_id", "position"); create table "journeys" ("id" bigserial primary key, "user_id" bigint not null, "title" text not null, "subtitle" text null, "cover_gradient" text null, "status" text null default 'draft', "created_at" bigint not null, "updated_at" bigint not null, "cover_image" text null, "show_trip_tracks" bigint not null default 0, "show_verdict" bigint not null default 1, "show_mood" bigint not null default 1, "show_weather" bigint not null default 1, "status_override" text null, "photo_location" bigint not null default 0, "auto_prepare_recordings" bigint not null default 0); create index "idx_journeys_user" on "journeys" ("user_id"); create table "trip_journal_links" ("id" bigserial primary key, "trip_id" bigint not null, "journey_id" bigint not null, "created_at" bigint not null, "linked_by" bigint null); @@ -368,7 +390,7 @@ create table "journey_entry_photos" ("entry_id" bigint not null, "journey_photo_ create index "idx_journey_entry_photos_entry" on "journey_entry_photos" ("entry_id"); create index "idx_journey_entry_photos_photo" on "journey_entry_photos" ("journey_photo_id"); alter table "journey_entry_photos" add constraint "journey_entry_photos_entry_id_journey_photo_id_unique" unique ("entry_id", "journey_photo_id"); -create table "day_assignments" ("id" bigserial primary key, "day_id" bigint not null, "place_id" bigint not null, "order_index" bigint null default 0, "notes" text null, "reservation_status" text null default 'none', "reservation_notes" text null, "reservation_datetime" text null, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "assignment_time" text null, "assignment_end_time" text null, "leg_transport_mode" text null, "incoming_leg_transport_mode" text null, "end_day" bigint not null default 0, "accommodation_id" bigint null, "route_excluded" bigint not null default 0, "tour_stage_key" text null); +create table "day_assignments" ("id" bigserial primary key, "day_id" bigint not null, "place_id" bigint not null, "order_index" bigint null default 0, "notes" text null, "reservation_status" text null default 'none', "reservation_notes" text null, "reservation_datetime" text null, "created_at" text null default to_char((CURRENT_TIMESTAMP AT TIME ZONE 'UTC'), 'YYYY-MM-DD HH24:MI:SS'), "assignment_time" text null, "assignment_end_time" text null, "leg_transport_mode" text null, "incoming_leg_transport_mode" text null, "end_day" bigint not null default 0, "accommodation_id" bigint null, "route_excluded" bigint not null default 0, "tour_stage_key" text null, "stay_minutes" bigint null); create index "idx_day_assignments_day_id" on "day_assignments" ("day_id"); create index "idx_day_assignments_place_id" on "day_assignments" ("place_id"); create index "idx_day_assignments_accommodation_id" on "day_assignments" ("accommodation_id"); @@ -574,6 +596,7 @@ alter table "todo_items" add constraint "todo_items_assigned_user_id_foreign" fo alter table "todo_category_assignees" add constraint "todo_category_assignees_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete cascade; alter table "todo_category_assignees" add constraint "todo_category_assignees_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; alter table "tags" add constraint "tags_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "tags" add constraint "tags_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete cascade; alter table "share_tokens" add constraint "share_tokens_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete cascade; alter table "share_tokens" add constraint "share_tokens_created_by_foreign" foreign key ("created_by") references "users" ("id"); alter table "settings" add constraint "settings_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; @@ -605,6 +628,16 @@ alter table "notifications" add constraint "notifications_sender_id_foreign" for alter table "notifications" add constraint "notifications_recipient_id_foreign" foreign key ("recipient_id") references "users" ("id") on delete cascade; alter table "notification_channel_preferences" add constraint "notification_channel_preferences_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; alter table "mcp_tokens" add constraint "mcp_tokens_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "mail_ingest_prefs" add constraint "mail_ingest_prefs_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "mail_ingest_addresses" add constraint "mail_ingest_addresses_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "mail_ingest_addresses" add constraint "mail_ingest_addresses_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete cascade; +alter table "mail_ingest_messages" add constraint "mail_ingest_messages_address_id_foreign" foreign key ("address_id") references "mail_ingest_addresses" ("id") on delete set null; +alter table "mail_ingest_messages" add constraint "mail_ingest_messages_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "mail_ingest_messages" add constraint "mail_ingest_messages_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete set null; +alter table "mail_ingest_candidates" add constraint "mail_ingest_candidates_message_id_foreign" foreign key ("message_id") references "mail_ingest_messages" ("id") on delete cascade; +alter table "mail_ingest_candidates" add constraint "mail_ingest_candidates_user_id_foreign" foreign key ("user_id") references "users" ("id") on delete cascade; +alter table "mail_ingest_candidates" add constraint "mail_ingest_candidates_suggested_trip_id_foreign" foreign key ("suggested_trip_id") references "trips" ("id") on delete set null; +alter table "mail_ingest_candidates" add constraint "mail_ingest_candidates_resolved_trip_id_foreign" foreign key ("resolved_trip_id") references "trips" ("id") on delete set null; alter table "journeys" add constraint "journeys_user_id_foreign" foreign key ("user_id") references "users" ("id"); alter table "trip_journal_links" add constraint "trip_journal_links_trip_id_foreign" foreign key ("trip_id") references "trips" ("id") on delete cascade; alter table "trip_journal_links" add constraint "trip_journal_links_journey_id_foreign" foreign key ("journey_id") references "journeys" ("id") on delete cascade;