cleanup and move config
This commit is contained in:
parent
3c44d27b12
commit
af2696385e
7
instance/config.py
Normal file
7
instance/config.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
SECRET_KEY='dev'
|
||||||
|
# DATABASE=os.path.join(app.instance_path, 'dbproj.db'),
|
||||||
|
DATABASE='bigwork'
|
||||||
|
DATABASE_USER='root'
|
||||||
|
DATABASE_HOST='localhost'
|
||||||
|
DATABASE_PASS='lil0,.lil0'
|
||||||
|
UPLOADDIR="file_storage/"
|
||||||
@ -1,154 +0,0 @@
|
|||||||
drop table if exists `admin`;
|
|
||||||
drop table if exists user;
|
|
||||||
drop table if exists book;
|
|
||||||
drop table if exists document;
|
|
||||||
drop table if exists note;
|
|
||||||
drop table if exists record;
|
|
||||||
drop table if exists typetable;
|
|
||||||
drop table if exists author;
|
|
||||||
drop table if exists book_author;
|
|
||||||
drop table if exists book_type;
|
|
||||||
drop table if exists user_stat;
|
|
||||||
create table `admin`
|
|
||||||
(
|
|
||||||
passwd varchar(100) NOT NULL
|
|
||||||
);
|
|
||||||
-- insert into `admin` (`passwd`) values('');
|
|
||||||
-- sqlite default no foreign key
|
|
||||||
PRAGMA FOREIGN_KEYS=ON;
|
|
||||||
|
|
||||||
-- user
|
|
||||||
drop table if exists user;
|
|
||||||
create table user
|
|
||||||
(
|
|
||||||
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_name varchar(100) NOT NULL UNIQUE,
|
|
||||||
user_mail varchar(100) NOT NULL UNIQUE,
|
|
||||||
user_passwd varchar(100) NOT NULL,
|
|
||||||
user_limit int NOT NULL,
|
|
||||||
user_regtime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
-- insert into user (`user_name`, `user_mail`, `user_passwd`, `user_limit`) values ('catfood', 'a@a.com', 'lil0', 100);
|
|
||||||
|
|
||||||
-- book
|
|
||||||
drop table if exists book;
|
|
||||||
create table book
|
|
||||||
(
|
|
||||||
book_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
book_name varchar(100) NOT NULL,
|
|
||||||
book_isbn varchar(100) DEFAULT NULL,
|
|
||||||
book_publisher varchar(100) DEFAULT NULL,
|
|
||||||
book_pubdate datetime DEFAULT NULL,
|
|
||||||
book_lang varchar(100) DEFAULT NULL,
|
|
||||||
user_id int NOT NULL,
|
|
||||||
CONSTRAINT `fk_book_user_id` FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE RESTRICT
|
|
||||||
);
|
|
||||||
|
|
||||||
-- insert into book (`book_name`, `book_isbn`, `book_publisher`, `book_pubdate`, `book_lang`, `user_id`) values ('mom pig', 'emm', NULL, NULL, 'CN', 1);
|
|
||||||
|
|
||||||
-- document
|
|
||||||
drop table if exists document;
|
|
||||||
create table document
|
|
||||||
(
|
|
||||||
doc_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
doc_name varchar(100) NOT NULL,
|
|
||||||
doc_url varchar(100) NOT NULL,
|
|
||||||
doc_size int NOT NULL,
|
|
||||||
doc_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
doc_type varchar(100) NOT NULL,
|
|
||||||
book_id int NOT NULL,
|
|
||||||
user_id int NOT NULL,
|
|
||||||
CONSTRAINT `fk_document_user_id` FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE RESTRICT,
|
|
||||||
CONSTRAINT `fk_document_book_id` FOREIGN KEY (`book_id`) REFERENCES book(`book_id`) ON DELETE RESTRICT
|
|
||||||
);
|
|
||||||
create index `idx_doc_name` on document(doc_name);
|
|
||||||
|
|
||||||
-- insert into document (`doc_name`,`doc_url`,`doc_size`,`doc_type`,`book_id`,`user_id`) values ("a.pdf", 'c:/shit/a.pdf', 10, 'pdf', 1, 1);
|
|
||||||
|
|
||||||
-- note
|
|
||||||
drop table if exists note;
|
|
||||||
create table note
|
|
||||||
(
|
|
||||||
note_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
note_name varchar(100) NOT NULL,
|
|
||||||
note_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
note_content text NOT NULL DEFAULT '',
|
|
||||||
book_id int NOT NULL,
|
|
||||||
user_id int NOT NULL,
|
|
||||||
CONSTRAINT `fk_note_user_id` FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE RESTRICT,
|
|
||||||
CONSTRAINT `fk_note_book_id` FOREIGN KEY (`book_id`) REFERENCES book(`book_id`) ON DELETE RESTRICT
|
|
||||||
);
|
|
||||||
create index `idx_note_name` on note(note_name);
|
|
||||||
|
|
||||||
-- insert into note (`note_name`, `note_content`,`book_id`,`user_id`) values ('long ago', 'well, nothing', 1, 1);
|
|
||||||
|
|
||||||
-- record
|
|
||||||
drop table if exists record;
|
|
||||||
create table record
|
|
||||||
(
|
|
||||||
record_time timestamp PRIMARY KEY DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
record_type varchar(10) NOT NULL,
|
|
||||||
doc_URL varchar(100) NOT NULL,
|
|
||||||
user_id int NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
-- insert into record (`record_type`,`doc_URL`,`user_id`)
|
|
||||||
-- values ('write', 'c:\a.pdf', 1);
|
|
||||||
|
|
||||||
-- typetable
|
|
||||||
drop table if exists typetable;
|
|
||||||
create table typetable
|
|
||||||
(
|
|
||||||
type_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
type_name varchar(20) NOT NULL UNIQUE
|
|
||||||
);
|
|
||||||
-- insert into typetable (`type_name`) values ('sjot');
|
|
||||||
|
|
||||||
-- author
|
|
||||||
drop table if exists author;
|
|
||||||
create table author
|
|
||||||
(
|
|
||||||
author_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
author_name varchar(50) NOT NULL
|
|
||||||
);
|
|
||||||
create index `idx_author_name` on author(author_name);
|
|
||||||
-- insert into author (`author_name`) values ('alabama.shit');
|
|
||||||
|
|
||||||
-- book_author
|
|
||||||
drop table if exists book_author;
|
|
||||||
create table book_author
|
|
||||||
(
|
|
||||||
author_id int NOT NULL,
|
|
||||||
book_id int NOT NULL,
|
|
||||||
PRIMARY KEY (`author_id`, `book_id`),
|
|
||||||
CONSTRAINT `fk_ba_book_id` FOREIGN KEY (`book_id`) REFERENCES book(`book_id`) ON DELETE RESTRICT,
|
|
||||||
CONSTRAINT `fk_ba_author_id` FOREIGN KEY (`author_id`) REFERENCES author(`author_id`) ON DELETE RESTRICT
|
|
||||||
);
|
|
||||||
-- insert into book_author values (1,1);
|
|
||||||
|
|
||||||
-- book_type
|
|
||||||
drop table if exists book_type;
|
|
||||||
create table book_type
|
|
||||||
(
|
|
||||||
type_id int NOT NULL,
|
|
||||||
book_id int NOT NULL,
|
|
||||||
PRIMARY KEY (`type_id`, `book_id`),
|
|
||||||
CONSTRAINT `fk_bt_book_id` FOREIGN KEY (`book_id`) REFERENCES book(`book_id`) ON DELETE RESTRICT,
|
|
||||||
CONSTRAINT `fk_bt_type_id` FOREIGN KEY (`type_id`) REFERENCES typetable(`type_id`) ON DELETE RESTRICT
|
|
||||||
);
|
|
||||||
-- insert into book_type values (1,1);
|
|
||||||
|
|
||||||
-- user_stat
|
|
||||||
drop table if exists user_stat;
|
|
||||||
create table user_stat
|
|
||||||
(
|
|
||||||
user_id int PRIMARY KEY,
|
|
||||||
user_limit int NOT NULL,
|
|
||||||
user_usedspace int NOT NULL DEFAULT 0,
|
|
||||||
user_bookcount int NOT NULL DEFAULT 0,
|
|
||||||
user_doccount int NOT NULL DEFAULT 0,
|
|
||||||
user_notecount int NOT NULL DEFAULT 0,
|
|
||||||
CONSTRAINT `fk_user_stat_user` FOREIGN KEY (`user_id`) REFERENCES user(`user_id`) ON DELETE RESTRICT,
|
|
||||||
CONSTRAINT `ck_usedspace` CHECK (user_usedspace <= user_limit)
|
|
||||||
);
|
|
||||||
-- insert into user_stat values (1,1,1,1,1,1);
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
drop trigger if exists `trig_create_user_stat`;
|
|
||||||
create trigger `trig_create_user_stat`
|
|
||||||
after insert on user
|
|
||||||
for each row begin
|
|
||||||
insert into user_stat (`user_id`, `user_limit`) values(NEW.user_id, NEW.user_limit);
|
|
||||||
end;
|
|
||||||
|
|
||||||
drop trigger if exists `trig_delete_user_stat`;
|
|
||||||
create trigger `trig_delete_user_stat`
|
|
||||||
after delete on user
|
|
||||||
for each row begin
|
|
||||||
delete from user_stat where user_id=OLD.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_book_ins`;
|
|
||||||
create trigger `trig_update_stat_book_ins`
|
|
||||||
after insert on book
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_bookcount=user_bookcount+1 where user_stat.user_id=NEW.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_book_del`;
|
|
||||||
create trigger `trig_update_stat_book_del`
|
|
||||||
after delete on book
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_bookcount=user_bookcount-1 where user_stat.user_id=OLD.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_doc_ins`;
|
|
||||||
create trigger `trig_update_stat_doc_ins`
|
|
||||||
after insert on document
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_doccount=user_doccount+1 where user_stat.user_id=NEW.user_id;
|
|
||||||
update user_stat set user_usedspace=user_usedspace+NEW.doc_size where user_stat.user_id=NEW.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_doc_del`;
|
|
||||||
create trigger `trig_update_stat_doc_del`
|
|
||||||
after delete on document
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_doccount=user_doccount-1 where user_stat.user_id=OLD.user_id;
|
|
||||||
update user_stat set user_usedspace=user_usedspace-OLD.doc_size where user_stat.user_id=OLD.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_note_ins`;
|
|
||||||
create trigger `trig_update_stat_note_ins`
|
|
||||||
after insert on note
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_notecount=user_notecount+1 where user_stat.user_id=NEW.user_id;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists `trig_update_stat_note_del`;
|
|
||||||
create trigger `trig_update_stat_note_del`
|
|
||||||
after delete on note
|
|
||||||
for each row begin
|
|
||||||
update user_stat set user_notecount=user_notecount-1 where user_stat.user_id=OLD.user_id;
|
|
||||||
end;
|
|
||||||
@ -6,22 +6,15 @@ from datetime import datetime
|
|||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
# create and configure the app
|
# create and configure the app
|
||||||
app = Flask(__name__, instance_relative_config=True)
|
app = Flask(__name__, instance_relative_config=True)
|
||||||
app.config.from_mapping(
|
|
||||||
SECRET_KEY='dev',
|
|
||||||
# DATABASE=os.path.join(app.instance_path, 'dbproj.db'),
|
|
||||||
DATABASE='bigwork',
|
|
||||||
DATABASE_USER='root',
|
|
||||||
DATABASE_HOST='localhost',
|
|
||||||
DATABASE_PASS='lil0,.lil0',
|
|
||||||
UPLOADDIR=os.path.join("./file_storage"),
|
|
||||||
)
|
|
||||||
if not os.path.exists(app.config['UPLOADDIR']):
|
|
||||||
os.mkdir(app.config['UPLOADDIR'])
|
|
||||||
if test_config is None:
|
if test_config is None:
|
||||||
app.config.from_pyfile('config.py', silent=True)
|
app.config.from_pyfile('config.py', silent=False)
|
||||||
else:
|
else:
|
||||||
app.config.from_mapping(test_config)
|
app.config.from_mapping(test_config)
|
||||||
|
# app.config['UPLOADDIR'] = os.path.join(app.instance_path, )
|
||||||
|
if not os.path.exists(app.config['UPLOADDIR']):
|
||||||
|
os.mkdir(app.config['UPLOADDIR'])
|
||||||
|
print(app.config.keys())
|
||||||
|
print(app.instance_path)
|
||||||
try:
|
try:
|
||||||
os.makedirs(app.instance_path)
|
os.makedirs(app.instance_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|||||||
2
src/static/axios.min.js
vendored
2
src/static/axios.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
|||||||
import sqlite3
|
|
||||||
conn = sqlite3.connect("test.db")
|
|
||||||
cur = conn.cursor()
|
|
||||||
cur.execute("insert into user (`user_name`, `user_mail`, `user_passwd`, `user_limit`) values ('catfood', 'a@a.com', 'lil0', 100)")
|
|
||||||
cur.execute("insert into user (`user_name`, `user_mail`, `user_passwd`, `user_limit`) values ('catfood', 'a@a.com', 'lil0', 100)")
|
|
||||||
print (cur.rowcount)
|
|
||||||
conn.commit()
|
|
||||||
cur.close()
|
|
||||||
conn.close()
|
|
||||||
Loading…
Reference in New Issue
Block a user