Module: Parse::Schema
- Defined in:
- lib/parse/schema.rb,
lib/parse/schema/index_migrator.rb,
lib/parse/schema/search_index_migrator.rb
Overview
Schema introspection and migration tools for Parse Server. Provides utilities to compare local Ruby models with server schema, generate migration scripts, and manage schema changes.
Defined Under Namespace
Classes: IndexMigrator, Migration, SchemaDiff, SchemaInfo, SearchIndexMigrator
Constant Summary collapse
- TYPE_MAP =
Parse field type mappings to Ruby types
{ "String" => :string, "Number" => :integer, "Boolean" => :boolean, "Date" => :date, "File" => :file, "GeoPoint" => :geopoint, "Polygon" => :polygon, "Array" => :array, "Object" => :object, "Pointer" => :pointer, "Relation" => :relation, "Bytes" => :bytes, }.freeze
- REVERSE_TYPE_MAP =
Reverse mapping from Ruby types to Parse types
{ string: "String", integer: "Number", float: "Number", boolean: "Boolean", date: "Date", file: "File", geopoint: "GeoPoint", geo_point: "GeoPoint", polygon: "Polygon", array: "Array", object: "Object", pointer: "Pointer", relation: "Relation", bytes: "Bytes", acl: "ACL", }.freeze
Class Attribute Summary collapse
-
.default_class_level_permissions ⇒ Object
Returns the value of attribute default_class_level_permissions.
Class Method Summary collapse
-
.all(client: nil) ⇒ Array<SchemaInfo>
Fetch all schemas from the Parse Server.
-
.class_names(client: nil) ⇒ Array<String>
Get all class names from the server.
-
.diff(model_class, client: nil) ⇒ SchemaDiff
Compare a local Parse::Object model with its server schema.
-
.exists?(class_name, client: nil) ⇒ Boolean
Check if a class exists on the server.
-
.fetch(class_name, client: nil) ⇒ SchemaInfo?
Fetch schema for a specific class.
-
.migration(model_class, client: nil) ⇒ Migration
Generate a migration for a model class.
Class Attribute Details
.default_class_level_permissions ⇒ Object
Returns the value of attribute default_class_level_permissions.
50 51 52 |
# File 'lib/parse/schema.rb', line 50 def @default_class_level_permissions end |
Class Method Details
.all(client: nil) ⇒ Array<SchemaInfo>
Fetch all schemas from the Parse Server.
92 93 94 95 96 97 98 99 |
# File 'lib/parse/schema.rb', line 92 def all(client: nil) client ||= Parse.client response = client.schemas return [] unless response.success? results = response.result.is_a?(Hash) ? response.result["results"] : response.result (results || []).map { |data| SchemaInfo.new(data) } end |
.class_names(client: nil) ⇒ Array<String>
Get all class names from the server.
144 145 146 |
# File 'lib/parse/schema.rb', line 144 def class_names(client: nil) all(client: client).map(&:class_name) end |
.diff(model_class, client: nil) ⇒ SchemaDiff
Compare a local Parse::Object model with its server schema.
117 118 119 120 121 122 |
# File 'lib/parse/schema.rb', line 117 def diff(model_class, client: nil) raise ArgumentError, "Expected a Parse::Object subclass" unless model_class < Parse::Object server_schema = fetch(model_class.parse_class, client: client) SchemaDiff.new(model_class, server_schema) end |
.exists?(class_name, client: nil) ⇒ Boolean
Check if a class exists on the server.
137 138 139 |
# File 'lib/parse/schema.rb', line 137 def exists?(class_name, client: nil) !fetch(class_name, client: client).nil? end |
.fetch(class_name, client: nil) ⇒ SchemaInfo?
Fetch schema for a specific class.
105 106 107 108 109 110 111 |
# File 'lib/parse/schema.rb', line 105 def fetch(class_name, client: nil) class_name = class_name.parse_class if class_name.respond_to?(:parse_class) client ||= Parse.client response = client.schema(class_name) return nil unless response.success? SchemaInfo.new(response.result) end |