CREATE TABLE `organizations` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`workspace` text DEFAULT 'Default Workspace' NOT NULL,
	`address_line_1` text,
	`address_line_2` text,
	`city` text,
	`region` text,
	`postcode` text,
	`country` text DEFAULT 'United Kingdom' NOT NULL,
	`bank_name` text,
	`bank_account_name` text,
	`bank_account_number` text,
	`bank_sort_code` text,
	`bank_iban` text,
	`bank_swift` text,
	`created_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL,
	`updated_at` integer DEFAULT (cast(unixepoch('subsecond') * 1000 as integer)) NOT NULL,
	`archived_at` integer
);
--> statement-breakpoint
INSERT INTO `organizations` (`id`, `name`, `workspace`) VALUES ('default-organization', 'Steel City Stadium', 'Blueprint Workspace');--> statement-breakpoint
ALTER TABLE `clients` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
ALTER TABLE `addresses` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `addresses_organization_id_idx` ON `addresses` (`organization_id`);--> statement-breakpoint
ALTER TABLE `contacts` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `contacts_organization_id_idx` ON `contacts` (`organization_id`);--> statement-breakpoint
ALTER TABLE `rooms` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
ALTER TABLE `services` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
ALTER TABLE `bookings` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `bookings_organization_id_idx` ON `bookings` (`organization_id`);--> statement-breakpoint
ALTER TABLE `invoices` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `invoices_organization_id_idx` ON `invoices` (`organization_id`);--> statement-breakpoint
ALTER TABLE `contracts` ADD `organization_id` text NOT NULL DEFAULT 'default-organization' REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `contracts_organization_id_idx` ON `contracts` (`organization_id`);--> statement-breakpoint
ALTER TABLE `session` ADD `active_organization_id` text;
