Skip to content

Commit

Permalink
add org schema #13
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jun 8, 2024
1 parent 9fc22b8 commit 614bfa3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
13 changes: 8 additions & 5 deletions BUILDIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,18 @@ COV FILE LINES RELEVANT MISSED

This app stores data in **five** schemas:

1. `users` - https://docs.github.com/en/rest/users/users - the GitHub [**`users`**](https://dwyl.github.io/book/auth/07-notes-on-naming.html).
2. `orgs` - https://docs.github.com/en/rest/orgs/orgs - organizations which can have `users` as members and `repositories`.
1. `users` - https://docs.github.com/en/rest/users/users - the GitHub [**`users`**](https://dwyl.github.io/book/auth/07-notes-on-naming.html) that _use_ the platform.
2. `orgs` - [https://docs.github.com/en/rest/orgs/orgs](https://docs.github.com/en/rest/orgs/orgs?#get-an-organization) - organizations which can have `users` as members and `repositories`.
3. `repositories` - https://docs.github.com/en/rest/repos/repos - the repositories of code on GitHub.
4. `stars` - [https://docs.github.com/en/rest/activity/starring](https://docs.github.com/en/rest/activity/starring?apiVersion=2022-11-28#list-stargazers) - the `stars` (on `repositories`) associated with each `user`.
5. `follows` - https://docs.github.com/en/rest/users/followers - List the `people` a `user` follows

For each of these schemas we are storing
a _subset_ of the data; only what we need right now.
We can always add more later as needed.
a _subset_ of the data;
only what we need right now.
We can always add more
("[backfill](https://stackoverflow.com/questions/70871818/what-is-backfilling-in-data)")
later as needed.


Create database schemas
Expand All @@ -446,7 +449,7 @@ commands:

```sh
mix phx.gen.schema User users login:string avatar_url:string name:string company:string bio:string blog:string location:string email:string created_at:string two_factor_authentication:boolean followers:integer following:integer

mix phx.gen.schema Org orgs login:string avatar_url:string name:string company:string public_repos:integer location:string description:string followers:integer
mix phx.gen.schema Repository repositories name:string full_name:string owner_id:integer description:string fork:boolean forks_count:integer watchers_count:integer stargazers_count:integer topics:string open_issues_count:integer created_at:string pushed_at:string

```
Expand Down
26 changes: 26 additions & 0 deletions lib/app/org.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule App.Org do
use Ecto.Schema
import Ecto.Changeset

schema "orgs" do
field :name, :string
field :description, :string
field :location, :string
field :login, :string
field :avatar_url, :string
field :company, :string
field :public_repos, :integer
field :followers, :integer

timestamps()
end

@doc false
def changeset(org, attrs) do
org
|> cast(attrs, [:login, :avatar_url, :name, :company, :public_repos, :location, :description, :followers])
|> validate_required([:login, :avatar_url, :name, :company, :public_repos, :description, :followers])
end


end
18 changes: 18 additions & 0 deletions priv/repo/migrations/20240608112859_create_orgs.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule App.Repo.Migrations.CreateOrgs do
use Ecto.Migration

def change do
create table(:orgs) do
add :login, :string
add :avatar_url, :string
add :name, :string
add :company, :string
add :public_repos, :integer
add :location, :string
add :description, :string
add :followers, :integer

timestamps()
end
end
end

0 comments on commit 614bfa3

Please sign in to comment.