CREATE TABLE `companies` (
  `id` text PRIMARY KEY NOT NULL,
  `name` text NOT NULL,
  `short_name` text NOT NULL
);
--> statement-breakpoint
INSERT INTO `companies` (`id`,`name`,`short_name`) VALUES
  ('lotrex','LOTREX','LOTREX'),
  ('ctl','Compagnie de Transport et de la Logistique','CTL');
--> statement-breakpoint
ALTER TABLE `bank_accounts` ADD `company_id` text DEFAULT 'lotrex' NOT NULL;
--> statement-breakpoint
ALTER TABLE `cash_flows` ADD `company_id` text DEFAULT 'lotrex' NOT NULL;
--> statement-breakpoint
ALTER TABLE `import_batches` ADD `company_id` text DEFAULT 'lotrex' NOT NULL;
--> statement-breakpoint
DROP INDEX `cash_flows_reference_unique`;
--> statement-breakpoint
DROP INDEX `cash_flows_source_key_unique`;
--> statement-breakpoint
CREATE UNIQUE INDEX `cash_flows_company_source_unique` ON `cash_flows` (`company_id`,`source_key`);
--> statement-breakpoint
CREATE INDEX `idx_cash_flows_company_active_date` ON `cash_flows` (`company_id`,`active`,`planned_date`);
--> statement-breakpoint
CREATE INDEX `idx_import_batches_company_date` ON `import_batches` (`company_id`,`imported_at`);
--> statement-breakpoint
INSERT INTO `bank_accounts` (`name`,`account_label`,`balance`,`minimum_balance`,`company_id`) VALUES
  ('Attijariwafa bank','Compte CTL · à renseigner',0,0,'ctl'),
  ('Banque Populaire','Compte CTL · à renseigner',0,0,'ctl'),
  ('Bank of Africa','Compte CTL · à renseigner',0,0,'ctl');
--> statement-breakpoint
PRAGMA optimize;
