feat: create clicks model + migration

This commit is contained in:
Juan Rodriguez
2024-07-12 07:27:36 +02:00
parent ff06e10b8f
commit 2f796dbdab
4 changed files with 37 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
require "crecto"
module App::Models
class Click < Crecto::Model
schema :clicks do
field :id, String, primary_key: true
field :user_agent, String
field :language, String
field :browser, String
field :os, String
field :source, String
belongs_to :link, Link
end
validate_required [:user_agent, :language, :source]
end
end
-1
View File
@@ -9,7 +9,6 @@ module App::Models
field :id, String, primary_key: true
field :slug, String
field :url, String
field :click_counter, Int64, default: 0
belongs_to :user, User
end
@@ -5,7 +5,6 @@ CREATE TABLE links (
user_id TEXT NOT NULL,
slug VARCHAR(4) UNIQUE NOT NULL,
url TEXT NOT NULL,
click_counter INTEGER NOT NULL DEFAULT 0,
created_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL,
@@ -0,0 +1,19 @@
-- +micrate Up
-- SQL in section 'Up' is executed when this migration is applied
CREATE TABLE clicks (
id TEXT PRIMARY KEY NOT NULL,
link_id TEXT NOT NULL,
user_agent TEXT,
language TEXT,
browser TEXT,
os TEXT,
source TEXT,
created_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (link_id) REFERENCES links(id) ON DELETE CASCADE
);
-- +micrate Down
-- SQL section 'Down' is executed when this migration is rolled back
DROP TABLE clicks;