<commit_before>CREATE TABLE rbs.resource_type(
	id BIGSERIAL PRIMARY KEY,
	owner VARCHAR(36) NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	visibility VARCHAR(9),
	CONSTRAINT type_owner_fk FOREIGN KEY(owner) REFERENCES rbs.users(id) ON UPDATE CASCADE ON DELETE CASCADE,

	name VARCHAR(255) NOT NULL,
	validation BOOLEAN NOT NULL,
	school_id VARCHAR(255) NOT NULL
);

ALTER TABLE rbs.resource_type_shares ADD CONSTRAINT resource_type_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource_type(id) ON UPDATE CASCADE ON DELETE CASCADE;


CREATE TABLE rbs.resource(
	id BIGSERIAL PRIMARY KEY,
	owner VARCHAR(36) NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	visibility VARCHAR(9),
	CONSTRAINT resource_owner_fk FOREIGN KEY(owner) REFERENCES rbs.users(id) ON UPDATE CASCADE ON DELETE CASCADE,

	name VARCHAR(255) NOT NULL,
	description TEXT,
	icon VARCHAR(255),
	periodic_booking BOOLEAN NOT NULL,
	is_available BOOLEAN NOT NULL,
	min_delay BIGINT,
	max_delay BIGINT,
	type_id BIGINT NOT NULL,
	CONSTRAINT type_fk FOREIGN KEY(type_id) REFERENCES rbs.resource_type(id) ON UPDATE CASCADE ON DELETE CASCADE,
	CONSTRAINT valid_delays CHECK (min_delay >= 0 AND max_delay >= min_delay)
);

ALTER TABLE rbs.resource_shares ADD CONSTRAINT resource_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource(id) ON UPDATE CASCADE ON DELETE CASCADE;



CREATE TABLE rbs.booking(
	id BIGSERIAL PRIMARY KEY,
	resource_id BIGSERIAL NOT NULL,
	booker_id VARCHAR(36) NOT NULL,
	booking_reason TEXT,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	start_date TIMESTAMP NOT NULL,
	end_date TIMESTAMP NOT NULL,
	status SMALLINT,
	moderator_id VARCHAR(36),
	refusal_reason TEXT,
	parent_booking_id BIGSERIAL,
	CONSTRAINT resource_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource(id) ON UPDATE CASCADE,
	CONSTRAINT booker_fk FOREIGN KEY(booker_id) REFERENCES rbs.users(id) ON UPDATE CASCADE,
	CONSTRAINT moderator_fk FOREIGN KEY(booker_id) REFERENCES rbs.users(id) ON UPDATE CASCADE,
	CONSTRAINT parent_booking_fk FOREIGN KEY(parent_booking_id) REFERENCES rbs.booking(id) ON UPDATE CASCADE ON DELETE CASCADE
);<commit_msg>Table booking : rename attribute booker_id to owner. Change type of attribute parent_booking_id to bigint, as it is a foreign key<commit_after>CREATE TABLE rbs.resource_type(
	id BIGSERIAL PRIMARY KEY,
	owner VARCHAR(36) NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	visibility VARCHAR(9),
	CONSTRAINT type_owner_fk FOREIGN KEY(owner) REFERENCES rbs.users(id) ON UPDATE CASCADE ON DELETE CASCADE,

	name VARCHAR(255) NOT NULL,
	validation BOOLEAN NOT NULL,
	school_id VARCHAR(255) NOT NULL
);

ALTER TABLE rbs.resource_type_shares ADD CONSTRAINT resource_type_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource_type(id) ON UPDATE CASCADE ON DELETE CASCADE;


CREATE TABLE rbs.resource(
	id BIGSERIAL PRIMARY KEY,
	owner VARCHAR(36) NOT NULL,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	visibility VARCHAR(9),
	CONSTRAINT resource_owner_fk FOREIGN KEY(owner) REFERENCES rbs.users(id) ON UPDATE CASCADE ON DELETE CASCADE,

	name VARCHAR(255) NOT NULL,
	description TEXT,
	icon VARCHAR(255),
	periodic_booking BOOLEAN NOT NULL,
	is_available BOOLEAN NOT NULL,
	min_delay BIGINT,
	max_delay BIGINT,
	type_id BIGINT NOT NULL,
	CONSTRAINT type_fk FOREIGN KEY(type_id) REFERENCES rbs.resource_type(id) ON UPDATE CASCADE ON DELETE CASCADE,
	CONSTRAINT valid_delays CHECK (min_delay >= 0 AND max_delay >= min_delay)
);

ALTER TABLE rbs.resource_shares ADD CONSTRAINT resource_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource(id) ON UPDATE CASCADE ON DELETE CASCADE;


CREATE TABLE rbs.booking(
	id BIGSERIAL PRIMARY KEY,
	resource_id BIGSERIAL NOT NULL,
	owner VARCHAR(36) NOT NULL,
	booking_reason TEXT,
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	modified TIMESTAMP NOT NULL DEFAULT NOW(),
	start_date TIMESTAMP NOT NULL,
	end_date TIMESTAMP NOT NULL,
	status SMALLINT,
	moderator_id VARCHAR(36),
	refusal_reason TEXT,
	parent_booking_id BIGINT,
	CONSTRAINT resource_fk FOREIGN KEY(resource_id) REFERENCES rbs.resource(id) ON UPDATE CASCADE,
	CONSTRAINT owner_fk FOREIGN KEY(owner) REFERENCES rbs.users(id) ON UPDATE CASCADE,
	CONSTRAINT moderator_fk FOREIGN KEY(moderator_id) REFERENCES rbs.users(id) ON UPDATE CASCADE,
	CONSTRAINT parent_booking_fk FOREIGN KEY(parent_booking_id) REFERENCES rbs.booking(id) ON UPDATE CASCADE ON DELETE CASCADE
);
{'fraction_non_alphanumeric': 0.061871447310887624, 'fraction_numerical': 0.010056843025797988, 'mean_word_length': 6.049306625577812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7130904', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1588, 'n_words': 511}