Giter Club home page Giter Club logo

Comments (10)

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

There is no official offline/local-first data handling for now.

PocketBase v0.9+ supports writing external migrations with JS (more documentation on that will be available soon).
It also comes with automigrate functionality, aka. when doing collection changes in the UI or via the web APIs it will automatically generate a js/go migration file inside pb_migrations that you can commit to your repo. Migrations are executed automatically on server start (aka. ./pocketbase serve).

I'm not sure that I understand your use case, but you can use the pb.collections.* apis (you'll have to be authenticated as admin in order to be able to modify the collections) since they will trigger the automigrate functionality.

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

Can you show us an example of adding a new column to a collection or
removing a column from a collection

Here is an example using the Dart SDK (I haven't tested it, but it should give you an idea of the expected workflow):

final pb = PocketBase("http://127.0.0.1:8090");

final collection = await pb.collections.getOne("uktsrgciaq83ltm"); // id or name

// add a new collection field...
collection.schema.add(SchemaField(
  id: "someRandomFieldId", // optional (it will be auto generated if missing)
  name: "myNewField",
  type: "text",
  required: true,
  // options differ depending on the field type
  // all field types and their options could be found in
  // https://pkg.go.dev/github.com/pocketbase/[email protected]/models/schema
  // (the `json` value is the body key, for example the date options are https://pkg.go.dev/github.com/pocketbase/[email protected]/models/schema#DateOptions)
  options: <String, dynamic>{
    "min": 10,
  },
));

// remove a field (aka. remove an element from the List)
collection.schema.removeAt(2);

// rename a field (aka. edit an existing List element)
collection.schema[1].unique = false;

// persist changes
await pb.collections.update(collection.id, body: collection.toJson());

About auto migration. Can you please show us an example of how updating or adding of a column work there.
How we can put migrating files in our repo and start a new project with the
same tables

The automigrations are automanaged, aka. when doing collection changes from the Admin UI or via the web API (as in the previous SDK example), it will automatically generate a js migration file for you in the pb_migrations folder. You can copy this folder to another location and place it next to your pb_data (or if you want to specify a different location, you can also use the --migrationsDir="/path/to/pb_migrations" flag when starting PocketBase; more info you can find with the --help flag).


When we ship a new version of our application adding columns or renaming
column shall be done automatically

I'm not sure what to recommend. As mentioned, for now offline/local-first data handling is not supported out of the box and this require some manual management from the developer side. I don't think there is a single generic solution for this since it really depends on your use case and the desired deployment flow, eg. how you are connecting to the remote server, how you are planning to propagate and sync changes, how you are planning to handle schema conflicts (eg. the user locally created a column with the same name but different id as your new remote update), etc.

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

Sorry, currently only Go and JS (via goja, an embedded go js runtime) migrations are supported and there are no plans for adding support for Dart since it will be too difficult and time consuming to maintain, document and test.

from dart-sdk.

iampopal avatar iampopal commented on June 18, 2024

And about sync: are there any plan to add offline first then sync to server feature?

from dart-sdk.

ganigeorgiev avatar ganigeorgiev commented on June 18, 2024

Offline/local-first data handling is in my todo to research it but for now is a very low priority and it is not planned for the near future.

from dart-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.