Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(locations): locations table migration and ecto.schema #7

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/book_my_gigs/locations/storage/location.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule BookMyGigs.Locations.Storage.Location do
@moduledoc """
The Ecto Schema for a Location
"""

use Ecto.Schema
import Ecto.Changeset

@schema_prefix "public"
@primary_key {:id, Ecto.UUID, autogenerate: true}
schema "locations" do
field(:name, :string)

timestamps(type: :utc_datetime)
end

def changeset(location, attrs) do
location
|> cast(attrs, [:name])
|> validate_required([:name])
|> unique_constraint(:name)
end

end
14 changes: 14 additions & 0 deletions priv/repo/migrations/20241021124116_create_locations_table.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule BookMyGigs.Repo.Migrations.CreateLocationsTable do
use Ecto.Migration

def change do
create table(:locations, primary_key: false, prefix: "public") do
add(:id, :uuid, primary_key: true)
add(:name, :string)

timestamps(type: :utc_datetime)
end

create unique_index(:locations, [:name])
end
end
Loading