<commit_before>import Model, enum from require "lapis.db.model"
import create_table, types, add_column, drop_column from require "lapis.db.schema"
import band, bor from require "bit"
Users = require "lazuli.modules.user_management.models.users"
config = (require "lapis.config").get!

class Timelines extends Model
  @relations: {
    {"user",               belongs_to: "Users"}
    {"acl",                belongs_to: "ACLs"}
    {"flags",              fetch: =>
      flags={}
      for k,v in pairs @@flags_values
        if type(k)=="number" and 0~=band(@flags_mask, 2^k)
          flags[v]=true
      flags
    }
  }
  @constraints: {
    flags: (tbl,_,obj) =>
      val=0
      for k,v in pairs @flags_values
        if type(k)=="number" and tbl[v]
          val=bor(val,2^k)
      obj.flags_mask=val
      obj.flags=nil
      false
  }


  @flags_values: {
    "markdown_posts"
    "image_posts"
    "video_posts"
    "profile_updates"
    "comments"
  }


  @get_relation_model: (name)=> switch name
    when "Users"
      require "lazuli.modules.user_management.models.users"
    when "ACLs"
      require "models.acls"

  @migrations: {
    ->
      create_table "timelines", {
        {"id", types.serial}
        {"user_id", types.integer}
        {"acl_id", types.integer}
        {"flags_mask", types.integer}
        "PRIMARY KEY (id)"
      }

  }<commit_msg>fuck bitmasks, we're going for boolean columns.<commit_after>import Model, enum from require "lapis.db.model"
import create_table, types, add_column, drop_column from require "lapis.db.schema"
import band, bor from require "bit"
Users = require "lazuli.modules.user_management.models.users"
config = (require "lapis.config").get!

class Timelines extends Model
  @relations: {
    {"user",               belongs_to: "Users"}
    {"acl",                belongs_to: "ACLs"}
  }

  @get_relation_model: (name)=> switch name
    when "Users"
      require "lazuli.modules.user_management.models.users"
    when "ACLs"
      require "models.acls"

  @migrations: {
    ->
      create_table "timelines", {
        {"id", types.serial}
        {"user_id", types.integer}
        {"acl_id", types.integer}
        --{"flag_include_posts_text", types.boolean}
        --{"flag_include_posts_image", types.boolean}
        --{"flag_include_posts_video", types.boolean}
        --{"flag_include_comments", types.boolean}
        --{"flag_include_likes", types.boolean}
        --{"flag_include_profiles", types.boolean}
        "PRIMARY KEY (id)"
      }

  }
{'fraction_non_alphanumeric': 0.13555291319857313, 'fraction_numerical': 0.0015854141894569957, 'mean_word_length': 2.616045845272206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5485375', 'n_tokens_mistral': 840, 'n_tokens_neox': 822, 'n_words': 180}