batman (working version kinda)
This commit is contained in:
commit
6dd38036e7
65 changed files with 3950 additions and 0 deletions
27
app/scripts/db_seed.py
Normal file
27
app/scripts/db_seed.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from app.core.extensions import db
|
||||
from app.core.models import Subnet, Server, App
|
||||
from app.core.auth import User
|
||||
|
||||
def seed_database():
|
||||
# Example seed data for network objects
|
||||
subnet = Subnet(cidr='192.168.1.0/24', location='Office', auto_scan=True)
|
||||
server = Server(hostname='server1', ip_address='192.168.1.10', subnet=subnet)
|
||||
app = App(name='Web App', server=server, documentation='# Welcome to Web App',
|
||||
_ports='[{"port": 80, "type": "tcp", "desc": "Web"}]')
|
||||
|
||||
# Create a default user if none exists
|
||||
if User.query.count() == 0:
|
||||
admin = User(email="admin@example.com", is_admin=True)
|
||||
admin.set_password("admin")
|
||||
db.session.add(admin)
|
||||
|
||||
db.session.add(subnet)
|
||||
db.session.add(server)
|
||||
db.session.add(app)
|
||||
|
||||
try:
|
||||
db.session.commit()
|
||||
print("Database seeded successfully")
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
print(f"Error seeding database: {e}")
|
Loading…
Add table
Add a link
Reference in a new issue