Remove the posts.privacy column
This commit is contained in:
12
database.go
12
database.go
@@ -824,7 +824,7 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const postCols = "id, slug, text_appearance, language, rtl, privacy, owner_id, collection_id, pinned_position, created, updated, view_count, title, content"
|
const postCols = "id, slug, text_appearance, language, rtl, owner_id, collection_id, pinned_position, created, updated, view_count, title, content"
|
||||||
|
|
||||||
// getEditablePost returns a PublicPost with the given ID only if the given
|
// getEditablePost returns a PublicPost with the given ID only if the given
|
||||||
// edit token is valid for the post.
|
// edit token is valid for the post.
|
||||||
@@ -835,7 +835,7 @@ func (db *datastore) GetEditablePost(id, editToken string) (*PublicPost, error)
|
|||||||
p := &Post{}
|
p := &Post{}
|
||||||
|
|
||||||
row := db.QueryRow("SELECT "+postCols+", (SELECT username FROM users WHERE users.id = posts.owner_id) AS username FROM posts WHERE id = ? LIMIT 1", id)
|
row := db.QueryRow("SELECT "+postCols+", (SELECT username FROM users WHERE users.id = posts.owner_id) AS username FROM posts WHERE id = ? LIMIT 1", id)
|
||||||
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.Privacy, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content, &ownerName)
|
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content, &ownerName)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
return nil, ErrPostNotFound
|
return nil, ErrPostNotFound
|
||||||
@@ -882,7 +882,7 @@ func (db *datastore) GetPost(id string, collectionID int64) (*PublicPost, error)
|
|||||||
where = "id = ?"
|
where = "id = ?"
|
||||||
}
|
}
|
||||||
row = db.QueryRow("SELECT "+postCols+", (SELECT username FROM users WHERE users.id = posts.owner_id) AS username FROM posts WHERE "+where+" LIMIT 1", params...)
|
row = db.QueryRow("SELECT "+postCols+", (SELECT username FROM users WHERE users.id = posts.owner_id) AS username FROM posts WHERE "+where+" LIMIT 1", params...)
|
||||||
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.Privacy, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content, &ownerName)
|
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content, &ownerName)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
if collectionID > 0 {
|
if collectionID > 0 {
|
||||||
@@ -914,7 +914,7 @@ func (db *datastore) GetOwnedPost(id string, ownerID int64) (*PublicPost, error)
|
|||||||
where := "id = ? AND owner_id = ?"
|
where := "id = ? AND owner_id = ?"
|
||||||
params := []interface{}{id, ownerID}
|
params := []interface{}{id, ownerID}
|
||||||
row = db.QueryRow("SELECT "+postCols+" FROM posts WHERE "+where+" LIMIT 1", params...)
|
row = db.QueryRow("SELECT "+postCols+" FROM posts WHERE "+where+" LIMIT 1", params...)
|
||||||
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.Privacy, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
err := row.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
return nil, ErrPostNotFound
|
return nil, ErrPostNotFound
|
||||||
@@ -1019,7 +1019,7 @@ func (db *datastore) GetPosts(c *Collection, page int, includeFuture bool) (*[]P
|
|||||||
posts := []PublicPost{}
|
posts := []PublicPost{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
p := &Post{}
|
p := &Post{}
|
||||||
err = rows.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.Privacy, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
err = rows.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed scanning row: %v", err)
|
log.Error("Failed scanning row: %v", err)
|
||||||
break
|
break
|
||||||
@@ -1076,7 +1076,7 @@ func (db *datastore) GetPostsTagged(c *Collection, tag string, page int, include
|
|||||||
posts := []PublicPost{}
|
posts := []PublicPost{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
p := &Post{}
|
p := &Post{}
|
||||||
err = rows.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.Privacy, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
err = rows.Scan(&p.ID, &p.Slug, &p.Font, &p.Language, &p.RTL, &p.OwnerID, &p.CollectionID, &p.PinnedPosition, &p.Created, &p.Updated, &p.ViewCount, &p.Title, &p.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed scanning row: %v", err)
|
log.Error("Failed scanning row: %v", err)
|
||||||
break
|
break
|
||||||
|
1
posts.go
1
posts.go
@@ -80,7 +80,6 @@ type (
|
|||||||
Font string `db:"text_appearance" json:"appearance"`
|
Font string `db:"text_appearance" json:"appearance"`
|
||||||
Language zero.String `db:"language" json:"language"`
|
Language zero.String `db:"language" json:"language"`
|
||||||
RTL zero.Bool `db:"rtl" json:"rtl"`
|
RTL zero.Bool `db:"rtl" json:"rtl"`
|
||||||
Privacy int64 `db:"privacy" json:"-"`
|
|
||||||
OwnerID null.Int `db:"owner_id" json:"-"`
|
OwnerID null.Int `db:"owner_id" json:"-"`
|
||||||
CollectionID null.Int `db:"collection_id" json:"-"`
|
CollectionID null.Int `db:"collection_id" json:"-"`
|
||||||
PinnedPosition null.Int `db:"pinned_position" json:"-"`
|
PinnedPosition null.Int `db:"pinned_position" json:"-"`
|
||||||
|
@@ -102,7 +102,6 @@ CREATE TABLE IF NOT EXISTS `posts` (
|
|||||||
`text_appearance` char(4) NOT NULL DEFAULT 'norm',
|
`text_appearance` char(4) NOT NULL DEFAULT 'norm',
|
||||||
`language` char(2) DEFAULT NULL,
|
`language` char(2) DEFAULT NULL,
|
||||||
`rtl` tinyint(1) DEFAULT NULL,
|
`rtl` tinyint(1) DEFAULT NULL,
|
||||||
`privacy` tinyint(1) NOT NULL,
|
|
||||||
`owner_id` int(6) DEFAULT NULL,
|
`owner_id` int(6) DEFAULT NULL,
|
||||||
`collection_id` int(6) DEFAULT NULL,
|
`collection_id` int(6) DEFAULT NULL,
|
||||||
`pinned_position` tinyint(1) DEFAULT NULL,
|
`pinned_position` tinyint(1) DEFAULT NULL,
|
||||||
@@ -114,8 +113,6 @@ CREATE TABLE IF NOT EXISTS `posts` (
|
|||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
CONSTRAINT `id_slug` UNIQUE (`collection_id`,`slug`),
|
CONSTRAINT `id_slug` UNIQUE (`collection_id`,`slug`),
|
||||||
CONSTRAINT `owner_id` UNIQUE (`owner_id`,`id`)
|
CONSTRAINT `owner_id` UNIQUE (`owner_id`,`id`)
|
||||||
-- FIXME: this is KEY `privacy_id` (`privacy`,`id`) in mysql
|
|
||||||
-- CONSTRAINT `privacy_id` (`privacy`,`id`)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user