PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_organizations` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`address_line_1` text DEFAULT '' NOT NULL,
	`address_line_2` text,
	`address_line_3` 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 `__new_organizations` (
	"id",
	"name",
	"address_line_1",
	"address_line_2",
	"address_line_3",
	"city",
	"region",
	"postcode",
	"country",
	"bank_name",
	"bank_account_name",
	"bank_account_number",
	"bank_sort_code",
	"bank_iban",
	"bank_swift",
	"created_at",
	"updated_at",
	"archived_at"
)
SELECT
	"id",
	"name",
	COALESCE(NULLIF("address_line_1", ''), "workspace", ''),
	"address_line_2",
	NULL,
	"city",
	"region",
	"postcode",
	"country",
	"bank_name",
	"bank_account_name",
	"bank_account_number",
	"bank_sort_code",
	"bank_iban",
	"bank_swift",
	"created_at",
	"updated_at",
	"archived_at"
FROM `organizations`;--> statement-breakpoint
DROP TABLE `organizations`;--> statement-breakpoint
ALTER TABLE `__new_organizations` RENAME TO `organizations`;--> statement-breakpoint
PRAGMA foreign_keys=ON;
