add a sort order to topics for the future
This commit is contained in:
		@@ -40,6 +40,8 @@ app:get("all_topics", "", function(self)
 | 
			
		||||
      ) threads ON threads.topic_id = topics.id AND threads.rn = 1
 | 
			
		||||
    LEFT JOIN
 | 
			
		||||
      users on users.id = threads.user_id
 | 
			
		||||
    ORDER BY
 | 
			
		||||
      topics.sort_order ASC
 | 
			
		||||
  ]])
 | 
			
		||||
  self.me = util.get_logged_in_user_or_transient(self)
 | 
			
		||||
  return {render = "topics.topics"}
 | 
			
		||||
@@ -68,10 +70,12 @@ app:post("topic_create", "/create", function(self)
 | 
			
		||||
  local time = os.time()
 | 
			
		||||
  local slug = lapis_util.slugify(topic_name) .. "-" .. time
 | 
			
		||||
 | 
			
		||||
  local topic_count = Topics:count()
 | 
			
		||||
  local topic = Topics:create({
 | 
			
		||||
    name = topic_name,
 | 
			
		||||
    description = topic_description,
 | 
			
		||||
    slug = slug,
 | 
			
		||||
    sort_order = topic_count + 1,
 | 
			
		||||
  })
 | 
			
		||||
  
 | 
			
		||||
  util.inject_infobox(self, "Topic created.")
 | 
			
		||||
 
 | 
			
		||||
@@ -57,5 +57,10 @@ return {
 | 
			
		||||
    db.query('DROP INDEX "idx_users_avatar"')
 | 
			
		||||
    schema.drop_column("users", "avatar_id")
 | 
			
		||||
    schema.add_column("users", "avatar_id", "REFERENCES avatars(id) DEFAULT 1")
 | 
			
		||||
  end,
 | 
			
		||||
  
 | 
			
		||||
  [8] = function ()
 | 
			
		||||
    schema.add_column("topics", "sort_order", types.integer{default = 0})
 | 
			
		||||
    db.query("UPDATE topics SET sort_order = (SELECT COUNT(*) FROM topics t2 WHERE t2.ROWID <= topics.ROWID)")
 | 
			
		||||
  end
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user