Skip to content

Commit 55333e4

Browse files
authored
Merge pull request #724 from code0-tech/720-add-development-seeders
Add development seeders
2 parents be894e2 + 33f71be commit 55333e4

File tree

8 files changed

+281
-0
lines changed

8 files changed

+281
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
User.seed_once :username do |u|
4+
u.email = 'admin@code0.tech'
5+
u.username = 'Admin'
6+
u.password = 'password'
7+
u.admin = true
8+
end
9+
10+
User.seed_once :username do |u|
11+
u.email = 'org-maintainer@code0.tech'
12+
u.username = 'Maintainer'
13+
u.password = 'password'
14+
u.admin = false
15+
end
16+
17+
User.seed_once :username do |u|
18+
u.email = 'org-owner@code0.tech'
19+
u.username = 'Owner'
20+
u.password = 'password'
21+
u.admin = false
22+
end
23+
24+
User.seed_once :username do |u|
25+
u.email = 'user@code0.tech'
26+
u.username = 'User'
27+
u.password = 'password'
28+
u.admin = false
29+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
Organization.seed_once :name do |organization|
4+
organization.name = 'Code0'
5+
end
6+
7+
Organization.seed_once :name do |organization|
8+
organization.name = 'Code1'
9+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
{
4+
Owner: [:namespace_administrator],
5+
Maintainer: %i[
6+
create_namespace_project
7+
delete_namespace_project
8+
update_organization
9+
create_runtime
10+
update_runtime
11+
delete_runtime
12+
],
13+
Member: %i[
14+
create_flow
15+
delete_flow
16+
update_flow
17+
read_namespace_project
18+
update_namespace_project
19+
],
20+
}.each do |name, abilities|
21+
role = NamespaceRole.seed_once :name, :namespace_id do |nr|
22+
nr.name = name
23+
nr.namespace_id = Organization.find_by(name: 'Code1').ensure_namespace&.id
24+
end
25+
next if role.first.nil?
26+
27+
abilities.each do |ability|
28+
NamespaceRoleAbility.seed_once :namespace_role_id, :ability do |nra|
29+
nra.namespace_role_id = role.first&.id
30+
nra.ability = ability
31+
end
32+
end
33+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
NamespaceMember.seed_once :namespace_id, :user_id do |nm|
4+
nm.namespace_id = Organization.find_by(name: 'Code1').ensure_namespace.id
5+
nm.user_id = User.find_by(username: 'User').id
6+
nm.roles = [
7+
NamespaceRole.find_by(
8+
name: 'Member',
9+
namespace_id: Organization.find_by(name: 'Code1').ensure_namespace.id
10+
)
11+
]
12+
end
13+
14+
NamespaceMember.seed_once :namespace_id, :user_id do |nm|
15+
nm.namespace_id = Organization.find_by(name: 'Code1').ensure_namespace.id
16+
nm.user_id = User.find_by(username: 'Maintainer').id
17+
nm.roles = [
18+
NamespaceRole.find_by(
19+
name: 'Maintainer',
20+
namespace_id: Organization.find_by(name: 'Code1').ensure_namespace.id
21+
),
22+
NamespaceRole.find_by(
23+
name: 'Member',
24+
namespace_id: Organization.find_by(name: 'Code1').ensure_namespace.id
25+
)
26+
]
27+
end
28+
29+
NamespaceMember.seed_once :namespace_id, :user_id do |nm|
30+
nm.namespace_id = Organization.find_by(name: 'Code1').ensure_namespace.id
31+
nm.user_id = User.find_by(username: 'Owner').id
32+
nm.roles = [
33+
NamespaceRole.find_by(
34+
name: 'Owner',
35+
namespace_id: Organization.find_by(name: 'Code1').ensure_namespace.id
36+
)
37+
]
38+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
Runtime.seed_once :name do |runtime|
4+
runtime.name = 'Global Runtime'
5+
runtime.description = 'A global runtime available to all projects.'
6+
runtime.token = 'global'
7+
end
8+
9+
Runtime.seed_once :name do |runtime|
10+
runtime.name = 'Code1-Runtime'
11+
runtime.description = 'A runtime specific to an organization.'
12+
runtime.namespace = Organization.find_by(name: 'Code1').ensure_namespace
13+
runtime.token = 'code1-runtime'
14+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
NamespaceProject.seed_once :namespace_id, :name do |np|
4+
np.namespace_id = Organization.find_by(name: 'Code1').ensure_namespace.id
5+
np.name = 'First Project'
6+
np.description = 'A sample project for Code1 organization.'
7+
np.primary_runtime = Runtime.find_by(name: 'Code1-Runtime')
8+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
Runtime.where(name: ['Global Runtime', 'Code1-Runtime']).find_each do |runtime|
4+
DataType.seed_once :runtime_id, :identifier do |dt|
5+
dt.version = '0.0.0'
6+
dt.variant = :primitive
7+
dt.runtime_id = runtime.id
8+
dt.identifier = 'string'
9+
dt.names = [
10+
Translation.new(
11+
code: 'en',
12+
content: 'String'
13+
)
14+
]
15+
end
16+
17+
DataType.seed_once :runtime_id, :identifier do |dt|
18+
dt.version = '0.0.0'
19+
dt.variant = :primitive
20+
dt.runtime_id = runtime.id
21+
dt.identifier = 'number'
22+
dt.names = [
23+
Translation.new(
24+
code: 'en',
25+
content: 'Number'
26+
)
27+
]
28+
end
29+
end
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# frozen_string_literal: true
2+
3+
FlowType.seed_once :runtime_id, :identifier do |ft|
4+
ft.runtime_id = Runtime.find_by(name: 'Code1-Runtime').id
5+
ft.identifier = 'sample-flow-type'
6+
ft.version = '0.0.0'
7+
ft.names = [
8+
Translation.new(
9+
code: 'en',
10+
content: 'Sample Flow Type'
11+
)
12+
]
13+
ft.descriptions = [
14+
Translation.new(
15+
code: 'en',
16+
content: 'A sample flow type for demonstration purposes.'
17+
)
18+
]
19+
ft.aliases = [
20+
Translation.new(
21+
code: 'en',
22+
content: 'SFT'
23+
)
24+
]
25+
ft.display_messages = [
26+
Translation.new(
27+
code: 'en',
28+
content: 'This is a sample flow type.'
29+
)
30+
]
31+
ft.flow_type_settings = [
32+
FlowTypeSetting.new(
33+
identifier: 'url',
34+
unique: false,
35+
data_type: DataType.find_by(identifier: 'string', runtime_id: Runtime.find_by(name: 'Code1-Runtime').id),
36+
names: [
37+
Translation.new(
38+
code: 'en',
39+
content: 'Url for callback'
40+
)
41+
],
42+
descriptions: [
43+
Translation.new(
44+
code: 'en',
45+
content: 'The URL to be used for callback operations.'
46+
)
47+
]
48+
)
49+
]
50+
end
51+
52+
RuntimeFunctionDefinition.seed_once :runtime_id, :runtime_name do |rfd|
53+
rfd.runtime_id = Runtime.find_by(name: 'Code1-Runtime').id
54+
rfd.runtime_name = 'std::math::square'
55+
rfd.version = '0.0.0'
56+
rfd.names = [
57+
Translation.new(
58+
code: 'en',
59+
content: 'Square Function'
60+
)
61+
]
62+
rfd.descriptions = [
63+
Translation.new(
64+
code: 'en',
65+
content: 'Calculates the square of a number.'
66+
)
67+
]
68+
rfd.aliases = [
69+
Translation.new(
70+
code: 'en',
71+
content: '^2'
72+
)
73+
]
74+
rfd.parameters = [
75+
RuntimeParameterDefinition.new(
76+
runtime_name: 'std::math::square::value',
77+
data_type: DataTypeIdentifier.new(data_type: DataType.find_by(identifier: 'number',
78+
runtime_id: Runtime.find_by(
79+
name: 'Code1-Runtime'
80+
).id)),
81+
names: [
82+
Translation.new(
83+
code: 'en',
84+
content: 'Value'
85+
)
86+
],
87+
descriptions: [
88+
Translation.new(
89+
code: 'en',
90+
content: 'The number to be squared.'
91+
)
92+
]
93+
)
94+
]
95+
end
96+
97+
Flow.seed_once :project_id, :name do |flow|
98+
flow.project_id = NamespaceProject.find_by(
99+
namespace: Organization.find_by(name: 'Code1').ensure_namespace,
100+
name: 'First Project'
101+
).id
102+
flow.name = 'Sample Flow'
103+
104+
flow.flow_settings = [
105+
FlowSetting.new(
106+
flow_setting_id: FlowType.find_by(identifier: 'sample-flow-type').flow_type_settings.first.identifier,
107+
object: 'https://example.com/callback'
108+
)
109+
]
110+
111+
flow.flow_type = FlowType.find_by(identifier: 'sample-flow-type')
112+
flow.starting_node = NodeFunction.new(
113+
runtime_function: RuntimeFunctionDefinition.find_by(runtime_name: 'std::math::square'),
114+
node_parameters: [
115+
NodeParameter.new(
116+
literal_value: '5',
117+
runtime_parameter_id: RuntimeFunctionDefinition.find_by(runtime_name: 'std::math::square').parameters.first.id
118+
)
119+
]
120+
)
121+
end

0 commit comments

Comments
 (0)