Add foreign key info, column comment support
This commit is contained in:
parent
ddf88fc994
commit
ea1d38da57
|
@ -1,6 +1,5 @@
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: ['fa', 'fa-info', 'enum-info'],
|
tagName: 'ol',
|
||||||
tagName: 'i',
|
|
||||||
|
|
||||||
enuminfo: function() {
|
enuminfo: function() {
|
||||||
const hash = this.get('col.enum');
|
const hash = this.get('col.enum');
|
||||||
|
|
|
@ -29,15 +29,24 @@ export default Ember.Component.extend({
|
||||||
notes = "default " + col.column_default;
|
notes = "default " + col.column_default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (notes) {
|
if (col.fkey_info) {
|
||||||
col.notes = notes;
|
if (notes) {
|
||||||
col.havetypeinfo = true;
|
notes += ", fkey " + col.fkey_info;
|
||||||
|
} else {
|
||||||
|
notes = "fkey " + col.fkey_info;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col.enum) {
|
if (notes) {
|
||||||
col.havetypeinfo = true;
|
col.notes = notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (col.enum || col.column_desc) {
|
||||||
|
col.havepopup = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
col.havetypeinfo = !!(col.notes || col.enum || col.column_desc);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
<ol>
|
{{#each enuminfo as |enum|}}
|
||||||
{{#each enuminfo as |enum|}}
|
<li value="{{enum.value}}">
|
||||||
<li value="{{enum.value}}">
|
{{enum.name}}
|
||||||
{{enum.name}}
|
</li>
|
||||||
</li>
|
{{/each}}
|
||||||
{{/each}}
|
|
||||||
</ol>
|
|
||||||
|
|
|
@ -21,11 +21,18 @@
|
||||||
{{col.data_type}}
|
{{col.data_type}}
|
||||||
{{#if col.havetypeinfo}}
|
{{#if col.havetypeinfo}}
|
||||||
<br>
|
<br>
|
||||||
|
{{#if col.havepopup}}
|
||||||
|
<i class="fa fa-info popup-info">
|
||||||
|
<div class="popup">
|
||||||
|
{{col.column_desc}}
|
||||||
|
{{#if col.enum}}
|
||||||
|
{{explorer-schema-enuminfo col=col}}
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
</i>
|
||||||
|
{{/if}}
|
||||||
<span class="schema-typenotes">
|
<span class="schema-typenotes">
|
||||||
{{col.notes}}
|
{{col.notes}}
|
||||||
{{#if col.enum}}
|
|
||||||
{{explorer-schema-enuminfo col=col}}
|
|
||||||
{{/if}}
|
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
dd {
|
dd {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: text-top;
|
vertical-align: text-top;
|
||||||
width: 70px;
|
width: 90px;
|
||||||
color: $tertiary;
|
color: $tertiary;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding-left: 7px;
|
padding-left: 7px;
|
||||||
|
@ -101,28 +101,31 @@
|
||||||
.schema-typenotes {
|
.schema-typenotes {
|
||||||
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
}
|
||||||
|
.popup-info {
|
||||||
|
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
||||||
|
|
||||||
ol { display: none; }
|
.popup { display: none; }
|
||||||
&:hover ol { display: block; }
|
&:hover .popup { display: block; }
|
||||||
&:focus ol { display: block; }
|
&:focus .popup { display: block; }
|
||||||
.enum-info {
|
|
||||||
|
|
||||||
ol {
|
.popup {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
padding-right: calc(5px + 2em);
|
padding-right: calc(5px + 2em);
|
||||||
border: 1px solid;
|
border: 1px solid;
|
||||||
background: white;
|
background: white;
|
||||||
list-style: none;
|
left: -120px;
|
||||||
left: -12em;
|
width: 180px;
|
||||||
top: 6px;
|
top: 6px;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
> li {
|
}
|
||||||
width: 150%;
|
|
||||||
}
|
.popup ol {
|
||||||
> li:before {
|
margin: 0;
|
||||||
content: attr(value) ": ";
|
list-style: none;
|
||||||
}
|
> li:before {
|
||||||
|
content: attr(value) ": ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
100
plugin.rb
100
plugin.rb
|
@ -177,9 +177,10 @@ select
|
||||||
c.table_name table_name,
|
c.table_name table_name,
|
||||||
pgd.description column_desc
|
pgd.description column_desc
|
||||||
from INFORMATION_SCHEMA.COLUMNS c
|
from INFORMATION_SCHEMA.COLUMNS c
|
||||||
inner join pg_catalog.pg_statio_all_tables st on (c.table_schema=st.schemaname and c.table_name=st.relname)
|
inner join pg_catalog.pg_statio_all_tables st on (c.table_schema = st.schemaname and c.table_name = st.relname)
|
||||||
left outer join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
|
left outer join pg_catalog.pg_description pgd on (pgd.objoid = st.relid and pgd.objsubid = c.ordinal_position)
|
||||||
where c.table_schema = 'public'
|
where c.table_schema = 'public'
|
||||||
|
ORDER BY c.table_name, c.ordinal_position
|
||||||
SQL
|
SQL
|
||||||
by_table = {}
|
by_table = {}
|
||||||
# Massage the results into a nicer form
|
# Massage the results into a nicer form
|
||||||
|
@ -214,10 +215,14 @@ SQL
|
||||||
if enum_info.include? full_col_name
|
if enum_info.include? full_col_name
|
||||||
hash['enum'] = enum_info[full_col_name]
|
hash['enum'] = enum_info[full_col_name]
|
||||||
end
|
end
|
||||||
|
fkey = fkey_info(hash['table_name'], hash['column_name'])
|
||||||
|
if fkey
|
||||||
|
hash['fkey_info'] = fkey
|
||||||
|
end
|
||||||
|
|
||||||
tname = hash.delete('table_name')
|
table_name = hash.delete('table_name')
|
||||||
by_table[tname] ||= []
|
by_table[table_name] ||= []
|
||||||
by_table[tname] << hash
|
by_table[table_name] << hash
|
||||||
end
|
end
|
||||||
|
|
||||||
# this works for now, but no big loss if the tables aren't quite sorted
|
# this works for now, but no big loss if the tables aren't quite sorted
|
||||||
|
@ -234,9 +239,9 @@ SQL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.enums
|
def self.enums
|
||||||
@enums ||= {
|
@enums ||= {
|
||||||
|
:'badges.badge_type_id' => BadgeType.all_types,
|
||||||
:'category_groups.permission_type' => CategoryGroup.permission_types,
|
:'category_groups.permission_type' => CategoryGroup.permission_types,
|
||||||
:'directory_items.period_type' => DirectoryItem.period_types,
|
:'directory_items.period_type' => DirectoryItem.period_types,
|
||||||
:'groups.alias_level' => Group::ALIAS_LEVELS,
|
:'groups.alias_level' => Group::ALIAS_LEVELS,
|
||||||
|
@ -266,6 +271,83 @@ SQL
|
||||||
enum_info
|
enum_info
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.fkey_info(table, column)
|
||||||
|
full_name = "#{table}.#{column}"
|
||||||
|
|
||||||
|
if fkey_defaults[column]
|
||||||
|
fkey_defaults[column]
|
||||||
|
elsif column =~ /_by_id$/ || column =~ /_user_id$/
|
||||||
|
:users
|
||||||
|
elsif foreign_keys[full_name]
|
||||||
|
foreign_keys[full_name]
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.foreign_keys
|
||||||
|
@fkey_columns ||= {
|
||||||
|
:'posts.last_editor_id' => :users,
|
||||||
|
|
||||||
|
:'topics.featured_user1_id' => :users,
|
||||||
|
:'topics.featured_user2_id' => :users,
|
||||||
|
:'topics.featured_user3_id' => :users,
|
||||||
|
:'topics.featured_user4_id' => :users,
|
||||||
|
:'topics.featured_user5_id' => :users,
|
||||||
|
|
||||||
|
:'users.seen_notification_id' => :notifications,
|
||||||
|
:'users.uploaded_avatar_id' => :uploads,
|
||||||
|
:'users.primary_group_id' => :groups,
|
||||||
|
|
||||||
|
:'categories.latest_post_id' => :posts,
|
||||||
|
:'categories.latest_topic_id' => :topics,
|
||||||
|
:'categories.parent_category_id' => :categories,
|
||||||
|
|
||||||
|
:'badges.badge_grouping_id' => :badge_groupings,
|
||||||
|
|
||||||
|
:'post_actions.related_post_id' => :posts,
|
||||||
|
|
||||||
|
:'color_scheme_colors.color_scheme_id' => :color_schemes,
|
||||||
|
|
||||||
|
:'incoming_links.incoming_referer_id' => :incoming_referers,
|
||||||
|
:'incoming_referers.incoming_domain_id' => :incoming_domains,
|
||||||
|
|
||||||
|
:'post_replies.reply_id' => :posts,
|
||||||
|
|
||||||
|
:'quoted_posts.quoted_post_id' => :posts,
|
||||||
|
|
||||||
|
:'topic_link_clicks.topic_link_id' => :topic_links,
|
||||||
|
:'topic_link_clicks.link_topic_id' => :topics,
|
||||||
|
:'topic_link_clicks.link_post_id' => :posts,
|
||||||
|
|
||||||
|
:'user_actions.target_topic_id' => :topics,
|
||||||
|
:'user_actions.target_post_id' => :posts,
|
||||||
|
|
||||||
|
:'user_avatars.custom_upload_id' => :uploads,
|
||||||
|
:'user_avatars.gravatar_upload_id' => :uploads,
|
||||||
|
|
||||||
|
:'user_badges.notification_id' => :notifications,
|
||||||
|
|
||||||
|
:'user_profiles.card_image_badge_id' => :badges,
|
||||||
|
}.with_indifferent_access
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.fkey_defaults
|
||||||
|
@fkey_defaults ||= {
|
||||||
|
:user_id => :users,
|
||||||
|
# :*_by_id => :users,
|
||||||
|
# :*_user_id => :users,
|
||||||
|
|
||||||
|
:category_id => :categories,
|
||||||
|
:group_id => :groups,
|
||||||
|
:post_id => :posts,
|
||||||
|
:post_action_id => :post_actions,
|
||||||
|
:topic_id => :topics,
|
||||||
|
:upload_id => :uploads,
|
||||||
|
|
||||||
|
}.with_indifferent_access
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead
|
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead
|
||||||
|
@ -784,3 +866,9 @@ SQL
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# polyfill
|
||||||
|
class ::BadgeType
|
||||||
|
def self.all_types
|
||||||
|
@all_types ||= Enum.new(:gold, :silver, :bronze, start: 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue