-- Paid subscriptions run for a whole number of months and keep working for a
-- short grace period after they lapse, so a late bank transfer never turns the
-- menu off mid-service. `plan = 'basic'` is the waiter-call-only tier the
-- platform admin can drop a client to by hand, and `locked_at` is the hard
-- switch that turns the whole restaurant off, waiter call included.
ALTER TABLE `restaurants` ADD `plan_expires_at` text;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `plan_months` integer;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `locked_at` text;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `lock_note` text;
--> statement-breakpoint
-- Contact details the platform admin needs in order to call or invoice a
-- client without opening another system.
ALTER TABLE `restaurants` ADD `contact_phone` text DEFAULT '' NOT NULL;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `address` text DEFAULT '' NOT NULL;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `city` text DEFAULT '' NOT NULL;
--> statement-breakpoint
ALTER TABLE `restaurants` ADD `postal_code` text DEFAULT '' NOT NULL;
--> statement-breakpoint
CREATE INDEX `idx_restaurants_plan_expires` ON `restaurants` (`plan`,`plan_expires_at`);
--> statement-breakpoint
-- Per-person details: the account itself only ever had a display name, but a
-- restaurant can have several managers and each needs their own numbers.
ALTER TABLE `memberships` ADD `full_name` text DEFAULT '' NOT NULL;
--> statement-breakpoint
ALTER TABLE `memberships` ADD `phone` text DEFAULT '' NOT NULL;
--> statement-breakpoint
ALTER TABLE `memberships` ADD `mobile` text DEFAULT '' NOT NULL;
--> statement-breakpoint
-- Restaurants unlocked before this version were switched on without an end
-- date and MUST NOT lose access now. An `active` plan with no
-- `plan_expires_at` therefore means "unlimited, activated by hand"; the
-- countdown only applies to subscriptions activated for a number of months
-- from this version on.
PRAGMA optimize;
