MikroWizard Initial commit | MikroMan Welcome to the world :)
This commit is contained in:
commit
8c49b9a55d
96 changed files with 12274 additions and 0 deletions
61
migrations/001_users.py
Normal file
61
migrations/001_users.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
"""Peewee migrations -- 001_create.py.
|
||||
|
||||
Some examples:
|
||||
|
||||
> Model = migrator.orm['model_name'] # Return model in current state by name
|
||||
|
||||
> migrator.sql(sql) # Run custom SQL
|
||||
> migrator.python(func, *args, **kwargs) # Run python code
|
||||
> migrator.create_model(Model) # Create a model
|
||||
> migrator.remove_model(model, cascade=True) # Remove a model
|
||||
> migrator.add_fields(model, **fields) # Add fields to a model
|
||||
> migrator.change_fields(model, **fields) # Change fields
|
||||
> migrator.remove_fields(model, *field_names, cascade=True)
|
||||
> migrator.rename_field(model, old_field_name, new_field_name)
|
||||
> migrator.rename_table(model, new_table_name)
|
||||
> migrator.add_index(model, *col_names, unique=False)
|
||||
> migrator.drop_index(model, *col_names)
|
||||
> migrator.add_not_null(model, *field_names)
|
||||
> migrator.drop_not_null(model, *field_names)
|
||||
> migrator.add_default(model, field_name, default)
|
||||
"""
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
"""Write your migrations here."""
|
||||
|
||||
# create extension manually - you must be a superuser to do this
|
||||
# is needed by uuid_generate_v4()
|
||||
|
||||
# migrator.sql("""CREATE EXTENSION IF NOT EXISTS "uuid-ossp";""")
|
||||
|
||||
|
||||
migrator.sql("""CREATE TYPE type_user_role AS ENUM (
|
||||
'disabled',
|
||||
'admin',
|
||||
'superuser',
|
||||
'user')
|
||||
""")
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE users (
|
||||
|
||||
id uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
|
||||
username text UNIQUE,
|
||||
password text,
|
||||
first_name text,
|
||||
last_name text,
|
||||
role type_user_role DEFAULT 'user',
|
||||
tags text[],
|
||||
hash text DEFAULT Null,
|
||||
email text DEFAULT Null,
|
||||
adminperms text DEFAULT Null,
|
||||
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
|
||||
)""")
|
||||
# normal integer-id: id serial PRIMARY KEY NOT NULL,
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
"""Write your rollback migrations here."""
|
||||
|
||||
40
migrations/002_devices.py
Normal file
40
migrations/002_devices.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
# 002_devices.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE devices(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name text,
|
||||
ip text,
|
||||
mac text UNIQUE,
|
||||
details text,
|
||||
uptime text,
|
||||
license text,
|
||||
interface text,
|
||||
user_name text,
|
||||
password text,
|
||||
port text,
|
||||
update_availble boolean,
|
||||
current_firmware text,
|
||||
arch text,
|
||||
upgrade_availble boolean,
|
||||
sensors text,
|
||||
router_type text,
|
||||
wifi_config text,
|
||||
peer_ip text,
|
||||
failed_attempt int DEFAULT 0,
|
||||
syslog_configured boolean,
|
||||
status text NOT NULL DEFAULT 'done',
|
||||
firmware_to_install text,
|
||||
owner uuid REFERENCES users(id),
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
modified timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE devices""")
|
||||
|
||||
20
migrations/003_sysconfig.py
Normal file
20
migrations/003_sysconfig.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
# 003_sysconfig.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE sysconfig(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
key text UNIQUE,
|
||||
value text,
|
||||
created_by uuid REFERENCES users(id),
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
modified timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE sysconfig""")
|
||||
|
||||
21
migrations/004_device_groups.py
Normal file
21
migrations/004_device_groups.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
# 004_device_groups.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE device_groups(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name text,
|
||||
owner uuid REFERENCES users(id),
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
modified timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE device_groups""")
|
||||
|
||||
22
migrations/005_device_groups_devices_rel.py
Normal file
22
migrations/005_device_groups_devices_rel.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
# 005_device_groups_devices_rel.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE device_groups_devices_rel(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
group_id serial REFERENCES device_groups(id),
|
||||
device_id serial REFERENCES devices(id),
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
modified timestamp not null default CURRENT_TIMESTAMP,
|
||||
UNIQUE(group_id, device_id)
|
||||
)""")
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE device_groups_devices_rel""")
|
||||
|
||||
22
migrations/006_tasks.py
Normal file
22
migrations/006_tasks.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
# 006_tasks.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE tasks(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
signal int UNIQUE,
|
||||
name text,
|
||||
starttime timestamp not null default CURRENT_TIMESTAMP,
|
||||
endtime timestamp not null default CURRENT_TIMESTAMP,
|
||||
status boolean
|
||||
)""")
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE tasks""")
|
||||
|
||||
25
migrations/007_events.py
Normal file
25
migrations/007_events.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
# 009_events.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE events(
|
||||
id bigserial PRIMARY KEY NOT NULL,
|
||||
devid bigint REFERENCES devices(id),
|
||||
eventtype text,
|
||||
comment text,
|
||||
status boolean,
|
||||
detail text,
|
||||
level text,
|
||||
src text,
|
||||
fixtime timestamp null default null,
|
||||
eventtime timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE events""")
|
||||
|
||||
20
migrations/008_backups.py
Normal file
20
migrations/008_backups.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
# 013_backups.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
# an example class for demonstrating CRUD...
|
||||
|
||||
migrator.sql("""CREATE TABLE backups(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
devid bigint REFERENCES devices(id),
|
||||
dir text,
|
||||
filesize int,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE backups""")
|
||||
|
||||
29
migrations/009_authorization.py
Normal file
29
migrations/009_authorization.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# 014_authorization.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""CREATE TYPE type_auth AS ENUM (
|
||||
'loggedin',
|
||||
'loggedout',
|
||||
'failed')
|
||||
""")
|
||||
|
||||
migrator.sql("""CREATE TABLE auth(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
devid bigint REFERENCES devices(id),
|
||||
ltype type_auth,
|
||||
ip text,
|
||||
by text,
|
||||
username text,
|
||||
started bigint DEFAULT 0,
|
||||
ended bigint DEFAULT 0,
|
||||
sessionid text DEFAULT Null,
|
||||
message text DEFAULT Null,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE auth""")
|
||||
|
||||
23
migrations/010_account.py
Normal file
23
migrations/010_account.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# 015_account.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE account(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
devid bigint REFERENCES devices(id),
|
||||
message text,
|
||||
action text,
|
||||
section text,
|
||||
username text,
|
||||
config text,
|
||||
address text,
|
||||
ctype text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE account""")
|
||||
|
||||
25
migrations/011_user_tasks.py
Normal file
25
migrations/011_user_tasks.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# 021_user_tasks.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE user_tasks(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name text,
|
||||
description text,
|
||||
dev_ids text,
|
||||
snippetid int,
|
||||
data text,
|
||||
cron text,
|
||||
action text,
|
||||
task_type text,
|
||||
selection_type text,
|
||||
desc_cron text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE user_tasks""")
|
||||
|
||||
18
migrations/012_snipppets.py
Normal file
18
migrations/012_snipppets.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# 023_snippets.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE snippets(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name text,
|
||||
description text,
|
||||
content text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE snippets""")
|
||||
|
||||
18
migrations/013_permissions.py
Normal file
18
migrations/013_permissions.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# 027_permissions.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE permissions(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
name text,
|
||||
perms text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
modified timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE permissions""")
|
||||
|
||||
19
migrations/014_user_group_perm.py
Normal file
19
migrations/014_user_group_perm.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
# 029_user_group_perm.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""CREATE TABLE user_group_perm_rel(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
group_id serial REFERENCES device_groups(id),
|
||||
user_id uuid REFERENCES users(id),
|
||||
perm_id serial REFERENCES permissions(id),
|
||||
UNIQUE(group_id, user_id)
|
||||
)""")
|
||||
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE user_group_perm_rel""")
|
||||
|
||||
20
migrations/015_firmware.py
Normal file
20
migrations/015_firmware.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
# 030_firmware.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""CREATE TABLE firmware(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
version text NOT NULL,
|
||||
location text NOT NULL,
|
||||
architecture text NOT NULL,
|
||||
sha256 text NOT NULL,
|
||||
created timestamp not null default CURRENT_TIMESTAMP,
|
||||
UNIQUE(version, architecture)
|
||||
|
||||
)""")
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE firmware""")
|
||||
|
||||
16
migrations/016_task_group_dev_rel.py
Normal file
16
migrations/016_task_group_dev_rel.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# 032_task_group_dev_rel.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""CREATE TABLE task_group_dev_rel(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
utask_id serial REFERENCES user_tasks(id) ,
|
||||
group_id bigint NULL REFERENCES device_groups(id) default null,
|
||||
device_id bigint NULL REFERENCES devices(id) default null,
|
||||
UNIQUE(utask_id, group_id , device_id)
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE task_group_dev_rel""")
|
||||
17
migrations/017_task_results.py
Normal file
17
migrations/017_task_results.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# 027_permissions.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
|
||||
|
||||
migrator.sql("""CREATE TABLE task_results(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
task_type text,
|
||||
result text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE task_results""")
|
||||
|
||||
20
migrations/018_syslogs.py
Normal file
20
migrations/018_syslogs.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# 038_syslogs.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
migrator.sql("""CREATE TABLE syslogs(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
user_id uuid REFERENCES users(id),
|
||||
action text,
|
||||
section text,
|
||||
data text,
|
||||
ip text,
|
||||
agent text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
|
||||
migrator.sql("""DROP TABLE syslogs""")
|
||||
|
||||
|
||||
17
migrations/019_device_radio.py
Normal file
17
migrations/019_device_radio.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# 038_device_radio.py
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
migrator.sql("""CREATE TABLE device_radio(
|
||||
id serial PRIMARY KEY NOT NULL,
|
||||
devid bigint REFERENCES devices(id),
|
||||
peer_dev_id bigint REFERENCES devices(id),
|
||||
data text,
|
||||
external_id text,
|
||||
mac text,
|
||||
created timestamp not null default CURRENT_TIMESTAMP
|
||||
)""")
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
migrator.sql("""DROP TABLE device_radio""")
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue