fixture_fox 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/TODO +79 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/diagram.drawio +1 -0
- data/examples/1-1-subrecord.fox +15 -0
- data/examples/1-1-subrecord.sql +22 -0
- data/examples/N-M.fox +25 -0
- data/examples/N-M.sql +34 -0
- data/examples/anchors.sql +13 -0
- data/examples/anchors.yml +4 -0
- data/examples/anchors1.fox +4 -0
- data/examples/anchors2.fox +6 -0
- data/examples/array.fox +84 -0
- data/examples/array.sql +53 -0
- data/examples/base.fox +81 -0
- data/examples/base.sql +52 -0
- data/examples/empty.fox +8 -0
- data/examples/empty.sql +33 -0
- data/examples/include/schema-included.fox +23 -0
- data/examples/inherit.fox +26 -0
- data/examples/inherit.sql +28 -0
- data/examples/kind.fox +17 -0
- data/examples/kind.sql +31 -0
- data/examples/link.fox +35 -0
- data/examples/link.sql +32 -0
- data/examples/root.fox +22 -0
- data/examples/schema-fragment-1.fox +9 -0
- data/examples/schema-fragment-2.fox +21 -0
- data/examples/schema-include.fox +10 -0
- data/examples/schema-indent.fox +29 -0
- data/examples/schema.fox +29 -0
- data/examples/schema.sql +33 -0
- data/examples/types.fox +8 -0
- data/examples/types.sql +17 -0
- data/examples/views.fox +15 -0
- data/examples/views.sql +38 -0
- data/exe/fox +178 -0
- data/fixture_fox.gemspec +37 -0
- data/lib/fixture_fox/analyzer.rb +371 -0
- data/lib/fixture_fox/anchor.rb +93 -0
- data/lib/fixture_fox/ast.rb +176 -0
- data/lib/fixture_fox/error.rb +23 -0
- data/lib/fixture_fox/hash_parser.rb +111 -0
- data/lib/fixture_fox/idr.rb +62 -0
- data/lib/fixture_fox/line.rb +217 -0
- data/lib/fixture_fox/parser.rb +153 -0
- data/lib/fixture_fox/token.rb +173 -0
- data/lib/fixture_fox/tokenizer.rb +78 -0
- data/lib/fixture_fox/version.rb +3 -0
- data/lib/fixture_fox.rb +216 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ae92cff06c14bdac0a19e36674ff3e41e964e4bdc9874db327426fc86d33c87
|
4
|
+
data.tar.gz: c0f91d36d6fc1320ce3670acb60568a5ccff746cedb94e9f54da8cf1d21c24b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e0ef0e77b1c9d182b1451620d3d70a3af68f1e3fc999acec9f291984082c6167e980160475ab0c25c060c12d4857786a69b79dee711725b87df907b4401b886
|
7
|
+
data.tar.gz: 875f4974c220a7c2a832d83658c2e7ebf600953df91bea721e2bd52bd61fde141880047bfed0facb124efdba57176dad4f1fd70db11297ea2b83e2a103094272
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/pkg/
|
6
|
+
/spec/reports/
|
7
|
+
/tmp/
|
8
|
+
|
9
|
+
# rspec failure tracking
|
10
|
+
.rspec_status
|
11
|
+
|
12
|
+
# Ignore auto-generated main file
|
13
|
+
/main
|
14
|
+
|
15
|
+
# Ignore Gemfile.lock. See https://stackoverflow.com/questions/4151495/should-gemfile-lock-be-included-in-gitignore
|
16
|
+
/Gemfile.lock
|
17
|
+
|
18
|
+
# Put your personal ignore files in /home/clr/.config/git/ignore
|
19
|
+
/bin/fox
|
20
|
+
/*.fox
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Fox
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fox`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fox'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fox
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fox.
|
36
|
+
|
data/Rakefile
ADDED
data/TODO
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
o Rename #use -> #fox
|
3
|
+
o Fix that functions are not available in #use (and #statement, probably):
|
4
|
+
|
5
|
+
Failure/Error:
|
6
|
+
def test_system() "test_system" end
|
7
|
+
...
|
8
|
+
describe "Something"
|
9
|
+
use %(
|
10
|
+
#{test_system}: System
|
11
|
+
kind: #{test_system_kind}
|
12
|
+
name: #{test_system}
|
13
|
+
|
14
|
+
`test_system` is not available on an example group (e.g. a `describe` or
|
15
|
+
`context` block). It is only available from within individual examples
|
16
|
+
(e.g. `it` blocks) or from constructs that run in the scope of an example
|
17
|
+
(e.g. `before`, `let`, etc).
|
18
|
+
|
19
|
+
o Allow dumping of state file per-directory. This can be used to make it easier
|
20
|
+
to run fox files by hand in a project
|
21
|
+
o Push associations of superclasses down to subclasses
|
22
|
+
o Scoped labels so that a label within a labelled record can be refered to at "*record_label.element_label"
|
23
|
+
o Solve the default_id-backreference-problem by having a rule that if the back-reference is unspecified, then
|
24
|
+
the value is taken from the enclosing record:
|
25
|
+
|
26
|
+
auth_domain: Domain
|
27
|
+
default_permission:
|
28
|
+
name: default
|
29
|
+
none: [auth]
|
30
|
+
domain: *auth_domain
|
31
|
+
|
32
|
+
vs
|
33
|
+
|
34
|
+
auth_domain: Domain
|
35
|
+
default_permission:
|
36
|
+
name: default
|
37
|
+
none: [auth]
|
38
|
+
|
39
|
+
o Allow functions ($do_something) - SQL vs. Ruby?
|
40
|
+
o Allow identifying records by unique columns: user[name=Alice] (if name was unique) or system[kind=USER] or even system[user,role]=[Alice,ADMIN]
|
41
|
+
o Kind references are fields that doesn't refer to the ID of the referenced table but to another unique column. Kind references use only the value of the field to address it: kind: USER
|
42
|
+
|
43
|
+
o 'Unclass' anchors and turn it into a simple map from name to Anchor class
|
44
|
+
|
45
|
+
o Check for missing not null values
|
46
|
+
o Check for tables when records are expected and vice-versa
|
47
|
+
o Check for illegal values (eg. "hello" when an integer is expected)
|
48
|
+
o Change root-table syntax to /^table:/
|
49
|
+
o Rename token so they all ends with "...Token"
|
50
|
+
o Make it possible to dump data in fox format
|
51
|
+
o Default records
|
52
|
+
|
53
|
+
+ Parse date/time (or maybe not)
|
54
|
+
+ Labels in IDR
|
55
|
+
+ Change fox to write SQL by default and require a -e/-x to execute against database
|
56
|
+
+ PG connection strings
|
57
|
+
+ Rewrite tokenization
|
58
|
+
+ Make it run on the mikras database
|
59
|
+
+ schema pragma
|
60
|
+
+ root table names including schema
|
61
|
+
+ Use link table link field names to create N:M and DAG/DCG relations
|
62
|
+
+ Refresh materialized views
|
63
|
+
|
64
|
+
- Single-line definitions: '*alice.age: 42'
|
65
|
+
Too complicated. Either the parser looks like shit (see branch
|
66
|
+
root-references-1) or the Ast hierarchy needs rework (see branch
|
67
|
+
root-references-2). In both cases resolving references becomes complicated
|
68
|
+
and we'll also have to consider circular dependencies
|
69
|
+
|
70
|
+
? Allow reset of existing relations and then assign new
|
71
|
+
&alice:
|
72
|
+
roles: [] <- Reset marker
|
73
|
+
- name: New role
|
74
|
+
- name: Another new role
|
75
|
+
? Allow adding relations to existing objects
|
76
|
+
&alice:
|
77
|
+
roles:
|
78
|
+
- name: An addition role
|
79
|
+
- name: Yet another additional role
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/doc/diagram.drawio
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<mxfile host="Electron" modified="2021-04-17T00:20:45.771Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.5.1 Chrome/89.0.4389.82 Electron/12.0.1 Safari/537.36" etag="J5Jf62OiXnZKbLMMq6aF" version="14.5.1" type="device"><diagram id="Lc7oDIB2kMrwpjbDrJJE" name="Page-1">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</diagram></mxfile>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
# This file illustrates that 0-1 relations can't automatically generate back-references
|
3
|
+
domains
|
4
|
+
- &this_domain
|
5
|
+
name: Domain
|
6
|
+
default_permission:
|
7
|
+
name: Default permissions
|
8
|
+
domain: *this_domain # This can't be assigned automatically
|
9
|
+
|
10
|
+
permissions
|
11
|
+
- &alices_permissions
|
12
|
+
name: Alice's permissions
|
13
|
+
domain:
|
14
|
+
name: Alice's domain
|
15
|
+
default_permission: *alices_permissions
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
\connect postgres
|
3
|
+
|
4
|
+
drop database if exists fox;
|
5
|
+
create database fox;
|
6
|
+
|
7
|
+
\connect fox
|
8
|
+
|
9
|
+
|
10
|
+
create table domains (
|
11
|
+
id integer generated by default as identity primary key,
|
12
|
+
name text not null
|
13
|
+
);
|
14
|
+
|
15
|
+
create table permissions (
|
16
|
+
id integer generated by default as identity primary key,
|
17
|
+
domain_id integer not null references domains(id),
|
18
|
+
name text not null
|
19
|
+
);
|
20
|
+
|
21
|
+
alter table domains add column
|
22
|
+
default_permission_id integer unique references permissions(id);
|
data/examples/N-M.fox
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
roles
|
3
|
+
- &sysadm_role
|
4
|
+
name: Sysadm
|
5
|
+
- &admin_role
|
6
|
+
name: Admin
|
7
|
+
|
8
|
+
posts
|
9
|
+
- &alices_first_post
|
10
|
+
title: "FIRST"
|
11
|
+
|
12
|
+
users
|
13
|
+
- name: Alice
|
14
|
+
roles:
|
15
|
+
- *sysadm_role
|
16
|
+
- &user_role
|
17
|
+
name: User
|
18
|
+
posts:
|
19
|
+
- *alices_first_post
|
20
|
+
- title: "SECOND"
|
21
|
+
- name: Bob
|
22
|
+
roles:
|
23
|
+
- *admin_role
|
24
|
+
- *user_role
|
25
|
+
|
data/examples/N-M.sql
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
\connect postgres
|
3
|
+
|
4
|
+
drop database if exists fox;
|
5
|
+
create database fox;
|
6
|
+
|
7
|
+
\connect fox
|
8
|
+
|
9
|
+
create table roles (
|
10
|
+
id integer generated by default as identity primary key,
|
11
|
+
name text not null
|
12
|
+
);
|
13
|
+
|
14
|
+
create index on roles(name);
|
15
|
+
|
16
|
+
create table users (
|
17
|
+
id integer generated by default as identity primary key,
|
18
|
+
name text not null unique
|
19
|
+
);
|
20
|
+
|
21
|
+
create table user_roles (
|
22
|
+
id integer generated by default as identity primary key,
|
23
|
+
role_id integer not null references roles(id),
|
24
|
+
user_id integer not null references users(id)
|
25
|
+
);
|
26
|
+
|
27
|
+
create unique index on user_roles(role_id, user_id);
|
28
|
+
|
29
|
+
create table posts (
|
30
|
+
id integer generated by default as identity primary key,
|
31
|
+
user_id integer not null references users(id),
|
32
|
+
title text not null
|
33
|
+
);
|
34
|
+
|
data/examples/array.fox
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
|
2
|
+
# this is a comment
|
3
|
+
|
4
|
+
# @schema "public"
|
5
|
+
# @include "file"
|
6
|
+
# @reserve table, table, table...
|
7
|
+
#
|
8
|
+
#@reflect users.last_post_id nil
|
9
|
+
|
10
|
+
alice: Users
|
11
|
+
name: "Alice"
|
12
|
+
age: 20
|
13
|
+
groups: [supers, users]
|
14
|
+
picture:
|
15
|
+
title: Picture of Alice
|
16
|
+
blob: "image"
|
17
|
+
role: &alices_role # this is a comment
|
18
|
+
name: "Administrator" # this is a comment
|
19
|
+
active: true # this is a comment
|
20
|
+
|
21
|
+
alice: Users
|
22
|
+
last_post: *alices_first_post
|
23
|
+
|
24
|
+
alices_blog: Blogs
|
25
|
+
user: *alice
|
26
|
+
title: "Alice's Blog"
|
27
|
+
|
28
|
+
Roles
|
29
|
+
- &user_role
|
30
|
+
name: "User"
|
31
|
+
active: true
|
32
|
+
- &anon_role
|
33
|
+
name: "Anon"
|
34
|
+
active: true
|
35
|
+
|
36
|
+
Posts
|
37
|
+
- &alices_first_post
|
38
|
+
blog: *alices_blog
|
39
|
+
head: My first blog post
|
40
|
+
body: This is the first post in my new blog
|
41
|
+
created_at: "1970-01-01"
|
42
|
+
|
43
|
+
bob: Users
|
44
|
+
name: "Bob"
|
45
|
+
role: *alices_role
|
46
|
+
last_post: *bobs_last_post
|
47
|
+
groups: ["42", "43"]
|
48
|
+
blogs:
|
49
|
+
- title: "Bob's Blog"
|
50
|
+
posts:
|
51
|
+
- &bobs_first_post
|
52
|
+
head: Bobs first blog post
|
53
|
+
body: Hi Alice!
|
54
|
+
created_at: "1970-01-01"
|
55
|
+
- &bobs_last_post
|
56
|
+
head: Happy birthday!
|
57
|
+
body: Cakeday!
|
58
|
+
created_at: "1970-01-02"
|
59
|
+
|
60
|
+
bill: Users
|
61
|
+
name: Bill
|
62
|
+
role: *user_role
|
63
|
+
groups: []
|
64
|
+
|
65
|
+
Comments
|
66
|
+
- author: *bill
|
67
|
+
post: *alices_first_post
|
68
|
+
head: Congratulations !
|
69
|
+
body: Good luck
|
70
|
+
created_at: "1970-01-01 00:00"
|
71
|
+
- author: &lizzy
|
72
|
+
name: Lizzy
|
73
|
+
role: *user_role
|
74
|
+
comments:
|
75
|
+
- post: *bobs_first_post
|
76
|
+
head: "Me too"
|
77
|
+
body: "Hugs from Lizzy"
|
78
|
+
created_at: "1970-01-03"
|
79
|
+
|
80
|
+
post: *alices_first_post
|
81
|
+
head: ""
|
82
|
+
body: Same from me
|
83
|
+
created_at: "1970-01-01 00:01"
|
84
|
+
|
data/examples/array.sql
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
\connect postgres
|
3
|
+
|
4
|
+
drop database if exists fox;
|
5
|
+
create database fox;
|
6
|
+
|
7
|
+
\connect fox
|
8
|
+
|
9
|
+
create unlogged table roles (
|
10
|
+
id integer generated by default as identity primary key,
|
11
|
+
name text not null,
|
12
|
+
active boolean not null default true
|
13
|
+
);
|
14
|
+
|
15
|
+
create unlogged table pictures (
|
16
|
+
id integer generated by default as identity primary key,
|
17
|
+
title text not null,
|
18
|
+
blob text not null
|
19
|
+
);
|
20
|
+
|
21
|
+
create unlogged table users (
|
22
|
+
id integer generated by default as identity primary key,
|
23
|
+
name text not null,
|
24
|
+
age integer,
|
25
|
+
groups varchar[],
|
26
|
+
role_id integer not null references roles(id),
|
27
|
+
picture_id integer unique references pictures(id)
|
28
|
+
);
|
29
|
+
|
30
|
+
create unlogged table blogs (
|
31
|
+
id integer generated by default as identity primary key,
|
32
|
+
user_id integer not null references users(id),
|
33
|
+
title text not null
|
34
|
+
);
|
35
|
+
|
36
|
+
create unlogged table posts (
|
37
|
+
id integer generated by default as identity primary key,
|
38
|
+
blog_id integer not null references blogs(id),
|
39
|
+
head text not null,
|
40
|
+
body text not null,
|
41
|
+
created_at timestamp without time zone default (now() at time zone 'UTC')
|
42
|
+
);
|
43
|
+
|
44
|
+
create unlogged table comments (
|
45
|
+
id integer generated by default as identity primary key,
|
46
|
+
post_id integer not null references posts(id),
|
47
|
+
author_id integer not null references users(id),
|
48
|
+
head text not null,
|
49
|
+
body text not null,
|
50
|
+
created_at timestamp without time zone default (now() at time zone 'UTC')
|
51
|
+
);
|
52
|
+
|
53
|
+
alter table users add column last_post_id integer references posts(id);
|
data/examples/base.fox
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
# this is a comment
|
3
|
+
|
4
|
+
# @schema "public"
|
5
|
+
# @include "file"
|
6
|
+
# @reserve table, table, table...
|
7
|
+
#
|
8
|
+
#@reflect users.last_post_id nil
|
9
|
+
|
10
|
+
alice: Users
|
11
|
+
name: "Alice"
|
12
|
+
age: 20
|
13
|
+
picture:
|
14
|
+
title: Picture of Alice
|
15
|
+
blob: "image"
|
16
|
+
role: &alices_role # this is a comment
|
17
|
+
name: "Administrator" # this is a comment
|
18
|
+
active: true # this is a comment
|
19
|
+
|
20
|
+
alice: Users
|
21
|
+
last_post: *alices_first_post
|
22
|
+
|
23
|
+
alices_blog: Blogs
|
24
|
+
user: *alice
|
25
|
+
title: "Alice's Blog"
|
26
|
+
|
27
|
+
Roles
|
28
|
+
- &user_role
|
29
|
+
name: "User"
|
30
|
+
active: true
|
31
|
+
- &anon_role
|
32
|
+
name: "Anon"
|
33
|
+
active: true
|
34
|
+
|
35
|
+
Posts
|
36
|
+
- &alices_first_post
|
37
|
+
blog: *alices_blog
|
38
|
+
head: My first blog post
|
39
|
+
body: This is the first post in my new blog
|
40
|
+
created_at: "1970-01-01"
|
41
|
+
|
42
|
+
bob: Users
|
43
|
+
name: "Bob"
|
44
|
+
role: *alices_role
|
45
|
+
last_post: *bobs_last_post
|
46
|
+
blogs:
|
47
|
+
- title: "Bob's Blog"
|
48
|
+
posts:
|
49
|
+
- &bobs_first_post
|
50
|
+
head: Bobs first blog post
|
51
|
+
body: Hi Alice!
|
52
|
+
created_at: "1970-01-01"
|
53
|
+
- &bobs_last_post
|
54
|
+
head: Happy birthday!
|
55
|
+
body: Cakeday!
|
56
|
+
created_at: "1970-01-02"
|
57
|
+
|
58
|
+
bill: Users
|
59
|
+
name: Bill
|
60
|
+
role: *user_role
|
61
|
+
|
62
|
+
Comments
|
63
|
+
- author: *bill
|
64
|
+
post: *alices_first_post
|
65
|
+
head: Congratulations !
|
66
|
+
body: Good luck
|
67
|
+
created_at: "1970-01-01 00:00"
|
68
|
+
- author: &lizzy
|
69
|
+
name: Lizzy
|
70
|
+
role: *user_role
|
71
|
+
comments:
|
72
|
+
- post: *bobs_first_post
|
73
|
+
head: "Me too"
|
74
|
+
body: "Hugs from Lizzy"
|
75
|
+
created_at: "1970-01-03"
|
76
|
+
|
77
|
+
post: *alices_first_post
|
78
|
+
head: ""
|
79
|
+
body: Same from me
|
80
|
+
created_at: "1970-01-01 00:01"
|
81
|
+
|
data/examples/base.sql
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
\connect postgres
|
3
|
+
|
4
|
+
drop database if exists fox;
|
5
|
+
create database fox;
|
6
|
+
|
7
|
+
\connect fox
|
8
|
+
|
9
|
+
create unlogged table roles (
|
10
|
+
id integer generated by default as identity primary key,
|
11
|
+
name text not null,
|
12
|
+
active boolean not null default true
|
13
|
+
);
|
14
|
+
|
15
|
+
create unlogged table pictures (
|
16
|
+
id integer generated by default as identity primary key,
|
17
|
+
title text not null,
|
18
|
+
blob text not null
|
19
|
+
);
|
20
|
+
|
21
|
+
create unlogged table users (
|
22
|
+
id integer generated by default as identity primary key,
|
23
|
+
name text not null,
|
24
|
+
age integer,
|
25
|
+
role_id integer not null references roles(id),
|
26
|
+
picture_id integer unique references pictures(id)
|
27
|
+
);
|
28
|
+
|
29
|
+
create unlogged table blogs (
|
30
|
+
id integer generated by default as identity primary key,
|
31
|
+
user_id integer not null references users(id),
|
32
|
+
title text not null
|
33
|
+
);
|
34
|
+
|
35
|
+
create unlogged table posts (
|
36
|
+
id integer generated by default as identity primary key,
|
37
|
+
blog_id integer not null references blogs(id),
|
38
|
+
head text not null,
|
39
|
+
body text not null,
|
40
|
+
created_at timestamp without time zone default (now() at time zone 'UTC')
|
41
|
+
);
|
42
|
+
|
43
|
+
create unlogged table comments (
|
44
|
+
id integer generated by default as identity primary key,
|
45
|
+
post_id integer not null references posts(id),
|
46
|
+
author_id integer not null references users(id),
|
47
|
+
head text not null,
|
48
|
+
body text not null,
|
49
|
+
created_at timestamp without time zone default (now() at time zone 'UTC')
|
50
|
+
);
|
51
|
+
|
52
|
+
alter table users add column last_post_id integer references posts(id);
|
data/examples/empty.fox
ADDED
data/examples/empty.sql
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
\connect postgres
|
3
|
+
|
4
|
+
drop database if exists fox;
|
5
|
+
create database fox;
|
6
|
+
|
7
|
+
\connect fox
|
8
|
+
|
9
|
+
create schema user_schema;
|
10
|
+
create schema role_schema;
|
11
|
+
|
12
|
+
create table role_schema.roles (
|
13
|
+
id integer generated by default as identity primary key,
|
14
|
+
name text not null
|
15
|
+
);
|
16
|
+
|
17
|
+
create table user_schema.users (
|
18
|
+
id integer generated by default as identity primary key,
|
19
|
+
name text not null
|
20
|
+
);
|
21
|
+
|
22
|
+
create table public.user_roles (
|
23
|
+
id integer generated by default as identity primary key,
|
24
|
+
role_id integer not null references role_schema.roles(id),
|
25
|
+
user_id integer not null references user_schema.users(id)
|
26
|
+
);
|
27
|
+
|
28
|
+
create table public.posts (
|
29
|
+
id integer generated by default as identity primary key,
|
30
|
+
user_id integer not null references user_schema.users(id),
|
31
|
+
title text not null
|
32
|
+
);
|
33
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
posts
|
3
|
+
- &alices_first_post
|
4
|
+
title: "FIRST"
|
5
|
+
|
6
|
+
@schema user_schema
|
7
|
+
|
8
|
+
users
|
9
|
+
- &alice
|
10
|
+
name: Alice
|
11
|
+
roles:
|
12
|
+
- *sysadm_role
|
13
|
+
- &user_role
|
14
|
+
name: User
|
15
|
+
posts:
|
16
|
+
- *alices_first_post
|
17
|
+
- title: "SECOND"
|
18
|
+
- &bob
|
19
|
+
name: Bob
|
20
|
+
roles:
|
21
|
+
- *admin_role
|
22
|
+
- *user_role
|
23
|
+
|