Don't forget to lycansubscribe

created initial tables & models

Changed files
+108
app
db
+12
app/models/like.rb
··· 1 + require 'active_record' 2 + 3 + require_relative 'post' 4 + require_relative 'user' 5 + 6 + class Like < ActiveRecord::Base 7 + validates_presence_of :time, :rkey 8 + validates_length_of :rkey, maximum: 13 9 + 10 + belongs_to :user, foreign_key: 'actor_id' 11 + belongs_to :post 12 + end
+14
app/models/post.rb
··· 1 + require 'active_record' 2 + 3 + require_relative 'user' 4 + 5 + class Post < ActiveRecord::Base 6 + validates_presence_of :time, :data, :rkey 7 + validates :text, length: { minimum: 0, allow_nil: false } 8 + 9 + validates_length_of :rkey, maximum: 13 10 + validates_length_of :text, maximum: 1000 11 + validates_length_of :data, maximum: 10000 12 + 13 + belongs_to :user 14 + end
+12
app/models/user.rb
··· 1 + require 'active_record' 2 + 3 + require_relative 'like' 4 + require_relative 'post' 5 + 6 + class User < ActiveRecord::Base 7 + validates_presence_of :did 8 + validates_length_of :did, maximum: 260 9 + 10 + has_many :posts 11 + has_many :likes, foreign_key: 'actor_id' 12 + end
+30
db/migrate/20250829000022_create_tables.rb
··· 1 + class CreateTables < ActiveRecord::Migration[7.2] 2 + def change 3 + create_table :users, id: :integer do |t| 4 + t.string "did", limit: 260, null: false 5 + end 6 + 7 + add_index :users, :did, unique: true 8 + 9 + create_table :posts do |t| 10 + t.integer "user_id", null: false 11 + t.string "rkey", limit: 13, null: false 12 + t.datetime "time", null: false 13 + t.text "text", null: false 14 + t.text "data", null: false 15 + end 16 + 17 + add_index :posts, [:user_id, :time, :id], order: { time: :desc, id: :desc } 18 + add_index :posts, [:user_id, :rkey], unique: true 19 + 20 + create_table :likes do |t| 21 + t.integer "actor_id", null: false 22 + t.string "rkey", limit: 13, null: false 23 + t.datetime "time", null: false 24 + t.bigint "post_id", null: false 25 + end 26 + 27 + add_index :likes, [:actor_id, :time, :id], order: { time: :desc, id: :desc } 28 + add_index :likes, [:actor_id, :rkey], unique: true 29 + end 30 + end
+40
db/schema.rb
··· 1 + # This file is auto-generated from the current state of the database. Instead 2 + # of editing this file, please use the migrations feature of Active Record to 3 + # incrementally modify your database, and then regenerate this schema definition. 4 + # 5 + # This file is the source Rails uses to define your schema when running `bin/rails 6 + # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to 7 + # be faster and is potentially less error prone than running all of your 8 + # migrations from scratch. Old migrations may fail to apply correctly if those 9 + # migrations use external dependencies or application code. 10 + # 11 + # It's strongly recommended that you check this file into your version control system. 12 + 13 + ActiveRecord::Schema[7.2].define(version: 2025_08_29_000022) do 14 + # These are extensions that must be enabled in order to support this database 15 + enable_extension "plpgsql" 16 + 17 + create_table "likes", force: :cascade do |t| 18 + t.integer "actor_id", null: false 19 + t.string "rkey", limit: 13, null: false 20 + t.datetime "time", null: false 21 + t.bigint "post_id", null: false 22 + t.index ["actor_id", "rkey"], name: "index_likes_on_actor_id_and_rkey", unique: true 23 + t.index ["actor_id", "time", "id"], name: "index_likes_on_actor_id_and_time_and_id", order: { time: :desc, id: :desc } 24 + end 25 + 26 + create_table "posts", force: :cascade do |t| 27 + t.integer "user_id", null: false 28 + t.string "rkey", limit: 13, null: false 29 + t.datetime "time", null: false 30 + t.text "text", null: false 31 + t.text "data", null: false 32 + t.index ["user_id", "rkey"], name: "index_posts_on_user_id_and_rkey", unique: true 33 + t.index ["user_id", "time", "id"], name: "index_posts_on_user_id_and_time_and_id", order: { time: :desc, id: :desc } 34 + end 35 + 36 + create_table "users", id: :serial, force: :cascade do |t| 37 + t.string "did", limit: 260, null: false 38 + t.index ["did"], name: "index_users_on_did", unique: true 39 + end 40 + end