CREATE TABLE vn.farming (
	id int(10) unsigned auto_increment NOT NULL,
	name varchar(100) NOT NULL,
	location varchar(255) NOT NULL,
	warehouseFk smallint(6) unsigned NOT NULL,
	description text DEFAULT NULL NULL,
	photo blob DEFAULT NULL NULL,
	isActive tinyint(1) DEFAULT 1 NOT NULL,
	created timestamp DEFAULT current_timestamp() NOT NULL,
	CONSTRAINT farming_PK PRIMARY KEY (id),
    CONSTRAINT farming_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;

CREATE TABLE vn.farmingDms (
	id int(10) unsigned auto_increment NOT NULL,
	farmingFk int(10) unsigned NOT NULL,
	dmsFk int(11) NOT NULL,
	CONSTRAINT farmingDms_PK PRIMARY KEY (id),
	CONSTRAINT farmingDms_FK FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE CASCADE ON UPDATE CASCADE,
	CONSTRAINT farmingDms_FK_1 FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;

CREATE TABLE vn.farmingInvoiceIn (
	id int(10) unsigned auto_increment NOT NULL,
	farmingFk int(10) unsigned NOT NULL,
	invoiceInFk mediumint(8) unsigned NOT NULL,
	amount decimal(10,2) DEFAULT NULL NULL,
	CONSTRAINT farmingInvoiceIn_PK PRIMARY KEY (id),
	CONSTRAINT farmingInvoiceIn_FK FOREIGN KEY (invoiceInFk) REFERENCES vn.invoiceIn(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
	CONSTRAINT farmingInvoiceIn_FK_1 FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;

CREATE TABLE vn.farmingNotes (
	id int(10) unsigned auto_increment NOT NULL,
	farmingFk int(10) unsigned NOT NULL,
	note text NOT NULL,
	userFk int(10) unsigned NOT NULL,
	created timestamp DEFAULT current_timestamp() NOT NULL,
	CONSTRAINT farmingNotes_PK PRIMARY KEY (id),
	CONSTRAINT farmingNotes_FK FOREIGN KEY (id) REFERENCES account.`user`(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
	CONSTRAINT farmingNotes_FK_1 FOREIGN KEY (farmingFk) REFERENCES vn.farming(id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;