[DEV] update BDD

This commit is contained in:
Edouard DUPIN 2020-02-18 18:43:18 +01:00
parent d0c6c07833
commit 6b678eed88
14 changed files with 186 additions and 90 deletions

View File

@ -41,6 +41,20 @@ tmp_value = 0
#curl -F 'file=@Totally_Spies.mp4;type=application/octet-stream' -H 'transfer-encoding:chunked' 127.0.0.1:15080/data -X POST -O; echo ;
# Create table
bdd_structure = '''
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
sha512 TEXT NOT NULL,
mime_type TEXT NOT NULL,
size BIGINT NOT NULL,
original_name TEXT)
''')
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)
"""

View File

@ -29,6 +29,19 @@ import tools
import data_interface
import data_global_elements
# Create table
bdd_structure = '''
CREATE TABLE grp (
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers INTEGER[] REFERENCES data(id))
''')
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)

View File

@ -29,6 +29,20 @@ import tools
import data_interface
import data_global_elements
# Create table
bdd_structure = '''
CREATE TABLE saison (
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
number INTEGER NOT NULL,
description TEXT,
group_id INTEGER REFERENCES grp(id),
covers INTEGER[] REFERENCES data(id))
'''
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)

View File

@ -29,6 +29,19 @@ import tools
import data_interface
import data_global_elements
# Create table
bdd_structure = '''
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers INTEGER[] REFERENCES data(id))
'''
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)

View File

@ -29,6 +29,18 @@ import tools
import data_interface
import data_global_elements
# Create table
bdd_structure = '''
CREATE TABLE univers (
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers INTEGER[] REFERENCES data(id))
'''
def add(_app, _name_api):
elem_blueprint = Blueprint(_name_api)

View File

@ -30,6 +30,27 @@ import tools
import data_interface
import data_global_elements
# Create table
bdd_structure = '''
CREATE TABLE video (
id INTEGER PRIMARY KEY,
deleted BOOLEAN,
create_date DATETIME NOT NULL,
modify_date DATETIME NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers INTEGER[] REFERENCES data(id),
data_id INTEGER REFERENCES data(id),
type_id INTEGER REFERENCES type(id),
univers_id INTEGER REFERENCES univers(id),
group_id INTEGER REFERENCES grp(id),
saison_id INTEGER REFERENCES saison(id),
episode INTEGER,
time INTEGER)
'''
def generate_name(_value):
group_name = ""
if "univers_id" in _value.keys():

View File

@ -2,6 +2,11 @@ from realog import debug
import psycopg2
debug.info("connect BDD: ")
conn = psycopg2.connect(dbname="karideo", user="postgres", password="postgres", host="localhost", port="15032")
def connect_bdd():
debug.info("connect BDD: ")
conn = psycopg2.connect(dbname="karideo", user="root", password="postgress_password", host="localhost", port="15032")
return conn
base_bdd_name = "karideo_"

View File

@ -16,7 +16,8 @@ import random
import copy
from dateutil import parser
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -33,17 +34,18 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE data(
id INTEGER PRIMARY KEY,
deleted INTEGER,
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
sha512 TEXT NOT NULL,
mime_type TEXT NOT NULL,
size BIGINT NOT NULL,
create_date BIGINT NOT NULL,
original_name TEXT)
''')
@ -53,21 +55,18 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
time = elem["create_date"].replace("Z","").replace("H"," ");
tmp_time = parser.parse(time)
debug.info(" => " + str(tmp_time) + " from " + elem["create_date"])
new_time = int(tmp_time.timestamp())
time_create = elem["create_date"];
mime_type = elem["mime_type"]
original_name = elem["original_name"]
sha512 = elem["sha512"]
size = elem["size"]
request_insert = (id, sha512, mime_type, size, new_time, original_name)
c.execute('INSERT INTO data VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, time_create, sha512, mime_type, size, original_name)
c.execute('INSERT INTO data VALUES (%s,false,%s,CURRENT_TIMESTAMP,%s,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -17,7 +17,9 @@ import copy
from dateutil import parser
import datetime
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -34,18 +36,20 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE group (
id INTEGER PRIMARY KEY,
deleted INTEGER,
create_date INTEGER NOT NULL,
modify_date INTEGER NOT NULL,
CREATE TABLE grp (
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers TEXT)
covers INTEGER[] REFERENCES data(id))
''')
def list_to_string(data):
@ -64,7 +68,6 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
new_time = int(datetime.datetime.utcnow().timestamp());
name = elem["name"]
if "description" not in elem.keys():
description = None
@ -76,13 +79,13 @@ for elem in my_old_bdd:
covers = elem["covers"]
if covers == None:
covers = [];
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
c.execute('INSERT INTO group VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, name, description, covers)
c.execute('INSERT INTO grp VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -17,7 +17,9 @@ import copy
from dateutil import parser
import datetime
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -34,19 +36,19 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE saison (
id INTEGER PRIMARY KEY,
deleted INTEGER,
create_date INTEGER NOT NULL,
modify_date INTEGER NOT NULL,
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
number INTEGER NOT NULL,
description TEXT,
group_id INTEGER NOT NULL,
covers TEXT)
group_id INTEGER REFERENCES grp(id),
covers INTEGER[] REFERENCES data(id))
''')
def list_to_string(data):
@ -65,7 +67,6 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
new_time = int(datetime.datetime.utcnow().timestamp());
name = elem["number"]
if "group_id" not in elem.keys():
group_id = None
@ -81,13 +82,13 @@ for elem in my_old_bdd:
covers = elem["covers"]
if covers == None:
covers = [];
request_insert = (id, new_time, new_time, name, description, group_id, list_to_string(covers))
c.execute('INSERT INTO saison VALUES (%s,0,%s,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, name, description, group_id, covers)
c.execute('INSERT INTO saison VALUES (%s,false,now,now,%s,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -17,7 +17,9 @@ import copy
from dateutil import parser
import datetime
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -34,18 +36,18 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE type (
id INTEGER PRIMARY KEY,
deleted INTEGER,
create_date INTEGER NOT NULL,
modify_date INTEGER NOT NULL,
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers TEXT)
covers INTEGER[] REFERENCES data(id))
''')
def list_to_string(data):
@ -64,7 +66,6 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
new_time = int(datetime.datetime.utcnow().timestamp());
name = elem["name"]
if "description" not in elem.keys():
description = None
@ -76,13 +77,13 @@ for elem in my_old_bdd:
covers = elem["covers"]
if covers == None:
covers = [];
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
c.execute('INSERT INTO type VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, name, description, covers)
c.execute('INSERT INTO type VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -17,7 +17,9 @@ import copy
from dateutil import parser
import datetime
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -34,18 +36,18 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE univers (
id INTEGER PRIMARY KEY,
deleted INTEGER,
create_date INTEGER NOT NULL,
modify_date INTEGER NOT NULL,
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers TEXT)
covers INTEGER[] REFERENCES data(id))
''')
def list_to_string(data):
@ -64,7 +66,6 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
new_time = int(datetime.datetime.utcnow().timestamp());
name = elem["name"]
if "description" not in elem.keys():
description = None
@ -76,13 +77,13 @@ for elem in my_old_bdd:
covers = elem["covers"]
if covers == None:
covers = [];
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
c.execute('INSERT INTO univers VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, name, description, covers)
c.execute('INSERT INTO univers VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -17,7 +17,9 @@ import copy
from dateutil import parser
import datetime
from db import conn
import db
connection = db.connect_bdd();
def file_read_data(path):
if not os.path.isfile(path):
@ -34,24 +36,23 @@ my_old_bdd = json.loads(data)
debug.info("create the table:")
c = conn.cursor()
c = connection.cursor()
# Create table
c.execute('''
CREATE TABLE video (
id INTEGER PRIMARY KEY,
deleted INTEGER,
create_date INTEGER NOT NULL,
modify_date INTEGER NOT NULL,
id SERIAL PRIMARY KEY,
deleted BOOLEAN,
create_date TIMESTAMPTZ NOT NULL,
modify_date TIMESTAMPTZ NOT NULL,
name TEXT NOT NULL,
description TEXT,
covers TEXT,
data_id INTEGER,
type_id INTEGER,
univers_id INTEGER,
group_id INTEGER,
saison_id INTEGER,
date VARCHAR,
covers INTEGER[] REFERENCES data(id),
data_id INTEGER REFERENCES data(id),
type_id INTEGER REFERENCES type(id),
univers_id INTEGER REFERENCES univers(id),
group_id INTEGER REFERENCES grp(id),
saison_id INTEGER REFERENCES saison(id),
episode INTEGER,
time INTEGER)
''')
@ -72,11 +73,7 @@ for elem in my_old_bdd:
iii+=1;
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
id = elem["id"]
time = elem["create_date"].replace("Z","").replace("H"," ");
tmp_time = parser.parse(time)
debug.info(" => " + str(tmp_time) + " from " + elem["create_date"])
new_time = int(tmp_time.timestamp())
modify_time = int(datetime.datetime.utcnow().timestamp());
time_create = elem["create_date"];
name = elem["name"]
if "description" not in elem.keys():
description = None
@ -120,11 +117,11 @@ for elem in my_old_bdd:
time = None
else:
time = elem["time"]
request_insert = (id, new_time, modify_time, name, description, list_to_string(covers), data_id, type_id, univers_id, group_id, saison_id, date, episode, time)
c.execute('INSERT INTO video VALUES (%s,0,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', request_insert)
request_insert = (id, time_create, name, description, covers, data_id, type_id, univers_id, group_id, saison_id, date, episode, time)
c.execute('INSERT INTO video VALUES (%s,false,%s,now,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', request_insert)
# Save (commit) the changes
conn.commit()
connection.commit()
# def dict_factory(cursor, row):
# d = {}
@ -140,5 +137,5 @@ conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn.close()
connection.close()

View File

@ -7,15 +7,17 @@ services:
environment:
PGDATA: /var/lib/postgresql/data
POSTGRES_DB: karideo
POSTGRES_USER: root
POSTGRES_PASSWORD: postgress_password
#this is for debug only
ports:
- "15032:5432"
- 15032:5432
volumes:
- ./data:/var/lib/postgresql/data
- ./data:/var/lib/postgresql/data:rw
adminer:
image: adminer
restart: always
ports:
- 15079:8080
links:
- bdd_service:bdd
- bdd_service:db