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

1601 default vals #1624

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
dd3b533
Full app added
tobz619 Mar 25, 2023
515e7f7
ignoring .vscode config
tobz619 Mar 25, 2023
3c00bd3
Starting adding default tables for tests
tobz619 Mar 25, 2023
dbabf79
making default values: putting them into the tests
tobz619 Mar 25, 2023
be2b59a
minor edit
tobz619 Mar 25, 2023
73d29bc
removing unecessary files
tobz619 Mar 25, 2023
ec4d3d7
removing some silly mistakes in haddock
tobz619 Mar 25, 2023
310166d
PBoolean -> Real
tobz619 Mar 25, 2023
c0d4c48
Full app added
tobz619 Mar 25, 2023
b83259c
ignoring .vscode config
tobz619 Mar 25, 2023
2aaa334
Starting adding default tables for tests
tobz619 Mar 25, 2023
4fc4e34
making default values: putting them into the tests
tobz619 Mar 25, 2023
bb549a6
minor edit
tobz619 Mar 25, 2023
cfa88f1
removing unecessary files
tobz619 Mar 25, 2023
4e8a56e
removing some silly mistakes in haddock
tobz619 Mar 25, 2023
aca9eb1
PBoolean -> Real
tobz619 Mar 25, 2023
0c6dffd
Merge branch '1601-default-vals' of https://github.com/tobz619/ihp in…
tobz619 Mar 26, 2023
83b319b
Full app added
tobz619 Mar 25, 2023
ce10af1
ignoring .vscode config
tobz619 Mar 25, 2023
a93a0ab
Starting adding default tables for tests
tobz619 Mar 25, 2023
e8380fe
making default values: putting them into the tests
tobz619 Mar 25, 2023
5b2b577
minor edit
tobz619 Mar 25, 2023
44cdec3
removing unecessary files
tobz619 Mar 25, 2023
8495d52
removing some silly mistakes in haddock
tobz619 Mar 25, 2023
846ac8b
PBoolean -> Real
tobz619 Mar 25, 2023
66996e2
Full app added
tobz619 Mar 25, 2023
16665ab
ignoring .vscode config
tobz619 Mar 25, 2023
4360d6e
Starting adding default tables for tests
tobz619 Mar 25, 2023
f3649df
making default values: putting them into the tests
tobz619 Mar 25, 2023
fbfe5b3
minor edit
tobz619 Mar 25, 2023
7b4326e
removing unecessary files
tobz619 Mar 25, 2023
7a7fec2
Merge branch '1601-default-vals' of https://github.com/tobz619/ihp in…
tobz619 Mar 26, 2023
2e60d08
rebased + put defaults together
tobz619 Mar 26, 2023
4a3a49f
ParserSpec file complete + refactorings/helpers
tobz619 Mar 26, 2023
7d9ebb8
starting schema operations spec
tobz619 Mar 26, 2023
caf2067
changed one of the tests
tobz619 Mar 26, 2023
2f649ad
all tests should now pass
tobz619 Mar 26, 2023
69c8647
arrayTable change: cleaning up for the night
tobz619 Mar 26, 2023
fb3a655
some more changes, nearly complete, one test fail
tobz619 Mar 27, 2023
f844402
Moving the defaults and adding to ihp.nix
tobz619 Mar 27, 2023
23a5dc1
made final test pass
tobz619 Mar 27, 2023
1b927d6
all done :)
tobz619 Mar 28, 2023
7cc745a
search.js returned
tobz619 Mar 28, 2023
fbb6211
.gitignore in Guide restored
tobz619 Mar 28, 2023
eadfe00
Update IHP/IDE/Defaults/TableColumnDefaults.hs
tobz619 Mar 29, 2023
f59d3a0
search.js restored
tobz619 Mar 29, 2023
8fd27de
ihp reverted
tobz619 Mar 29, 2023
c8bd906
Readme.MD reverted
tobz619 Mar 29, 2023
eb64f2b
refactoring + removal of unnecessary names
tobz619 Mar 29, 2023
2f176a2
minor edits + removing pure in favour of list
tobz619 Mar 29, 2023
24829d4
Haddock
tobz619 Mar 29, 2023
72a7d4e
some minor, last minute errors
tobz619 Mar 29, 2023
f0a4814
Update IHP/IDE/Defaults/TableColumnDefaults.hs
tobz619 Mar 31, 2023
2f7bb68
Update Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs
tobz619 Mar 31, 2023
63c578e
restored PGListener from Master
tobz619 Mar 31, 2023
b1793cf
Merge branch '1601-default-vals' of https://github.com/tobz619/ihp in…
tobz619 Mar 31, 2023
4a04c12
starting rewrite of tests - CompilerSpec complete
tobz619 Apr 5, 2023
7f7ab12
ParserSpec rewritten
tobz619 Apr 13, 2023
12a0179
Merge branch 'digitallyinduced:master' into 1601-default-vals
tobz619 Apr 13, 2023
cc4f359
Started Schema edits
tobz619 Apr 13, 2023
bfcb974
CompilerSpec Completed
tobz619 Apr 14, 2023
7b2ba87
fixed to fix broken tests
tobz619 Apr 14, 2023
26da4fa
final changes and test passes
tobz619 Apr 14, 2023
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: 21 additions & 3 deletions Guide/search.js
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
tobz619 marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

425 changes: 425 additions & 0 deletions IHP/IDE/Defaults/TableColumnDefaults.hs

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions IHP/IDE/SchemaDesigner/SchemaOperations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@ import IHP.IDE.SchemaDesigner.Types
import Data.Maybe (fromJust)
import qualified Data.List as List
import qualified Data.Text as Text
import IHP.IDE.Defaults.TableColumnDefaults

-- | A Schema.sql basically is just a list of sql DDL statements
type Schema = [Statement]

-- | Creates a new tables with a 'id' columns as the primary key
addTable :: Text -> Schema -> Schema
addTable tableName list = list <> [StatementCreateTable CreateTable
{ name = tableName
, columns =
[Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}]
addTable tableName list = list <> [StatementCreateTable (defCreateTable tableName)
{ columns = [colUUID]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
Expand Down
43 changes: 11 additions & 32 deletions IHP/PGListener.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import qualified Data.Aeson as Aeson
import qualified IHP.Log as Log
import qualified Control.Exception as Exception
import qualified Control.Concurrent.Chan.Unagi as Queue
import qualified Control.Concurrent

-- TODO: How to deal with timeout of the connection?

Expand Down Expand Up @@ -232,38 +231,18 @@ notifyLoop listeningToVar listenToVar subscriptions = do
let inChan = get #inChan subscription
Queue.writeChan inChan notification

-- Initial delay (in microseconds)
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
let initialDelay = 500 * 1000
-- Max delay (in microseconds)
let maxDelay = 60 * 1000 * 1000
-- This outer loop restarts the listeners if the database connection dies (e.g. due to a timeout)
let retryLoop delay isFirstError = do
result <- Exception.try innerLoop
case result of
Left (error :: SomeException) -> do
case fromException error of
Just (error :: AsyncCancelled) -> throw error
notification -> do
let ?context = ?modelContext -- Log onto the modelContext logger
if isFirstError then do
Log.info ("PGListener is going to restart, loop failed with exception: " <> (displayException error) <> ". Retrying immediately.")
retryLoop delay False -- Retry with no delay interval on first error, but will increase delay interval in subsequent retries
else do
let increasedDelay = delay * 2 -- Double current delay
let nextDelay = min increasedDelay maxDelay -- Picks whichever delay is lowest of increasedDelay * 2 or maxDelay
Log.info ("PGListener is going to restart, loop failed with exception: " <> (displayException error) <> ". Retrying in " <> cs (printTimeToNextRetry delay) <> ".")
Control.Concurrent.threadDelay delay -- Sleep for the current delay
retryLoop nextDelay False -- Retry with longer interval
Right _ ->
retryLoop initialDelay True -- If all went well, re-run with no sleeping and reset current delay to the initial value
retryLoop initialDelay True

printTimeToNextRetry :: Int -> Text
printTimeToNextRetry microseconds
| microseconds >= 1000000000 = show (microseconds `div` 1000000000) <> " min"
| microseconds >= 1000000 = show (microseconds `div` 1000000) <> " s"
| microseconds >= 1000 = show (microseconds `div` 1000) <> " ms"
| otherwise = show microseconds <> " µs"
forever do
result <- Exception.try innerLoop
case result of
Left (error :: SomeException) -> do
case fromException error of
Just (error :: AsyncCancelled) -> throw error
notification -> do
let ?context = ?modelContext -- Log onto the modelContext logger
Log.info ("PGListener is going to restart, loop failed with exception: " <> displayException error)
Right _ -> pure ()


listenToChannel :: PG.Connection -> Channel -> IO ()
listenToChannel databaseConnection channel = do
Expand Down
11 changes: 1 addition & 10 deletions README.md
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,16 @@ If you just want to improve docs, [you can find the markdown files in the Guide

### Bounties

We use algora.io for bounties on IHP issues. Check out the open bounties below:

<a href="https://console.algora.io/org/digitallyinduced/bounties?status=open">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://console.algora.io/api/og/digitallyinduced/bounties.png?p=0&status=open&theme=dark">
<img alt="Bounties of digitallyinduced" src="https://console.algora.io/api/og/digitallyinduced/bounties.png?p=0&status=open&theme=light">
</picture>
</a>

<a href="https://console.algora.io/org/digitallyinduced/leaderboard">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://console.algora.io/api/og/digitallyinduced/leaderboard.png?p=0&theme=dark">
<img alt="Leaderboard of digitallyinduced" src="https://console.algora.io/api/og/digitallyinduced/leaderboard.png?p=0&theme=light">
</picture>
</a>

## Releases

You can find information on IHP releases in the GitHub [releases section](https://github.com/digitallyinduced/ihp/releases).
During beta, there is a new release every two weeks on Friday. You can find steps to update to the latest version [in the release notes](https://github.com/digitallyinduced/ihp/releases).

[📧 Subscribe to the IHP release emails to stay in the loop.](https://ihp.digitallyinduced.com/MailingList)

Expand Down
55 changes: 4 additions & 51 deletions Test/IDE/CodeGeneration/ControllerGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,14 @@ import qualified Text.Megaparsec as Megaparsec
import IHP.IDE.CodeGen.Types
import IHP.IDE.SchemaDesigner.Types
import IHP.NameSupport
import IHP.IDE.Defaults.TableColumnDefaults

tests = do
describe "Controller Generator Tests:" do
let schema = [
StatementCreateTable CreateTable {
mpscholten marked this conversation as resolved.
Show resolved Hide resolved
name = "pages"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
},
StatementCreateTable CreateTable {
name = "people"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
,
Column
{ name = "name"
, columnType = PText
, defaultValue = Nothing
, notNull = True
, isUnique = False
, generator = Nothing
}
,
Column
{ name = "email"
, columnType = PText
, defaultValue = Nothing
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
}
]
StatementCreateTable pagesTable
, StatementCreateTable peopleTable
]
it "should build a controller with name \"pages\"" do
let rawControllerName = "pages"
let controllerName = tableNameToControllerName rawControllerName
Expand Down
21 changes: 3 additions & 18 deletions Test/IDE/CodeGeneration/MailGenerator.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-|
Module: Test.IDE.CodeGeneration.MailGenerator
Module: Test.IDE.CodeGeneration.MailGenerator/ID
Copyright: (c) digitally induced GmbH, 2020
-}
module Test.IDE.CodeGeneration.MailGenerator where
Expand All @@ -12,27 +12,12 @@ import qualified Text.Megaparsec as Megaparsec
import IHP.IDE.CodeGen.Types
import IHP.IDE.SchemaDesigner.Types
import IHP.NameSupport

import IHP.IDE.Defaults.TableColumnDefaults

tests = do
describe "Mail Generator Tests:" do
let schema = [
StatementCreateTable CreateTable {
name = "users"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
}
StatementCreateTable mailTable
]
it "should build a mail with name \"PurchaseConfirmationMail\"" do
let mailName = "PurchaseConfirmationMail"
Expand Down
18 changes: 2 additions & 16 deletions Test/IDE/CodeGeneration/ViewGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@ import qualified Text.Megaparsec as Megaparsec
import IHP.IDE.CodeGen.Types
import IHP.IDE.SchemaDesigner.Types
import IHP.NameSupport
import IHP.IDE.Defaults.TableColumnDefaults (compilerSpecTable)


tests = do
describe "View Generator Tests:" do
let schema = [
StatementCreateTable CreateTable {
name = "pages"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
}
StatementCreateTable compilerSpecTable
]
it "should build a view with name \"EditView\"" do
let viewName = "EditView"
Expand Down
Loading