Skip to content

Commit

Permalink
Merge pull request #807 from OmniDB/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
wind39 committed Dec 20, 2018
2 parents 86a3276 + ca55c25 commit df29df2
Show file tree
Hide file tree
Showing 76 changed files with 2,592 additions and 1,404 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Expand Up @@ -7,9 +7,9 @@ RUN apt-get update \
RUN mkdir /app
WORKDIR /app

RUN wget -q https://omnidb.org/dist/2.12.0/omnidb-server_2.12.0-debian-amd64.deb \
&& dpkg -i /app/omnidb-server_2.12.0-debian-amd64.deb \
&& rm -rf omnidb-server_2.12.0-debian-amd64.deb
RUN wget -q https://omnidb.org/dist/2.13.0/omnidb-server_2.13.0-debian-amd64.deb \
&& dpkg -i /app/omnidb-server_2.13.0-debian-amd64.deb \
&& rm -rf omnidb-server_2.13.0-debian-amd64.deb

EXPOSE 8000
EXPOSE 25482
Expand Down
4 changes: 2 additions & 2 deletions OmniDB/OmniDB/custom_settings.py
@@ -1,7 +1,7 @@
import os

OMNIDB_VERSION = 'OmniDB 2.12.0'
OMNIDB_SHORT_VERSION = '2.12.0'
OMNIDB_VERSION = 'OmniDB 2.13.0'
OMNIDB_SHORT_VERSION = '2.13.0'
DEV_MODE = True
DESKTOP_MODE = False
HOME_DIR = None
Expand Down
Expand Up @@ -394,7 +394,7 @@ CREATE TABLE users (
constraint users_fk_0 foreign key (theme_id) references themes (theme_id) on update NO ACTION on delete NO ACTION,
constraint uq_users_0 unique (user_name)
);--omnidb--
INSERT INTO users VALUES(1,'admin','8IqxKdQ=',1,'14',1,1,'utf-8',';');--omnidb--
INSERT INTO users VALUES(1,'admin','48b19163bdb02cadab1a09c9dd4eafae',1,'14',1,1,'utf-8',';');--omnidb--

CREATE TABLE messages (
mes_in_code integer not null,
Expand Down Expand Up @@ -446,7 +446,6 @@ CREATE TABLE connections (
port varchar(20),
service varchar(500),
user varchar(100),
password varchar(100),
alias varchar(100),
ssh_server varchar(500),
ssh_port varchar(20),
Expand Down Expand Up @@ -609,8 +608,20 @@ CREATE TABLE console_history (
constraint fk_ch_conn foreign key (conn_id) references connections (conn_id) on update CASCADE on delete CASCADE
);--omnidb--

CREATE TABLE cgroups (
cgroup_id integer primary key,
user_id integer references users (user_id) ON UPDATE CASCADE ON DELETE CASCADE,
cgroup_name text
);--omnidb--

CREATE TABLE cgroups_connections (
cgroup_id integer references cgroups (cgroup_id) ON UPDATE CASCADE ON DELETE CASCADE,
conn_id integer references connections (conn_id) ON UPDATE CASCADE ON DELETE CASCADE,
primary key (cgroup_id, conn_id)
);--omnidb--

CREATE TABLE version (
ver_id text not null,
constraint pk_versions primary key (ver_id)
);--omnidb--
INSERT INTO version VALUES('2.12.0');--omnidb--
INSERT INTO version VALUES('2.13.0');--omnidb--
97 changes: 97 additions & 0 deletions OmniDB/OmniDB/migrations/omnidb_2.12.0_2.13.0.py
@@ -0,0 +1,97 @@
v_cryptor = Utils.Cryptor('omnidb', 'iso-8859-1')

p_database.v_connection.Open()
p_database.v_connection.Execute('BEGIN TRANSACTION;')

v_table = p_database.v_connection.Query('SELECT user_id, password FROM users;')
for v_row in v_table.Rows:
v_hashed_pwd = v_cryptor.Hash(v_row['password'])
p_database.v_connection.Execute("UPDATE users SET password = '{0}' WHERE user_id = {1};".format(v_hashed_pwd, v_row['user_id']))

p_database.v_connection.Execute('''
CREATE TABLE connections_bak AS
SELECT *
FROM connections;
''')

p_database.v_connection.Execute('DROP TABLE connections;')

p_database.v_connection.Execute('''
CREATE TABLE connections (
conn_id integer,
user_id integer,
dbt_st_name varchar(40),
server varchar(500),
port varchar(20),
service varchar(500),
user varchar(100),
alias varchar(100),
ssh_server varchar(500),
ssh_port varchar(20),
ssh_user varchar(100),
ssh_password varchar(100),
ssh_key text,
use_tunnel integer,
constraint pk_connections primary key (conn_id),
constraint connections_fk_0 foreign key (user_id) references users (user_id) on update CASCADE on delete CASCADE,
constraint connections_fk_1 foreign key (dbt_st_name) references db_type (dbt_st_name) on update CASCADE on delete CASCADE
);
''')

p_database.v_connection.Execute('''
INSERT INTO connections (
conn_id,
user_id,
dbt_st_name,
server,
port,
service,
user,
alias,
ssh_server,
ssh_port,
ssh_user,
ssh_password,
ssh_key,
use_tunnel
)
SELECT conn_id,
user_id,
dbt_st_name,
server,
port,
service,
user,
alias,
ssh_server,
ssh_port,
ssh_user,
ssh_password,
ssh_key,
use_tunnel
FROM connections_bak;
''')

p_database.v_connection.Execute('DROP TABLE connections_bak;')

p_database.v_connection.Execute('''
CREATE TABLE cgroups (
cgroup_id integer primary key,
user_id integer references users (user_id) ON UPDATE CASCADE ON DELETE CASCADE,
cgroup_name text
);
''')

p_database.v_connection.Execute('''
CREATE TABLE cgroups_connections (
cgroup_id integer references cgroups (cgroup_id) ON UPDATE CASCADE ON DELETE CASCADE,
conn_id integer references connections (conn_id) ON UPDATE CASCADE ON DELETE CASCADE,
primary key (cgroup_id, conn_id)
);
''')

p_database.v_connection.Execute("UPDATE version SET ver_id = '2.13.0';")

p_database.v_connection.Execute('COMMIT;')
p_database.v_connection.Close()
p_database.v_connection.Execute('VACUUM;')
3 changes: 3 additions & 0 deletions OmniDB/OmniDB/settings.py
Expand Up @@ -61,6 +61,9 @@
else:
SECRET_KEY = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(50))

SESSION_COOKIE_NAME = 'omnidb_sessionid'
CSRF_COOKIE_NAME = 'omnidb_csrftoken'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

Expand Down
34 changes: 23 additions & 11 deletions OmniDB/OmniDB/user_database.py
@@ -1,12 +1,13 @@
from . import settings
import os
import shutil
import OmniDB_app.include.Spartacus as Spartacus
import OmniDB_app.include.Spartacus.Database as Database
import OmniDB_app.include.Spartacus.Utils as Utils
import OmniDB_app.include.OmniDatabase as OmniDatabase

migrations = {
'0.0.0': ('2.12.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_0.0.0_2.12.0.sql')),
'0.0.0': ('2.13.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_0.0.0_2.13.0.sql')),
'2.4.0': ('2.4.1', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.4.0_2.4.1.sql')),
'2.4.1': ('2.5.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.4.1_2.5.0.sql')),
'2.5.0': ('2.6.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.5.0_2.6.0.sql')),
Expand All @@ -16,6 +17,7 @@
'2.9.0': ('2.10.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.9.0_2.10.0.sql')),
'2.10.0': ('2.11.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.10.0_2.11.0.sql')),
'2.11.0': ('2.12.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.11.0_2.12.0.sql')),
'2.12.0': ('2.13.0', os.path.join(settings.BASE_DIR, 'OmniDB/migrations/omnidb_2.12.0_2.13.0.py')),
}

def get_current_version(p_database):
Expand All @@ -26,18 +28,26 @@ def get_current_version(p_database):

def migrate(p_database, p_current_version):
if p_current_version in migrations:
next_version = migrations[p_current_version][0]
sql_file = migrations[p_current_version][1]
try:
next_version = migrations[p_current_version][0]
print('Starting migration of user database from version {0} to version {1}...'.format(p_current_version, next_version))
with open(sql_file, 'r') as f:
p_database.v_connection.Open()
p_database.v_connection.Execute('BEGIN TRANSACTION;')
for sql in f.read().split('--omnidb--'):
p_database.v_connection.Execute(sql)
p_database.v_connection.Execute('COMMIT;')
p_database.v_connection.Close()
p_database.v_connection.Execute('VACUUM;')
file = migrations[p_current_version][1]
tmp = file.split('.')
ext = tmp[len(tmp)-1]
if ext == 'sql':
with open(file, 'r') as f:
p_database.v_connection.Open()
p_database.v_connection.Execute('BEGIN TRANSACTION;')
for sql in f.read().split('--omnidb--'):
p_database.v_connection.Execute(sql)
p_database.v_connection.Execute('COMMIT;')
p_database.v_connection.Close()
p_database.v_connection.Execute('VACUUM;')
elif ext == 'py':
with open(file, 'r') as f:
exec(f.read())
else:
raise Exception('Unsupported migration file format: {0}'.format(file))
print('OmniDB successfully migrated user database from version {0} to version {1}'.format(p_current_version, next_version))
return True
except Exception as exc:
Expand All @@ -52,6 +62,8 @@ def work():
current_version = get_current_version(database)
if current_version != settings.OMNIDB_SHORT_VERSION:
if int(current_version.replace('.', '')) < int(settings.OMNIDB_SHORT_VERSION.replace('.', '')):
if os.path.exists(settings.OMNIDB_DATABASE):
shutil.copyfile(settings.OMNIDB_DATABASE, '{0}.bak_{1}'.format(settings.OMNIDB_DATABASE, settings.OMNIDB_SHORT_VERSION))
while int(current_version.replace('.', '')) < int(settings.OMNIDB_SHORT_VERSION.replace('.', '')):
if not migrate(database, current_version):
break
Expand Down

0 comments on commit df29df2

Please sign in to comment.