-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
97 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Twenty::Migration | ||
require "sequel/extensions/migration" | ||
## | ||
# @return [String] | ||
# Returns the path to twenty's migrations. | ||
def self.migrations_path | ||
[File.join(__dir__, "migration")] | ||
File.join(__dir__, "migration") | ||
end | ||
|
||
## | ||
# Runs migrations (if neccessary). | ||
# @return [void] | ||
def self.run! | ||
context.migrate | ||
Sequel::Migrator.run(Twenty.connection, migrations_path) | ||
end | ||
ActiveRecord.timestamped_migrations = false | ||
|
||
## | ||
# @return [Boolean] | ||
# Returns true when there are pending migrations. | ||
def self.pending_migrations? | ||
context.open.pending_migrations.any? | ||
Sequel::Migrator.is_current?(Twenty.connection, migrations_path) | ||
end | ||
|
||
## | ||
# @return [ActiveRecord::MigrationContext] | ||
# Returns an instance of | ||
# {ActiveRecord::MigrationContext ActiveRecord::MigrationContext}. | ||
def self.context | ||
@context ||= ActiveRecord::MigrationContext.new(migrations_path) | ||
end | ||
private_class_method :context | ||
end |
18 changes: 9 additions & 9 deletions
18
twenty-server/lib/twenty-server/migration/1_create_projects.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateProjects < ActiveRecord::Migration[7.1] | ||
def up | ||
create_table(:projects) do |t| | ||
t.string :name, null: false | ||
t.string :path, null: false | ||
t.timestamps | ||
Sequel.migration do | ||
up do | ||
create_table(:projects) do | ||
primary_key :id | ||
String :name, null: false | ||
String :path, null: false | ||
DateTime :created_at | ||
DateTime :updated_at | ||
end | ||
add_index :projects, [:name, :path], unique: true | ||
end | ||
|
||
def down | ||
down do | ||
drop_table(:projects) | ||
end | ||
end |
18 changes: 10 additions & 8 deletions
18
twenty-server/lib/twenty-server/migration/2_create_tasks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateTasks < ActiveRecord::Migration[7.1] | ||
def up | ||
Sequel.migration do | ||
up do | ||
create_table(:tasks) do |t| | ||
t.string :title, null: false | ||
t.text :content, null: false | ||
t.integer :status, null: false, default: 0 | ||
t.belongs_to :project, null: false | ||
t.timestamps | ||
primary_key :id | ||
String :title, null: false | ||
Text :content, null: false | ||
Integer :status, null: false, default: 0 | ||
DateTime :created_at | ||
DateTime :updated_at | ||
foreign_key :project_id, :projects, null: false | ||
end | ||
end | ||
|
||
def down | ||
down do | ||
drop_table(:tasks) | ||
end | ||
end |
6 changes: 3 additions & 3 deletions
6
twenty-server/lib/twenty-server/migration/3_add_color_to_projects.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddColorToProjects < ActiveRecord::Migration[7.1] | ||
def up | ||
Sequel.migration do | ||
up do | ||
default = Twenty::ColorableMixin.random_color | ||
add_column :projects, :color, :string, null: false, default: | ||
end | ||
|
||
def down | ||
down do | ||
drop_column :projects, :color | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class Twenty::Task < Twenty::Model | ||
self.table_name = "tasks" | ||
class Twenty::Task < Sequel::Model | ||
include Twenty::Model | ||
|
||
STATUS = {backlog: 0, ready: 1, in_progress: 2, complete: 3} | ||
enum :status, STATUS, default: :backlog | ||
plugin(:enum) | ||
STATUS_MAP = {backlog: 0, ready: 1, in_progress: 2, complete: 3} | ||
STATUS_KEYS = STATUS_MAP.keys | ||
enum :status, STATUS_MAP | ||
|
||
## | ||
# Validations | ||
validates :title, presence: true | ||
validates :content, presence: true | ||
validates :project, presence: true | ||
def self.by_status(status) | ||
if STATUS_KEYS.any? { _1.to_s == status.to_s } | ||
public_send(status) | ||
else | ||
where(id: nil) | ||
end | ||
end | ||
|
||
## | ||
# Associations | ||
belongs_to :project, class_name: "Twenty::Project" | ||
validates_presence_of :title | ||
validates_presence_of :content | ||
validates_presence_of :project | ||
validates_inclusion_of :status, in: [STATUS_KEYS, *STATUS_KEYS.map(&:to_s)] | ||
many_to_one :project, class_name: "Twenty::Project" | ||
|
||
def status=(v) | ||
super(v.to_sym) | ||
end | ||
|
||
def status | ||
super.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters