[DEV] update BDD
This commit is contained in:
parent
d0c6c07833
commit
6b678eed88
@ -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 ;
|
#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):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
"""
|
"""
|
||||||
|
@ -29,6 +29,19 @@ import tools
|
|||||||
import data_interface
|
import data_interface
|
||||||
import data_global_elements
|
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):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
|
@ -29,6 +29,20 @@ import tools
|
|||||||
import data_interface
|
import data_interface
|
||||||
import data_global_elements
|
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):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
|
@ -29,6 +29,19 @@ import tools
|
|||||||
import data_interface
|
import data_interface
|
||||||
import data_global_elements
|
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):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
|
@ -29,6 +29,18 @@ import tools
|
|||||||
import data_interface
|
import data_interface
|
||||||
import data_global_elements
|
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):
|
def add(_app, _name_api):
|
||||||
elem_blueprint = Blueprint(_name_api)
|
elem_blueprint = Blueprint(_name_api)
|
||||||
|
|
||||||
|
@ -30,6 +30,27 @@ import tools
|
|||||||
import data_interface
|
import data_interface
|
||||||
import data_global_elements
|
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):
|
def generate_name(_value):
|
||||||
group_name = ""
|
group_name = ""
|
||||||
if "univers_id" in _value.keys():
|
if "univers_id" in _value.keys():
|
||||||
|
@ -2,6 +2,11 @@ from realog import debug
|
|||||||
|
|
||||||
import psycopg2
|
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_"
|
||||||
|
@ -16,7 +16,8 @@ import random
|
|||||||
import copy
|
import copy
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -33,17 +34,18 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data(
|
CREATE TABLE data(
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
sha512 TEXT NOT NULL,
|
sha512 TEXT NOT NULL,
|
||||||
mime_type TEXT NOT NULL,
|
mime_type TEXT NOT NULL,
|
||||||
size BIGINT NOT NULL,
|
size BIGINT NOT NULL,
|
||||||
create_date BIGINT NOT NULL,
|
|
||||||
original_name TEXT)
|
original_name TEXT)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
@ -53,21 +55,18 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
time = elem["create_date"].replace("Z","").replace("H"," ");
|
time_create = elem["create_date"];
|
||||||
tmp_time = parser.parse(time)
|
|
||||||
debug.info(" => " + str(tmp_time) + " from " + elem["create_date"])
|
|
||||||
new_time = int(tmp_time.timestamp())
|
|
||||||
mime_type = elem["mime_type"]
|
mime_type = elem["mime_type"]
|
||||||
original_name = elem["original_name"]
|
original_name = elem["original_name"]
|
||||||
sha512 = elem["sha512"]
|
sha512 = elem["sha512"]
|
||||||
size = elem["size"]
|
size = elem["size"]
|
||||||
request_insert = (id, sha512, mime_type, size, new_time, original_name)
|
request_insert = (id, time_create, sha512, mime_type, size, original_name)
|
||||||
c.execute('INSERT INTO data VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
|
c.execute('INSERT INTO data VALUES (%s,false,%s,CURRENT_TIMESTAMP,%s,%s,%s,%s)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import copy
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -34,18 +36,20 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
|
||||||
|
|
||||||
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE group (
|
CREATE TABLE grp (
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
create_date INTEGER NOT NULL,
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
covers TEXT)
|
covers INTEGER[] REFERENCES data(id))
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def list_to_string(data):
|
def list_to_string(data):
|
||||||
@ -64,7 +68,6 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
new_time = int(datetime.datetime.utcnow().timestamp());
|
|
||||||
name = elem["name"]
|
name = elem["name"]
|
||||||
if "description" not in elem.keys():
|
if "description" not in elem.keys():
|
||||||
description = None
|
description = None
|
||||||
@ -76,13 +79,13 @@ for elem in my_old_bdd:
|
|||||||
covers = elem["covers"]
|
covers = elem["covers"]
|
||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, name, description, covers)
|
||||||
c.execute('INSERT INTO group VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
|
c.execute('INSERT INTO grp VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import copy
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -34,19 +36,19 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE saison (
|
CREATE TABLE saison (
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
create_date INTEGER NOT NULL,
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
number INTEGER NOT NULL,
|
number INTEGER NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
group_id INTEGER NOT NULL,
|
group_id INTEGER REFERENCES grp(id),
|
||||||
covers TEXT)
|
covers INTEGER[] REFERENCES data(id))
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def list_to_string(data):
|
def list_to_string(data):
|
||||||
@ -65,7 +67,6 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
new_time = int(datetime.datetime.utcnow().timestamp());
|
|
||||||
name = elem["number"]
|
name = elem["number"]
|
||||||
if "group_id" not in elem.keys():
|
if "group_id" not in elem.keys():
|
||||||
group_id = None
|
group_id = None
|
||||||
@ -81,13 +82,13 @@ for elem in my_old_bdd:
|
|||||||
covers = elem["covers"]
|
covers = elem["covers"]
|
||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, group_id, list_to_string(covers))
|
request_insert = (id, name, description, group_id, covers)
|
||||||
c.execute('INSERT INTO saison VALUES (%s,0,%s,%s,%s,%s,%s,%s)', request_insert)
|
c.execute('INSERT INTO saison VALUES (%s,false,now,now,%s,%s,%s,%s)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import copy
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -34,18 +36,18 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE type (
|
CREATE TABLE type (
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
create_date INTEGER NOT NULL,
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
covers TEXT)
|
covers INTEGER[] REFERENCES data(id))
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def list_to_string(data):
|
def list_to_string(data):
|
||||||
@ -64,7 +66,6 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
new_time = int(datetime.datetime.utcnow().timestamp());
|
|
||||||
name = elem["name"]
|
name = elem["name"]
|
||||||
if "description" not in elem.keys():
|
if "description" not in elem.keys():
|
||||||
description = None
|
description = None
|
||||||
@ -76,13 +77,13 @@ for elem in my_old_bdd:
|
|||||||
covers = elem["covers"]
|
covers = elem["covers"]
|
||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, name, description, covers)
|
||||||
c.execute('INSERT INTO type VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
|
c.execute('INSERT INTO type VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import copy
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -34,18 +36,18 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE univers (
|
CREATE TABLE univers (
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
create_date INTEGER NOT NULL,
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
covers TEXT)
|
covers INTEGER[] REFERENCES data(id))
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def list_to_string(data):
|
def list_to_string(data):
|
||||||
@ -64,7 +66,6 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
new_time = int(datetime.datetime.utcnow().timestamp());
|
|
||||||
name = elem["name"]
|
name = elem["name"]
|
||||||
if "description" not in elem.keys():
|
if "description" not in elem.keys():
|
||||||
description = None
|
description = None
|
||||||
@ -76,13 +77,13 @@ for elem in my_old_bdd:
|
|||||||
covers = elem["covers"]
|
covers = elem["covers"]
|
||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, name, description, covers)
|
||||||
c.execute('INSERT INTO univers VALUES (%s,0,%s,%s,%s,%s,%s)', request_insert)
|
c.execute('INSERT INTO univers VALUES (%s,false,now,now,%s,%s,%s)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -17,7 +17,9 @@ import copy
|
|||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from db import conn
|
import db
|
||||||
|
connection = db.connect_bdd();
|
||||||
|
|
||||||
|
|
||||||
def file_read_data(path):
|
def file_read_data(path):
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
@ -34,24 +36,23 @@ my_old_bdd = json.loads(data)
|
|||||||
|
|
||||||
debug.info("create the table:")
|
debug.info("create the table:")
|
||||||
|
|
||||||
c = conn.cursor()
|
c = connection.cursor()
|
||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE video (
|
CREATE TABLE video (
|
||||||
id INTEGER PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
deleted INTEGER,
|
deleted BOOLEAN,
|
||||||
create_date INTEGER NOT NULL,
|
create_date TIMESTAMPTZ NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date TIMESTAMPTZ NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT,
|
description TEXT,
|
||||||
covers TEXT,
|
covers INTEGER[] REFERENCES data(id),
|
||||||
data_id INTEGER,
|
data_id INTEGER REFERENCES data(id),
|
||||||
type_id INTEGER,
|
type_id INTEGER REFERENCES type(id),
|
||||||
univers_id INTEGER,
|
univers_id INTEGER REFERENCES univers(id),
|
||||||
group_id INTEGER,
|
group_id INTEGER REFERENCES grp(id),
|
||||||
saison_id INTEGER,
|
saison_id INTEGER REFERENCES saison(id),
|
||||||
date VARCHAR,
|
|
||||||
episode INTEGER,
|
episode INTEGER,
|
||||||
time INTEGER)
|
time INTEGER)
|
||||||
''')
|
''')
|
||||||
@ -72,11 +73,7 @@ for elem in my_old_bdd:
|
|||||||
iii+=1;
|
iii+=1;
|
||||||
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
debug.info("[" + str(iii) + "/" + str(len(my_old_bdd)) + "] send new element")
|
||||||
id = elem["id"]
|
id = elem["id"]
|
||||||
time = elem["create_date"].replace("Z","").replace("H"," ");
|
time_create = elem["create_date"];
|
||||||
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());
|
|
||||||
name = elem["name"]
|
name = elem["name"]
|
||||||
if "description" not in elem.keys():
|
if "description" not in elem.keys():
|
||||||
description = None
|
description = None
|
||||||
@ -120,11 +117,11 @@ for elem in my_old_bdd:
|
|||||||
time = None
|
time = None
|
||||||
else:
|
else:
|
||||||
time = elem["time"]
|
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)
|
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,0,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', request_insert)
|
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
|
# Save (commit) the changes
|
||||||
conn.commit()
|
connection.commit()
|
||||||
|
|
||||||
# def dict_factory(cursor, row):
|
# def dict_factory(cursor, row):
|
||||||
# d = {}
|
# d = {}
|
||||||
@ -140,5 +137,5 @@ conn.commit()
|
|||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# 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.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
connection.close()
|
||||||
|
|
||||||
|
@ -7,15 +7,17 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
PGDATA: /var/lib/postgresql/data
|
PGDATA: /var/lib/postgresql/data
|
||||||
POSTGRES_DB: karideo
|
POSTGRES_DB: karideo
|
||||||
|
POSTGRES_USER: root
|
||||||
|
POSTGRES_PASSWORD: postgress_password
|
||||||
#this is for debug only
|
#this is for debug only
|
||||||
ports:
|
ports:
|
||||||
- "15032:5432"
|
- 15032:5432
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/var/lib/postgresql/data
|
- ./data:/var/lib/postgresql/data:rw
|
||||||
adminer:
|
adminer:
|
||||||
image: adminer
|
image: adminer
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 15079:8080
|
- 15079:8080
|
||||||
links:
|
links:
|
||||||
- bdd_service:bdd
|
- bdd_service:db
|
||||||
|
Loading…
x
Reference in New Issue
Block a user