CREATE TABLE "clusters" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"api_server_url" text NOT NULL,
	"join_credential_reference_id" text NOT NULL,
	"status" text DEFAULT 'active' NOT NULL,
	"revision" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "machine_capabilities" (
	"id" text PRIMARY KEY NOT NULL,
	"machine_id" text NOT NULL,
	"key" text NOT NULL,
	"value" text NOT NULL,
	"source" text NOT NULL,
	"observed_at" timestamp with time zone NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "machine_enrollments" (
	"id" text PRIMARY KEY NOT NULL,
	"operation_id" text NOT NULL,
	"machine_id" text NOT NULL,
	"phase" text DEFAULT 'requested' NOT NULL,
	"preflight" jsonb,
	"failure_reason" text,
	"requested_at" timestamp with time zone NOT NULL,
	"updated_at" timestamp with time zone NOT NULL,
	"revision" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "machines" (
	"id" text PRIMARY KEY NOT NULL,
	"cluster_id" text NOT NULL,
	"name" text NOT NULL,
	"address" text NOT NULL,
	"ssh_user" text NOT NULL,
	"ssh_connection_id" text NOT NULL,
	"ssh_credential_reference_id" text NOT NULL,
	"labels" jsonb DEFAULT '{}'::jsonb NOT NULL,
	"status" text DEFAULT 'onboarding' NOT NULL,
	"provider_node_name" text,
	"failure_reason" text,
	"last_observed_at" timestamp with time zone,
	"revision" integer DEFAULT 1 NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX "machine_capabilities_machine_key_unique" ON "machine_capabilities" USING btree ("machine_id","key");--> statement-breakpoint
CREATE UNIQUE INDEX "machine_enrollments_operation_unique" ON "machine_enrollments" USING btree ("operation_id");