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 8 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
54 changes: 0 additions & 54 deletions Guide/search.js
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
tobz619 marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

3 changes: 2 additions & 1 deletion IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module IHP.IDE.SchemaDesigner.Parser

import IHP.Prelude
import IHP.IDE.SchemaDesigner.Types
import Test.DefaultValues.CreateTableDefaults
import qualified Prelude
import qualified Data.Text.IO as Text
import Text.Megaparsec
Expand Down Expand Up @@ -116,7 +117,7 @@ createTable = do
_ -> Prelude.fail ("Primary key defined in both column and table constraints on table " <> cs name)
_ -> Prelude.fail "Multiple columns with PRIMARY KEY constraint"

pure CreateTable { name, columns, primaryKeyConstraint, constraints, unlogged }
pure defCreateTable { name, columns, primaryKeyConstraint, constraints, unlogged }

createEnumType = do
lexeme "CREATE"
Expand Down
14 changes: 4 additions & 10 deletions IHP/IDE/SchemaDesigner/SchemaOperations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ import IHP.IDE.SchemaDesigner.Types
import Data.Maybe (fromJust)
import qualified Data.List as List
import qualified Data.Text as Text
import Test.DefaultValues.CreateTableDefaults
import Test.IDE.CodeGeneration.Defaults.CodeGeneratorDefaults

-- | 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
addTable tableName list = list <> [StatementCreateTable defCreateTable
{ name = tableName
, columns =
[Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}]
, columns = [colUUID]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
Expand Down
84 changes: 84 additions & 0 deletions Test/DefaultValues/CreateTableDefaults.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{-# OPTIONS_GHC -Wno-ambiguous-fields #-}
module Test.DefaultValues.CreateTableDefaults where
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
{- | This module aims to create some default tables and columns for tables for use
elsewhere and make it easier to add fields elsewhere whenever necessary.
-}
import IHP.Prelude
import IHP.IDE.SchemaDesigner.Types


{- | Creates a default column where all values are empty lists/text,
'Nothing' or 'False'; and for 'ColumnType', the default is 'PUUID'.

Add a new field to the 'Column' type in the
"IHP.IDE.SchemaDesigner.Types" file and then
set its default value here

Defined as:

@
defColumn :: Column
defColumn = Column {
name = ""
, columnType = PUUID
, defaultValue = Nothing
, notNull = False
, isUnique = False
, generator = Nothing
}
@

If you want a different 'PostgresType' you will need to
specify with like so by either using a function:

@setColumnType pgt = defColumn {columnType = pgt}@

Or

Just as part of where you're calling it:

@someDefaultColumnType = defColumn {columnType = PDate}@
-}
defColumn :: Column
tobz619 marked this conversation as resolved.
Show resolved Hide resolved
defColumn = Column {
name = ""
, columnType = PUUID
, defaultValue = Nothing
, notNull = False
, isUnique = False
, generator = Nothing
}


{- | Creates a table where all values are empty lists, including columns. @unlogged@ is set to 'False'.

Defined as such:

@
defCreateTable :: CreateTable
defCreateTable = CreateTable {
name = ""
, columns = []
, primaryKeyConstraint = PrimaryKeyConstraint []
, constraints = []
, unlogged = False
}
@

-}
defCreateTable :: CreateTable
defCreateTable = CreateTable {
name = ""
, columns = []
, primaryKeyConstraint = PrimaryKeyConstraint []
, constraints = []
, unlogged = False
}

-- | Takes a list of column and adds it to our default table.
defCreateTableWCol :: [Column] -> CreateTable
defCreateTableWCol cols = defCreateTable {columns = cols}

-- | Creates one default table with a singleton list of one 'defColumn' .
defCreateTableWDefCol :: CreateTable
defCreateTableWDefCol = defCreateTableWCol (pure defColumn)
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 Test.IDE.CodeGeneration.Defaults.CodeGeneratorDefaults

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
Loading