Repository navigation
Expand file tree
/
Copy pathAdvanced.ps1
More file actions
79 lines (75 loc) · 2.89 KB
/
Copy pathAdvanced.ps1
File metadata and controls
79 lines (75 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
[CmdletBinding()]
param(
[string]$DatabasePath = (Join-Path $PSScriptRoot 'powershell-schema-advanced.sqlite')
)
if (-not (Get-Module devsetup.core.sqlite)) {
Import-Module devsetup.core.sqlite -ErrorAction Stop
}
$schema = @{
UserVersion = 3
Tables = @(
@{
Name = 'Organizations'
Strict = $true
Columns = @(
@{ Name = 'Id'; Type = 'INTEGER'; PrimaryKey = $true; AutoIncrement = $true }
@{ Name = 'Name'; Type = 'TEXT'; Nullable = $false; Unique = $true; Collation = 'NOCASE' }
)
}
@{
Name = 'Projects'
Strict = $true
Columns = @(
@{ Name = 'Id'; Type = 'INTEGER'; PrimaryKey = $true; AutoIncrement = $true }
@{ Name = 'OrganizationId'; Type = 'INTEGER'; Nullable = $false }
@{ Name = 'Slug'; Type = 'TEXT'; Nullable = $false; Collation = 'NOCASE' }
@{ Name = 'State'; Type = 'TEXT'; Nullable = $false; Default = 'planned' }
@{ Name = 'CreatedAt'; Type = 'TEXT'; Nullable = $false; DefaultExpression = 'CURRENT_TIMESTAMP' }
)
UniqueConstraints = @(
@{ Name = 'UQ_Projects_OrganizationSlug'; Columns = @('OrganizationId', 'Slug') }
)
ForeignKeys = @(
@{
Name = 'FK_Projects_Organizations'
Columns = @('OrganizationId')
References = @{ Table = 'Organizations'; Columns = @('Id') }
OnDelete = 'CASCADE'
OnUpdate = 'NO ACTION'
}
)
Indexes = @(
@{ Name = 'IX_Projects_StateCreatedAt'; Columns = @('State', 'CreatedAt') }
)
}
@{
Name = 'ProjectLabels'
Strict = $true
WithoutRowId = $true
Columns = @(
@{ Name = 'ProjectId'; Type = 'INTEGER'; Nullable = $false }
@{ Name = 'Label'; Type = 'TEXT'; Nullable = $false; Collation = 'NOCASE' }
)
PrimaryKey = @('ProjectId', 'Label')
ForeignKeys = @(
@{
Columns = @('ProjectId')
References = @{ Table = 'Projects'; Columns = @('Id') }
OnDelete = 'CASCADE'
}
)
}
)
}
New-SqliteDatabase -Path $DatabasePath -Schema $schema
Add-SqliteRow -DataSource $DatabasePath -On Organizations -Data @{ Id = 1; Name = 'PwshDevs' }
Add-SqliteRow -DataSource $DatabasePath -On Projects -Data @{
Id = 1
OrganizationId = 1
Slug = 'devsetup-core-sqlite'
}
Add-SqliteRow -DataSource $DatabasePath -On ProjectLabels -Data @(
@{ ProjectId = 1; Label = 'powershell' }
@{ ProjectId = 1; Label = 'sqlite' }
)
Get-SqliteRow -DataSource $DatabasePath -On Projects -Where @{ OrganizationId = 1 }