migrationsscript erstellt
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
module.exports = {
|
||||
id: "001_create_base_schema",
|
||||
async up(db) {
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS resources (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
position INT,
|
||||
name VARCHAR(255),
|
||||
produkt VARCHAR(255),
|
||||
provider VARCHAR(255),
|
||||
art VARCHAR(100),
|
||||
cpu VARCHAR(50),
|
||||
ram VARCHAR(50),
|
||||
disk VARCHAR(50),
|
||||
os VARCHAR(100),
|
||||
ipv6_net VARCHAR(255),
|
||||
providername VARCHAR(255),
|
||||
kosten_monat DECIMAL(10,2),
|
||||
kosten_jahr DECIMAL(10,2),
|
||||
laufzeit_monate INT,
|
||||
bestelldatum DATE,
|
||||
kuendbar_ab DATE,
|
||||
kuendigungsdatum DATE,
|
||||
status VARCHAR(50),
|
||||
bemerkung TEXT
|
||||
)
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS resource_ips (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
resource_id INT,
|
||||
ip VARCHAR(100),
|
||||
type VARCHAR(50),
|
||||
comment VARCHAR(255)
|
||||
)
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS domains (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
position INT,
|
||||
domain_name VARCHAR(255),
|
||||
provider VARCHAR(255),
|
||||
ip_address VARCHAR(100),
|
||||
yearly_cost DECIMAL(10,2),
|
||||
notes TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS subdomains (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
domain_id INT,
|
||||
subdomain VARCHAR(100),
|
||||
ip_address VARCHAR(100)
|
||||
)
|
||||
`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
id: "002_add_position_columns",
|
||||
async up(db) {
|
||||
await db.query(`
|
||||
ALTER TABLE resources
|
||||
ADD COLUMN IF NOT EXISTS position INT
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
ALTER TABLE domains
|
||||
ADD COLUMN IF NOT EXISTS position INT
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
UPDATE resources
|
||||
SET position = id
|
||||
WHERE position IS NULL
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
UPDATE domains
|
||||
SET position = id
|
||||
WHERE position IS NULL
|
||||
`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const migrationsDir = __dirname;
|
||||
|
||||
const migrations = fs
|
||||
.readdirSync(migrationsDir)
|
||||
.filter((file) => file.endsWith(".js") && file !== "index.js")
|
||||
.sort()
|
||||
.map((file) => require(path.join(migrationsDir, file)));
|
||||
|
||||
module.exports = migrations;
|
||||
Reference in New Issue
Block a user