Files
old-riskletpy/db/db.go
2024-11-17 19:41:30 +01:00

94 lines
2.1 KiB
Go

package db
import (
"database/sql"
"log"
"sync"
_ "github.com/mattn/go-sqlite3"
)
var (
db *sql.DB
once sync.Once
)
func InitDB() {
once.Do(func() {
var err error
db, err = sql.Open("sqlite3", "./risklet.db")
if err != nil {
log.Fatal(err)
}
createTables()
})
}
func createTables() {
tables := []string{
`
CREATE TABLE IF NOT EXISTS Company (
id INTEGER PRIMARY KEY AUTOINCREMENT,
UUID TEXT NOT NULL,
Name TEXT NOT NULL,
TaxId TEXT NOT NULL,
Email TEXT NOT NULL,
Password TEXT NOT NULL
);`,
`
CREATE TABLE IF NOT EXISTS BasicProfile (
id INTEGER PRIMARY KEY AUTOINCREMENT,
CompanyId INTEGER,
Employees TEXT,
Revenue TEXT,
Applications TEXT,
Compliance TEXT,
Industry TEXT,
ITDependency TEXT,
DataSensitivity TEXT,
DataVolume TEXT,
NetworkSegmentation TEXT,
LegacySystems TEXT,
IoTIntegration TEXT,
RemoteWork TEXT,
BYOD TEXT,
VPN TEXT,
API TEXT,
VendorAccess TEXT,
InternalDev TEXT,
GeoScope TEXT, -- Geographic operational scope
CustomerBase TEXT, -- Customer base distribution
CustomerType TEXT, -- Primary customer type
ProductPortfolio TEXT, -- Product/service portfolio
SupplierBase TEXT, -- Supplier base structure
ITInfrastructure TEXT, -- IT infrastructure model (comma-separated values)
IPProtection TEXT, -- Intellectual property protection (comma-separated values)
SensitiveData TEXT, -- Sensitive data types (comma-separated values)
IntegrationLevel TEXT, -- Integration level of business systems
RemotePolicy TEXT, -- Remote work policy
FOREIGN KEY (CompanyId) REFERENCES Company(id)
);`,
`CREATE TABLE IF NOT EXISTS Session (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT NOT NULL,
value TEXT NOT NULL
);`,
`CREATE INDEX IF NOT EXISTS idx_session_key ON Session(key);`,
}
for _, table := range tables {
_, err := db.Exec(table)
if err != nil {
log.Fatalf("Error creating table: %v", err)
}
}
}
func GetDB() *sql.DB {
return db
}