CREATE TABLE raid_builder.raid_instance (
	raid_instance_id uuid PRIMARY KEY,
	raid_group_id uuid REFERENCES raid_builder.raid_group(raid_group_id),
	raid_layout_id uuid REFERENCES raid_builder.raid_layout(raid_layout_id),
	raid_instance_name text,
	raid_size int,
	number_runs int NOT NULL,
	raid_start_date timestamptz NOT NULL,
	raid_end_date timestamptz NOT NULL,

	--Auditing
	modified_by uuid,
	modified_date timestamptz,
	created_by uuid NOT NULL,
	created_date timestamptz NOT NULL
);

CREATE INDEX idx_raid_instance_raid_group_id ON raid_builder.raid_instance(raid_group_id);
CREATE INDEX idx_raid_instance_raid_layout_id ON raid_builder.raid_instance(raid_layout_id);
CREATE INDEX idx_raid_instance_raid_instance_name ON raid_builder.raid_instance(raid_instance_name);
CREATE INDEX idx_raid_instance_raid_start_date ON raid_builder.raid_instance(raid_start_date);

GRANT ALL ON TABLE raid_builder.raid_instance TO raid_builder;
