Commit 43a4dee5 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Merge branch 'WIPdb'

parents 62e598ae def5e394
LysNS SQL parts
===============
The debug MySql database is stored on an Virtual Machine
which is in the time of writing 2018-01-09located at
~hugo/VirtualBox VMs/LysMemberSQL
The `manage` script here is for starting, stopping and connecting
to that machine. SSH is also avalible.
Ports and Logins
----------------
Login:
Linux:
user: root
pass: password
MySQL:
user: lysns
pass: password
Ports:
- ssh
- local :: 22
- extern :: 2222
- mysql
- local :: 3306
- extern :: 2223
Other files in this directory
-----------------------------
- domaindb.db -- SQLite Database
- domaindb.schema -- SQLite create script
- domaindb.sql -- MySQL create script
- mysql_setup.sql -- MySQL user create script
- test_data.sql -- MySQL dummy data
DROP TABLE person;
DROP TABLE domain;
DROP TABLE mail;
DROP TABLE record_types;
CREATE TABLE person (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
username TEXT
);
CREATE TABLE domain (
id INTEGER PRIMARY KEY AUTOINCREMENT,
userid INTEGER,
name TEXT,
FOREIGN KEY(userid) REFERENCES person(id)
);
CREATE TABLE record_types (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT
);
INSERT INTO record_types (name),
("MX"),
("A"),
("AAAA");
CREATE TABLE subdomain (
id INTEGER PRIMARY KEY AUTOINCREMENT,
domainid INTEGER,
name TEXT,
ttl INTEGER,
rr INTEGER,
dest BLOB,
class TEXT,
FOREIGN KEY(domainid) REFERENCES domain(id),
FOREIGN KEY(rr) REFERENCES record_types(id);
);
CREATE TABLE keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
domainid INTEGER,
key BLOB,
secret BLOB,
FOREIGN KEY(domainid) REFERENCES domain(id)
);
-- TODO why?
delimiter //
DROP TABLE IF EXISTS dkeys;//
DROP TABLE IF EXISTS update_key;//
DROP TABLE IF EXISTS subdomain;//
DROP TABLE IF EXISTS domain;//
DROP TABLE IF EXISTS person;//
DROP TABLE IF EXISTS record_types;//
DROP TABLE IF EXISTS domain;//
create table person
-- This table is used as an enum table
CREATE TABLE record_types
(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255),
username varchar(255),
name varchar (16) NOT NULL,
CONSTRAINT pk_person_id PRIMARY KEY (id)
CONSTRAINT pk_record_types_id PRIMARY KEY (id),
CONSTRAINT uc_record_types_name UNIQUE (name)
)ENGINE=InnoDB;//
create table domain
CREATE TABLE domain
(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255),
personid int(11),
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(191), -- hornquist.se
uid int(11), -- 2278
dirtybit bool NOT NULL DEFAULT 0,
deletebit bool NOT NULL DEFAULT 0,
CONSTRAINT pk_domain_id PRIMARY KEY (id),
CONSTRAINT fk_domain_perid FOREIGN KEY (personid) REFERENCES person(id)
CONSTRAINT uc_domain_name UNIQUE (name),
INDEX idx_domain_dirtybit (dirtybit),
INDEX idx_domain_deletebit (deletebit)
)ENGINE=InnoDB;//
create table subdomain
CREATE TABLE subdomain
(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255),
ttl int(11) DEFAULT 86400 NOT NULL,
class varchar(255) default "IN" NOT NULL,
-- rr varchar(255) default "A" NOT NULL,
rr int(11) NOT NULL,
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(191) NOT NULL, -- blog, `@' for no subdomain
ttl int(11) DEFAULT 600 NOT NULL,
class varchar(255) DEFAULT "IN" NOT NULL,
rr int(11) NOT NULL, -- A, MX
destination varchar(255), -- only for cname
domainid int(11),
dirtybit bool NOT NULL DEFAULT 0,
deletebit bool NOT NULL DEFAULT 0,
CONSTRAINT pk_subdomain_id PRIMARY KEY (id),
CONSTRAINT fk_subdomain_domid FOREIGN KEY (domainid) REFERENCES domain(id)
CONSTRAINT fk_subdomain_domid FOREIGN KEY (domainid) REFERENCES domain(id),
CONSTRAINT fk_subdomain_rr FOREIGN KEY (rr) REFERENCES record_types (id),
CONSTRAINT uc_subdomain_name_domainid UNIQUE (name, domainid),
INDEX idx_subdomain_dirtybit (dirtybit),
INDEX idx_subdomain_deletebit (deletebit)
)ENGINE=InnoDB;//
-- dkey really should be key, but that's a reserver SQL keyword
create table dkeys
CREATE TABLE update_key
(
id int(11) NOT NULL AUTO_INCREMENT,
domainid int(11),
dkey varchar(255),
secret varchar(255),
CONSTRAINT pk_dkeys_id PRIMARY KEY (id),
CONSTRAINT fk_dkeys_domid FOREIGN KEY (domainid) REFERENCES domain(id)
subid int(11) NOT NULL,
)ENGINE=InnoDB;//
update_key varchar(255) NOT NULL,
secret varchar(255) NOT NULL,
-- This table is used as an enum table
CREATE TABLE record_types
(
id int(11) NOT NULL AUTO_INCREMENT,
name varchar (16) NOT NULL,
CONSTRAINT pk_record_types_id PRIMARY KEY (id),
CONSTRAINT uc_record_types_name UNIQUE (name)
CONSTRAINT pk_update_key_id PRIMARY KEY (id),
CONSTRAINT fk_update_key_subid FOREIGN KEY (subid) REFERENCES subdomain (id)
)ENGINE=InnoDB;//
-- Insert intial values.
-- Should probably be moved somewhere else
-- INSERT INTO record_types (name) VALUES ("A"), ("AAAA");
INSERT INTO record_types (id, name)
VALUES ("A"),
("AAAA"),
("CNAME"),
("TXT");
DELETE FROM subdomain;
DELETE FROM record_types;
DELETE FROM domain;
INSERT INTO domain (id, uid, name)
VALUES (1, 2278, "hornquist.se"),
(2, 2278, "hugoweb.ga"),
(3, 2116, "jiffe.jiff");
INSERT INTO subdomain (id, domainid, name, rr, ttl)
SELECT (1, 1, "@", id, 300) FROM record_types WHERE name = "A";
INSERT INTO subdomain (id, domainid, name, rr, ttl)
SELECT (2, 2, "www", id, 300) FROM record_types WHERE name = "A";
INSERT INTO subdomain (id, domainid, name, rr, ttl)
SELECT (3, 1, "blog", id, 300) FROM record_types WHERE name = "A";
INSERT INTO subdomain (id, domainid, name, rr, ttl)
SELECT (4, 3, "jeff", id, 86400) FROM record_types WHERE name = "AAAA";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment