Schema and version number changes
This commit is contained in:
parent
ef8d5343e9
commit
a70b4f2eae
4 changed files with 34 additions and 2 deletions
|
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## 0.8-dev
|
||||
|
||||
* Schema changes: moved `full_name` field from table `userprofile` to table `user` for search improvement reasons.
|
||||
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (what I've done to 0.7.1 too).
|
||||
|
||||
## 0.7.1-dev
|
||||
|
||||
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (forgot to release).
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import datetime, time, re, os, sys, string, json, html
|
|||
from functools import wraps
|
||||
from flask_login import LoginManager
|
||||
|
||||
__version__ = '0.7.0'
|
||||
__version__ = '0.8-dev'
|
||||
|
||||
# we want to support Python 3 only.
|
||||
# Python 2 has too many caveats.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ class BaseModel(Model):
|
|||
class User(BaseModel):
|
||||
# The unique username.
|
||||
username = CharField(unique=True)
|
||||
# The user's full name (here for better search since 0.8)
|
||||
full_name = TextField()
|
||||
# The password hash.
|
||||
password = CharField()
|
||||
# An email address.
|
||||
|
|
@ -107,7 +109,6 @@ class UserAdminship(BaseModel):
|
|||
# New in 0.6
|
||||
class UserProfile(BaseModel):
|
||||
user = ForeignKeyField(User, primary_key=True)
|
||||
full_name = TextField()
|
||||
biography = TextField(default='')
|
||||
location = IntegerField(null=True)
|
||||
year = IntegerField(null=True)
|
||||
|
|
@ -115,6 +116,12 @@ class UserProfile(BaseModel):
|
|||
instagram = TextField(null=True)
|
||||
facebook = TextField(null=True)
|
||||
telegram = TextField(null=True)
|
||||
@property
|
||||
def full_name(self):
|
||||
'''
|
||||
Moved to User in 0.8 for search improvement reasons.
|
||||
'''
|
||||
return self.user.full_name
|
||||
|
||||
# The message privacy values.
|
||||
MSGPRV_PUBLIC = 0 # everyone
|
||||
|
|
|
|||
20
migrate_0_7_to_0_8.py
Normal file
20
migrate_0_7_to_0_8.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import sqlite3
|
||||
|
||||
import sqlite3
|
||||
|
||||
conn = sqlite3.connect('coriplus.sqlite')
|
||||
|
||||
if __name__ == '__main__':
|
||||
conn.executescript('''
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE "new_userprofile" ("user_id" INTEGER NOT NULL PRIMARY KEY, "biography" TEXT NOT NULL, "location" INTEGER, "year" INTEGER, "website" TEXT, "instagram" TEXT, "facebook" TEXT, telegram TEXT, FOREIGN KEY ("user_id") REFERENCES "user" ("id"));
|
||||
CREATE TABLE "new_user" ("id" INTEGER NOT NULL PRIMARY KEY, "username" VARCHAR(30) NOT NULL, "full_name" VARCHAR(30), "password" VARCHAR(255) NOT NULL, "email" VARCHAR(255) NOT NULL, "birthday" DATE NOT NULL, "join_date" DATETIME NOT NULL, "is_disabled" INTEGER NOT NULL);
|
||||
INSERT INTO new_user (id, username, full_name, password, email, birthday, join_date, is_disabled) SELECT t1.id, t1.username, t2.full_name, t1.password, t1.email, t1.birthday, t1.join_date, t1.is_disabled FROM user AS t1 LEFT JOIN userprofile AS t2 ON t1.id = t2.user_id;
|
||||
INSERT INTO new_userprofile (user_id, biography, location, year, website, instagram, facebook, telegram) SELECT user_id, biography, location, year, website, instagram, facebook, telegram FROM userprofile;
|
||||
UPDATE new_user SET full_name = username WHERE username IS NULL;
|
||||
DROP TABLE user;
|
||||
DROP TABLE userprofile;
|
||||
ALTER TABLE new_user RENAME TO user;
|
||||
ALTER TABLE new_userprofile RENAME TO userprofile;
|
||||
COMMIT;
|
||||
''')
|
||||
Loading…
Add table
Add a link
Reference in a new issue