CREATE TABLE `wohnheimbuchung` (
	`Oid` BIGINT(19) NOT NULL AUTO_INCREMENT,
	`InsTs` DATETIME DEFAULT NULL,
	`InsUser` VARCHAR(256) DEFAULT NULL,
	`Notice` VARCHAR(1024) DEFAULT NULL,
	`Tid` INT(10) DEFAULT NULL,
	`UdpUser` VARCHAR(256) DEFAULT NULL,
	`Version` BIGINT(19) DEFAULT NULL,
	`IsActive` TINYINT(4) DEFAULT NULL,
	`SystemEntryID` INT(10) DEFAULT NULL,
	`Buchungsdatum` DATETIME DEFAULT NULL,
	`WohnheimOid` BIGINT(19) DEFAULT NULL,
	PRIMARY KEY (`Oid`),
	KEY `WOHNHEIMBUCHUNG_WOHNHEIM_FK` (`WohnheimOid`),
	CONSTRAINT `FK_WOHNHEIMBUCHUNG_WOHNHEIM` FOREIGN KEY (`WohnheimOid`) REFERENCES `Wohnheim` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `wohnheimbuchung2costbearer2supportconcept` (
	`Oid` BIGINT(19) NOT NULL AUTO_INCREMENT,
	`InsTs` DATETIME DEFAULT NULL,
	`InsUser` VARCHAR(256) DEFAULT NULL,
	`Notice` VARCHAR(1024) DEFAULT NULL,
	`Tid` INT(10) DEFAULT NULL,
	`UdpUser` VARCHAR(256) DEFAULT NULL,
	`Version` BIGINT(19) DEFAULT NULL,
	`IsActive` TINYINT(4) DEFAULT NULL,
	`SystemEntryID` INT(10) DEFAULT NULL,
	`StartDate` DATETIME DEFAULT NULL,
	`EndDate` DATETIME DEFAULT NULL,
	`WohnheimbuchungsOid` BIGINT(19) DEFAULT NULL,
	`Costbearer2SupportConceptOid` BIGINT(19) DEFAULT NULL,
	PRIMARY KEY (`Oid`),
	KEY `WOHNHEIMBUCHUNG2CB2SC_FK` (`WohnheimbuchungsOid`),
	CONSTRAINT `FK_WOHNHEIMBUCHUNG2CB2SC_WOHNHEIMBUCHUNG` FOREIGN KEY (`WohnheimbuchungsOid`) REFERENCES `Wohnheimbuchung` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
	KEY `WOHNHEIMBUCHUNG2CB2SC_COSTBEARER2SUPPORTCONCEPT_FK` (`Costbearer2SupportConceptOid`),
	CONSTRAINT `FK_WOHNHEIMBUCHUNG2CB2SC_COSTBEARER2SUPPORTCONCEPT` FOREIGN KEY (`Costbearer2SupportConceptOid`) REFERENCES `Costbearer2SupportConcept` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `wohnheimbuchung2employee` (
	`Oid` BIGINT(19) NOT NULL AUTO_INCREMENT,
	`InsTs` DATETIME DEFAULT NULL,
	`InsUser` VARCHAR(256) DEFAULT NULL,
	`Notice` VARCHAR(1024) DEFAULT NULL,
	`Tid` INT(10) DEFAULT NULL,
	`UdpUser` VARCHAR(256) DEFAULT NULL,
	`Version` BIGINT(19) DEFAULT NULL,
	`IsActive` TINYINT(4) DEFAULT NULL,
	`SystemEntryID` INT(10) DEFAULT NULL,
	`StartDate` DATETIME DEFAULT NULL,
	`EndDate` DATETIME DEFAULT NULL,
	`WohnheimbuchungsOid` BIGINT(19) DEFAULT NULL,
	`EmployeeOid` BIGINT(19) DEFAULT NULL,
	PRIMARY KEY (`Oid`),
	KEY `WOHNHEIMBUCHUNG2EMPLOYEE_WOHNHEIMBUCHUNG_FK` (`WohnheimbuchungsOid`),
	CONSTRAINT `FK_WOHNHEIMBUCHUNG2EMPLOYEE_WOHNHEIMBUCHUNG` FOREIGN KEY (`WohnheimbuchungsOid`) REFERENCES `Wohnheimbuchung` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
	KEY `WOHNHEIMBUCHUNG2EMPLOYEE_EMPLOYEE_FK` (`EmployeeOid`),
	CONSTRAINT `FK_WOHNHEIMBUCHUNG2EMPLOYEE_EMPLOYEE` FOREIGN KEY (`EmployeeOid`) REFERENCES `Employee` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `servicerecord` ADD COLUMN `WohnheimbuchungsOid` BIGINT(19) DEFAULT NULL;
ALTER TABLE `servicerecord` ADD CONSTRAINT `FK_SERVICERECORD_WOHNHEIMBUCHUNG` FOREIGN KEY(`WohnheimbuchungsOid`) REFERENCES `wohnheimbuchung` (`Oid`);