ALTER TABLE `applicationuser` 
ADD COLUMN `CreationDate` DATETIME DEFAULT NULL AFTER `Salt`;

ALTER TABLE `customer` ADD COLUMN `Pflegegrad` INT NULL DEFAULT NULL AFTER `GradDerBehinderung`;

ALTER TABLE `customer` ADD CustomerImage longblob NULL DEFAULT NULL AFTER `Pflegegrad`;


CREATE TABLE `wohnheim` (
  `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,
  `WohnheimName` varchar(256) DEFAULT NULL,
  `Strasse` varchar(256) DEFAULT NULL,
  `PLZ` varchar(256) DEFAULT NULL,
  `Ort` varchar(256) DEFAULT NULL,
  `Bemerkung` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`Oid`)
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=latin1;

CREATE TABLE `customer2wohnheim` (
  `Oid` bigint(19) NOT NULL AUTO_INCREMENT,
  `WohnheimOid` bigint(19) DEFAULT NULL,
  `CustomerOid` bigint(19) DEFAULT NULL,
  `Tid` int(10) DEFAULT NULL,
  `Notice` varchar(1024) DEFAULT NULL,
  `InsTs` datetime DEFAULT NULL,
  `InsUser` varchar(256) DEFAULT NULL,
  `Version` bigint(19) DEFAULT NULL,
  `UdpUser` varchar(256) DEFAULT NULL,
  `IsActive` tinyint(4) DEFAULT NULL,
  `SystemEntryID` int(10) DEFAULT NULL,
  PRIMARY KEY (`Oid`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

CREATE TABLE `employee2wohnheim` (
  `Oid` bigint(19) NOT NULL AUTO_INCREMENT,
  `WohnheimOid` bigint(19) DEFAULT NULL,
  `EmployeeOid` bigint(19) DEFAULT NULL,
  `Tid` int(10) DEFAULT NULL,
  `Notice` varchar(1024) DEFAULT NULL,
  `InsTs` datetime DEFAULT NULL,
  `InsUser` varchar(256) DEFAULT NULL,
  `Version` bigint(19) DEFAULT NULL,
  `UdpUser` varchar(256) DEFAULT NULL,
  `IsActive` tinyint(4) DEFAULT NULL,
  `SystemEntryID` int(10) DEFAULT NULL,
  PRIMARY KEY (`Oid`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;



CREATE TABLE `signature` (
  `Oid` bigint(19) NOT NULL AUTO_INCREMENT,
  `ServiceRecordOid` bigint(19) DEFAULT NULL,
  `Tid` int(10) DEFAULT NULL,
  `Notice` varchar(1024) DEFAULT NULL,
  `InsTs` datetime DEFAULT NULL,
  `InsUser` varchar(256) DEFAULT NULL,
  `Version` bigint(19) DEFAULT NULL,
  `UdpUser` varchar(256) DEFAULT NULL,
  `isActive` tinyint(4) DEFAULT NULL,
  `SystemEntryID` int(10) DEFAULT NULL,
  `Latitute` varchar(1024) DEFAULT NULL,
  `Longitute` varchar(1024) DEFAULT NULL,
  `Zeitstempel` datetime DEFAULT NULL,
  `DataBild` longtext,
  PRIMARY KEY (`Oid`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=latin1;


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`);


