Update database operation

This commit is contained in:
jinhai 2019-03-20 11:54:33 +08:00
parent 577ee06710
commit 7d18b6b019
6 changed files with 53 additions and 19 deletions

View File

@ -8,3 +8,20 @@
- `conda install faiss-gpu cuda90 -c pytorch # For CUDA9.0` - `conda install faiss-gpu cuda90 -c pytorch # For CUDA9.0`
- `conda install flask` - `conda install flask`
- `pip install flask-restful` - `pip install flask-restful`
### Create Database
- Install MySQL
- `sudo apt-get update`
- `sudo apt-get install mariadb-server`
- Create user and database:
- `create user vecwise;`
- `create database vecdata;`
- `grant all privileges on vecdata.* to 'vecwise'@'%';`
- `flush privileges;`
- Create table:
- `python` # enter python3 interaction environment
- `from engine import db`
- `db.create_all()`

View File

@ -10,6 +10,7 @@ app.config.from_object('engine.settings')
print ("Create database instance") print ("Create database instance")
db = SQLAlchemy(app) db = SQLAlchemy(app)
from engine.model.IndexTable import IndexTable from engine.model.GroupTable import GroupTable
from engine.model.FileTable import FileTable
from engine.controller import IndexManage from engine.controller import IndexManage

View File

@ -0,0 +1,18 @@
from engine import db
class FileTable(db.Model):
__tablename__ = 'file_table'
id = db.Column(db.Integer, primary_key=True)
group_name = db.Column(db.String(100))
filename = db.Column(db.String(100))
type = (db.Integer)
row_number = db.Column(db.Integer)
def __init__(self, group_name, filename, type):
self.group_name = group_name
self.filename = filename
self.type = type
self.row_number = 0
def __repr__(self):
return '<FileTable $r>' % self.tablename

View File

@ -0,0 +1,14 @@
from engine import db
class GroupTable(db.Model):
__tablename__ = 'group_table'
id = db.Column(db.Integer, primary_key=True)
group_name = db.Column(db.String(100))
file_number = db.Column(db.Integer)
def __init__(self, group_name):
self.group_name = group_name
self.file_number = 0
def __repr__(self):
return '<GroupTable $r>' % self.group_name

View File

@ -1,16 +0,0 @@
from engine import db
class IndexTable(db.Model):
__tablename__ = 'index_table'
id = db.Column(db.Integer, primary_key=True)
tablename = db.Column(db.String(100))
filename = db.Column(db.String(100))
type = (db.Integer)
def __init__(self, tablename, filename, type):
self.tablename = tablename
self.filename = filename
self.type = type
def __repr__(self):
return '<IndexTable $r>' % self.tablename

View File

@ -2,5 +2,5 @@
DEBUG = True DEBUG = True
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' # SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
SQLALCHEMY_DATABASE_URI = "mysql://user:passwd@ip:port/BLOG_DB" SQLALCHEMY_DATABASE_URI = "mysql+pymysql://vecwise@127.0.0.1:3306/vecdata"