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

absorb database into common #40

Open
wants to merge 105 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
5185b31
npm audit fix
iggi42 May 10, 2019
b64e278
config tag_editor on port 4040 in dev
iggi42 May 10, 2019
8890cdb
setup up the controller for modlists
iggi42 May 13, 2019
a4f5f4a
improve database setup
iggi42 May 13, 2019
01fa5c0
add modlists to the data model
iggi42 May 13, 2019
4c0a9f5
(try to) fix abc_seeds
iggi42 May 13, 2019
f764f7a
(try to) fix abc_seeds
iggi42 May 13, 2019
0ee22e4
make ModFile a simple string (e.g. a url)
iggi42 May 13, 2019
b7c9a05
fix tags in abc_seeds (and merge local)
iggi42 May 13, 2019
c81a7f0
remove unused variables in abc_seeds
iggi42 May 14, 2019
f999477
Merge branch 'feature/basic-tag-editor' of github.com:Belethors-Gener…
iggi42 May 14, 2019
19398f2
remove unnecessary relation from mod_file to mod for embedding
iggi42 May 15, 2019
4fd69f6
remove useless comments
iggi42 May 15, 2019
f7d1b67
add schema <-> struct transformation and make ModFile naming consistent.
iggi42 May 15, 2019
ff67381
make "desc" used consistent as "description"
iggi42 May 15, 2019
e656945
correct function name
iggi42 May 17, 2019
10017a8
start working on the database interface itself
iggi42 May 17, 2019
345a264
npm audit fix
iggi42 May 10, 2019
f3b20fc
config tag_editor on port 4040 in dev
iggi42 May 10, 2019
08b1cdd
setup up the controller for modlists
iggi42 May 13, 2019
2baead0
improve database setup
iggi42 May 13, 2019
eb24f99
add modlists to the data model
iggi42 May 13, 2019
99593fd
(try to) fix abc_seeds
iggi42 May 13, 2019
9e58f60
(try to) fix abc_seeds
iggi42 May 13, 2019
d48c14c
make ModFile a simple string (e.g. a url)
iggi42 May 13, 2019
b4aa58f
remove unused variables in abc_seeds
iggi42 May 14, 2019
042ff05
remove unnecessary relation from mod_file to mod for embedding
iggi42 May 15, 2019
6e38992
remove useless comments
iggi42 May 15, 2019
c744f1a
add schema <-> struct transformation and make ModFile naming consistent.
iggi42 May 15, 2019
bda033f
make "desc" used consistent as "description"
iggi42 May 15, 2019
179ab46
correct function name
iggi42 May 17, 2019
255db6d
start working on the database interface itself
iggi42 May 17, 2019
e70915b
Merge branch 'feature/basic-tag-editor' of github.com:Belethors-Gener…
iggi42 Sep 12, 2019
a07bab5
Merge branch 'feature/basic-tag-editor' of github.com:Belethors-Gener…
iggi42 Sep 27, 2019
d0450e7
absorb database into common
iggi42 Sep 27, 2019
a6b41d8
update docs
iggi42 Sep 27, 2019
7365dbe
well, some docs were missing
iggi42 Sep 27, 2019
ae8a30a
fix import warnings
iggi42 Sep 27, 2019
fdb778d
mix format
iggi42 Sep 27, 2019
d58aa68
fix dialyzer warning
iggi42 Sep 27, 2019
b431ad1
update docs
iggi42 Sep 27, 2019
1d5bcde
add postgres to travis
iggi42 Sep 27, 2019
95769c2
add modlist fully to the database
iggi42 Sep 30, 2019
f53924a
npm update
iggi42 Oct 1, 2019
603e9e4
add bgm logo from design
iggi42 Oct 1, 2019
539f015
working on mod crud
iggi42 Oct 1, 2019
1729ed6
working modlist
iggi42 Oct 1, 2019
dd17fe5
add elm to tag editor
iggi42 Oct 15, 2019
da7e26c
wip switching workstation
iggi42 Oct 15, 2019
4a03729
Merge branch 'feature/basic-tag-editor' of github.com:Belethors-Gener…
iggi42 Oct 15, 2019
a6c380d
ignore elm-stuff
iggi42 Oct 16, 2019
852a781
more progress on the elm code base
iggi42 Oct 19, 2019
f0703f2
ignore elm-stuff folder
iggi42 Oct 22, 2019
abf0a10
more elm webform wip
iggi42 Oct 22, 2019
7c8171e
Merge branch 'feature/basic-tag-editor' of github.com:Belethors-Gener…
iggi42 Oct 22, 2019
c11df67
fix npm vulns, node 12 compat
skwerlman Oct 22, 2019
fbe89e2
upgrade elm webpack loader to fix a vuln
iggi42 Oct 24, 2019
a148518
wip on elm form to edit a mod. (mostly done)
iggi42 Nov 6, 2019
a4942c5
dirty push to mess with
iggi42 Nov 6, 2019
81e20f5
fix form with (a little dirty) jsonp trick.
iggi42 Nov 6, 2019
b6c6fa9
add real urls for my test abc seed.
iggi42 Nov 6, 2019
1d166f5
fix checkboxes and add attr path to the elm form
iggi42 Nov 7, 2019
6b037ca
fix checkboxes in form put
iggi42 Nov 7, 2019
a96c322
enable debugging verbose logging in development env
iggi42 Nov 7, 2019
07ef3b4
represent the boolean values as html selects
iggi42 Nov 7, 2019
460ac62
use single select radio buttons for boolean attributes in form
iggi42 Nov 10, 2019
64a8b3e
add a little documentation to Utils/Html.elm
iggi42 Nov 10, 2019
a6ee1b4
allow modfiles to be deleted
iggi42 Nov 10, 2019
ac56546
mix format
iggi42 Nov 10, 2019
5fa0db4
delete unrequired templates
iggi42 Nov 10, 2019
d5cfd1e
start using tags in the elm webform (not done)
iggi42 Nov 10, 2019
978b289
remove not required template
iggi42 Nov 14, 2019
fe8ed1f
make tagging mods functional (but butthurt ugly)
iggi42 Nov 19, 2019
bee5268
upgrade to nodejs12 and install elm-format and elm-test
iggi42 Nov 20, 2019
75c13b1
add json encoder
iggi42 Nov 23, 2019
ed7cf1f
some elm test stuff (wip)
iggi42 Nov 23, 2019
90cd540
fix stupid error
iggi42 Nov 23, 2019
74940cc
json encode and decode fuzz tests
iggi42 Nov 23, 2019
f0e77bf
make travis use elm-test (please?)
iggi42 Nov 24, 2019
3a8ce50
elm-format everything :)
iggi42 Nov 24, 2019
162c28a
mix format
iggi42 Nov 24, 2019
e73b9a5
another travis test
iggi42 Nov 24, 2019
2174a4f
try to make elm-test and elm-format work in travis
iggi42 Nov 25, 2019
599a875
install elm for elm-test and elm-format
iggi42 Nov 25, 2019
a34b289
make elm-format error messages a human text not json
iggi42 Nov 25, 2019
9baf15a
revert pretty error msg for elm-format
iggi42 Nov 25, 2019
93c450d
fix elm-format test cases
iggi42 Nov 25, 2019
2912db1
fix a bunch of compiler warnings
iggi42 Nov 28, 2019
f5ea5bf
more small stuff
iggi42 Nov 28, 2019
5eff11a
fix credoo issues and remove hello world test
iggi42 Nov 30, 2019
a21015e
use form_for/4 for dialyzer
iggi42 Dec 4, 2019
1ed8a6a
update docs
iggi42 Dec 6, 2019
ad31656
basic moddb implementation
iggi42 Dec 6, 2019
6337c7f
wip on ModDB and tests
iggi42 Dec 16, 2019
cdfce4d
update docs
iggi42 Dec 17, 2019
5e64d11
wip on moddb and clean_changes
iggi42 Dec 17, 2019
5733dd5
fix changeset sets
iggi42 Jan 3, 2020
a89a05a
mix docs
iggi42 Jan 3, 2020
40449dc
fix mod crud test
iggi42 Jan 3, 2020
f051d94
mix format
iggi42 Jan 3, 2020
eb8ea50
start working on relation changes
iggi42 Feb 10, 2020
2ce6547
npm update && npm audit fix
iggi42 Mar 18, 2020
e20d4d4
fix postgres authentication in the dev env
iggi42 Mar 19, 2020
255c04b
update docs
iggi42 Mar 28, 2020
bc7c80e
write moddb tests with string keys and implement the change protcol more
iggi42 Mar 28, 2020
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ erl_crash.dump

/.elixir_ls/

/apps/tag_editor/assets/package-lock.json
/apps/website/assets/package-lock.json

# Ignore ZSH plugin files
**/.mix_tasks
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ git:

sudo: false

addons:
postgresql: '9.6'

env:
global:
- ELIXIR_ASSERT_TIMEOUT=2000
Expand All @@ -24,6 +27,11 @@ install:
- mix do local.hex --force, local.rebar --force || echo "WARNING! Unable to update hex or rebar"
- mix deps.get
- mix deps.compile
- npm install -g elm elm-format elm-test
- pushd apps/tag_editor/assets
- npm install
- popd

script:
- mix format --check-formatted
- for f in $(mix format --check-formatted 2>&1 | cut -s -d' ' -f4- | grep -E '^.+\.exs?$'); do echo $f; cat $f | mix format - | diff $f -; done
Expand All @@ -33,12 +41,17 @@ script:
- mix coveralls.travis -u
- mix credo --strict
- travis_wait mix dialyzer --halt-exit-status
- pushd apps/tag_editor/assets/
- travis_wait elm-test
- elm-format $(find tests elm-src -name '*.elm') --validate #| jq '.[] | .path + ":\t" + .message' -r
- popd

# Cache as much as possible
cache:
directories:
- deps
- _build
- apps/tag_editor/assets/tests/elm-stuff

# Trigger our discord webhook
after_success:
Expand Down
13 changes: 10 additions & 3 deletions apps/common/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use Mix.Config

# You can configure your application as:
#
# config :common, key: :value
# config :database, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:common, :key)
# Application.get_env(:database, :key)
#
# You can also configure a 3rd-party app:
#
Expand All @@ -27,4 +27,11 @@ use Mix.Config
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
# import_config "#{Mix.env}.exs"

config :common,
namespace: Common,
ecto_repos: [Common.Repo]

import_config "#{Mix.env()}.exs"
import_config "config.mappings.exs"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use Mix.Config

config :database, :tag_translations, %{
config :common, :tag_translations, %{
"Animation - Modified" => ["Animation"],
"Animation" => ["Animation"],
"Armour - Shields" => ["Items.Armour.Shields"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use Mix.Config

# Configure your database
config :website, Database.Repo,
config :common, Common.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use Mix.Config

config :website, Database.Repo,
config :common, Common.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use Mix.Config

# Configure your database
config :website, Database.Repo,
config :common, Common.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
Expand Down
4 changes: 4 additions & 0 deletions apps/common/lib/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ defmodule Common do
@moduledoc """
Documentation for Common.
"""

@type unclean_change :: %{
optional(binary) => binary() | unclean_change()
}
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Database.Application do
defmodule Common.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
Expand All @@ -11,14 +11,14 @@ defmodule Database.Application do
# List all child processes to be supervised
children = [
# Start the Ecto repository
supervisor(Database.Repo, [])
# Starts a worker by calling: Database.Worker.start_link(arg)
# {Database.Worker, arg},
supervisor(Common.Repo, [])
# Starts a worker by calling: Common.Worker.start_link(arg)
# {Common.Worker, arg},
]

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Database.Supervisor]
opts = [strategy: :one_for_one, name: Common.Supervisor]
Supervisor.start_link(children, opts)
end
end
171 changes: 171 additions & 0 deletions apps/common/lib/common/moddb.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
defmodule Common.ModDB do
@moduledoc """
The Mods context.
"""

require Logger
import Common.Utils, only: [debug: 1]

alias Common.Repo
alias Common.Schema.Mod
# alias Common.Schema.ModFile
alias Common.Schema.ModTag
alias Common.Schema.Modlist

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias Common.Schema.Modlist is not alphabetically ordered among its group.

alias Common.Utils

alias Ecto.Changeset

### ====== TAGS ======

@doc """
Returns the list of _all_ tags.
"""
@spec list_tags() :: [ModTag.t()]
def list_tags, do: Repo.all(ModTag)

@doc """
Gets a single tag.

Raises `Ecto.NoResultsError` if the ModTag does not exist.
"""
@spec get_tag!(id :: ModTag.id()) :: ModTag.t()
def get_tag!(id), do: Repo.get!(ModTag, id)

@doc """
Creates a tag.
"""
@spec create_tag(change :: Utils.unclean_change()) ::
{:ok, ModTag.t()} | {:error, Changeset.t(Mod.t())}
def create_tag(change \\ %{}) do
clean_ch = ModTag.clean_changes(change)

%ModTag{}
|> ModTag.changeset(clean_ch)
|> Repo.insert()
end

### ====== MODS ======

@doc """
Returns the list of _all_ mods.
"""
@spec list_mods() :: [Mod.t()]
def list_mods, do: Repo.all(Mod)
# TODO page this stuff, Repo.stream/2 seems useful

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a TODO tag in a comment: # TODO page this stuff, Repo.stream/2 seems useful


@doc """
Creates a mod.
"""
@spec create_mod(change :: Utils.change()) :: {:ok, Mod.t()} | {:error, Changeset.t(Mod.t())}
def create_mod(change \\ %{}) do
cs =
change
|> Mod.clean_changes()
|> Mod.new()

if cs.valid? do
Repo.insert(cs)
else
{:error, cs}
end
end

@doc """
Gets a single mod. The tags are not loaded, to access `mod.tags` do `Repo.preload(mod, [:tags])` before try to access them.

Raises `Ecto.NoResultsError` if the ModTag does not exist.
"""
@spec get_mod!(id :: Mod.id()) :: Mod.t()
def get_mod!(id), do: Repo.get!(Mod, id)

@doc """
Updates a mod.
"""
@spec update_mod(mod :: Mod.t(), change :: Utils.unclean_change()) ::
{:ok, Mod.t()} | {:error, Changeset.t(Mod.t())}
def update_mod(%Mod{} = mod, change) do
clean_change = Mod.clean_changes(change)

mod
|> Mod.changeset(clean_change)
|> Repo.update()
end

@doc """
Deletes a mod.
"""
@spec delete_mod(Mod.t()) :: {:ok, Mod.t()} | {:error, Changeset.t(Mod.t())}
def delete_mod(%Mod{} = mod), do: Repo.delete(mod)

@doc """
Returns an `%Ecto.Changeset{}` for tracking mod changes.
"""
@spec change_mod(Mod.t()) :: Changeset.t(Mod.t())
def change_mod(%Mod{} = mod), do: Mod.changeset(mod, %{})

### ====== MOD LISTS ======

@doc """
Returns the list of _all_ modlists.
"""
@spec list_modlists() :: [Modlist.t()]
def list_modlists(), do: Repo.all(Modlist)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use parentheses when defining a function which has no arguments.

# TODO needs paging

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a TODO tag in a comment: # TODO needs paging


@spec get_modlist!(id :: Modlist.id()) :: Modlist.t()
def get_modlist!(id), do: Repo.get!(Modlist, id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no more than 1 consecutive blank lines.

@doc """
Return the list of _all_ modlist.
"""
@spec add_mod_to_list(list :: Modlist.t(), mod :: Mod.t()) ::
{:ok, Modlist.t()} | {:error, Changeset.t(Modlist.t())}
def add_mod_to_list(list, mod) do
_cs = Modlist.changeset(list)
# TODO

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

{:ok, list}
end

@doc """
Creates a modlist.
"""
@spec create_modlist(change :: Utils.unclean_change()) ::
{:ok, Modlist.t()} | {:error, Changeset.t(Modlist.t())}
def create_modlist(change \\ %{}) do
change
|> Modlist.clean_changes()
|> Modlist.new()
|> Repo.insert()
end

@doc """
Gets a single modlist.

Raises `Ecto.NoResultsError` if the ModTag does not exist.
"""
@spec get_modlist!(id :: Modlist.id()) :: Modlist.t()
def get_modlist!(id), do: Repo.get!(Modlist, id)

@doc """
Updates a modlist.
"""
@spec update_modlist(Modlist.t(), change :: Utils.unclean_change()) ::
{:ok, Modlist.t()} | {:error, Changeset.t(Modlist.t())}
def update_modlist(%Modlist{} = modlist, change) do
modlist
|> Modlist.changeset(change)
|> Repo.update()
end

@doc """
Deletes a modlist.
"""
@spec delete_modlist(Modlist.t()) :: {:ok, Modlist.t()} | {:error, Changeset.t(Modlist.t())}
def delete_modlist(%Modlist{} = modlist), do: Repo.delete(modlist)

@doc """
Returns an `%Ecto.Changeset{}` for tracking modlist changes.
"""
@spec change_modlist(modlist :: Modlist.t()) :: Changeset.t(Modlist.t())
def change_modlist(%Modlist{} = modlist), do: Modlist.changeset(modlist, %{})
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Database.Repo do
defmodule Common.Repo do
use Ecto.Repo,
otp_app: :website,
otp_app: :common,
adapter: Ecto.Adapters.Postgres

@doc """
Expand Down
Loading