summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-11 16:49:07 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-11 16:49:07 +0000
commit9d18b9e9d9ab7561deadc867654f7cc4db15d2e1 (patch)
treef3460b802b4c9ac3e9c6e89424e356a565b9bd06
parent9ac5d6b7ee1eeeed873d5341336c6c8df3cd56b1 (diff)
Started the Operation model
-rw-r--r--internal/models/operation.go16
-rw-r--r--populate.sql28
2 files changed, 43 insertions, 1 deletions
diff --git a/internal/models/operation.go b/internal/models/operation.go
new file mode 100644
index 0000000..8547030
--- /dev/null
+++ b/internal/models/operation.go
@@ -0,0 +1,16 @@
+package models
+
+import (
+ "database/sql"
+)
+
+type Operation struct {
+ ID int
+ Name string
+ Description string
+ Organisation Organisation
+}
+
+type OperationMOdel struct {
+ DB *sql.DB
+}
diff --git a/populate.sql b/populate.sql
index bb7821b..b7dc783 100644
--- a/populate.sql
+++ b/populate.sql
@@ -3,8 +3,13 @@
/* Switch to using it. */
USE ded;
+/* Create the Operations table */
+SET FOREIGN_KEY_CHECKS = 0;
+DROP TABLE organisations;
+DROP TABLE operations;
+SET FOREIGN_KEY_CHECKS = 1;
+
/* Create the Organisations table. */
-DROP TABLE IF EXISTS organisations;
CREATE TABLE organisations (
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
@@ -19,6 +24,27 @@ INSERT INTO organisations (name, created) VALUES ("Random Organisation 1", UTC_T
INSERT INTO organisations (name, created) VALUES ("Random Organisation 2", UTC_TIMESTAMP());
INSERT INTO organisations (name, created) VALUES ("Random Organisation 3", UTC_TIMESTAMP());
+
+CREATE TABLE operations (
+ id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
+ name VARCHAR(100) NOT NULL,
+ description VARCHAR(255) NOT NULL,
+ organisation_id INT NOT NULL,
+ created DATETIME NOT NULL,
+ CONSTRAINT fk_operation_organisation
+ FOREIGN KEY(organisation_id)
+ REFERENCES organisations(id)
+ ON DELETE CASCADE
+ ON UPDATE RESTRICT
+);
+
+/* Add index to created column. */
+CREATE INDEX idx_operations_created ON operations(created);
+
+INSERT INTO operations (name, created, description, organisation_id) VALUES ("Operation 1", UTC_TIMESTAMP(), "Operation 1 Description", 1);
+
+
+
/* /1* The following should be carried out on the database server *1/ */
/* -- CREATE USER 'web'@'localhost'; */
/* -- GRANT SELECT, INSERT, UPDATE, DELETE ON ded.* TO 'web'@'localhost'; */