CREATE TABLE raid_builder.raid_layout(
	raid_layout_id uuid PRIMARY KEY,
	raid_group_id uuid REFERENCES raid_builder.raid_group(raid_group_id) NOT NULL,
	raid_layout_name text NOT NULL,
	raid_size int NOT NULL,

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

CREATE INDEX idx_raid_layout_raid_group_id ON raid_builder.raid_layout(raid_group_id);
CREATE INDEX idx_raid_layout_raid_layout_name ON raid_builder.raid_layout(raid_layout_name);

GRANT ALL ON TABLE raid_builder.raid_layout TO raid_builder;



CREATE TABLE raid_builder.raid_layout_class_group_xref(
	raid_layout_class_group_xref_id uuid PRIMARY KEY,
	raid_layout_id uuid REFERENCES raid_builder.raid_layout(raid_layout_id) NOT NULL,
	class_group_id uuid REFERENCES raid_builder.class_group(class_group_id) NOT NULL,
	layout_location int NOT NULL,

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

CREATE INDEX idx_raid_layout_class_group_xref_raid_layout_id ON raid_builder.raid_layout_class_group_xref(raid_layout_id);
CREATE INDEX idx_raid_layout_class_group_xref_class_group_id ON raid_builder.raid_layout_class_group_xref(class_group_id);

GRANT ALL ON TABLE raid_builder.raid_layout_class_group_xref TO raid_builder;
