Created
June 15, 2019 00:11
-
-
Save watzon/bb3d91d379872ac49391bdb60d1afeae to your computer and use it in GitHub Desktop.
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
class CreateOrganizationMembers::V20190614161024 < Avram::Migrator::Migration::V1 | |
def migrate | |
create :organization_member do | |
add_belongs_to user : User, on_delete: :cascade | |
add_belongs_to organization : Organization, on_delete: :cascade | |
add can_add_shards : Bool | |
add can_delete_shards : Bool | |
add can_edit_shards : Bool | |
add can_edit_info : Bool | |
add can_edit_billing_info : Bool | |
end | |
end | |
def rollback | |
drop :organization_member | |
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
class CreateOrganizations::V20190614155536 < Avram::Migrator::Migration::V1 | |
def migrate | |
create :organizations do | |
add name : String | |
add profile_image_url : String? | |
add description : String? | |
add github_username : String? | |
add gitlab_username : String? | |
add twitter_username : String? | |
add website_url : String? | |
end | |
end | |
def rollback | |
drop :organizations | |
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
class CreateUsers::V00000000000001 < Avram::Migrator::Migration::V1 | |
def migrate | |
create :users do | |
add email : String, unique: true | |
add username : String, unique: true | |
add full_name : String? | |
add profile_picture_url : String? | |
add github_username : String? | |
add gitlab_username : String? | |
add twitter_username : String? | |
add personal_website : String? | |
add encrypted_password : String | |
add newsletter : Bool, default: false | |
add superuser : Bool, default: false | |
end | |
end | |
def rollback | |
drop :users | |
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
class Organization < BaseModel | |
table :organizations do | |
column name : String | |
column profile_image_url : String? | |
column description : String? | |
column github_username : String? | |
column gitlab_username : String? | |
column twitter_username : String? | |
column website_url : String? | |
has_many organization_members : OrganizationMember | |
has_many members : User, through: :organization_members | |
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
require "./user" | |
class OrganizationMember < BaseModel | |
table :organization_members do | |
belongs_to user : User | |
belongs_to organization : Organization | |
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
class User < BaseModel | |
include Carbon::Emailable | |
include Authentic::PasswordAuthenticatable | |
table :users do | |
column email : String | |
column username : String | |
column full_name : String? | |
column profile_picture_url : String? | |
column encrypted_password : String | |
column github_username : String? | |
column gitlab_username : String? | |
column twitter_username : String? | |
column personal_website : String? | |
column newsletter : Bool | |
column superuser : Bool? | |
has_many organization_members : OrganizationMember | |
has_many organizations : Organization, through: :organization_members | |
end | |
def is_superuser? | |
@superuser | |
end | |
def emailable | |
Carbon::Address.new(email) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment