switch to sqlite, generate new project as 'quip'

This commit is contained in:
2024-09-02 19:47:01 -04:00
parent 3e77cb13b2
commit f5c2b7d67e
47 changed files with 220 additions and 231 deletions

View File

@@ -1,36 +0,0 @@
defmodule PhoenixTest.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
PhoenixTestWeb.Telemetry,
PhoenixTest.Repo,
{DNSCluster, query: Application.get_env(:phoenix_test, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: PhoenixTest.PubSub},
# Start the Finch HTTP client for sending emails
{Finch, name: PhoenixTest.Finch},
# Start a worker by calling: PhoenixTest.Worker.start_link(arg)
# {PhoenixTest.Worker, arg},
# Start to serve requests, typically the last entry
PhoenixTestWeb.Endpoint
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: PhoenixTest.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
PhoenixTestWeb.Endpoint.config_change(changed, removed)
:ok
end
end

View File

@@ -1,3 +0,0 @@
defmodule PhoenixTest.Mailer do
use Swoosh.Mailer, otp_app: :phoenix_test
end

View File

@@ -1,5 +0,0 @@
defmodule PhoenixTest.Repo do
use Ecto.Repo,
otp_app: :phoenix_test,
adapter: Ecto.Adapters.Postgres
end

View File

@@ -1,6 +1,6 @@
defmodule PhoenixTest do
defmodule Quip do
@moduledoc """
PhoenixTest keeps the contexts that define your domain
Quip keeps the contexts that define your domain
and business logic.
Contexts are also responsible for managing your data, regardless

44
lib/quip/application.ex Normal file
View File

@@ -0,0 +1,44 @@
defmodule Quip.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
QuipWeb.Telemetry,
Quip.Repo,
{Ecto.Migrator,
repos: Application.fetch_env!(:quip, :ecto_repos),
skip: skip_migrations?()},
{DNSCluster, query: Application.get_env(:quip, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: Quip.PubSub},
# Start the Finch HTTP client for sending emails
{Finch, name: Quip.Finch},
# Start a worker by calling: Quip.Worker.start_link(arg)
# {Quip.Worker, arg},
# Start to serve requests, typically the last entry
QuipWeb.Endpoint
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Quip.Supervisor]
Supervisor.start_link(children, opts)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
@impl true
def config_change(changed, _new, removed) do
QuipWeb.Endpoint.config_change(changed, removed)
:ok
end
defp skip_migrations?() do
# By default, sqlite migrations are run when using a release
System.get_env("RELEASE_NAME") != nil
end
end

3
lib/quip/mailer.ex Normal file
View File

@@ -0,0 +1,3 @@
defmodule Quip.Mailer do
use Swoosh.Mailer, otp_app: :quip
end

View File

@@ -1,9 +1,9 @@
defmodule PhoenixTest.Release do
defmodule Quip.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :phoenix_test
@app :quip
def migrate do
load_app()

5
lib/quip/repo.ex Normal file
View File

@@ -0,0 +1,5 @@
defmodule Quip.Repo do
use Ecto.Repo,
otp_app: :quip,
adapter: Ecto.Adapters.SQLite3
end

View File

@@ -1,12 +1,12 @@
defmodule PhoenixTestWeb do
defmodule QuipWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, components, channels, and so on.
This can be used in your application as:
use PhoenixTestWeb, :controller
use PhoenixTestWeb, :html
use QuipWeb, :controller
use QuipWeb, :html
The definitions below will be executed for every controller,
component, etc, so keep them short and clean, focused
@@ -40,10 +40,10 @@ defmodule PhoenixTestWeb do
quote do
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: PhoenixTestWeb.Layouts]
layouts: [html: QuipWeb.Layouts]
import Plug.Conn
import PhoenixTestWeb.Gettext
import QuipWeb.Gettext
unquote(verified_routes())
end
@@ -52,7 +52,7 @@ defmodule PhoenixTestWeb do
def live_view do
quote do
use Phoenix.LiveView,
layout: {PhoenixTestWeb.Layouts, :app}
layout: {QuipWeb.Layouts, :app}
unquote(html_helpers())
end
@@ -84,8 +84,8 @@ defmodule PhoenixTestWeb do
# HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation
import PhoenixTestWeb.CoreComponents
import PhoenixTestWeb.Gettext
import QuipWeb.CoreComponents
import QuipWeb.Gettext
# Shortcut for generating JS commands
alias Phoenix.LiveView.JS
@@ -98,9 +98,9 @@ defmodule PhoenixTestWeb do
def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: PhoenixTestWeb.Endpoint,
router: PhoenixTestWeb.Router,
statics: PhoenixTestWeb.static_paths()
endpoint: QuipWeb.Endpoint,
router: QuipWeb.Router,
statics: QuipWeb.static_paths()
end
end

View File

@@ -1,4 +1,4 @@
defmodule PhoenixTestWeb.CoreComponents do
defmodule QuipWeb.CoreComponents do
@moduledoc """
Provides core UI components.
@@ -17,7 +17,7 @@ defmodule PhoenixTestWeb.CoreComponents do
use Phoenix.Component
alias Phoenix.LiveView.JS
import PhoenixTestWeb.Gettext
import QuipWeb.Gettext
@doc """
Renders a modal.
@@ -661,9 +661,9 @@ defmodule PhoenixTestWeb.CoreComponents do
# with our gettext backend as first argument. Translations are
# available in the errors.po file (as we use the "errors" domain).
if count = opts[:count] do
Gettext.dngettext(PhoenixTestWeb.Gettext, "errors", msg, msg, count, opts)
Gettext.dngettext(QuipWeb.Gettext, "errors", msg, msg, count, opts)
else
Gettext.dgettext(PhoenixTestWeb.Gettext, "errors", msg, opts)
Gettext.dgettext(QuipWeb.Gettext, "errors", msg, opts)
end
end

View File

@@ -1,14 +1,14 @@
defmodule PhoenixTestWeb.Layouts do
defmodule QuipWeb.Layouts do
@moduledoc """
This module holds different layouts used by your application.
See the `layouts` directory for all templates available.
The "root" layout is a skeleton rendered as part of the
application router. The "app" layout is set as the default
layout on both `use PhoenixTestWeb, :controller` and
`use PhoenixTestWeb, :live_view`.
layout on both `use QuipWeb, :controller` and
`use QuipWeb, :live_view`.
"""
use PhoenixTestWeb, :html
use QuipWeb, :html
embed_templates "layouts/*"
end

View File

@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="csrf-token" content={get_csrf_token()} />
<.live_title suffix=" · Phoenix Framework">
<%= assigns[:page_title] || "PhoenixTest" %>
<%= assigns[:page_title] || "Quip" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>

View File

@@ -1,17 +1,17 @@
defmodule PhoenixTestWeb.ErrorHTML do
defmodule QuipWeb.ErrorHTML do
@moduledoc """
This module is invoked by your endpoint in case of errors on HTML requests.
See config/config.exs.
"""
use PhoenixTestWeb, :html
use QuipWeb, :html
# If you want to customize your error pages,
# uncomment the embed_templates/1 call below
# and add pages to the error directory:
#
# * lib/phoenix_test_web/controllers/error_html/404.html.heex
# * lib/phoenix_test_web/controllers/error_html/500.html.heex
# * lib/quip_web/controllers/error_html/404.html.heex
# * lib/quip_web/controllers/error_html/500.html.heex
#
# embed_templates "error_html/*"

View File

@@ -1,4 +1,4 @@
defmodule PhoenixTestWeb.ErrorJSON do
defmodule QuipWeb.ErrorJSON do
@moduledoc """
This module is invoked by your endpoint in case of errors on JSON requests.

View File

@@ -1,5 +1,5 @@
defmodule PhoenixTestWeb.PageController do
use PhoenixTestWeb, :controller
defmodule QuipWeb.PageController do
use QuipWeb, :controller
def home(conn, _params) do
# The home page is often custom made,

View File

@@ -1,10 +1,10 @@
defmodule PhoenixTestWeb.PageHTML do
defmodule QuipWeb.PageHTML do
@moduledoc """
This module contains pages rendered by PageController.
See the `page_html` directory for all templates available.
"""
use PhoenixTestWeb, :html
use QuipWeb, :html
embed_templates "page_html/*"
end

View File

@@ -1,13 +1,13 @@
defmodule PhoenixTestWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :phoenix_test
defmodule QuipWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :quip
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
@session_options [
store: :cookie,
key: "_phoenix_test_key",
signing_salt: "YJZpfzhw",
key: "_quip_key",
signing_salt: "1JjSQfVH",
same_site: "Lax"
]
@@ -21,9 +21,9 @@ defmodule PhoenixTestWeb.Endpoint do
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :phoenix_test,
from: :quip,
gzip: false,
only: PhoenixTestWeb.static_paths()
only: QuipWeb.static_paths()
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
@@ -31,7 +31,7 @@ defmodule PhoenixTestWeb.Endpoint do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :phoenix_test
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :quip
end
plug Phoenix.LiveDashboard.RequestLogger,
@@ -49,5 +49,5 @@ defmodule PhoenixTestWeb.Endpoint do
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug PhoenixTestWeb.Router
plug QuipWeb.Router
end

View File

@@ -1,11 +1,11 @@
defmodule PhoenixTestWeb.Gettext do
defmodule QuipWeb.Gettext do
@moduledoc """
A module providing Internationalization with a gettext-based API.
By using [Gettext](https://hexdocs.pm/gettext),
your module gains a set of macros for translations, for example:
import PhoenixTestWeb.Gettext
import QuipWeb.Gettext
# Simple translation
gettext("Here is the string to translate")
@@ -20,5 +20,5 @@ defmodule PhoenixTestWeb.Gettext do
See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
"""
use Gettext, otp_app: :phoenix_test
use Gettext, otp_app: :quip
end

View File

@@ -1,11 +1,11 @@
defmodule PhoenixTestWeb.Router do
use PhoenixTestWeb, :router
defmodule QuipWeb.Router do
use QuipWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {PhoenixTestWeb.Layouts, :root}
plug :put_root_layout, html: {QuipWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
@@ -14,19 +14,19 @@ defmodule PhoenixTestWeb.Router do
plug :accepts, ["json"]
end
scope "/", PhoenixTestWeb do
scope "/", QuipWeb do
pipe_through :browser
get "/", PageController, :home
end
# Other scopes may use custom stacks.
# scope "/api", PhoenixTestWeb do
# scope "/api", QuipWeb do
# pipe_through :api
# end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:phoenix_test, :dev_routes) do
if Application.compile_env(:quip, :dev_routes) do
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
@@ -37,7 +37,7 @@ defmodule PhoenixTestWeb.Router do
scope "/dev" do
pipe_through :browser
live_dashboard "/dashboard", metrics: PhoenixTestWeb.Telemetry
live_dashboard "/dashboard", metrics: QuipWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end

View File

@@ -1,4 +1,4 @@
defmodule PhoenixTestWeb.Telemetry do
defmodule QuipWeb.Telemetry do
use Supervisor
import Telemetry.Metrics
@@ -52,23 +52,23 @@ defmodule PhoenixTestWeb.Telemetry do
),
# Database Metrics
summary("phoenix_test.repo.query.total_time",
summary("quip.repo.query.total_time",
unit: {:native, :millisecond},
description: "The sum of the other measurements"
),
summary("phoenix_test.repo.query.decode_time",
summary("quip.repo.query.decode_time",
unit: {:native, :millisecond},
description: "The time spent decoding the data received from the database"
),
summary("phoenix_test.repo.query.query_time",
summary("quip.repo.query.query_time",
unit: {:native, :millisecond},
description: "The time spent executing the query"
),
summary("phoenix_test.repo.query.queue_time",
summary("quip.repo.query.queue_time",
unit: {:native, :millisecond},
description: "The time spent waiting for a database connection"
),
summary("phoenix_test.repo.query.idle_time",
summary("quip.repo.query.idle_time",
unit: {:native, :millisecond},
description:
"The time the connection spent waiting before being checked out for the query"
@@ -86,7 +86,7 @@ defmodule PhoenixTestWeb.Telemetry do
[
# A module, function and arguments to be invoked periodically.
# This function must call :telemetry.execute/3 and a metric must be added above.
# {PhoenixTestWeb, :count_users, []}
# {QuipWeb, :count_users, []}
]
end
end